I implemented a different method to convert 8-bit gray scale to 24-bit rgb from what I suggested above. This method converts 8-bit gray scale using a custom csc matrix and color space transformation from planar YUV to rgb24. Because there is no U,V component, coefficients are chosen such that:
R, G, B = Y * 1 + U * 0 + V * 0
Please see attached changes to the imx6 IPU BSP to enable custom csc matrices download.
The way 8-bit gray scale is converted is as follows:
First capture from gray scale camera using 24-bit rgb pixel format but specify h-res as 1/3 of original gray scale h-res. Make sure that the capture buffer is large enough for U/V planes. U/V bytes are not actually captured nor used but are needed for IPU unit to properly function during conversion YUV->RGB.
In the application use the following code to perform the conversion:
| void CameraHal::setupCustomIpuMatrixForGrayscaleToRgbConversion() |
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 3; j++)
mIpuTask.custom_coeff[i][j] = 0;
mIpuTask.custom_coeff[0][0] = 128;
mIpuTask.custom_coeff[1][0] = 128;
mIpuTask.custom_coeff[2][0] = 128;
}
setupCustomIpuMatrixForGrayscaleToRgbConversion();
mIpuTask.custom_matrix = 1;
mIpuTask.input.format = IPU_PIX_FMT_YUV444P;
mIpuTask.output.format = IPU_PIX_FMT_RGB32;
mIpuTask.output.rotate = IPU_ROTATE_HORIZ_FLIP;
...
if (ioctl(mIpuFd, IPU_QUEUE_TASK, &mIpuTask) < 0)
CAMERA_LOG_ERR("%s: convert Y8->RGB32: ioct(IPU_QUEUE_TASK) fail", __func__);
Let me know if you need more clarification.