JPEG头文件结构及组成

2018-11-25

最近在做关于图片显示方面的嵌入式程序.发现国内这方面资料介绍得还是比较少的,所以发表在这里.

Before the image data is ever loaded when a JPEG image is selected for viewing the markers must be read.  In a JPEG image, the very first marker is the SOI, or Start Of Image, marker.  This is the first "hey, I"m a JPEG" declaration by the file.  The JPEG standard, as written by the Joint Picture Expert"s Group, specified the JPEG interchange format.  This format had several shortcomings for which the JFIF (JPEG File Interchange Format) was an attempted remedy.  The JFIF is the format used by almost all JPEG file readers/writers.  It tells the image readers, "Hey, I"m a JPEG that almost anyone can understand."

Most markers will have additional information following them.  When this is the case, the marker and its associated information is referred to as a "header."   In a header the marker is immediately followed by two bytes that indicate the length of the information, in bytes, that the header contains.  The two bytes that indicate the length are always included in that count.

A marker is prefixed by FF (hexadecimal).  The marker/header information that follows does not specify all known markers, just the essential ones for baseline JPEG.

A component is a specific color channel in an image.  For instance, an RGB image contains three components; Red, Green, and Blue.

1998 by James R. Weeks

Start of Image (SOI) marker -- two bytes (FFD8)

JFIF marker (FFE0)

length -- two bytes

identifier -- five bytes: 4A, 46, 49, 46, 00 (the ASCII code equivalent of a zero terminated "JFIF" string)

version -- two bytes: often 01, 02

the most significant byte is used for major revisions

the least significant byte for minor revisions

units -- one byte: Units for the X and Y densities

0 => no units, X and Y specify the pixel aspect ratio

1 => X and Y are dots per inch

2 => X and Y are dots per cm

Xdensity -- two bytes

Ydensity -- two bytes

Xthumbnail -- one byte: 0 = no thumbnail

Ythumbnail -- one byte: 0 = no thumbnail

(RGB)n -- 3n bytes: packed (24-bit) RGB values for the thumbnail pixels, n = Xthumbnail * Ythumbnail

Define Quantization table marker (FFDB)

the first two bytes, the length, after the marker indicate the number of bytes, including the two length bytes, that this header contains

until the length is exhausted (loads two quantization tables for baseline JPEG)

the precision and the quantization table index -- one byte: precision is specified by the higher four bits and index is specified by the lower four bits

precision in this case is either 0 or 1 and indicates the precision of the quantized values; 8-bit (baseline) for 0 and  up to 16-bit for 1

the quantization values -- 64 bytes

the quantization tables are stored in zigzag format

Define Huffman table marker (FFC4)

the first two bytes, the length, after the marker indicate the number of bytes, including the two length bytes, that this header contains

until length is exhausted (usually four Huffman tables)

index -- one byte: if >15 (i.e. 0x10 or more) then an AC table, otherwise a DC table

bits -- 16 bytes

Huffman values -- # of bytes = the sum of the previous 16 bytes

Start of frame marker (FFC0)

the first two bytes, the length, after the marker indicate the number of bytes, including the two length bytes, that this header contains

P -- one byte: sample precision in bits (usually 8, for baseline JPEG)

Y -- two bytes

X -- two bytes

Nf -- one byte: the number of components in the image

3 for color baseline JPEG images

1 for grayscale baseline JPEG images

Nf times:

Component ID -- one byte

H and V sampling factors -- one byte: H is first four bits and V is second four bits

Quantization table number-- one byte

The H and V sampling factors dictate the final size of the component they are associated with. For instance, the color space defaults to YCbCr and the H and V sampling factors for each component, Y, Cb, and Cr, default to 2, 1, and 1, respectively (2 for both H and V of the Y component, etc.) in the Jpeg-6a library by the Independent Jpeg Group. While this does mean that the Y component will be twice the size of the other two components--giving it a higher resolution, the lower resolution components are quartered in size during compression in order to achieve this difference. Thus, the Cb and Cr components must be quadrupled in size during decompression.

Start of Scan marker (FFDA)

the first two bytes, the length, after the marker indicate the number of bytes, including the two length bytes, that this header contains

Number of components, n -- one byte: the number of components in this scan

n times:

Component ID -- one byte

DC and AC table numbers -- one byte: DC # is first four bits and AC # is last four bits

Ss -- one byte

Se -- one byte

Ah and Al -- one byte

Comment marker (FFFE)

the first two bytes, the length, after the marker indicate the number of bytes, including the two length bytes, that this header contains

whatever the user wants

End of Image (EOI) marker (FFD9)

the very last marker

JPEG文件由八个部分组成,每个部分的标记字节为两个,首字节固定为:0xFF,当然,准许在其前面再填充多个0xFF,以最后一个为准。下面为各部分的名称和第二个标记字节的数值,用ultraedit的16进制搜索功能可找到各部分的起始位置,在嵌入式系统中可用类似的数值匹配法定位。

一、图像开始SOI(Start of Image)标记,数值0xD8

二、APP0标记(Marker),数值0xE0

1、APP0长度(length)                            2byte

2、标识符(identifier)                     5byte

3、版本号(version)                        2byte

4、X和Y的密度单位(units=0:无单位;units=1:点数/英寸;units=2:点数/厘米)                        1byte

5、X方向像素密度(X density)                      2byte

6、Y方向像素密度(Y density)                       2byte

7、缩略图水平像素数目(thumbnail horizontal pixels)                       1byte

8、缩略图垂直像素数目(thumbnail vertical pixels)                            1byte

9、缩略图RGB位图(thumbnail RGB bitmap),由前面的数值决定,取值3n,n为缩略图总像素   3n byte

三、APPn标记(Markers),其中n=1~15,数值对应0xE1~0xEF

1、APPn长度(length)

2、应用细节信息(application specific information)

四、一个或者多个量化表DQT(difine quantization table),数值0xDB

1、量化表长度(quantization table length)

2、量化表数目(quantization table number)

3、量化表(quantization table)

五、帧图像开始SOF0(Start of Frame),数值0xC0

1、帧开始长度(start of frame length)

2、精度(precision),每个颜色分量每个像素的位数(bits per pixel per color component)

3、图像高度(image height)

4、图像宽度(image width)

5、颜色分量数(number of color components)

6、对每个颜色分量(for each component)

包括:ID、垂直方向的样本因子(vertical sample factor)、水平方向的样本因子(horizontal sample factor) 、量化表号(quantization table#)

六、一个或者多个霍夫曼表DHT(Difine Huffman Table),数值0xC4

1、霍夫曼表的长度(Huffman table length)

2、类型、AC或者DC(Type, AC or DC)

3、索引(Index)

4、位表(bits table)

5、值表(value table)

七、扫描开始SOS(Start of Scan),数值0xDA

1、扫描开始长度(start of scan length)

2、颜色分量数(number of color components)

3、每个颜色分量

包括:ID、交流系数表号(AC table #)、直流系数表号(DC table #)

4、压缩图像数据(compressed image data)

八、图像结束EOI(End of Image),数值0xD9

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。

http://www.pinlue.com/style/images/nopic.gif

major头文件_JPEG头文件结构及组成相关推荐

  1. #include sys/xxx.h头文件 UNIX头文件

    原文地址:#include sys/xxx.h头文件 UNIX头文件 作者:embededgood #include sys/xxx.h是Linux系统中的系统头文件 应用程序的头文件在/usr/in ...

  2. string类 string.h头文件 cstring头文件区别以及读取一行字符串总结

    以前一直分不清string类  string.h头文件 cstring头文件的去别,今天ce了一发才稍微弄懂了. 首先C语言中只有string.h头文件,string.h包含了一些字符数组和字符串的函 ...

  3. python编程头文件_python头文件怎么写

    本文主要以python2为例.首先介绍一下Python头文件的编程风格,然后再给大家详细介绍import部分的基本用法.这两个部分就是Python中头文件的组成模块. 编程风格#!/usr/bin/e ...

  4. python编程头文件_python头文件的编程风格

    python头文件的编程风格 发布时间:2020-09-03 10:23:25 来源:亿速云 阅读:96 作者:小新 小编给大家分享一下python头文件的编程风格,希望大家阅读完这篇文章后大所收获, ...

  5. linux 常用头文件,(常用头文件详解.doc

    (常用头文件详解 linux常用头文件详解 POSIX标准定义的头文件??????? 目录项 ???????? 文件控制 ??? 文件名匹配类型 ??? 路径名模式匹配类型 ??????? 组文件 ? ...

  6. cstring头文件(cstring头文件)

    头文件有什么样的作用呢? (eg.C++编译模式[1])从以上结构图来看,头文件是用户应用程序和函数库之间的桥梁和纽带 CStringW是什么啊?和CString有什么不同? CStringW是CSt ...

  7. HTML展开头文件,html头文件css的写法

    html头文件css的写法 发布时间:2021-02-12 18:08:59 来源:亿速云 阅读:103 作者:小新 小编给大家分享一下html头文件css的写法,相信大部分人都还不怎么了解,因此分享 ...

  8. java生成.h头文件_javah头文件生成器

    javah头文件生成器 javah程序创建C头文件和存根文件,这些是把本地C成员函数包入java 所需要的.被创建的头文件给出了有关java类的信息,这些信息是C成员函数与java类交换数据所必需的. ...

  9. 链表的c语言头文件,链表头文件C语言

    因为眼前有个例程要使用链表,索性写了一个链表,纯洁的链表其实写得很少.写了一次,感觉又是受益匪浅. /* linked_list.h -- 链表头文件 */ /* 数据类型定义 */ typedef ...

最新文章

  1. linux网络编程IPv6socket,简单的IPv6 UDP/TCP socket编程 -- 两台Linux实现简单的ipv6通信...
  2. sql移动加权计算利润_计算机视觉中的半监督学习
  3. mysql操作数据库的步骤,Golang操作MySql数据库的完整步骤记录
  4. C++中内存分配方式、空指针及野指针的区别
  5. 认真,respect!
  6. Zookeeper案例之监听配置中心
  7. 20220626-JAVA高德地图天气API调用总结
  8. 模拟cmos集成电路 第二版 razavi
  9. 桌面级显卡天梯图(显卡性能对比图.2018.11)
  10. 企业预算管理实践:小故事大道理
  11. 游戏开发19课 tilemap 创建瓦片
  12. Jason Brown的R快速入门方法
  13. windows下更改Apache以fastcgi方式运行php
  14. Linux修改网卡配置
  15. Markdown语法-从基础到进阶
  16. linux下mysql写中文变成问号_如何解决数据库插入中文字体时显示问号
  17. 用 Python 写个计算器
  18. 一文搞定设计模式!五万字超详细解析!带着耐心点进来!
  19. 远程视频会议系统/视频调度指挥平台/音视频通话系统EasyRTC在应急指挥领域中的应用
  20. 高德地图API——信息窗体InfoWindow

热门文章

  1. EF optimize the perfermance
  2. 《那些年啊,那些事——一个程序员的奋斗史》——76
  3. Html5相关文章链接
  4. 别让扁平化设计平淡无奇
  5. 家长会PPT教师的福利模板
  6. Linux学习之用户管理和组管理
  7. 设置让php能够以root权限来执行exec() 或者 shell_exec()
  8. 【262】pscp命令 实现windows与linux互传文件
  9. 通过×××路由器实现跨网段访问
  10. 【云上ELK系列】Logstash迁移Elasticsearch数据方法解读