mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
334 stars 171 forks source link

Non-JFIF JPEG image has resolution 0/0 on Linux #611

Closed provegard closed 4 years ago

provegard commented 4 years ago

I noticed that .NET Core 3 reports the resolution of some of my JPEG images as 0/0 on Linux but not on Windows. These images are EXIF/JPEG rather than JFIF/JPEG.

Git repo that shows the problem: https://github.com/provegard/jpegtest

On Windows, the output of dotnet run is the expected 300/300, but on Linux it's 0/0.

I tested on Debian with libgdiplus version 4.2-2.

I chose to open the issue here rather than over at corefx because it appears to me that the .NET Core core just delegates to libgdiplus. If that's wrong, please let me know and I'll move the issue.

qmfrederik commented 4 years ago

I think this was fixed by #596. Can you try to use a recent version of libgdiplus? You can get a recent version by adding the Mono repositories to your system: https://www.mono-project.com/download/stable/#download-lin-debian

provegard commented 4 years ago

Thanks for the quick reply! I followed the instructions and now I have version 6.0.4-0xamarin1+debian10b1.

Still 0/0 though.

qmfrederik commented 4 years ago

Bummer. Do you have an image which you can share, which helps reproduce this behavior?

If you want to take a stab at this yourself - #596 should give a good indication where the ExifData is being parsed by libgdiplus, and has a unit test (in the comments) which should help you get started. You can develop libgdiplus on Windows, Linux or macOS.

provegard commented 4 years ago

There's an image in the repo I referred to, but I'd be happy to give it a shot!

qmfrederik commented 4 years ago

There's an image in the repo I referred to

Oops, my reading skills are not what they used to be 😄

I'd be happy to give it a shot!

Cool, let me know if you have questions - the more contributors to libgdiplus, the better.

provegard commented 4 years ago

I wrote the following test, and it passes on master:

static void test_readExifResolution ()
{
    REAL resolution;
    GpBitmap *bitmap;
    WCHAR *bitmapFile = createWchar ("exif.jpg");

    assertEqualInt (GdipCreateBitmapFromFile (bitmapFile, &bitmap), Ok);

    assertEqualInt (GdipGetImageVerticalResolution (bitmap, &resolution), Ok);
    assertEqualInt (resolution, 300);

    assertEqualInt (GdipGetImageHorizontalResolution (bitmap, &resolution), Ok);
    assertEqualInt (resolution, 300);

    GdipDisposeImage ((GpImage *) bitmap);
    freeWchar (bitmapFile);
}

However, while the 8c5b0d48317af4c6fd702a1372f58a487e934f67 commit is part of master, it isn't visible from the 6.0.4 tag, which may explain why version 6.0.4-0xamarin1+debian10b1 doesn't work for me. The odd thing is that the 6.0.4 commit is newer than 8c5b0d48317af4c6fd702a1372f58a487e934f67,

In any case, perhaps there's value in adding the above test case? The test image is only 43K.

qmfrederik commented 4 years ago

Ah, the 6.0 series branched off master in August 2019 (https://github.com/mono/libgdiplus/pull/578), so commits made to master after that date are not part of the 6.0 releases.

Master currently is 36 commits head of the 6.0 series, some of which are maintenance commits, some of which bug fixes.

I guess that for the time being, your solution is to build off master until a new version of libgdiplus is released.

A unit test would be really useful, so feel free to send a PR.

provegard commented 4 years ago

PR added: #612