JPEG文件结构

JPEG文件根据不同的标记将文件分成不同的标记段,解析方式与dicom文件类似。
每个tag固定为2个byte
每个标记之前可以填充数目不限的0xFF

主要的标记(marker)如下表
markermarker名称含义
0xFFD8SOI图像开始(Start of Image)
0xFFD9EOI图像结束(End of Image)
0xFFC0SOF0帧开始(Start of Frame 0)
0xFFC4DHT霍夫曼(Huffman)表
0xFFDASOS扫描线开始
0xFFDBDQT量化表
0xFFE0APP0JFIF(JPEG File Interchange Format)应用数据块
0xFFE1~0xFFEFAPPn其它的应用数据块(n, 1~15)
比较详细的标记列表
0xFFC0 ~ 0xFFCF
标记代码(Code Assignment)符号(Symbol)描述(Description)
Start of Frame markers, none-hierarchical Huffman coding
0xFFC0SOF0BaseLine DCT(离散余弦变换,Discrete Cosine Transform)
0xFFC1SOF1Extended sequential DCT
0xFFC2SOF2Progressive DCT
0xFFC3SOF3Spatial (sequential) lossless
Huffman table specification
0xFFC4DHTDefine Huffman tables(s)
Start of Frame markers, hierarchical Huffman coding
0xFFC5SOF5Differential sequential DCT
0xFFC6SOF6Differential progressive DCT
0xFFC7SOF7Differential spatial lossless
arithmetic coding conditioning specification
0xFFCCDACDefine arithmetic conditioning table
Start of Frame markers, hierarchical arithmetic
0xFFCDSOF13Differential sequential DCT
0xFFCESOF14Differential progressive DCT
0xFFCFSOF15Differential spatial Lossless
0xFFD0 ~ 0xFFDF
标记代码(Code Assignment)符号(Symbol)描述(Description)
Restart of interval termination
0xFFD0~0xFFD7RSTmRestart with modulo 8 counter m
Other marker
0xFFD8SOIStart of image
0xFFD9EOIEnd of image
0xFFDASOSStart of scan
0xFFDBDQTDefine quantization table(s)
0xFFDCDNLDefine number of lines
0xFFDDDRIDefine restart interval
0xFFDEDHPDefine hierarchical progression
0xFFDFEXPExpand reference image(s)
0xFFE0 ~ 0xFFEF
标记代码(Code Assignment)符号(Symbol)描述(Description)
0xFFE0~0xFFEFAPPnReserved for application use
0xFFF0 ~ 0xFFFE
标记代码(Code Assignment)符号(Symbol)描述(Description)
0xFFF0~0xFFFDJPGnReserved for JPEG extension
0xFFFECOMComment
Reserved markers
标记代码(Code Assignment)符号(Symbol)描述(Description)
0xFF01TEMFor remporary use in arithmetic coding
0xFF02~0XFFBFRESReserved
主要标记域的结构

每个标记域的结构轮廓一致如下

markersizedata
2bytes2bytes,表示当前标记域 size和data两项共占用的字节数当前标记域的数据,具体结构划分根据marker的不同进行不同的划分,长度为(size-2)bytes
###### APP0域(标记为0xFFE0)的详细结构
长度块的名称说明
2bytesAPP0(JFIF application segment)JFIF应用数据块
2byteslength of APP0 blockAPP0块的长度
5bytes"JFIF"+"0"识别APP0标记
1byteMajor version主要版本号(如版本1.02中的1)
1byteMinor version次要版本号(如版本1.02中的02)
1byteUnits for the X and Y densitiesX和Y的密度单位 units=0:无单位 units=1:点数/英寸 units=2:点数/厘米
2bytesX density水平方向像素密度
2bytesY density竖直方向像素密度
1byteX thumbnail缩略图水平像素数目
1byteY thumbnail缩略图竖直像素数目
3nThumbnail RGB bitmap缩略RGB位图(n为缩略图的像素数)
Optional JFIF extension APP0 marker segment(s)任选的JFIF扩展APP0标记段
......
APP1域(标记为0xFFE1)的详细结构
长度块的名称说明
2bytesAPP1APP1标记
2byteslength of APP1 blockAPP1块的长度
6bytes"EXIF"+"00"识别APP1标记
8bytesTIFF HeaderTIFF头信息
IFD0 Image File Directory1. IFD0(main image):Directory / Link to IFD1
2. Data area of IFD0
Exif SubIFD1. Exif SubIFD: Directory / End of link
2. Data area of IFD0
IFD1 Image File Directory1. IFD1(thumbnail image): directory / End of link
2. Data area of IFD1
Thumbnail image缩略图,可能为JPEG格式存储,也可能为TIFF格式存储
TIFF Header的详细结构
长度说明
2bytesByte align "II"或"MM"
字节顺序:II(Intel字节序)表示小端存储,MM(Motorola字节序)表示大端存储
2bytesTag Mark 0x2a00或0x002a
验证字节顺序:如果为小端(II),则为0x2a00,如果为大端 (MM),则为0x002a
4bytesOffset to first IFD
到IFD0的偏移,偏移起始位置为TIFFHeader的位置
APP1段中IFD0,Exif SubIFD, IFD1的偏移都以TIFFHeader的位置作为起始位置
Image File Directory的结构

每个IFD中包含多个Directory Entry,每个Entry记录图片的一条属性信息。

长度含义
2bytesDirectory Entry数量
12bytesDirectory Entry0
12bytesDirectory Entry1
......
12bytesDirectory EntryN
4bytesOffset to next IFD
Directory Entry Data Area(存储Directory EntEntry对应的值)
Directory Entry的结构
2bytes2bytes4bytes4bytes
Exif Tag(表示当前Entry记录的信息含义)Component Type(存储元素的数据类型)Component Count(存储元素的数量)存储值小于等于4bytes,则为对应值,大于4bytes,则为基于TIFF Header的偏移量
Component Type
Component Type ValueFormatbytes
1Unsigned Byte1
2Ascii String1
3Unsigned Short2
4Unsigned Long4
5Unsigned rational8
6Signed Byte1
7Undefined1
8Signed Short2
9Signed Long4
10Signed Rational8
11Single Float4
12Double Float8
Exif Tag含义举例
Tag IDTag Name
0x0100ImageWidth
0x0101ImageHeight
......

更多Exif Tag含义可查阅
https://exiftool.org/TagNames/EXIF.html

参考文章:

  1. Exif Tags
  2. JPEG文件格式解析(一) Exif 与 JFIF
  3. JPEG图像编码标准-共86页文档
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值