打印
[应用相关]

jpeg 编码解码验证数据

[复制链接]
912|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tpgf|  楼主 | 2024-1-21 18:33 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
1. yuv420p  16×16 像素点 384字节全部数据

把上面的384个char从左到右,从上到下的顺序输入文件,就能显示红绿蓝白4个水平条





2. 256字节的亮度分量

81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,
40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,
40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,
40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,40 ,
235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,
235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,
235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,
235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,235 ,

Y 分量要8×8 分割,UV 刚好64字节不用分割

3 . 64字节的U分量

90 ,90 ,90 ,90 ,90 ,90 ,90 ,90 ,
90 ,90 ,90 ,90 ,90 ,90 ,90 ,90 ,
53 ,53 ,53 ,53 ,53 ,53 ,53 ,53 ,
53 ,53 ,53 ,53 ,53 ,53 ,53 ,53 ,
239 ,239 ,239 ,239 ,239 ,239 ,239 ,239 ,
239 ,239 ,239 ,239 ,239 ,239 ,239 ,239 ,
128 ,128 ,128 ,128 ,128 ,128 ,128 ,128 ,
128 ,128 ,128 ,128 ,128 ,128 ,128 ,128 ,
4.  64字节的V 分量

239 ,239 ,239 ,239 ,239 ,239 ,239 ,239 ,
239 ,239 ,239 ,239 ,239 ,239 ,239 ,239 ,
34 ,34 ,34 ,34 ,34 ,34 ,34 ,34 ,
34 ,34 ,34 ,34 ,34 ,34 ,34 ,34 ,
109 ,109 ,109 ,109 ,109 ,109 ,109 ,109 ,
109 ,109 ,109 ,109 ,109 ,109 ,109 ,109 ,
128 ,128 ,128 ,128 ,128 ,128 ,128 ,128 ,
128 ,128 ,128 ,128 ,128 ,128 ,128 ,128 ,
5. Y分割为4个8×8块

    y0:

81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
81 ,81 ,81 ,81 ,81 ,81 ,81 ,81 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
144 ,144 ,144 ,144 ,144 ,144 ,144 ,144 ,
144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0 ,0 ,0 ,0 ,
-136 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
369 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
-247 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
56 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
58 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
++++++++
V: 余弦变换

-4 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
204 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
413 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
262 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
-175 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
-171 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
-40 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
++++++++
==============================================================

JPEG 官方通用量化表

    unsigned char lhb0[0x45]={0xff ,0xdb ,0 ,0x43 ,0 ,
        16,11,10,16,24,40,51,61,
        12,12,14,19,26,58,60,55,
        14,13,16,24,40,57,69,56,
        14,17,22,29,51,87,80,62,
        18,22,37,56,68,109,103,77,
        24,35,55,64,81,104,113,92,
        49,64,78,87,103,121,120,101,
        72,92,95,98,112,100,103,99};

    unsigned char lhb1[0x45]={0xff,0xdb ,0 ,0x43 ,1 ,
        17,18,24,47,99,99,99,99,
        18,21,26,66,99,99,99,99,
        24,26,56,99,99,99,99,99,
        47,66,99,99,99,99,99,99,
        99,99,99,99,99,99,99,99,
        99,99,99,99,99,99,99,99,
        99,99,99,99,99,99,99,99,
        99,99,99,99,99,99,99,99
    };
    =========================================================

JPEG 官方通用霍夫曼表


    unsigned char hfm0[] = {0xff, 0xc4, 0, 0x1f, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb
    };
    unsigned char hfm1[] = { 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17,
        5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240,
        36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69,
        70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118,
        119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162,
        163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198,
        199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233,
        234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250
    };

    unsigned char hfm2[] = { 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
    };
    unsigned char hfm3[] = {255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2,
        119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177,
        193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41,
        42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101,
        102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137,
        138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179,
        180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214,
        215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249,
        250
    };
   ========================================================================= 4个Y Z排序:第一个是DC,后面是AC

(0,-7), (1,-19), (6,5), (10,-2), (0,0),
(0,-7), (1,-19), (6,5), (10,-2), (0,0),
(0,4), (1,-58), (6,17), (10,-6), (14,1), (0,0),
(0,4), (1,-58), (6,17), (10,-6), (14,1), (0,0),

U:

(0,0), (1,-16), (0,-5), (5,7), (10,-2), (0,0),

V:

(0,0), (1,11), (0,17), (5,5), (10,-1), (0,-1), (0,0),
==================================================================

    unsigned char zhen[] = {255, 192, 0, 17, 8, 0, 16, 0, 16, 3, 1, 0x22, 0, 2, 0x11, 1, 3, 0x11, 1 }; //帧头
    unsigned char sos[] = {255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0 };   //比特流开始

=====================================================================

Y,U,V比特流:

131 ,251 ,51 ,254 ,154 ,255 ,0 ,227 ,180 ,127 ,102 ,127 ,211 ,95 ,252 ,118 ,173 ,255 ,0 ,194 ,11 ,255 ,0 ,81 ,31 ,252 ,131 ,255 ,0 ,215 ,163 ,254 ,16 ,95 ,250 ,136 ,255 ,0 ,228 ,31 ,254 ,189 ,31 ,217 ,244 ,191 ,231 ,255 ,0 ,254 ,74 ,31 ,91 ,204 ,127 ,231 ,239 ,224 ,143
--------------------------------
比特流的存储顺序:先是4个Y,再是U,最后是V。

YUV420P 三分量存储顺序是:首先存全部图片的Y分量,再存全部∪分量,最后存V分量。Y分量数等于图片像数,也就是图片的长X宽。U和V的数量相同,都等于1/4 长X宽。
————————————————
版权声明:本文为CSDN博主「乐山劲松」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_59802969/article/details/135395665

使用特权

评论回复
沙发
玛尼玛尼哄| | 2024-1-23 20:40 | 只看该作者
STM32微控制器通常没有直接内置JPEG编码和解码的硬件模块,因此在STM32上实现JPEG编码和解码需要依赖软件库。一个常用的JPEG编码和解码库是libjpeg,但要在STM32上使用它,你需要确保库被适当地移植到STM32平台。

以下是一个基本的步骤,用于在STM32上实现JPEG编码和解码:

JPEG解码:
选择JPEG解码库: 选择适合STM32平台的JPEG解码库。一些流行的库包括TinyJPEG、libjpeg等。你可能需要对库进行适度的修改,以便与STM32的体系结构和工具链兼容。

配置I/O和内存: 根据你的应用场景配置JPEG解码库的输入输出(I/O)接口以及内存缓冲区。JPEG解码过程中需要从文件或其他来源读取JPEG图像数据。

解码JPEG图像: 使用JPEG解码库对JPEG图像进行解码。此过程将JPEG压缩的图像数据转换为位图或RGB数据。

显示图像: 将解码后的图像数据显示在你的STM32应用程序中,可以使用LCD、HDMI或其他适当的显示设备。

使用特权

评论回复
板凳
玛尼玛尼哄| | 2024-1-23 20:40 | 只看该作者
JPEG编码:
选择JPEG编码库: 选择适合STM32平台的JPEG编码库。同样,libjpeg是一个常用的选择。

配置I/O和内存: 根据你的应用场景配置JPEG编码库的输入输出(I/O)接口以及内存缓冲区。JPEG编码过程中需要将位图或RGB数据提供给编码库。

编码RGB图像: 使用JPEG编码库对RGB图像进行编码。此过程将RGB数据压缩为JPEG格式。

保存JPEG图像: 将编码后的JPEG数据保存到文件或其他存储设备。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1975

主题

15764

帖子

12

粉丝