移植参考的ourdev上的一篇基于LPCXXX移植的文章,在STM32上采用开窗显示的方法。。。
TJpgDec中重定义的数据类型和他早先作品FATFS中一样。
移植主要是针对其图片数据结构体中的两个函数指针编写出函数原型。如下:
UINT STM32_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
{
return (f_lseek(fil, f_tell(fil) + nd) == FR_OK) ? nd : 0;/* Skip nd bytes on the input stream */
}
}
/* User defined call-back function to output RGB bitmap */
UINT STM32_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) */
STM32_disp_blt(rect->left, rect->right, rect->top, rect->bottom, (uint16_t*)bitmap);
return 1; /* Continue decompression */
}
还有一个输出函数调用的显示函数
// 在屏幕上显示图片
void STM32_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;
u32 i;
u32 len=0;
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;
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;
left = MaskL;
}
if (right > MaskR) // Clip right of source image it is out of active area
{
xc -= right - MaskR;
right = MaskR;
}
// 已经计算出了要绘制的x方向pixels和y方向pixels
// 上下左右的值已经校正为,为屏幕上的绝对位置,由此可以算出屏幕缓冲区的起始位置
if(whflag==1)
{
LCD_Set_Window(left,top,right,bottom);
LCD_Scan_Dir(U2D_L2R);//从上到下,从左到右
LCD_SetCursor(left,top);//设置光标位置
}
else
{
LCD_Set_Window(left,top,right,bottom);
LCD_Scan_Dir(L2R_U2D);//从左到右,从上到下
LCD_SetCursor(left,top);//设置光标位置
}
LCD_WR_REG(R34); //开始写入GRAM
len=(right-left+1)*(bottom-top+1); //写入的数据长度
for(i=0;i<len;i++)
{
LCD_WR_DATA(*pat);
pat++;
}
LCD_Set_Window(0,0,239,319);
}
//绘制图像函数
BYTE Buff[4096] __attribute__ ((aligned(4)));
u32 Commander_DRAWJPEG(FIL* fJpeg,const char* filename)
{
FRESULT FatFsRet;
JDEC jd; /* Decoder object (124 bytes) */
JRESULT rc;
BYTE scale;
FatFsRet = f_open(fJpeg,filename,FA_READ);
if(FatFsRet != FR_OK)
{
LCD_ShowString(60,130,"open jpeg error!");
Delay(10000);
f_close(fJpeg);
return FatFsRet;
}
rc = jd_prepare(&jd, STM32_tjd_input, Buff, sizeof(Buff), fJpeg);
// LCD_ShowNum(100,220,rc,16,12); //调试输出错误信息为JDR_INP。显示输入设备错误!!
if (rc == JDR_OK)
{
for (scale = 0; scale < 3; scale++) //确定比例因子
{
//此处可修改图像显示大小,3个等级。1/2,1/4,1/8
if ((jd.width >> scale) <= 400 && (jd.height >> scale) <= 600)
{
break;
}
}
rc = jd_decomp(&jd, STM32_tjd_output, scale); //开始解压JPEG文件
}
else
{
LCD_ShowString(60,130,"jpegDecode error!");
Delay(10000);
f_close(fJpeg);
return FatFsRet;
}
f_close(fJpeg);
return 0;
}
以上就是解码模块的需要改动的地方。
目前还存在的问题:
1.
这个表格的作用。
2.图像只有竖屏显示,当宽大于高时显示别扭,我做了一点修改,效果不理想,可以横屏,但是显示出来的与原图成镜像对称。
我修改过的几个地方:
1.Tjpgd.c中的jd_prepare函数;加入了一个宽高标志。
2.Tjpgd.c中的mcu_output函数;根据宽高标志做了一个判断。
希望哪位大虾,抽空帮俺看看。不胜感谢。。。
PS:吐槽,原子哥的图片解码程序真心不好看。一堆全局变量,菜鸟儿表示压力山大。。。
源码在附件.
|