On wxForum, there is a report about what looks like another MSVC 2022 compiler optimization bug manifesting with wxImage scaling.
This time it appears to be in wxImage::ShrinkBy(), (called from wxImage::Scale() when certain conditions are met), where in the Release build the scaled image is monochrome. I tested 64-bit shared build of the current master with MSVS 2022 v17.4.3 (using CMake).
Scaled image in release build

Also as can be seen in the above picture, even the color used for image labels is different in the release build? Moreover, the sample menubar is also black (not in Debug build, Windows is in the dark mode). I tried to build the drawing sample and it seems broken too, the the top of the canvas background is black and so is the menubar. I did not look into this any further, having ran out of time for today.
How to reproduce:
diff --git a/samples/image/canvas.cpp b/samples/image/canvas.cpp index 25139741f2..1dcb5e5e00 100644 --- a/samples/image/canvas.cpp +++ b/samples/image/canvas.cpp @@ -113,7 +113,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, my_toucan_flipped_both = wxBitmap(image.Mirror(true).Mirror(false)); my_toucan_grey = wxBitmap(image.ConvertToGreyscale()); my_toucan_head = wxBitmap(image.GetSubImage(wxRect(40, 7, 80, 60))); - my_toucan_scaled_normal = wxBitmap(image.Scale(110,90,wxIMAGE_QUALITY_NORMAL)); + my_toucan_scaled_normal = wxBitmap(image.ShrinkBy(2,2)); my_toucan_scaled_high = wxBitmap(image.Scale(110,90,wxIMAGE_QUALITY_HIGH)); my_toucan_blur = wxBitmap(image.Blur(10));
I did not try any other compilers.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Seems that alpha calculation is optimized away. Moving it inside the if fixes it for me:
diff --git "a/src/common/image.cpp" "b/src/common/image.cpp" index 6360f5a447..fc0f391381 100644 --- "a/src/common/image.cpp" +++ "b/src/common/image.cpp" @@ -390,11 +390,11 @@ wxImage wxImage::ShrinkBy( int xFactor , int yFactor ) const unsigned char red = pixel[0] ; unsigned char green = pixel[1] ; unsigned char blue = pixel[2] ; - unsigned char alpha = 255 ; - if ( source_alpha ) - alpha = *(source_alpha + y_offset + x * xFactor + x1) ; if ( !hasMask || red != maskRed || green != maskGreen || blue != maskBlue ) { + unsigned char alpha = 255; + if (source_alpha) + alpha = *(source_alpha + y_offset + x * xFactor + x1); if ( alpha > 0 ) { avgRed += red ;
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I can confirm that after using Maarten's patch the issue is gone. I have also upgraded MSVC from 17.4.3 to 17.4.4 but without the patch, the issue was still there.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I don't see any drawback in doing this, so I'm going to apply this soon, thanks for finding and fixing this, respectively!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #23164 as completed via e51bc73.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Oh, and I'll cherry-pick this into 3.2 too soon.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()