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?