Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f52e9fd

Browse files
committedJun 12, 2021
fix: Correctly catch unsupported colorSpace errors
1 parent 0aab414 commit f52e9fd

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
 

‎ios/CameraError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ enum FormatError {
112112
case invalidFps(fps: Int)
113113
case invalidHdr
114114
case invalidFormat
115+
case invalidColorSpace(colorSpace: String)
115116
case invalidPreset(preset: String)
116117

117118
var code: String {
@@ -124,6 +125,8 @@ enum FormatError {
124125
return "invalid-hdr"
125126
case .invalidPreset:
126127
return "invalid-preset"
128+
case .invalidColorSpace:
129+
return "invalid-color-space"
127130
}
128131
}
129132

@@ -135,6 +138,8 @@ enum FormatError {
135138
return "The given FPS were not valid for the currently selected format. Make sure you select a format which `frameRateRanges` includes \(fps) FPS!"
136139
case .invalidHdr:
137140
return "The currently selected format does not support HDR capture! Make sure you select a format which `frameRateRanges` includes `supportsPhotoHDR`!"
141+
case let .invalidColorSpace(colorSpace):
142+
return "The currently selected format does not support the colorSpace \"\(colorSpace)\"! Make sure you select a format which `colorSpaces` includes \"\(colorSpace)\"!"
138143
case let .invalidPreset(preset):
139144
return "The preset \"\(preset)\" is not available for the current camera device."
140145
}

‎ios/CameraView+AVCaptureSession.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ extension CameraView {
186186
device.automaticallyEnablesLowLightBoostWhenAvailable = lowLightBoost!.boolValue
187187
}
188188
}
189-
if colorSpace != nil, let avColorSpace = try? AVCaptureColorSpace(string: String(colorSpace!)) {
189+
if let colorSpace = self.colorSpace as String? {
190+
guard let avColorSpace = try? AVCaptureColorSpace(string: colorSpace),
191+
device.activeFormat.supportedColorSpaces.contains(avColorSpace) else {
192+
invokeOnError(.format(.invalidColorSpace(colorSpace: colorSpace)))
193+
return
194+
}
190195
device.activeColorSpace = avColorSpace
191196
}
192197

‎src/CameraError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type FormatError =
1919
| 'format/invalid-hdr'
2020
| 'format/invalid-low-light-boost'
2121
| 'format/invalid-format'
22+
| 'format/invalid-color-space'
2223
| 'format/invalid-preset';
2324
export type SessionError =
2425
| 'session/camera-not-ready'

0 commit comments

Comments
 (0)
Please sign in to comment.