Example usage for android.hardware.camera2 CameraCharacteristics SENSOR_FORWARD_MATRIX2

List of usage examples for android.hardware.camera2 CameraCharacteristics SENSOR_FORWARD_MATRIX2

Introduction

In this page you can find the example usage for android.hardware.camera2 CameraCharacteristics SENSOR_FORWARD_MATRIX2.

Prototype

Key SENSOR_FORWARD_MATRIX2

To view the source code for android.hardware.camera2 CameraCharacteristics SENSOR_FORWARD_MATRIX2.

Click Source Link

Document

A matrix that transforms white balanced camera colors from the reference sensor colorspace to the CIE XYZ colorspace with a D50 whitepoint.

This matrix is used to convert to the standard CIE XYZ colorspace, and is used when processing raw buffer data.

This matrix is expressed as a 3x3 matrix in row-major-order, and contains a color transform matrix that maps white balanced colors from the reference sensor color space to the CIE XYZ color space with a D50 white point.

Under the second reference illuminant ( CameraCharacteristics#SENSOR_REFERENCE_ILLUMINANT2 android.sensor.referenceIlluminant2 ) this matrix is chosen so that the standard white point for this reference illuminant in the reference sensor colorspace is mapped to D50 in the CIE XYZ colorspace.

This matrix will only be present if the second reference illuminant is present.

Optional - This value may be null on some devices.

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);//  w  ww .j  a  v  a2s.  c  om
    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);
}