LibRaw (dcraw?) orientation tag wrong?

Hi team,

I am starting to use LibRaw for my own software package (Astro Pixel Processor). I have already written full metadata extraction of TIFF IFDs, EXIF & Makernote tags and Raw conversion of both Canon CR2 and Nikon NEF files.

I have now started with building LibRaw support into my software using Java JNI and I am testing this now on Sony ARW files.

I am able to retreive the Sony arw raw data and I am also able to get certain important metadata values like exposure time, time of exposure, iso etc...

Now, I think, I have possibly found a strange error with regard to the TIFF specification orientation tag and I would like to hear your opinion on this.

My software can read the full metadata according to the TIFF IFD specification. And it can extract the orientation tag from regular TIFF IFDs or Exif IFD using my own java code.In this case the tag comes from TIFF IDF 1:

case 274: // orientation
tagName = "Orientation";
orientation = RawStreamByteReader.get2(iis, byteOrder);
if (orientation == 1){
value = "Horizontal (normal)";
} else if (orientation == 2){
value = "Mirror horizontal";
} else if (orientation == 3){
value = "Rotate 180";
} else if (orientation == 4){
value = "Mirror vertical";
} else if (orientation == 5){
value = "Mirror horizontal and rotate 270 CW";
} else if (orientation == 6){
value = "Rotate 90 CW";
} else if (orientation == 7){
value = "Mirror horizontal and rotate 90 CW";
} else if (orientation == 8){
value = "Rotate 270 CW";

} else {
value = Integer.toString(orientation);
}
break;

The metadata as read:

IFD 1 contains 19 tags
IFD1 - NewSubfileType: 1
IFD1 - compression: 6
IFD1 - ImageDescription:
IFD1 - Make: SONY
IFD1 - Model: ILCE-7M3
IFD1 - Orientation: Rotate 270 CW
IFD1 - XResolution: 350/1
IFD1 - YResolution: 350/1
IFD1 - ResolutionUnit: Inch
IFD1 - Software: ILCE-7M3 v1.00
IFD1 - DateTime: 2018:02:26 17:48:09
IFD1 - SubIFD offsets: 149620
IFD1 - ThumbnailOffset: 151714
IFD1 - ThumbnailLenght: 705655
IFD1 - YCbCrPositioning: Co-sited
IFD1 - XML packet: not shown
IFD1 - Exif: 4544
IFD1 - tag c4a5: 80 114 105 110 116 73 77 0 48 51 48 48 0 0 3 0 2 0 1 0 0 0 3 0 34 0 0 0 1 1 0 0 0 0 9 17 0 0 16 39 0 0 11 15 0 0 16 39 0 0 -105 5 0 0 16 39 0 0 -80 8 0 0 16 39 0 0 1 28 0 0 16 39 0 0 94 2 0 0 16 39 0 0 -117 0 0 0 16 39 0 0 -53 3 0 0 16 39 0 0 -27 27 0 0 16 39 0 0
IFD1 - tag c634: 126 -39 0 0
Exif contains 41 tags
Exif - ExposureTime: 0.0125
Exif - FNumber: 56/10
etc....

The reported orientation tag value from LibRaw is not the same as this tag which I think can't be right? Is LibRaw and perhaps dcraw using it's own orientation specification? If so, why?

An example can be downloaded here, a Sony A7 III arw file with a non-zero orientation tag:
https://s3.eu-central-1.amazonaws.com/apastropixelprocessordl/LibRawSupp...

LibRaw gives for the orientation tag : 5
using imgdata.sizes.flip :

LibRaw iProcessor;
iProcessor.open_file(xxxx);
iProcessor.imgdata.sizes.flip

Now, my metadata reader extracts the value of 8 from the IFD1 which corresponds to Rotate 270CW according to the orientation TIFF specification as shown by both these sites:

https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
https://www.awaresystems.be/imaging/tiff/tifftags/orientation.html

And if I apply orientation of 5 to the image, the image is up side down, not shown correctly. With 8 it is shown correctly.

Can you please comment on this? To me this looks like that the orientation tag in LibRaw is not following the tiff specification.

If I look here:
https://www.libraw.org/docs/API-datastruct-eng.html
"int flip;
Image orientation (0 if does not require rotation; 3 if requires 180-deg rotation; 5 if 90 deg counterclockwise, 6 if 90 deg clockwise)."

it seems to confirm that the orientation tag in dcraw/libraw is other than the TIFF specification.

Thank you for your great work,

Kind regards,
Mabula Haverkamp
Aries Productions.

Forums: 

Yes, libraw imgdata.sizes

Yes, libraw imgdata.sizes.flip and tiff:Orientation tag are different.

-- Alex Tutubalin

Ah thank you Alex, it was a

Ah thank you Alex, it was a bit confusing, but I guess this is due to my own assumptions ;-) ...

Kind regards,
Mabula

Mabula Haverkamp
Owner of Aries Productions
Main developer of Astro Pixel Processer - Deep Sky Image Processing Software

Here is small code snippet

Here is small code snippet that may help you in flip->orientation conversion:

int arr[10] = { 1, 1, 2, 4, 3, 5, 8, 6, 7, 1 };
return arr[qBound(0, flip + 1, 9)]; // add 1 and set limit to 9 to handle out of range values

-- Alex Tutubalin

And followup:

And followup:

dcraw_emu/dcraw.c also accepts user_flip in degrees (e.g. 90, 270, or -90), to handle this too, add these lines before snippet in previous message:

if (flip > 89 || flip < -89)
{
flip = (flip + 720) % 360;
switch (flip)
{
case 90: return 6;
case 180: return 3;
case 270: return 8;
default: return 1;
}
}

-- Alex Tutubalin

Thank you very much Alex ;-)

Thank you very much Alex ;-) !

Mabula Haverkamp
Owner of Aries Productions
Main developer of Astro Pixel Processer - Deep Sky Image Processing Software