如题,图片解码不正常,用的是ili9325,320*240的的屏。显示英文数字正常。
望大神们不吝赐教,谢谢。
解码用的是ChaN的Tiny解码函数。解析出来如下图:
代码如下:
#include "stm32f0xx.h"#include "takepic.h"
#include "tjpgd.h"
static FRESULT res; // FatFs function common result code
BYTE Buff[4096] __attribute__ ((aligned(4)));
/* Dot screen size */
#define DISP_XS 320
#define DISP_YS 240
/*-----------------------------------*/
/* JPEG file loader */
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
//#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
/* User defined call-back function to input JPEG data */
static
UINT tjd_input (
JDEC* jd, /* Decoder object */
BYTE* buff, /* Pointer to the read buffer (NULL:skip) */
UINT nd /* Number of bytes to read/skip from input stream */
)
{
UINT rb;
FIL *fil = (FIL*)jd->device; /* Input stream of this session */
if (buff) { /* Read nd bytes from the input strem */
f_read(fil, buff, nd, &rb);
return rb; /* Returns number of bytes could be read */
} else { /* Skip nd bytes on the input stream */
return (f_lseek(fil, f_tell(fil) + nd) == FR_OK) ? nd : 0;
}
}
static int MaskT, MaskL, MaskR, MaskB; /* Active drawing area */
void disp_mask (
int left, /* Left end of active window (0 to DISP_XS-1) */
int right, /* Right end of active window (0 to DISP_XS-1, >=left) */
int top, /* Top end of active window (0 to DISP_YS-1) */
int bottom /* Bottom end of active window (0 to DISP_YS-1, >=top) */
)
{
//if (left >= 0 && right < DISP_XS && left <= right && top >= 0 && bottom < DISP_XS && top <= bottom)
{
MaskL = left;
MaskR = right;
MaskT = top;
MaskB = bottom;
}
}
//LCDµ×²ãÏÔʾº¯Êý
void disp_blt (
int left, /* Left end (-32768 to 32767) */
int right, /* Right end (-32768 to 32767, >=left) */
int top, /* Top end (-32768 to 32767) */
int bottom, /* Bottom end (-32768 to 32767, >=right) */
const uint16_t *pat /* Pattern data */
)
{
int yc, xc, xl, xs;
uint16_t pd;
if (left > right || top > bottom) return; /* Check varidity */
if (left > MaskR || right < MaskL || top > MaskB || bottom < MaskT) return; /* Check if in active area */
yc = bottom - top + 1; /* Vertical size */
xc = right - left + 1; xs = 0; /* Horizontal size and skip */
if (top < MaskT) { /* Clip top of source image if it is out of active area */
pat += xc * (MaskT - top);
yc -= MaskT - top;
top = MaskT;
}
if (bottom > MaskB) { /* Clip bottom of source image if it is out of active area */
yc -= bottom - MaskB;
bottom = MaskB;
}
if (left < MaskL) { /* Clip left of source image if it is out of active area */
pat += MaskL - left;
xc -= MaskL - left;
xs += MaskL - left;
left = MaskL;
}
if (right > MaskR) { /* Clip right of source image it is out of active area */
xc -= right - MaskR;
xs += right - MaskR;
right = MaskR;
}
LCD_Set_Window(left, top, right, bottom);
LCD_WriteGRAM_EN();
do { /* Send image data */
xl = xc;
do {
pd = *pat++;
LCD_WR_DATA(pd);//ÏÔʾÏñËØ
} while (--xl);
pat += xs;
} while (--yc);
LCD_CS(1);
}
/* User defined call-back function to output RGB bitmap */
static
UINT tjd_output (
JDEC* jd, /* Decoder object */
void* bitmap, /* Bitmap data to be output */
JRECT* rect /* Rectangular region to output */
)
{
jd = jd; /* Suppress warning (device identifier is not needed) */
/* Check user interrupt at left end */
//if (!rect->left && __kbhit()) return 0; /* Abort decompression */
//if (rect->left) return 0; /* Abort decompression */
/* Put the rectangular into the display */
disp_blt(rect->left, rect->right, rect->top, rect->bottom, (uint16_t*)bitmap);
return 1; /* Continue decompression */
}
void load_jpg (
FIL *fp, /* Pointer to the open file object to load */
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; /* Decoder object (124 bytes) */
JRESULT rc;
BYTE scale;
//ÇåÆÁ×¢Ê͵ô
//disp_fill(0, DISP_XS, 0, DISP_YS, 0); /* Clear screen */
//disp_font_color(C_WHITE);
/* Prepare to decompress the file */
rc = jd_prepare(&jd, tjd_input, work, sz_work, fp);
if (rc == JDR_OK)
{
//UPrintf("sz_work:%d,&work:%d,work:%d,jd:%d\n",sz_work,&work,work,jd);
/* Determine scale factor */
for (scale = 0; scale < 3; scale++)
{
if (((jd.width >> scale) <= DISP_XS) && ((jd.height >> scale) <= DISP_YS)) break;
}
/* Display size information at bottom of screen */
//disp_locate(0, TS_HEIGHT - 1);
//(disp_putc, "%ux%u 1/%u", jd.width, jd.height, 1 << scale);
/* Start to decompress the JPEG file */
rc = jd_decomp(&jd, tjd_output, scale); /* Start to decompress */
} else {
/* Display error code */
//disp_locate(0, 0);
}
//__getch(); //×¢ÊÍ
}
void load_file (
const char *fn, /* Pointer to the file name */
void *work, /* Pointer to filer work area (must be word aligned) */
UINT sz_work /* Size of the filer work area */
)
{
FIL fil; /* Pointer to a file object */
if (f_open(&fil, fn, FA_READ) == FR_OK)
{
// if (strstr_ext(fn, ".BMP"))
// { /* BMP image viewer (24bpp, 1280pix in width max) */
// load_bmp(&fil, work, sz_work);
// }
load_jpg(&fil, work, sz_work);
// if (strstr_ext(fn, ".IMG"))
// { /* Motion image viewer */
// load_img(&fil, work, sz_work);
// }
// if (strstr_ext(fn, ".WAV"))
// { /* Sound file player (RIFF-WAVE only) */
// load_wav(&fil, fn, work, sz_work);
// }
f_close(&fil);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
int main(void)
{
u16 i = 0;
u16 j = 0;
u16 temp = 0;
u16 data = 0;
u8 key_down = 0;
u16 key_cnt = 0;
system_init();
disp_mask(0, DISP_XS - 1, 0, DISP_YS - 1); //ÉèÖûæͼÇøÓò
load_file("0:33.jpg", Buff, sizeof(Buff)); //´ò¿ªjpgÎļþ²¢½âÂëÏÔʾ
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|
|