在数据流的最开始,我应该期待JPEG SOI标记吗? [英] Should I expect JPEG SOI marker at very beginning of the data stream?

查看:310
本文介绍了在数据流的最开始,我应该期待JPEG SOI标记吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...或者我应该更深入地寻找 0xFF 0xD8 序列的数据流?

... or should I go deeper into the data stream looking for 0xFF 0xD8 sequence?

来自这个问题,我已经了解了APPn没有立即关注SOI的内容。是否有符合规范的JPEG案例,SOI位置!=流的开头?

From this Q, I've learned what APPn does not have to follow SOI immediately. Are there specification compliant JPEG cases where SOI position != beginning of the stream?

规范引用(附件B) ,§1.1.2):

A quote from the specification (Annex B, § 1.1.2):


标记用于识别
压缩数据格式的各种结构部分。大多数标记开始包含
相关参数组的标记段;一些标记独立。所有标记
都分配了两个字节的代码:一个X'FF'字节后跟一个字节,即
不等于0或X'FF'(见表B.1)。任何标记可以选择是
,前面是任意数量的填充字节,这些字节分配代码
X'FF'。

Markers serve to identify the various structural parts of the compressed data formats. Most markers start marker segments containing a related group of parameters; some markers stand alone. All markers are assigned two-byte codes: an X’FF’ byte followed by a byte which is not equal to 0 or X’FF’ (see Table B.1). Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code X’FF’.


推荐答案

libjpeg 在SOI之前不允许垃圾:

libjpeg does not allow garbage before the SOI:

/* Like next_marker, but used to obtain the initial SOI marker. */
/* For this marker, we do not allow preceding garbage or fill; otherwise,
* we might well scan an entire input file before realizing it ain't JPEG.
* If an application wants to process non-JFIF files, it must seek to the
* SOI before calling the JPEG library.
*/

来自:随机libjpeg镜像

例如 go 实施也不允许先前的垃圾。

E.g. the go implementation also does not allow preceding garbage.

然而,如果有疑问,坚持Postel定律:

However, if in doubt, stick to Postel's Law:


在接受的内容中保持宽松,在发送的内容中保守一些

Be liberal in what you accept, and conservative in what you send

虽然,你不想过于自由,或者你最终可能不会从流中提取实际的JPEG,而是提取嵌入的EXIF缩略图或类似的东西。

Although, you don't want to be too liberal, or you might end up extracting not the actual JPEG from the stream but the embedded EXIF thumbnail or something like that.

这篇关于在数据流的最开始,我应该期待JPEG SOI标记吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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