搜索
bottom↓
回复: 3

LPC2478移植TJpgDec成功,分享用户自定义接口函数

[复制链接]

出0入0汤圆

发表于 2012-2-3 14:57:40 | 显示全部楼层 |阅读模式
#include "lpc24xx_types.h"
#include "ff.h"
#include "tjpgd.h"

#include "LCDConf.h"

// 以下3句宏定义在tjpgd.h中修改
#define        JD_SZBUF                2048/* Size of stream input buffer (should be multiple of 512) */
#define JD_FORMAT                1        /* Output RGB format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
#define        JD_USE_SCALE        1        /* Use descaling feature for output */

#define DISP_XS    800
#define DISP_YS    600


static int MaskL = 0;
static int MaskR = DISP_XS - 1;
static int MaskT = 0;
static int MaskB = DISP_YS - 1;



u16 Covert_RGB565_to_BGR565(unsigned short inRGB)
{
    u16    outBGR = 0;
   
    u16 r,g,b;
    b = (inRGB    ) & 0x1F;
    g = (inRGB>> 5) & 0x3F;
    r = (inRGB>>11) & 0x1F;
    outBGR = (b << 11) | (g << 5) | r;


    return outBGR;
}


// 在屏幕上显示图片
// 屏幕的起始地址在LCD_UPBASE中保存
void lpc24xx_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;
    uint16_t *pScrBuf;
   
    uint16_t i;


    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;
    }

    // 已经计算出了要绘制的x方向pixels和y方向pixels
    // 上下左右的值已经校正为,为屏幕上的绝对位置,由此可以算出屏幕缓冲区的起始位置
   
    i = 0;
    do     /* Send image data */
    {
        pScrBuf = (uint16_t *)(LCD_UPBASE) + (top+i)*DISP_XS + left;
        i++;
        
        xl = xc;    // x方向的pixels
        do
        {
            pd = *pat++;
            *pScrBuf = Covert_RGB565_to_BGR565(pd);
            pScrBuf ++;
        } while (--xl);
        pat += xs;
    } while (--yc);
}


/*-----------------------------------*/
/* JPEG file loader                  */


/* User defined call-back function to input JPEG data */

UINT lpc24xx_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 lpc24xx_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) */

//    特定的情况下返回0,停止解码,自行定义
//    if (!rect->left)     /* Check user interrupt at left end */
//    {
//        return 0;    /* Abort decompression */
//    }
   
//    /* Put the rectangular into the display */
    lpc24xx_disp_blt(rect->left, rect->right, rect->top, rect->bottom, (uint16_t*)bitmap);

    return 1;    /* Continue decompression */
}







// 绘制Jpeg
u32 Commander_DRAWJPEG(char *pPara)
{
    FIL     fJpeg;
    FRESULT FatFsRet;
   
    JDEC     jd;                                                                        /* Decoder object (124 bytes) */
    JRESULT rc;
    BYTE     scale;
   
    BYTE Buff[8192] __attribute__ ((aligned(4)));
   
    FatFs_Addons_MountDisk(_T("2:"));
    FatFsRet = f_open(&fJpeg,_T("2:/Test.jpg"),FA_READ);
    if(FatFsRet != FR_OK)
    {
        printf("打开 图片 失败!\n");
        
        f_close(&fJpeg);
        return FatFsRet;
    }
   
    rc = jd_prepare(&jd, lpc24xx_tjd_input, Buff, sizeof(Buff), &fJpeg);
    if (rc == JDR_OK)
    {
        for (scale = 0; scale < 3; scale++)                     //确定比例因子
        {
            if ((jd.width >> scale) <= 800 && (jd.height >> scale) <= 600)
            {
                break;
            }
        }
   
        rc = jd_decomp(&jd, lpc24xx_tjd_output, scale);         //开始解压JPEG文件
    }
    else
    {
        printf("图片解码失败!\n");
        f_close(&fJpeg);
        return FatFsRet;
    }
   
    f_close(&fJpeg);
    return 0;
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2012-2-4 16:56:08 | 显示全部楼层
mark 正在找一个JPG编解码的程序。谢谢楼主

出0入0汤圆

发表于 2012-3-3 22:52:10 | 显示全部楼层
楼主这个不错,学习了

出0入0汤圆

发表于 2012-4-23 23:10:22 | 显示全部楼层
lz有没有移植教程啊?我移植后出现这样的警告。。
..\tjpgd.c(488): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:             if (b < 0) return 0 - b;                                /* Err: invalid code or input */
..\tjpgd.c:                               ^
..\tjpgd.c(492): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:                     if (e < 0) return 0 - e;                        /* Err: input */
..\tjpgd.c:                                       ^
..\tjpgd.c(510): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:                     if (b < 0) return 0 - b;                        /* Err: invalid code or input error */
..\tjpgd.c:                                       ^
..\tjpgd.c(518): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:                             if (d < 0) return 0 - d;                /* Err: input device */
..\tjpgd.c:                                               ^
..\tjpgd.c(831): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:                     rc = create_huffman_tbl(jd, seg, len);
..\tjpgd.c:                        ^
..\tjpgd.c(841): warning:  #188-D: enumerated type mixed with another type
..\tjpgd.c:                     rc = create_qt_tbl(jd, seg, len);
..\tjpgd.c:                        ^
..\tjpgd.c: ..\tjpgd.c: 6 warnings, 0 errors
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 17:31

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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