Example usage for android.hardware.camera2 CaptureResult SENSOR_NEUTRAL_COLOR_POINT

List of usage examples for android.hardware.camera2 CaptureResult SENSOR_NEUTRAL_COLOR_POINT

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureResult SENSOR_NEUTRAL_COLOR_POINT.

Prototype

Key SENSOR_NEUTRAL_COLOR_POINT

To view the source code for android.hardware.camera2 CaptureResult SENSOR_NEUTRAL_COLOR_POINT.

Click Source Link

Document

The estimated camera neutral color in the native sensor colorspace at the time of capture.

This value gives the neutral color point encoded as an RGB value in the native sensor color space.

Usage

From source file:freed.cam.apis.camera2.modules.PictureModuleApi2.java

@NonNull
private DngProfile getDngProfile(int rawFormat, ImageHolder image) {
    int black = cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_BLACK_LEVEL_PATTERN)
            .getOffsetForIndex(0, 0);/*from  w ww .ja v  a  2s. c o m*/
    int c = cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT);
    String colorpattern;
    int[] cfaOut = new int[4];
    switch (c) {
    case 1:
        colorpattern = DngProfile.GRBG;
        cfaOut[0] = 1;
        cfaOut[1] = 0;
        cfaOut[2] = 2;
        cfaOut[3] = 1;
        break;
    case 2:
        colorpattern = DngProfile.GBRG;
        cfaOut[0] = 1;
        cfaOut[1] = 2;
        cfaOut[2] = 0;
        cfaOut[3] = 1;
        break;
    case 3:
        colorpattern = DngProfile.BGGR;
        cfaOut[0] = 2;
        cfaOut[1] = 1;
        cfaOut[2] = 1;
        cfaOut[3] = 0;
        break;
    default:
        colorpattern = DngProfile.RGGB;
        cfaOut[0] = 0;
        cfaOut[1] = 1;
        cfaOut[2] = 1;
        cfaOut[3] = 2;
        break;
    }
    float[] color2;
    float[] color1;
    float[] neutral = new float[3];
    float[] forward2 = null;
    float[] forward1 = null;
    float[] reduction1 = null;
    float[] reduction2 = null;
    double[] finalnoise = null;
    String cmat = appSettingsManager.getApiString(AppSettingsManager.CUSTOMMATRIX);
    if (cmat != null && !cmat.equals("") && !cmat.equals("off")) {
        CustomMatrix mat = ((MatrixChooserParameter) parameterHandler.matrixChooser).GetCustomMatrix(cmat);
        color1 = mat.ColorMatrix1;
        color2 = mat.ColorMatrix2;
        neutral = mat.NeutralMatrix;
        if (mat.ForwardMatrix1.length > 0)
            forward1 = mat.ForwardMatrix1;
        if (mat.ForwardMatrix2.length > 0)
            forward2 = mat.ForwardMatrix2;
        if (mat.ReductionMatrix1.length > 0)
            reduction1 = mat.ReductionMatrix1;
        if (mat.ReductionMatrix2.length > 0)
            reduction2 = mat.ReductionMatrix2;
        if (mat.NoiseReductionMatrix.length > 0)
            finalnoise = mat.NoiseReductionMatrix;
    } else {
        color1 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_COLOR_TRANSFORM1));
        color2 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_COLOR_TRANSFORM2));
        Rational[] n = image.getCaptureResult().get(CaptureResult.SENSOR_NEUTRAL_COLOR_POINT);
        neutral[0] = n[0].floatValue();
        neutral[1] = n[1].floatValue();
        neutral[2] = n[2].floatValue();
        forward2 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_FORWARD_MATRIX2));
        //0.820300f, -0.218800f, 0.359400f, 0.343800f, 0.570300f,0.093800f, 0.015600f, -0.726600f, 1.539100f
        forward1 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_FORWARD_MATRIX1));
        reduction1 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_CALIBRATION_TRANSFORM1));
        reduction2 = getFloatMatrix(
                cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_CALIBRATION_TRANSFORM2));
        //noise
        Pair[] p = image.getCaptureResult().get(CaptureResult.SENSOR_NOISE_PROFILE);
        double[] noiseys = new double[p.length * 2];
        int i = 0;
        for (int h = 0; h < p.length; h++) {
            noiseys[i++] = (double) p[h].first;
            noiseys[i++] = (double) p[h].second;
        }
        double[] noise = new double[6];
        int[] cfaPlaneColor = { 0, 1, 2 };
        generateNoiseProfile(noiseys, cfaOut, cfaPlaneColor, 3, noise);
        finalnoise = new double[6];
        for (i = 0; i < noise.length; i++)
            if (noise[i] > 2 || noise[i] < -2)
                finalnoise[i] = 0;
            else
                finalnoise[i] = (float) noise[i];
        //noise end
    }

    return DngProfile.getProfile(black, image.getImage().getWidth(), image.getImage().getHeight(), rawFormat,
            colorpattern, 0, color1, color2, neutral, forward1, forward2, reduction1, reduction2, finalnoise);
}