libsdl-org/SDL_image

On Mac, rotating image in Finder does not result in rotated image after loading

Opened this issue · 8 comments

Here's the code:

SDL_Surface* surface = IMG_Load(path.string().c_str());

This works usually, but if I use the Mac Finder to rotate an image (command-L), the image appears rotated in the Finder, but loads with the original orientation in SDLImage.

I suspect this is some kind of optimization in MacOS to make rotation a change in metadata instead of actually rotating the image pixels to save time, but I'm not sure.

Can you attach a link to a rotated image?

heart-full

Here is a simple pixel heart. It was originally oriented like a normal heart. Then I rotated it in the Finder. Photoshop opens it as rotated, but SDLImage does not. Hopefully uploading to GitHub here doesn't change it.

heart-full.png.zip

Just in case uploading alters the image somehow, here it is compressed.

What happens if you remove the __MACOSX folder next to the image?

I don't see a __MACOSX folder, that might just be added when you zip it.

Interestingly the image appears rotated in both Finder and Photoshop, but non-rotated in the GitHub app.

So this may be some edge case that Adobe optimized for since they're Mac friendly.

Screenshot 2024-09-09 at 6 23 55 AM
Screenshot 2024-09-09 at 6 31 50 AM

Ok, I figured it out. I opened the png in an app that shows the png metadata.

And the rotated image has an Orientation property that non-rotated pngs do not.

So I guess it would be up to SDLImage to rotate the png? Or maybe at least send us the metadata for orientation so we can do it ourselves.

gimp and gnome's image viewer also show the image as non-rotated.

I opened the file in imhex, and see an embedded iTXT chunk with a ML:com.adobe.xmp key, containing:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about=""
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
    xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
    xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
    xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
   dc:format="image/png"
   xmp:CreatorTool="Adobe Photoshop 24.4 (Macintosh)"
   xmp:ModifyDate="2023-05-09T19:32:18-07:00"
   xmp:CreateDate="2022-11-16T19:14:27-08:00"
   xmp:MetadataDate="2023-05-09T19:32:18-07:00"
   xmpMM:OriginalDocumentID="xmp.did:9d46c96f-0c34-4c07-a596-61726ed10945"
   xmpMM:DocumentID="xmp.did:9d46c96f-0c34-4c07-a596-61726ed10945"
   xmpMM:InstanceID="xmp.iid:9d46c96f-0c34-4c07-a596-61726ed10945"
   tiff:Orientation="8"
   photoshop:ColorMode="3">
   <xmpMM:History>
    <rdf:Seq>
     <rdf:li
      stEvt:softwareAgent="Adobe Photoshop 24.4 (Macintosh)"
      stEvt:when="2022-11-16T19:14:27-08:00"
      stEvt:instanceID="xmp.iid:9d46c96f-0c34-4c07-a596-61726ed10945"
      stEvt:action="created"/>
    </rdf:Seq>
   </xmpMM:History>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>
<?xpacket end="r"?>

SDL_image does not have a xml parser.

I would say, if it's difficult to fix, maybe just document it somewhere. Because it is confusing for Mac users.

Not the end of the world, since we can rotate with other apps than the Finder, just less convenient.