Example usage for android.hardware.camera2 CameraCharacteristics SENSOR_COLOR_TRANSFORM2

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

Introduction

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

Prototype

Key SENSOR_COLOR_TRANSFORM2

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

Click Source Link

Document

A matrix that transforms color values from CIE XYZ color space to reference sensor color space.

This matrix is used to convert from the standard CIE XYZ color space to the reference sensor colorspace, and is used when processing raw buffer data.

The matrix is expressed as a 3x3 matrix in row-major-order, and contains a color transform matrix that maps colors from the CIE XYZ color space to the reference sensor color space (i.e.

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 . java  2 s  . 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);
}