cancel
Showing results for 
Search instead for 
Did you mean: 

JPEG_Decode_DMA from binary array

AWent
Associate III

Hey.

I am using the STM32F769I Discovery board,

and I want to decode a JPEG which I receive from Arducam Mini via SPI.

I used the code from the JPEG_DecodingUsingFs_DMA Example and modified the JPEG_Decode_DMA function in a way, that it takes a binary array as data input, rather than a file object. Everything else stayed the same.

However, when I start decoding, I won't get to JpegProcessingEnd triggered by the JPEG_OutputHandler. This seem to be, because of the Jpeg_OUT_BufferTabs won't change their state to "FULL".

Any idea or hint for me why this is not working?

Or what I can test to find out the cause for that?

1 ACCEPTED SOLUTION
3 REPLIES 3
AWent
Associate III

To clarify, some code snippets:

call in the Main loop:

....
/* Start JPEG decoding with DMA method */
JPEG_Decode_DMA(&JPEG_Handle, &frame_buffer[5], frame_size,  JPEG_IMAGE_DATA_BUFFER);
				
do //Wait till end of JPEG decoding and perfom Input/Output Processing in BackGround
        {
		JPEG_InputHandler(&JPEG_Handle);
                JpegProcessing_End = JPEG_OutputHandler(&JPEG_Handle);
        }while(JpegProcessing_End == 0);
				
HAL_JPEG_GetInfo(&JPEG_Handle, &JPEG_Info);      //Get JPEG Info 
          
				
/* Copy RGB decoded Data to the display FrameBuffer */
 xPos = (BSP_LCD_GetXSize() - JPEG_Info.ImageWidth)/2;
 yPos = (BSP_LCD_GetYSize() - JPEG_Info.ImageHeight)/2;        
        				
DMA2D_CopyBuffer((uint32_t *)JPEG_IMAGE_DATA_BUFFER, (uint32_t *) LCD_FB_START_ADDRESS, xPos , yPos, JPEG_Info.ImageWidth, JPEG_Info.ImageHeight);
....

Modified JPEG_Decode_DMA function (exchanged file object input parameter with uint8_t data_array and data length):

uint32_t JPEG_Decode_DMA(JPEG_HandleTypeDef *hjpeg, uint8_t *pDataIn, uint32_t InDataLength, uint32_t DestAddress)
{
  uint32_t i;
  
  FrameBufferAddress = DestAddress;
          
  /* Read from JPG file and fill input buffers */
  for(i = 0; i < NB_INPUT_DATA_BUFFERS; i++)
  {
    memcpy(Jpeg_IN_BufferTab[i].DataBuffer, pDataIn, CHUNK_SIZE_IN);
    Jpeg_IN_BufferTab[i].DataBufferSize = CHUNK_SIZE_IN;
    Jpeg_IN_BufferTab[i].State = JPEG_BUFFER_FULL;       
  } 
  /* Start JPEG decoding with DMA method */
  HAL_JPEG_Decode_DMA(hjpeg ,Jpeg_IN_BufferTab[0].DataBuffer ,Jpeg_IN_BufferTab[0].DataBufferSize ,Jpeg_OUT_BufferTab[0].DataBuffer ,CHUNK_SIZE_OUT);
  
  return 0;
}

And the JPEG_OutputHandler which won't return a '1' for indicating JpegProcessing_End (I did not edit this function):

uint32_t JPEG_OutputHandler(JPEG_HandleTypeDef *hjpeg)
{
  uint32_t ConvertedDataCount;
  
  if(Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].State == JPEG_BUFFER_FULL)
  {  
    MCU_BlockIndex += pConvert_Function(Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].DataBuffer, (uint8_t *)FrameBufferAddress, MCU_BlockIndex, Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].DataBufferSize, &ConvertedDataCount);   
    
    Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].State = JPEG_BUFFER_EMPTY;
    Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].DataBufferSize = 0;
    
    JPEG_OUT_Read_BufferIndex++;
    if(JPEG_OUT_Read_BufferIndex >= NB_OUTPUT_DATA_BUFFERS)
    {
      JPEG_OUT_Read_BufferIndex = 0;
    }
    
    if(MCU_BlockIndex == MCU_TotalNb)
    {
      return 1;
    }
  }
  else if((Output_Is_Paused == 1) && \
          (JPEG_OUT_Write_BufferIndex == JPEG_OUT_Read_BufferIndex) && \
          (Jpeg_OUT_BufferTab[JPEG_OUT_Read_BufferIndex].State == JPEG_BUFFER_EMPTY))
  {
    Output_Is_Paused = 0;
    HAL_JPEG_Resume(hjpeg, JPEG_PAUSE_RESUME_OUTPUT);            
  }
 
  return 0;  
}

AWent
Associate III

Could it be, because my jpeg data might be corrupted?

So that the decoding won't find an end, becasue the "End Of Image Flag" (0xFFD9) won't be found? Is that possible?

In the meantime, I also found that the STM library has a JPEG_DecodingFrimFLASH_DMA function as well. However, the code gets stuck at the same point again.