0
\$\begingroup\$

I am encoding a 200x300 image using the JPEG codec available in the STM32H743. The input format is ARGB8888, with the input buffer having a size of 240000 bytes (200 x 300 x 4). As I do not know what the output size of the JPEG codec will be , I have allocated also a 240000 byte output buffer. The quality is set to 100, but I found the issue to occurr with other quality settings as well.

My problem is that when using the JPEG accelerator using the CPU to feed and retrieve data, the output size of the JPEG image (i.e., the size from the beginning of the output buffer to the last non-null byte) is 19116, both for optimization levels -O0 and -O3, which is ok. When using JPEG codec using DMA, more specifically using the HAL_JPEG_Encode_DMA HAL function, and setting the optimization level to -O0, the output size is 25796. I do not understand the difference in size to the CPU fed alternative, but apart from that, this size also seems to be ok. When using DMA and -O3 however, the output size becomes 200260. This happens because the last 20 bytes are shifted to later in the output buffer, like so:

=====

25776 bytes of data --

174464 bytes of 0x00 (empty space) --

20 bytes of data --

More empty space

====

I checked that the last 20 bytes are exactly the same for -O0 and -O3, so the output from the JPEG codec seems to be identical. It is just the position of the last 20 bytes in the output buffer that changes. Anyone have any idea what could cause this behaviour?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

After carefully reading the manual and the examples provided by ST I came to the conclusion that I was not performing the JPEG encoding operation correctly.

The raw RGB pixels must first be converted into YCbCr using the provided functions in the jpeg_utils.c module. I am not even sure how I was getting valid images from the JPEG encoding/decoding process without this conversion. Similarly, the output of the JPEG encoder will be in YCbCr format, and must be converted back to RGB.

See the example provided here: https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H743I-EVAL/Examples/JPEG/JPEG_EncodingUsingFs_DMA/Src/encode_dma.c

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.