解析JPEG SOS标记 [英] Parsing JPEG SOS Marker

查看:242
本文介绍了解析JPEG SOS标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个标题相同的问题,但不幸的是,它没有帮助我.

There is a question with the same title but unfortunatly it doesn't help me.

我正在尝试解析SOS标记的数据.我能找到的所有文档都说,在标记(0xFFDA)之后是两个字节的数字,该数字定义了此段的长度-例如此处-与大多数可变尺寸标记一样.但在这种情况下,我似乎无法正确理解.它适用于所有其他标记类型.

I am trying to parse the data of a SOS marker. All documentations I can find say that after the marker (0xFFDA) a two byte number follows which defines how long this segment is -- for example here -- as with most variable size markers. But I seem not to understand it correctly in this case. It works for every other marker type.

我检查了多个文件,但无法正确执行此操作.这个数字不是在定义完整的SOS字段多长时间吗?因此,对于基线JPEG,应至少有一个SOS段,此后应跟随图像结束"标记.如果它是渐进式的,则可以有多个SOS段,但所有段都应有一个length字段.

I checked multiple files but just can't get this right. Is this number not defining how long the complete SOS field is? So for a baseline JPEG there should be exaclty one SOS segment and after this should the End Of Image marker follow. If it is progressive there can be multiple SOS segments but still all should have a length field.

我有一幅带有SOF0标记的图片,因此它应该是基线.我相信这是正确的SOFn标记,因为可以在该标记之后找到图像分辨率.使用十六进制编辑器,我发现了3个0xFFDA标记,并且它们在接下来的2个字节中都具有0x000C.因此,据我所知,该段应始终为12字节长.但是在所有3种情况下,在12个字节的数据之后都没有新的标记.我猜最后一个是我要查找的扫描,因为如果出现0xFF值,它后面便是0x00 -重设标记除外.

I have one picture with a SOF0 Marker so it should be baseline. I believe that this is the correct SOFn marker because the image resolution can be found after that marker. With a hex editor I have found 3 0xFFDA marker and all of them have 0x000C in the following 2 bytes. So that segment, as I understand it, should always be 12 Byte long. But in all 3 cases no new marker is following after 12 byte of data. I guess the very last one is the scan I am looking for because if the value 0xFF comes up it is followed by 0x00 -- except the reset markers.

0xFFDA之后的那两个字节不是长度字段吗?

Are those two byte following 0xFFDA not the length fields?

因此,由于有了注释和回答,实际的压缩数据似乎没有长度字段,只有知道其结尾的方法似乎正在对它进行解码.

So thanks to the comments and answer there seems to be no length field for the actual compressed data and only way to know where it ends seems to be decoding it.

为什么基线DCT图像会进行多次扫描?我会理解为什么它有两个;为什么?主图像和缩略图,但是第三次​​扫描是什么?

Why does a Baseline DCT Image have multiple scans? I would understand why it has two; the main image and a thumbnail, but what is the third scan?

但是还有一件事.根据DRI标记(定义重新启动间隔),它包含一个值,在此值之后,扫描应具有重新启动标记0xFFD0 - 0xFFD7.但是我似乎也误会了这一点,或者我做错了.例如,标记包含值0x0140作为重新启动间隔.在下面的扫描中,我从头开始,搜索了第一个0xFFD0,但是它是在862个字节而不是320个字节之后出现的.

But there is one more thing. According to DRI Marker (Define Restart Interval) it contains the value after which a Scan should have a restart marker 0xFFD0 - 0xFFD7. But I seem to misunderstand that too or I'm not doing it right. For example a marker contained the value 0x0140 as restart interval. In the following Scan I started from the beginning and searched for the first 0xFFD0 but it came after 862 bytes instead of 320.

推荐答案

SOS标记包含压缩数据. JPEG流中最复杂的部分. SOFn标记指示数据的格式. SOF0和SOF1的处理方式相同. SOF2(渐进式)有很大的不同. (读取SOFn标记并不常用,也不普遍支持.)

The SOS marker contains the compressed data; the most complex part of the JPEG stream. The SOFn marker indicates the format of the data. SOF0 and SOF1 are processed identically. SOF2 (progressive) is quite a bit different. (The read of the SOFn markers are not in common use or commonly supported).

长度是SOS标头的长度,而不是压缩数据的长度.大多数标题仅适用于渐进式扫描(SOF2).

The length is that of the SOS header, not the compressed data. Most of the header is only applicable to progressive scans (SOF2).

压缩后的数据跟随标题.压缩后的数据没有长度.您必须浏览数据以找到下一个标记.

The compressed data follows the header. The compressed data has no length. You have to scan through the data to find the next marker.

这篇关于解析JPEG SOS标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆