feat(ios): customize white balance
added possibility to customize white balance settings (temperature, tint, rgb gains offset)
This commit is contained in:
parent
4c54bd5f2f
commit
8c2100dd63
@ -35,6 +35,7 @@
|
||||
@property(copy, nonatomic) NSDictionary *autoFocusPointOfInterest;
|
||||
@property(assign, nonatomic) float focusDepth;
|
||||
@property(assign, nonatomic) NSInteger whiteBalance;
|
||||
@property(copy, nonatomic) NSDictionary *customWhiteBalance;
|
||||
@property(assign, nonatomic) float exposure;
|
||||
@property(assign, nonatomic) float exposureIsoMin;
|
||||
@property(assign, nonatomic) float exposureIsoMax;
|
||||
|
||||
@ -616,11 +616,30 @@ BOOL _sessionInterrupted = NO;
|
||||
[device setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
|
||||
[device unlockForConfiguration];
|
||||
} else {
|
||||
AVCaptureWhiteBalanceTemperatureAndTintValues temperatureAndTint = {
|
||||
.temperature = [RNCameraUtils temperatureForWhiteBalance:self.whiteBalance],
|
||||
.tint = 0,
|
||||
};
|
||||
AVCaptureWhiteBalanceGains rgbGains = [device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint];
|
||||
AVCaptureWhiteBalanceGains rgbGains;
|
||||
if (self.whiteBalance == RNCameraWhiteBalanceCustom
|
||||
&& [self.customWhiteBalance objectForKey:@"temperature"]
|
||||
&& [self.customWhiteBalance objectForKey:@"tint"]) {
|
||||
|
||||
float temperature = [self.customWhiteBalance[@"temperature"] floatValue];
|
||||
float tint = [self.customWhiteBalance[@"tint"] floatValue];
|
||||
|
||||
AVCaptureWhiteBalanceTemperatureAndTintValues temperatureAndTint = {
|
||||
.temperature = temperature,
|
||||
.tint = tint,
|
||||
};
|
||||
rgbGains = [device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint];
|
||||
rgbGains.redGain += [self.customWhiteBalance[@"redGainOffset"] floatValue];
|
||||
rgbGains.greenGain += [self.customWhiteBalance[@"greenGainOffset"] floatValue];
|
||||
rgbGains.blueGain += [self.customWhiteBalance[@"blueGainOffset"] floatValue];
|
||||
} else {
|
||||
AVCaptureWhiteBalanceTemperatureAndTintValues temperatureAndTint = {
|
||||
.temperature = [RNCameraUtils temperatureForWhiteBalance:self.whiteBalance],
|
||||
.tint = 0,
|
||||
};
|
||||
rgbGains = [device deviceWhiteBalanceGainsForTemperatureAndTintValues:temperatureAndTint];
|
||||
}
|
||||
|
||||
__weak __typeof__(device) weakDevice = device;
|
||||
if ([device lockForConfiguration:&error]) {
|
||||
@try{
|
||||
|
||||
@ -32,6 +32,7 @@ typedef NS_ENUM(NSInteger, RNCameraAutoFocus) {
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RNCameraWhiteBalance) {
|
||||
RNCameraWhiteBalanceCustom = -1,
|
||||
RNCameraWhiteBalanceAuto = 0,
|
||||
RNCameraWhiteBalanceSunny = 1,
|
||||
RNCameraWhiteBalanceCloudy = 2,
|
||||
|
||||
@ -51,6 +51,7 @@ RCT_EXPORT_VIEW_PROPERTY(videoStabilizationMode, NSInteger);
|
||||
@"AutoFocus" :
|
||||
@{@"on" : @(RNCameraAutoFocusOn), @"off" : @(RNCameraAutoFocusOff)},
|
||||
@"WhiteBalance" : @{
|
||||
@"custom" : @(RNCameraWhiteBalanceCustom),
|
||||
@"auto" : @(RNCameraWhiteBalanceAuto),
|
||||
@"sunny" : @(RNCameraWhiteBalanceSunny),
|
||||
@"cloudy" : @(RNCameraWhiteBalanceCloudy),
|
||||
@ -233,6 +234,13 @@ RCT_CUSTOM_VIEW_PROPERTY(whiteBalance, NSInteger, RNCamera)
|
||||
[view updateWhiteBalance];
|
||||
}
|
||||
|
||||
RCT_CUSTOM_VIEW_PROPERTY(customWhiteBalance, NSDictionary *, RNCamera)
|
||||
{
|
||||
[view setWhiteBalance:RNCameraWhiteBalanceCustom];
|
||||
[view setCustomWhiteBalance:[RCTConvert NSDictionary:json]];
|
||||
[view updateWhiteBalance];
|
||||
}
|
||||
|
||||
RCT_CUSTOM_VIEW_PROPERTY(exposure, NSNumber, RNCamera)
|
||||
{
|
||||
[view setExposure:[RCTConvert float:json]];
|
||||
|
||||
@ -270,6 +270,7 @@ type PropsType = typeof View.props & {
|
||||
googleVisionBarcodeType?: number,
|
||||
googleVisionBarcodeMode?: number,
|
||||
whiteBalance?: number | string,
|
||||
customWhiteBalance?: {temperature: number, tint: number, redGainOffset?: number, greenGainOffset?: number, blueGainOffset?: number },
|
||||
faceDetectionLandmarks?: number,
|
||||
autoFocus?: string | boolean | number,
|
||||
autoFocusPointOfInterest?: { x: number, y: number },
|
||||
@ -418,6 +419,10 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
flashMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
exposure: PropTypes.number,
|
||||
whiteBalance: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
customWhiteBalance: PropTypes.shape({temperature: PropTypes.number, tint: PropTypes.number,
|
||||
redGainOffset: PropTypes.number,
|
||||
greenGainOffset: PropTypes.number,
|
||||
blueGainOffset: PropTypes.number }),
|
||||
autoFocus: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
||||
autoFocusPointOfInterest: PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }),
|
||||
permissionDialogTitle: PropTypes.string,
|
||||
@ -448,6 +453,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
|
||||
flashMode: CameraManager.FlashMode.off,
|
||||
exposure: -1,
|
||||
whiteBalance: CameraManager.WhiteBalance.auto,
|
||||
customWhiteBalance: null,
|
||||
faceDetectionMode: (CameraManager.FaceDetection || {}).fast,
|
||||
barCodeTypes: Object.values(CameraManager.BarCodeType),
|
||||
googleVisionBarcodeType: ((CameraManager.GoogleVisionBarcodeDetection || {}).BarcodeType || {})
|
||||
|
||||
3
types/index.d.ts
vendored
3
types/index.d.ts
vendored
@ -32,6 +32,7 @@ type WhiteBalance = Readonly<{
|
||||
incandescent: any;
|
||||
fluorescent: any;
|
||||
auto: any;
|
||||
custom: any;
|
||||
}>;
|
||||
type BarCodeType = Readonly<{
|
||||
aztec: any;
|
||||
@ -147,6 +148,8 @@ export interface RNCameraProps {
|
||||
useCamera2Api?: boolean;
|
||||
exposure?: number;
|
||||
whiteBalance?: keyof WhiteBalance;
|
||||
customWhiteBalance?: {temperature: number; tint: number; redGainOffset?: number; greenGainOffset?: number; blueGainOffset?: number };
|
||||
|
||||
captureAudio?: boolean;
|
||||
|
||||
onCameraReady?(): void;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user