OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5599|回复: 9

图片解码不正常!

[复制链接]

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
发表于 2014-12-16 10:58:58 | 显示全部楼层 |阅读模式
5金钱
如题,图片解码不正常,用的是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****/

tjpgd.c

34.63 KB, 下载次数: 89

tjpgd.h

2.77 KB, 下载次数: 78

最佳答案

查看完整内容[请看2#楼]

回复【8楼】zongyu0210: --------------------------------- http://www.openedv.com/posts/list/43514.htm
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2014-12-16 10:58:59 | 显示全部楼层
回复【8楼】zongyu0210:
---------------------------------
http://www.openedv.com/posts/list/43514.htm
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-16 11:06:02 | 显示全部楼层
没有大神吗?自己先顶一下~~用的是STM32F072的cpu
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-16 13:53:29 | 显示全部楼层
算了,还是得靠自己!论坛也是毛用没有~~
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2014-12-16 23:24:29 | 显示全部楼层
请参考我们的代码。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-17 08:31:50 | 显示全部楼层
回复【4楼】正点原子:
---------------------------------
参考了。太占内存,所以给pass掉了。现在只能用ChaN的小型的jpeg解码程序了~
回复

使用道具 举报

10

主题

94

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
200
金钱
200
注册时间
2014-3-8
在线时间
11 小时
发表于 2014-12-17 08:38:17 | 显示全部楼层
回复【3楼】zongyu0210:
---------------------------------
刚发就想给解决,那论坛确实毛用都没,你别在这混了
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-17 08:56:07 | 显示全部楼层
回复【6楼】wangxipeng:
---------------------------------
过来打打酱油@!!!!
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-17 09:01:52 | 显示全部楼层
回复【4楼】正点原子:
---------------------------------
麻烦给个链接,有用ChaN解码的没?官方的太占内存,要管理15K内存至少,我用的CPU最大才16K,只能管理12K。。。
回复

使用道具 举报

7

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
176
金钱
176
注册时间
2014-11-20
在线时间
36 小时
 楼主| 发表于 2014-12-18 09:39:51 | 显示全部楼层
回复【9楼】正点原子:
---------------------------------
谢谢院子大神,已经解决了!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-27 19:42

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表