2025-10-22 8:42 AM
Hello everyone,
For a while now, I have been writing my hardware jpeg driver for the STM3U5G9, I am near the end but a last (last?) major problem remains.
With a grayscale 8-bit image (on the left), the output encoded image (on the right) is totally different from the input. (the output screenshot is decoded by an external jpeg decoder).
I also observe the same behavior with HAL/MX configuration, so I only share the HAL/MX code for simplicity matter.
MX_JPEG_Init();
JPEG_ConfTypeDef cfg = {0};
cfg.ChromaSubsampling = JPEG_444_SUBSAMPLING;
cfg.ColorSpace = JPEG_GRAYSCALE_COLORSPACE;
cfg.ImageHeight = 480;
cfg.ImageWidth = 640;
cfg.ImageQuality = 75;
int length = cfg.ImageHeight * cfg.ImageWidth;
HAL_JPEG_ConfigEncoding(&hjpeg, &cfg);
HAL_JPEG_Encode(&hjpeg, img, length, img_jpeg, length, HAL_MAX_DELAY);
For grayscale only image, do I need to do extra steps to make it work ?
I saw (A)RGB image conversion to YCbCr functions (expensives to perform as a whole), do I need to perform similar actions like padding the y8 input stream with zeros to imitate a YCbCr stream with only active luminance? Or the issue remains somewhere else ?
I don't face this issue with stm example jpeg with RGB images as inputs.
I'm using cubeIDE1.19, cubeMX 6.15, FW 1.8 for the mentionned RGB example (JPEG_EncodingFromFLASH_DMA).