cancel
Showing results for 
Search instead for 
Did you mean: 

How to display a jpeg while decoding?

Christian B
Associate II
Posted on June 05, 2018 at 16:22

Hello,

we are trying to decode a jpeg on the STM32F769I-DISCO and display it on the LCD while decoding. For that we modified the JPEG example JPEG_DecodingUsingFs_DMA a little bit. Here is the important part of code:

unsigned char* jpegData = new unsigned char[65000];

unsigned int jpegDataLength = decode_base64(input, jpegData);

unsigned int displayedMcus = 0;

unsigned int mcusTotal = 1200;

unsigned int imageWidthInByte = 2560;

unsigned int mcuPixel = 16;

unsigned int bytePerPixel = 4;

unsigned int jpegBytesRead = JPEG_Decode_DMA(&hjpeg, jpegData, jpegDataLength, JPEG_OUTPUT_DATA_BUFFER);

HAL_JPEG_GetInfo(&hjpeg, &JPEG_Info);

uint32_t xPos = 0;

uint32_t yPos = 0;

do {

       jpegBytesRead += JPEG_InputHandler(&hjpeg, jpegData, jpegBytesRead, jpegDataLength);

       mcusProcessed = JPEG_OutputHandler(&hjpeg);

       if(displayedMcus < mcusProcessed) {

           xRef = (((displayedMcus) * 16) / JPEG_Info.ImageWidth) * 16;

           yRef = (((displayedMcus) * 16) % JPEG_Info.ImageWidth);

           refline = imageWidthInByte * xRef + (bytePerPixel * yRef);

           DMA2D_CopyBuffer((uint32_t *)JPEG_OUTPUT_DATA_BUFFER + refline, (uint32_t *)LCD_FRAME_BUFFER, xPos , yPos, mcuPixel, mcuPixel);

           DMA2D_CopyBuffer((uint32_t *)JPEG_OUTPUT_DATA_BUFFER + refline + imageWidthInByte, (uint32_t *)LCD_FRAME_BUFFER, xPos , yPos + mcuPixel, mcuPixel, mcuPixel);

           xPos += 16;

           if (xPos >= JPEG_Info.ImageWidth) {

               xPos = xPos % JPEG_Info.ImageWidth;

               yPos += (mcusProcessed - displayedMcus) * 16;

           }

           displayedMcus = mcusProcessed;

       }

   } while (mcusProcessed < 1200);

Our problem is: how do we know the right place to copy from the JPEG_OUTPUT_DATA_BUFFER to the LCD_FRAME_BUFFER with function DMA2D_CopyBuffer() (located in the above mentioned example).  

We tried to understand JPEG_MCU_YCbCr420_ARGB_ConvertBlocks() in the jpeg_utils.c and rebuild the buffer access for copying the right MCUs from JPEG_OUTPUT_DATA_BUFFER to the LCD_FRAME_BUFFER but it's quite hard to understand how it works in detail.

Displaying the whole decoded jpeg works by the way.

Can someone give us a hint?

Thanks in advanced.

2 REPLIES 2
Posted on June 05, 2018 at 18:46

Doesn't the library have call-backs, or repeated decode calls, that allow you to fill an arbitrary length output buffer?

I haven't dug deeply into the model here, but typically you pass an output buffer by location/size, and each time the decoder fills that it gives you a whole buffer at the location you provided, and you write that raster data to a file or screen, or whatever output device you have. If the output buffer is a fractional size you call again to get the next piece.

The other alternative is to have the output buffer BE the frame buffer.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 11:39

add to code WM_MULTIBUF_Enable(0);