PreviewImage tag in Sony's MakerNote - tag 0x2001

Started by drcq, December 29, 2024, 01:20:42 PM

Previous topic - Next topic

drcq

I investigated the PreviewImage tag for a lot of Sony cameras (DSC-RX100M7, DSLR-, ILCE-, ILCA-,NEX-, SLT-) and found out, that all models follow the same schema. The implementation is different for cameras with and without MP-images only. In my opinion the ExifTool documentation could be simplified.

Take a look at DSLR-A200 (JPG-format):
  • MP-Image is not available (APP2 segment is not available in the main image)
  • MakerNote contains the PreviewImage tag (0x2001) with length of 0x0a97ae and offset of 0x30f77f, the related address value is 0x308003
  • The (32 bytes long) image info block located at this address provides the image length of 0x0a978e and image size values 1616 and 1080 stored as TIFF long values.
  • The first item behind this info block contains the 0x00, 0xd8 byte values
This is the crucial point! Just replace the 0x00 with 0xff and we have the SOI (start-of-image) marker. The length value fits exactly with the EOI marker. Starting at PreviewImage address + 0x20 bytes for the info block, we have our JPG Preview image.
The content of this image is shown below.
JPEG DQT (130 bytes):
JPEG DHT (416 bytes):
JPEG SOF0 (15 bytes):
  ImageWidth = 1616
  ImageHeight = 1080
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
  YCbCrSubSampling = 2 1
JPEG SOS


To understand, why Sony is writing 0x00d8 instead of 0xffd8, we must look at an image with MP-Image inside.

Take a look at DSLR-A380 image (JPG-format):
  • MP Image (specified with APP2 segment) is located at 0x750005 with length of 0x00128a90
  • MakerNote contains the PreviewImage tag with length of 0x00128a22 at address 0x00750073
  • The image info block defines the image length with 0x00128a02 and size of 1616 x 1080
  • The crucial marker with 0x00d8 is located at 0x00750093

Now we must look at the MP image layout shown below.

MPImage-layout.png

The image info block is located between the MakerNote IFD and the DQT segment of the MP image. The JPG reader for the MP Image will skip the preview image block while processing the APP1 segment (0x750007 + 0x00000c + 2 = 0x750095). So we can process and save the PreviewImage content using the MP tags only (address and length). This APP1 segment contains 3 IFD's (see next picture below). Using 0x00d8 instead of 0xffd8 is avoiding errors with JPG-reader searching the binary data for JPG markers (always starting with 0xff!)

But Sony also supports saving of the PreviewImage content as a plain JPG. Just replace the 0x00d8 with 0xffd8 behind the image info block and store the next 0x00128a02 bytes.

MPImage-tags.png

One point is still unclear to me! The MakerNote IFD of the MP Image contains also the PreviewImage tag (0x2001) but specifying the wrong address!

Phil Harvey

I'm not clear on how you think ExifTool could be improved.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

drcq

Hi Phil,

just update the notes, that the preview image starts directly behind the 32 byte info block and 0x00d8 value should be interpreted as 0xffd8 (SOI marker). The current info is a little bit confusing.

        # DSLR-A230/A290/A330/A380/A390:
        # - PreviewImage start-offset is at 110 bytes inside MPImage2
        # DSLR-A450/A500/A550/A560/A580, SLT-A33/A35/A55V, NEX-3/5/5C/C3/VG10/VG10E:
        # - PreviewImage start-offset is at 106 bytes inside MPImage2
        # - different first bytes after 32-byte header
        # SLT-A37/A57/A58/A65V/A77V/A99V, ILCA-77M2, NEX-3N/5N/5R/5T/6/7/F3, ILCE-3000/3500/5000/6000/7/7R/7S:
        # - PreviewImage start-offset is at 130 bytes inside MPImage2

The preview image start-offset is always directly behind the info block and isn't dependent on the camera type.

Regards,
Christoph

Phil Harvey

Hi Christoph,

Thanks for explaining, but I think the comments may be correct, but seeminly misleading.

I think the PreviewImage data exists in the MPImage2 trailer at the specified offset within this trailer.  The pointer for tag 0x2001 points into the MPImage2 trailer, at an offset of 32 bytes before the start of the image.

And you are correct, the first byte of the image may not be 0xff as it should be, but this is mentioned in the comments, at least for some models.

BTW, these comments are by Jos Roost, who has done much of the Sony decoding.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

drcq

Hi Phil,

First of all - Happy New Year 2025!

Thanks for your fast response. I don't like to appear stubborn, but the first DLSR cameras (like A350 and A200) released in the beginning of 2008 use already PreviewImage tag without the MP-image support. The PreviewImage tag points to the 32-bit block (with image length and dimension values) and the image starts directly behind the info block with 0x00d8.

With the DSLR-A550 and A380 cameras (released in 2009) we got MP support. In my opinion, Sony decided to introduce APP2-MPF support while still keeping the PreviewImage solution of the earlier cameras. If you look at my pictures above, you can see that the PreviewImage and the MP2-Image have the same binary content. The difference is, that the MP-Image starts with an APP1-Exif segment. The SonyIFD content located in this APP1-Exif segment ends at 0x00750072 and the info block starts directly behind at 0x00750073. The DQT segment at 0x00750095 is used by both "images": MP image and Preview image.

So you are right, the PreviewImage points to the APP1-Exif segment trailer of the MP-Image. But I'm impressed about the way, how Sony implemented this "additional entry" into the MP-Image.

All the best for 2025!
Christoph