欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6792|回復: 0
打印 上一主題 下一主題
收起左側

JPG圖片C語言解碼顯示例子-期末傾情奉獻

[復制鏈接]
跳轉到指定樓層
樓主
ID:90014 發表于 2015-9-14 18:54 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
     企圖解碼JPG的圖片并且代碼完全由自己來寫,那是不容易的,據我所知這種代碼完全可以當做碩士研究生的畢業論文了.
    我今天用的是Tjpg解碼庫庫函數大概1000行,顯示過程中除了需要Tjpg解碼庫提供的兩個庫函數
/* Error code */
typedef enum {
        JDR_OK = 0,        /* 0: Succeeded */
        JDR_INTR,        /* 1: Interrupted by output function */       
        JDR_INP,        /* 2: Device error or wrong termination of input stream */
        JDR_MEM1,        /* 3: Insufficient memory pool for the image */
        JDR_MEM2,        /* 4: Insufficient stream input buffer */
        JDR_PAR,        /* 5: Parameter error */
        JDR_FMT1,        /* 6: Data format error (may be damaged data) */
        JDR_FMT2,        /* 7: Right format but not supported */
        JDR_FMT3        /* 8: Not supported JPEG standard */
} JRESULT;






/* Rectangular structure */
typedef struct {
        WORD left, right, top, bottom;
} JRECT;






/* Decompressor object structure */
typedef struct JDEC JDEC;
struct JDEC {
        UINT dctr;                                /* Number of bytes available in the input buffer */
        BYTE* dptr;                                /* Current data read ptr */
        BYTE* inbuf;                        /* Bit stream input buffer */
        BYTE dmsk;                                /* Current bit in the current read byte */
        BYTE scale;                                /* Output scaling ratio */
        BYTE msx, msy;                        /* MCU size in unit of block (width, height) */
        BYTE qtid[3];                        /* Quantization table ID of each component */
        SHORT dcv[3];                        /* Previous DC element of each component */
        WORD nrst;                                /* Restart inverval */
        UINT width, height;                /* Size of the input image (pixel) */
        BYTE* huffbits[2][2];        /* Huffman bit distribution tables [id][dcac] */
        WORD* huffcode[2][2];        /* Huffman code word tables [id][dcac] */
        BYTE* huffdata[2][2];        /* Huffman decoded data tables [id][dcac] */
        LONG* qttbl[4];                        /* Dequaitizer tables [id] */
        void* workbuf;                        /* Working buffer for IDCT and RGB output */
        BYTE* mcubuf;                        /* Working buffer for the MCU */
        void* pool;                                /* Pointer to available memory pool */
        UINT sz_pool;                        /* Size of momory pool (bytes available) */
        UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
        void* device;                        /* Pointer to I/O device identifiler for the session */
};
之外,還需要自己寫兩個函數.
先來看下其中一個庫函數的聲明:
JRESULT jd_prepare (
JDEC* jd,/* Blank decompressor object */
UINT (*infunc)(JDEC*, BYTE*, UINT),/* JPEG strem input function */
void* pool,/* Working buffer for the decompression session */
UINT sz_pool,/* Size of working buffer */
void* dev/* I/O device identifier for the session */
)

UINT (*infunc)(JDEC*, BYTE*, UINT),/* JPEG strem input function */這是這個庫函數的第二個參數的聲明.這是一個指向函數的指針.
為了給這個參數賦值 首先要先寫一個函數 這個函數由庫函數調用.用來從磁盤讀取圖像的數據
UINT InputData(JDEC * jdec , BYTE *buff , UINT nbyte)
{
    /* 這個函數將被
jd_prepare  調用 調用此函數后希望將得到的數據 保存在buff為首地址的內存中 數據的長度為nbyte */
    if(buff)/* buff 如果不為NULL */
    {
        f_read(&fil , buff , nbyte ,&br);/* &fil 保存圖片數據的地址 */
        return br;
    }
    else/* 否則將移動數據 */
    {
        return (f_lseek(&fil, f_tell(dev->fp) + nbyte) == FR_OK) ? nbyte : 0;
    }
   
}


UINT OutputData(JDEC *jdec , void bitmap , JRECT *rect)
{
/* */

    LCD_Disp(rect->left,rect->top,rect->right,rect->bottom,(uint16_t*)bitmap);

    return 1;

}
  

int main(void)
{
    JDEC jdec;
    JRESULT res;
   
    uint8_t work[4096];

    /* 首先要打開文件 */
    /*......*/
    res=jd_prepare(&jdec,InputData,work,4096, ... );/* 根據我的實驗這個函數的最后一個參數可以不用傳 但是為了能編譯通過 隨便傳一個指針就可以了 */
   
    if(res==JDR_OK)
    {
        res=jd_decomp(&jdec,OutputData,0);
        
        if(res==JDR_OK)
        {
            /* 成功 */
        }

    }
}












分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表