硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4531|回复: 1
收起左侧

[LibJPEG] 【LibJPEG专题系列二十二】提取图像大小

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-5-18 17:13:46 | 显示全部楼层 |阅读模式
              Section - [22] How can my program extract
                    image dimensions from a JPEGfile?

The header of a JPEG file consists of a series of blocks, called "markers". The image height and width are stored
in a marker of type SOFn (Start Of Frame, type N).  To find the SOFn you must skip over the preceding markers;
you don't have to know what's in the other types of markers, just use their length words to skip over them.  The
minimum logic needed is perhaps a page of C code.  (Some people have recommended just searching for the byte
pair representing SOFn, without paying attention to the marker block structure. This is unsafe because a prior
marker might contain the SOFn pattern, either by chance or because it contains a JPEG-compressed thumbnail
image.  If you don't follow the marker structure you will retrieve the thumbnail's size instead of the main image
size.)  A profusely commented example in C can be found in rdjpgcom.c in the IJG distribution (see part 2, item
15).  Perl code can be found in wwwis, from http://www.tardis.ed.ac.uk/~ark/wwwis/.
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-5-18 17:14:58 | 显示全部楼层
                                   Section 22—提取图像尺寸

        JPEG文件的头文件包含一系列的块,被称为“标记”( markers)。图像的高度和宽度都存储在SOFn
类型(帧图像开始,N型)标记。为了找到SOFn必须跳过前面的标记;你不必知道其他类型的标记包含什么,
只需要使用它们的length words来跳过即可。所需的最低的逻辑也许只是一页C代码。(一些人曾建议只要搜
索一对一对的字节来表示SOFn,而不用把注意力放在块结构化标记上。但这是不保险的,因为以前的标记可
能包含SOFn模式,无论是偶然还是因为它包含了一个JPEG压缩的缩略图。如果不遵循标记结构,你检索的
将是缩略图的大小而非主图像的大小。)在IJG分区(part 2, item 15)的rdjpgcom.c中可以找到很多注释过
的例子。在wwwis中可找到Perl代码,可见于http://www.tardis.ed.ac.uk/~ark/wwwis/
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-12 06:57 , Processed in 0.142348 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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