mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.14k stars 522 forks source link

[BUG] CR2 image orientation being detected incorrectly. #2850

Open Webreaper opened 2 weeks ago

Webreaper commented 2 weeks ago

Description

I'm loading and orienting a CR2 image using the code below. However, whilst ExifTool correctly shows the orientation as: Orientation = Left side, bottom (Rotate 270 CW), SkiaSharp seems to be incorrectly decoding the orientation to SKEncodedOrigin.TopLeft. This means I don't rotate the image, and the thumbnails are rendered incorrectly.

I have a sample image, but it's too large to attach, so I've zipped it and put it in my GDrive folder here:

LV1_3765.CR2.zip

Code

        var codec = SKCodec.Create(source.FullName);
        var info = codec.Info;

        // get the scale that is nearest to what we want (eg: jpg returned 512)
        var supportedScale = codec.GetScaledDimensions((float)desiredWidth / info.Width);

        // decode the bitmap at the nearest size
        var nearest = new SKImageInfo(supportedScale.Width, supportedScale.Height);
        var bmp = SKBitmap.Decode(codec, nearest);

My code then uses codec.EncodedOrigin to auto-orient the image to the right way, before I resize to generate thumbs.

Expected Behavior

I expect the image orientation to be SKEncodedOrigin.LeftBottom which would allow the image to be rotated correctly.

Actual Behavior

The image orientation is evaluated as SKEncodedOrigin.TopLeft, so my code never attempts to rotate.

Version of SkiaSharp

2.88.8 (Current)

Last Known Good Version of SkiaSharp

n/a

IDE / Editor

Rider

Platform / Operating System

.Net 8.0 on Linux, macOS

Platform / Operating System Version

Linux and MacOS

Devices

No response

Relevant Screenshots

Screenshot 2024-04-30 at 10 14 30

Relevant Log Output

No response

Code of Conduct