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).
2025-11-10 2:19 AM
Hello everyone,
Any idea on this issue ?
Using HAL or my own code gives the exact same result.
The JPEG standard used for the ST jpeg hardware codec is supposed to allow grayscale pixels as input format.
2025-11-14 6:46 AM
Hello @guigrogue
Yes, the JPEG standard used in ST JPEG hardware codec supports pixel input/output formats grayscale.
Please refer to the AN4996.
2025-11-17 4:59 AM
Hello @Saket_Om,
Thank you for your confirmation for grayscale input format, the opposite would have been quite surprising.
Have you managed to replicate my result ? The cubemx config is bare minimum, encode mode rgb888 as there is no y8 format choice in ioc.
The input is attached.
The arrays aren't defined in the provided code, but are:
uint8_t img[640*480] __attribute__((aligned(4))) = {0};
uint8_t img_jpeg[640*480] __attribute__((aligned(4))) = {0};
2025-11-19 1:08 AM