AnsweredAssumed Answered

How to display a jpeg while decoding?

Question asked by Christian B on Jun 5, 2018
Latest reply on Jun 6, 2018 by Vitaliy Chernobay

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.

Outcomes