I am working at an app where I need to take many pictures (possibly tens of thousands) and they have to be RAW, which I process in native code. Right now I am converting the RAWs to DNGs, and in the native code I unpack them using libraw. I get the white balance color multipliers, and the color matrix from the dng.
However, converting the raw to dng and then processing the dng takes quite a bit of time, and I would like to skip this step, and process the raw info directly, without the DNG intermediary. But for that I need to get the color matrix and WB values. I did look at the docs, but I didn't find any way on how to do that. Any help would be appreciated.
That information is available in the CameraCharacteristics and CaptureResult objects that you pass to DngCreator, specifically fields like:
https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#sensor_calibration_transform1 https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#sensor_color_transform1 https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#sensor_forward_matrix1 https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#sensor_reference_illuminant1 https://developer.android.com/reference/android/hardware/camera2/CaptureResult#SENSOR_NEUTRAL_COLOR_POINT
Most of those fields map basically directly to the DNG spec, but you can try to look at the DngCreator implementation to see how to go from the camera2 API to the DNG fields: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/jni/android_hardware_camera2_DngCreator.cpp;l=1217
While there's no official sample for using this information to process a raw buffer, the Android compliance tests include a simple RAW converter in Java, used to confirm that the resulting image reasonably matches the JPEG image provided by the device (to double-check that the various metadata fields are reasonably correct): https://cs.android.com/android/platform/superproject/+/master:cts/tests/camera/src/android/hardware/camera2/cts/rs/RawConverter.java;l=279