Is the 2nd and 3rd byte of a JPEG image always the APP0 or APP1 marker?

前端 未结 8 943
失恋的感觉
失恋的感觉 2020-12-10 17:18

I have a few different JPEG images I\'ve been testing with. As far as I\'ve seen the 0th and first bytes are always 0xFF and 0xD8.

The s

相关标签:
8条回答
  • 2020-12-10 17:27

    In theory, yes. According to the JFIF spec (pdf), its APP0 section should come first in the file. And the Exif spec (pdf) requires the same for its APP1 section.

    But you shouldn't count on the order (or even the existance of) APPn sections; there are crazy JPEG writers out there. Start with the SOI and read the sections as they come by.

    0 讨论(0)
  • 2020-12-10 17:28

    For a JFIF file, a JFIF header should follow immediately after FFD8. The JFIF header is contained within an APP0 marker. The specification doesn't say anything about padding though.

    Without the JFIF header we can only guess what color format is used.

    0 讨论(0)
  • 2020-12-10 17:34

    Those first two bytes are the JPEG SOI marker so are always present.

    The 2nd and 3rd bytes appear to store meta data, which probably isn't present in every JPEG.

    Further Reading.

    0 讨论(0)
  • 2020-12-10 17:37

    Typically yes, however my understanding of JPEG is that any segment type can follow the header.

    0 讨论(0)
  • 2020-12-10 17:38

    No. There are e.g. several cameras that create JPEGs without these markers, or with other APP markers. The only thing you can rely on is the SOI sequence, FF D8, not even EOI is produced by all cameras. Also be aware that JPEGs with embedded JPEGs exist - you can have nested SOI/EOI within an image.

    If you need to deal with embedded JPEG data in raw camera images, several models produce JPEG-like data that can only be parsed by being a bit slack with the jpeg spec - especially in relation to escaped FF bytes in data. And then you have cameras that produce proprietary data that at first glance looks like jpeg data (e.g. some of Sony's "encrypted" raw formats)

    0 讨论(0)
  • 2020-12-10 17:38

    No. There are programs that remove some markers. ImageOptim is such a program. You only need some of the markers. This program will also optimise the huffman tables

    0 讨论(0)
提交回复
热议问题