cancel
Showing results for 
Search instead for 
Did you mean: 

Problem while decoding jpeg with Tjpegdec

Wasilewski.Piotr
Associate III
Posted on August 04, 2015 at 00:19

Hello!

Currently I'm working on a jpeg decompression. I've found a great lib from elm-chan, but it seems that's there's something wrong. All the returns are JDR_OK, but despite that on the lcd I get only first pixel of the block. I can see they are valid, because the colors match. In debug mode I see that the decompressor gives my output funtion only 4 bytes. I don't know what is going on. I think I've read all the discussion in the internet and I cannot find an error like this. I hope that someone has succesfully ported this lib to STM and can tell me what am I doing wrong. the code:

UINT tjd_input (
JDEC* jd, 
/* Decompression object */
BYTE* buff, 
/* Pointer to the read buffer (NULL:skip) */
UINT nd 
/* Number of bytes to read/skip from input stream */
){
UINT rb;
if
(buff) { 
/* Read nd bytes from the input strem */
fres= f_read(&fsrc, buff, nd, &rb);
return
rb; 
/* Returns number of bytes could be read */
} 
else
{ 
/* Skip nd bytes on the input stream */
return
(f_lseek(&fsrc, f_tell(&fsrc) + nd) == FR_OK) ? nd : 0;
}
}
/* User defined call-back function to output RGB bitmap */
UINT tjd_output (
JDEC* jd, 
/* Decompression object of current session */
void
* bitmap, 
/* Bitmap data to be output */
JRECT* rect 
/* Rectangular region to output */
)
{
jd = jd; 
/* Suppress warning (device identifier is not needed in this appication) */
LCD_area(rect->left, rect->bottom, rect->right, rect->top);
DMA_Config(
sizeof
(bitmap),(uint8_t*)bitmap);
return
1; 
/* Continue to decompression */
}
void
load_jpg (
FIL *fp, 
/* File to open */
char
*fn,
void
*work, 
/* Pointer to the working buffer (must be 4-byte aligned) */
UINT sz_work 
/* Size of the working buffer (must be power of 2) */
)
{
JDEC jd; 
/* Decompression object (70 bytes) */
JRESULT rc;
BYTE scale=0;
fres = f_open(&fsrc,fn, FA_READ | FA_OPEN_EXISTING);
rc = jd_prepare(&jd, tjd_input, work, sz_work, fp);
if
(rc == JDR_OK)
{
rc = jd_decomp(&jd, tjd_output, 0);
if
(rc==JDR_OK)
{
LCD_char(
'a'
,100,100,0,RED,BLUE,3);
}
}
}
void
DMA_Config(
int
ele, u8* buf)
{
DMA1_Channel5->CCR=0x00000000;
DMA1_Channel5->CCR|=DMA_CCR1_MEM2MEM; 
//DMA type mem to mem
DMA1_Channel5->CCR|=DMA_CCR1_PL; 
//priority very high
DMA1_Channel5->CCR&=~DMA_CCR1_MSIZE; 
// memory 8bit
DMA1_Channel5->CCR&=~DMA_CCR1_PSIZE; 
//peripheral 8bit
DMA1_Channel5->CCR|=DMA_CCR1_MINC; 
//inc mem adress
DMA1_Channel5->CCR|=DMA_CCR1_PINC; 
// inc per adress
DMA1_Channel5->CCR|=DMA_CCR1_DIR; 
//mem to per
DMA1_Channel5->CNDTR=ele; 
// buf size
DMA1_Channel5->CPAR=&LCD_WRITE_DATA; 
//per adress
DMA1_Channel5->CMAR=buf; 
//mem adress
DMA1_Channel5->CCR|=DMA_CCR1_EN; 
//turn on DMA1_ch5
}

Function DMA_config is 100% valid, because I can display a normal BMP file with it. Hope You manage to help me :) Greetings, Peter
3 REPLIES 3
Posted on August 04, 2015 at 00:47

sizeof
(bitmap) == 4

Perhaps you need to compute the actual length/size of the bitmap, not the size of a void* pointer? The length's going to be a function of the width, height, and colour depth.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Wasilewski.Piotr
Associate III
Posted on August 04, 2015 at 01:31

to be migrated, sourceId: 56216:697285D7-A9CA-445D-B16C-F23BF0E3B1A3

Wasilewski.Piotr
Associate III
Posted on August 04, 2015 at 14:07

Problem solved - I didn't wait for the DMA transfer finish. Thank You clive1 for help ! You're great :) 

greetings,

Peter