ExifTool Forum

General => Metadata => Topic started by: blue-j on March 13, 2024, 07:48:22 PM

Title: EXR embedded preview
Post by: blue-j on March 13, 2024, 07:48:22 PM
I've been trying to extract embedded previews in EXR files without joy.  Has anyone had success?

I've been working with the test images provided by OpenEXR:
https://openexr.com/en/latest/_test_images/index.html#test-images (https://openexr.com/en/latest/_test_images/index.html#test-images)

This one specifically, which ExifTool reports as having a binary preview:
https://openexr.com/en/latest/_test_images/Tiles/GoldenGate.html (https://openexr.com/en/latest/_test_images/Tiles/GoldenGate.html)

(I have tested with others as well.)  I get an export, but it is not a valid image type of any sort.

- J

 
Title: Re: EXR embedded preview
Post by: StarGeek on March 14, 2024, 11:04:35 AM
Hmmm... Exiftool says the Preview contains 27,208 bytes, but the extracted data is only 69 bytes long.  And there are a lot of NUL characters.  But looking at the Preview with -v4 doesn't show hardly any NULs.  Though I don't know how it is actually encoded, as every fourth byte is 0x7f, which lead me to StackOverflow question (https://stackoverflow.com/questions/50764797/).

In other words, I don't have a clue :D
Title: Re: EXR embedded preview
Post by: greybeard on March 14, 2024, 11:23:13 AM
Quote from: StarGeek on March 14, 2024, 11:04:35 AMHmmm... Exiftool says the Preview contains 27,208 bytes, but the extracted data is only 69 bytes long.  And there are a lot of NUL characters.  But looking at the Preview with -v4 doesn't show hardly any NULs.  Though I don't know how it is actually encoded, as every fourth byte is 0x7f, which lead me to StackOverflow question (https://stackoverflow.com/questions/50764797/).

In other words, I don't have a clue :D

I think the 7F is just part of the floating point numbers that describe the preview image
Title: Re: EXR embedded preview
Post by: blue-j on March 18, 2024, 05:18:41 PM
This is the source code, FWIW:

https://github.com/AcademySoftwareFoundation/openexr/blob/main/src/bin/exrmakepreview/makePreview.cpp
 (https://github.com/AcademySoftwareFoundation/openexr/blob/main/src/bin/exrmakepreview/makePreview.cpp)
GPT-4 says this:

"The preview image in an OpenEXR file, as created by the code snippet you've provided, is indeed a binary object, but it's not stored in a standalone file format like JPEG or PNG. Instead, it's embedded directly within the OpenEXR file as a part of the file's header. The preview image is an array of binary data that represents a simple, low-resolution version of the main image, intended to be used as a thumbnail or a quick preview.

Each pixel in this preview is represented by the PreviewRgba structure, which suggests that each pixel is stored as a sequence of four bytes, corresponding to the red, green, blue, and alpha (transparency) channels of the image. This format is quite straightforward and does not adhere to any external or complex file format specifications. Instead, it is a simple, uncompressed, straight-to-the-point representation of pixel data designed for ease of access and minimal processing.

The key characteristics of the binary preview image in OpenEXR can be summarized as follows:

Embedded Directly in EXR File: The preview image is stored within the EXR file's header, not as a separate file.

Simple Binary Format: Each pixel is encoded in a basic RGBA format, with each channel typically represented by one byte.

No External Format Adherence: The preview does not conform to standalone image file formats like JPEG or PNG. It is designed to be a part of the EXR file structure.

Purpose: The primary purpose of this preview image is to provide a quick and easily accessible visual representation of the content, useful for viewing in file browsers or editing software that can parse EXR headers.

To extract and use this preview, one would need to read the EXR file's header, identify the preview image section, and then decode the binary data according to the RGBA byte structure. This process would not require interpreting the data according to external image format specifications but would require an understanding of the EXR file format and the specific structure of the preview image data as defined by the OpenEXR specifications."

So a preview is not formatted, but instead raw gamma-corrected RGBA values, if it's correct.

- J
Title: Re: EXR embedded preview
Post by: blue-j on March 18, 2024, 05:21:50 PM
The fact that "every fourth byte is 0x7f" indicates that the image has a universal transparency set to 127 or 50% opaque possibly, if it is in RGBA?  Is that true?  127 is perfectly in the middle, which is curious.

- J
Title: Re: EXR embedded preview
Post by: blue-j on March 18, 2024, 05:24:51 PM
It appears my prior links to test images no longer works?  Here they are in the source code:

https://github.com/AcademySoftwareFoundation/openexr-images (https://github.com/AcademySoftwareFoundation/openexr-images)

- J
Title: Re: EXR embedded preview
Post by: Phil Harvey on March 19, 2024, 12:47:00 PM
Thanks for the sample.  I'll fix ExifTool 12.80 so the binary data is extracted properly as is.

- Phil
Title: Re: EXR embedded preview
Post by: blue-j on March 19, 2024, 11:48:09 PM
Thanks, Phil!  I did test with test image Spirals.exr and didn't what I expected, but this format is utterly batshit flexible.  It is breaking my mind.

I have labeled the binary as .raw, and assigned dimensions of 100x (default X for EXR previews) and it does not result in clear output, more like a misshapen beastie against transparency.  have you tested with a few other samples?  which one did it work on for you?

I am studying its metadata / attributes and gobsmacked (have to borrow that word from the Brits for this!).

it seems that the metadata is broken into structs per part.  here's an example from composited.exr (attached - also at the same URL as what I shared before):

exrinfo -a composited.exr
File '/Users/jharmon/Documents/Downloads/EXR Samples/composited.exr': ver 2 flags longnames multipart
parts: 4
part 1: rgba.left
  channels: chlist 4 channels
  'A': half samp 1 1
  'B': half samp 1 1
  'G': half samp 1 1
  'R': half samp 1 1
  chunkCount: int 1078
  compression: compression 'zips' (0x02)
  dataWindow: box2i [ 1, 1 - 1918 1078 ] 1918 x 1078
  displayWindow: box2i [ 0, 0 - 1919 1079 ] 1920 x 1080
  lineOrder: lineOrder 0 (increasing)
  name: string 'rgba.left'
  nuke/node_hash: string 'b4ea9f917764b762'
  owner: string 'Copyright 2012 Weta Digital Ltd'
  pixelAspectRatio: float 1
  screenWindowCenter: v2f [ 0, 0 ]
  screenWindowWidth: float 1
  type: string 'scanlineimage'
  view: string 'left'
part 2: depth.left
  channels: chlist 1 channels
  'Z': half samp 1 1
  chunkCount: int 1078
  compression: compression 'zips' (0x02)
  dataWindow: box2i [ 1, 1 - 1918 1078 ] 1918 x 1078
  displayWindow: box2i [ 0, 0 - 1919 1079 ] 1920 x 1080
  lineOrder: lineOrder 0 (increasing)
  name: string 'depth.left'
  owner: string 'Copyright 2012 Weta Digital Ltd'
  pixelAspectRatio: float 1
  screenWindowCenter: v2f [ 0, 0 ]
  screenWindowWidth: float 1
  type: string 'scanlineimage'
  view: string 'left'
part 3: rgba.right
  channels: chlist 4 channels
  'A': half samp 1 1
  'B': half samp 1 1
  'G': half samp 1 1
  'R': half samp 1 1
  chunkCount: int 1078
  compression: compression 'zips' (0x02)
  dataWindow: box2i [ 1, 1 - 1918 1078 ] 1918 x 1078
  displayWindow: box2i [ 0, 0 - 1919 1079 ] 1920 x 1080
  lineOrder: lineOrder 0 (increasing)
  name: string 'rgba.right'
  owner: string 'Copyright 2012 Weta Digital Ltd'
  pixelAspectRatio: float 1
  screenWindowCenter: v2f [ 0, 0 ]
  screenWindowWidth: float 1
  type: string 'scanlineimage'
  view: string 'right'
part 4: depth.right
  channels: chlist 1 channels
  'Z': half samp 1 1
  chunkCount: int 1078
  compression: compression 'zips' (0x02)
  dataWindow: box2i [ 1, 1 - 1918 1078 ] 1918 x 1078
  displayWindow: box2i [ 0, 0 - 1919 1079 ] 1920 x 1080
  lineOrder: lineOrder 0 (increasing)
  name: string 'depth.right'
  owner: string 'Copyright 2012 Weta Digital Ltd'
  pixelAspectRatio: float 1
  screenWindowCenter: v2f [ 0, 0 ]
  screenWindowWidth: float 1
  type: string 'scanlineimage'
  view: string 'right'


i used exrinfo (https://openexr.com/en/latest/bin/exrinfo.html) with the "all" -a switch, a utility included in the OpenEXR package. I'm looking at various ways of cracking the metadata open - we may just use exrinfo and format the output.  are you interested in supporting the format further in ET?

- J
Title: Re: EXR embedded preview
Post by: blue-j on March 20, 2024, 12:37:11 AM
Minor:

OpenEXR:TimeZone

should be

OpenEXR:UTCOffset

Offset ≠ Time Zone
Title: Re: EXR embedded preview
Post by: Phil Harvey on March 20, 2024, 06:27:19 AM
What is the difference?

My time zone is currently -04:00, and the offset from UTC is -4 hours.  Are there cases where this is different?  I thought this was the definition of the time zone.

- Phil
Title: Re: EXR embedded preview
Post by: blue-j on March 20, 2024, 02:21:25 PM
it's a very common misunderstanding, one that i myself had until a month or so ago.  i have been almost solely studying datetime representation for the past month, ISO 8601, offsets, time zones, all that stuff.  super dry but for some reason i am getting into it, please tell no one, as this is surely a sign of mental illness.

so, a single UTC offset can correspond to multiple time zones. that's the biggie.  for example, -05:00 could represent Eastern Standard Time in the US during standard time or Central Daylight Time during DST in the US, and also other time zones in different countries. bada boom.

and speaking of DST, when a region observes daylight savings it changes their offset for part of the year. the current offset doesn't tell you whether it observes DST or if the offset is due to standard time or daylight saving.

also, rules and offsets can change over time due to political stuff, too. an offset might give you a correct time zone for the current date but could be wrong for historical or future dates.
Title: Re: EXR embedded preview
Post by: blue-j on March 20, 2024, 02:27:44 PM
so, basically, it's a one-way function.  you can get offset from time zone, but not time zone from offset.  for example, check Google's time zone API:

https://developers.google.com/maps/documentation/timezone/requests-timezone (https://developers.google.com/maps/documentation/timezone/requests-timezone)

it *requires* not only a location but a timestamp precisely because you can't know whether DST is in play.
Title: Re: EXR embedded preview
Post by: Phil Harvey on March 20, 2024, 09:30:58 PM
I completely understand what you are saying, but we already have a number of "TimeZone" tags which just give the offset.  I admit to being lazy and not calling these TimeZoneOffset.

- Phil
Title: Re: EXR embedded preview
Post by: blue-j on March 21, 2024, 07:07:00 PM
No complaints from me.  I am so grateful for ExifTool!  : )
Title: Re: EXR embedded preview
Post by: blue-j on March 27, 2024, 04:41:48 PM
Phil, Monsieur StarGeek, did either of you have joy extracting the previews from EXRs?  Maybe the issue here is the .raw -> pixels step, not in ExifTool's export...?  - J


Quote from: blue-j on March 19, 2024, 11:48:09 PMThanks, Phil!  I did test with test image Spirals.exr and didn't what I expected, but this format is utterly batshit flexible.  It is breaking my mind.

I have labeled the binary as .raw, and assigned dimensions of 100x (default X for EXR previews) and it does not result in clear output, more like a misshapen beastie against transparency.  have you tested with a few other samples?  which one did it work on for you?
Title: Re: EXR embedded preview
Post by: StarGeek on March 27, 2024, 04:48:17 PM
The latest exiftool extracts the full 27k, but nothing I have can identify it as an image.  Every 4th byte is still 0x7f.
Title: Re: EXR embedded preview
Post by: blue-j on March 27, 2024, 05:10:50 PM
it's raw image data - Photoshop can open it if you give it the .raw extension; default size for a preview is 100px longest dimension.  maybe a different reader would work better.  but it is a ".raw" image.  - J
Title: Re: EXR embedded preview
Post by: blue-j on March 30, 2024, 04:27:01 PM
... or maybe it is another EXR file?  i will check into that hypothesis later today.  - J