Author Topic: EXIF rotation with jpg?  (Read 3216 times)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
EXIF rotation with jpg?
« on: 2012-Mar-16 »
Can be the JPEG loading routine updated to read images with correct rotation using EXIF information?
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
EXIF rotation with jpg?
« Reply #1 on: 2012-Mar-17 »
:S the WHAT!?

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: EXIF rotation with jpg?
« Reply #2 on: 2012-Mar-17 »
Digital cameras saves metadatas inside JPEG files, they are called EXIF. There is a metadata that saves the device's orientation, so the photos will be displayed correctly even if the camera was rotated.

Example: iPhone saves the photos as 2592x1936, no matter if the phone was landscape or portrait when taken it. If the phone was portrait, it saves a metadata saying "rotate 90ยบ the image when displaying it"

When I have time, I will look for it.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: EXIF rotation with jpg?
« Reply #3 on: 2012-Mar-29 »
I have found a document called "how to read an image exif rotation in VisualBasic" http://www.vb-helper.com/howto_net_read_exif_orientation.html that could help you.

Can you implement it? If not, I will implement my own rotation routine.

Anyway, thanks.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: EXIF rotation with jpg?
« Reply #4 on: 2012-Mar-29 »
Implementing reading of metadata is simple enough Ampos as I'm sure you're aware. Be it EXIF data or ID1 ID2 tags in mp3's. I was just in the toilet thinking of writing a routine to strip metadata from files or possibly pre-populating it with pre-determined data in a batch file fashion.

Would be handy if we could access meta info from within GLB though and write to it too, but as I say it's simple enough :)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: EXIF rotation with jpg?
« Reply #5 on: 2012-Mar-29 »
can anyone find info where to get these information from? I have no idea, and the VB code you posted uses some VB library that gains access to that data.

MrTAToad

  • Guest
Re: EXIF rotation with jpg?
« Reply #6 on: 2012-Mar-29 »
This library any use  : http://www.exiv2.org/doc/index.html ?

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: EXIF rotation with jpg?
« Reply #7 on: 2012-Mar-29 »
The EXIF especification is here http://www.exif.org/specifications.html

I have made a few more research, and the key is:

(hex:)
01 12 00 03 00 00 00 01 00 0X

(01 12 is the orientation tag id, 00 03 is SHORT, 00 00 00 01 is only 1 value and 00 0X de rotation needed (1-nothing, 3-180, 6=90 and 8=-90).
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: EXIF rotation with jpg?
« Reply #8 on: 2012-Mar-29 »
Time and time again you get proven right that it was a bad idea to include jpg support in GLBasic :-)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: EXIF rotation with jpg?
« Reply #9 on: 2012-Mar-29 »
I have checked 4 files from different cameras (iOS, 2xNikon and Canon)

In all the cases, the 00 0X values are stored in offset 0x36 from the start of the file (the pos +0x36 holds the 00 and +0x37 holds the 0X). In iOS and Nikon it is 00 0X and Canon uses 0X 00. Also noted all other values are big-endian or the hell is called (bytes swaped)

So iOS and Nikon are

01 12 00 03 00 00 00 01 00 0X

and Canon

12 01 03 00 01 00 00 00 0X 00

bastards...

If it safe to do a Rotation=byte(start+0x36)+byte(start+0x37)?

Checked jpeg files saved by photoshop and there was not exif orientation information, so you will have to look for 01 12 00 03 00 00 00 01, if fails, 12 01 03 00 01 00 00 00, and if fail again, ignore rotation.
« Last Edit: 2012-Mar-29 by ampos »
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: EXIF rotation with jpg?
« Reply #10 on: 2012-Mar-29 »
yikes.
Could you write your own using LOADSPRITEMEM and then check the bytes yourself in the file and rotate the image bytes in the array?
Rotating an image in an array is easy:

Code: GLBasic [Select]

FUNCTION Rotate90right%: img%[], out%[], w%, h%

REDIM out%[w*h]

LOCAL src%, dst%
LOCAL line% = dst% + h%-1
FOR y% = 0 to h%-1
dst = line; dec line
for x%=0 to w-1
  out[dst] = img[src]; inc src; inc dst, h
next
next
 

untested, but that should work.