Page 1 of 1

Exif orientation with LoadImage

Posted: Fri Nov 06, 2015 4:00 pm
by wilbert
It looks like the exif orientation is not handled properly with LoadImage.
I have an image from my digital camera that is taken in portrait orientation, shows fine in OSX Preview but is in landscape orientation when PureBasic loads the image (90 degrees rotated compared to how it should look).

Re: Exif orientation with LoadImage

Posted: Fri Nov 06, 2015 5:07 pm
by infratec
Hi wilbert,

I would not call this a bug.
The image is loaded as it is inside the file.
EXIF is only an addition.

It is not handled. Yes, that's true.
But I would call it a feature request and not a bug.

In IrfanView it is an option, which is disabled as default (if I'm right).

Bernd

Re: Exif orientation with LoadImage

Posted: Fri Nov 06, 2015 5:54 pm
by wilbert
I think PureBasic should respect the Operating System it is working on.
I tried OSX Preview, Acorn image editor, Photoshop Elements, Safari, Chrome, Firefox (all on OSX) and every one of them handles the image orientation correctly. The only one which behaves differently is PureBasic.
The other applications probably all use the jpeg decoder built into OSX itself while PureBasic uses its own decoder.

Re: Exif orientation with LoadImage

Posted: Fri Nov 06, 2015 10:28 pm
by Wolfram
I think Bernd is right.
EXIF is an addition, which you can read and use as you like.
Otherwise PB should read the color profile too, what is not does.

Did you try what's happened if you load it by cocoa?

Re: Exif orientation with LoadImage

Posted: Sat Nov 07, 2015 6:50 am
by wilbert
Wolfram wrote:I think Bernd is right.
EXIF is an addition, which you can read and use as you like.
Otherwise PB should read the color profile too, what is not does.

Did you try what's happened if you load it by cocoa?
After some more thinking, you both do have a point. Maybe it should be a feature request.
I just was surprised the image didn't load correctly (from my point of view).

If I load it with Cocoa, the orientation is fine. So that's a good alternative.

Re: Exif orientation with LoadImage

Posted: Sat Nov 07, 2015 12:27 pm
by freak
Moved to feature requests.

Re: Exif orientation with LoadImage

Posted: Thu Aug 27, 2020 12:54 am
by AMpos
LOADIMAGE has a 3rd unused parameter, #flag.

What about using it to auto rotate images?

If 0, load as is, if #PB_Image_Idontknow the loadimage function will autorotate the image using EXIF info.

Re: Exif orientation with LoadImage

Posted: Thu Aug 27, 2020 12:34 pm
by kenmo
+1 as a flag, not the default.


wilbert, I have procedures that will handle this, if you want a workaround for now.

Re: Exif orientation with LoadImage

Posted: Thu Aug 27, 2020 1:13 pm
by AMpos
Cool if you have this! Sent me a link, please.

Re: Exif orientation with LoadImage

Posted: Mon Aug 31, 2020 2:24 pm
by kenmo
I did not realize this thread was 5 years old when I replied :)

AMpos, save my IncludeFiles RotateImage.pbi and GetExifData.pbi
https://raw.githubusercontent.com/kenmo ... eImage.pbi
https://raw.githubusercontent.com/kenmo ... ifData.pbi

and then try:

Code: Select all

XIncludeFile "RotateImage.pbi"
XIncludeFile "GetExifData.pbi"

LoadImageEXIFRotated(0, MyFile)

Re: Exif orientation with LoadImage

Posted: Sun Feb 06, 2022 3:11 am
by BarryG
The above includes don't work with this image -> https://www.dropbox.com/s/oe2sf7je8a8d1 ... d.jpg?dl=1

Note: Clicking the link will auto-download the file, because saving it from your browser will remove the EXIF data.

It fails to detect the orientation ("Right top" in EXIF data):

Code: Select all

XIncludeFile "RotateImage.pbi"
XIncludeFile "GetExifData.pbi"
Debug LoadImageEXIFRotated(0, "D:\Keyboard.jpg") ; Returns 0
However, LoadImage() loads it in the correct orientation:

Image

Re: Exif orientation with LoadImage

Posted: Thu Feb 10, 2022 5:17 am
by kenmo
Hello @BarryG

There are two things going on here:

1. You are correct! My code had a bug in reading Little Endian encoded EXIF orientation. (Most of my test JPEGs are apparently Big Endian.)
I have pushed an update to GetExifData.pbi which should work. Don't forget UseJpegImageDecoder()
https://github.com/kenmo-pb/includes/bl ... ifData.pbi

2. PB's LoadImage() does not process EXIF orientation. What you're showing as "correct" has not been EXIF-rotated.
Try opening Keyboard.jpg in Firefox or Chrome or another pro software, you should see it rotated extra 90 clockwise.
My updated code should detect Keyboard.jpg needing a 90 CW rotation, matching Firefox etc.
I think it's confusing because the un-rotated PB result looks like the expected, natural orientation.