Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Comments

Consolidate the Image class, fix bug#40181

Merged
safern merged 18 commits intodotnet:masterfrom
CoreCompat:fixes/graphics-consolidate
Aug 14, 2019
Merged

Consolidate the Image class, fix bug#40181
safern merged 18 commits intodotnet:masterfrom
CoreCompat:fixes/graphics-consolidate

Conversation

@qmfrederik
Copy link

@qmfrederik qmfrederik commented Aug 9, 2019

This PR digs a bit deeper into the System.Drawing.Image class:

  1. Fixes a bug where GetEncoderParameterList was broken on .NET Core (worked on .NET Framework) because of a bug in EncoderParameters.ConvertFromMemory. Fixes OverflowException from GetEncoderParameterList docs#5607, dotnet/corefx#33188
  2. Pending API Review - Fixes a bug where GetEncoderParameterList was broken for the JPEG encoder, which now returns (an empty list of) parameters of type EncoderParameterValueTypePointer. This was broken in .NET Framework, too (see e.g. this StackOverflow report)
  3. Shares code across Windows & Unix. The implementations for IsAlphaPixelFormat and GetPixelFormatSize were different; I kept the Windows implementation and added unit tests based on the Unix implementation.

As a result of 2, I also updated Encoder doc and EncoderParameterValueType doc with values which have been added in newer versions of GDI+.

@qmfrederik
Copy link
Author

I filed #40182 in case the new values to Encoder, EncoderParameterValueType require an API proposal. I can exclude these changes from this PR if that speeds up things.

@qmfrederik
Copy link
Author

/azp run corefx-ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qmfrederik
Copy link
Author

Linux x64_Debug failed with

/__w/1/s/src/System.Runtime/tests/TestStructs/System.TestStructs.ilproj : error : Failed to resolve SDK 'Microsoft.NET.Sdk.IL'. Package restore was successful but a package with the ID of "Microsoft.NET.Sdk.IL" was not installed.

@karelz karelz added this to the 5.0 milestone Aug 9, 2019
case EncoderParameterValueType.ValueTypeRationalRange:
size = 2 * 2 * 4;
break;
case EncoderParameterValueType.ValueTypePointer:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch uses ValueTypePointer, which was added to EncoderParameterValueType (public API) as part of this PR. That value is required to implement the fix. I can hard-coded it to 9, if you want to keep the API & the fix separate, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think we should keep the fix separate from this PR until the API is approved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I reverted that change for now. Any idea how long it would take for that API to get reviewed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. I just marked it as read-for-review, and it is marked as ready-for-review, so it is just a matter of waiting for the API Review team to get to it.

@qmfrederik qmfrederik changed the title Consolidate the Image class, fix bugs Consolidate the Image class, fix bug Aug 10, 2019
@qmfrederik
Copy link
Author

@safern Anything else you need for this PR?


ValidateImage(image);

Image img = CreateImageObject(image);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in Unix we should be able to cleanup and remove CreateFromHandle and just move the code to CreateImageObject, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those things are rabbit holes 😄. CreateImageObject only differed in the exception that is thrown (good, so we streamlined that, too), and the way a Metafile object is created from a handle. So I cleaned that up, too. Looks like there are some opportunities left in Metafile, let me see if I can cook up a separate PR for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thanks. Taking another look.

}
}

[ActiveIssue(20884, TestPlatforms.AnyUnix)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this. Hopefully CI is happy about it 😄

@safern safern merged commit 31a04af into dotnet:master Aug 14, 2019
@safern
Copy link
Member

safern commented Aug 14, 2019

Thanks @qmfrederik nice cleanup. The Image class is now simpler to read in between different OSs.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add new values for Encoder, EncoderParameterValueType

* Support encoder parameters of type ValueTypePointer

* Fix an overflow error when reading EncoderParameters

* Add unit tests

* Consolidate the Image class

Share the following methods across Windows & Unix:
- FromFile
- GetEncoderParameterList
- GetPixelFormatSize
- IsAlphaPixelFormat

* Fix P/Invoke declaration

* Fix compliation on NetFX

* Skip test on NetFX

* Fix typo

* Always skip GetEncoderParameterList_ReturnsExpected on netFX

* Remove new API

* Revert changes which require an API change

* Suppress failing test

* Image: Consolidate CreateImageObject
Metafile: Consolidate initialization from native handle

* Throw SkipTestException instead of silently skipping the test

* Enable some on Unix which rely on consolidated code

* Add missing using statement

* Get SkipTestException right


Commit migrated from dotnet/corefx@31a04af
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OverflowException from GetEncoderParameterList

4 participants