cancel
Showing results for 
Search instead for 
Did you mean: 

Incoherent Output JPEG Grayscale Image STM32U5G9

guigrogue
Associate II

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).

input_img_y8.bmp out_jpeg_y8.bmp

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).

4 REPLIES 4
guigrogue
Associate II

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.

Hello @guigrogue 

Yes, the JPEG standard used in ST JPEG hardware codec supports pixel input/output formats grayscale.

Please refer to the AN4996.

Saket_Om_0-1763131497425.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

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};