Merge branch 'image-paste-fix'

Fix recent regression resulting in a crash in wxImage::Paste().

See https://github.com/wxWidgets/wxWidgets/pull/2076
This commit is contained in:
Vadim Zeitlin 2020-10-10 18:12:35 +02:00
commit 7ed330a197
7 changed files with 107 additions and 65 deletions

View File

@ -1786,13 +1786,14 @@ wxImage::Paste(const wxImage & image, int x, int y,
{
// Copy the non masked pixel
memcpy(target_data + i, source_data + i, 3);
// Make the copied pixel fully opaque
alpha_target_data[i / 3] = wxALPHA_OPAQUE;
if (alpha_target_data != NULL) // Make the copied pixel fully opaque
alpha_target_data[i / 3] = wxALPHA_OPAQUE;
}
}
source_data += source_step;
target_data += target_step;
alpha_target_data += target_alpha_step;
if (alpha_target_data != NULL)
alpha_target_data += target_alpha_step;
}
}
}

View File

@ -548,7 +548,7 @@ data:
data-images:
@mkdir -p image
@for f in horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png; do \
@for f in horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png; do \
if test ! -f image/$$f -a ! -d image/$$f ; \
then x=yep ; \
else x=`find $(srcdir)/image/$$f -newer image/$$f -print` ; \

View File

@ -1493,6 +1493,46 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
"y y y y y",
};
const static char* transparent_image_xpm[] =
{
"5 5 2 1",
" c None", // Mask
"y c #FFFF00",
" ",
" ",
" ",
" ",
" ",
};
const static char* light_image_xpm[] =
{
"5 5 2 1",
" c None",
"y c #FFFF00",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
};
const static char* black_image_xpm[] =
{
"5 5 2 1",
" c #000000",
"y c None", // Mask
" ",
" ",
" ",
" ",
" ",
};
// Execute AddHandler() just once.
static const bool
registeredHandler = (wxImage::AddHandler(new wxPNGHandler()), true);
SECTION("Paste same size image")
{
wxImage actual(squares_xpm);
@ -1500,6 +1540,10 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
wxImage expected(toggle_equal_size_xpm);
actual.Paste(paste, 0, 0);
CHECK_THAT(actual, RGBSameAs(expected));
// Without alpha using "compose" doesn't change anything.
actual.Paste(paste, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
CHECK_THAT(actual, RGBSameAs(expected));
}
SECTION("Paste larger image")
@ -1690,18 +1734,11 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
CHECK_THAT(actual, RGBSameAs(expected));
}
wxImage::AddHandler(new wxPNGHandler());
wxImage background("image/paste_input_background.png");
CHECK(background.IsOk());
wxImage opaque_square("image/paste_input_overlay_transparent_border_opaque_square.png");
CHECK(opaque_square.IsOk());
wxImage transparent_square("image/paste_input_overlay_transparent_border_semitransparent_square.png");
CHECK(transparent_square.IsOk());
wxImage transparent_circle("image/paste_input_overlay_transparent_border_semitransparent_circle.png");
CHECK(transparent_circle.IsOk());
SECTION("Paste fully opaque image onto blank image without alpha")
{
const wxImage background("image/paste_input_background.png");
REQUIRE(background.IsOk());
wxImage actual(background.GetSize());
actual.Paste(background, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
CHECK_THAT(actual, RGBSameAs(background));
@ -1709,6 +1746,9 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste fully opaque image onto blank image with alpha")
{
const wxImage background("image/paste_input_background.png");
REQUIRE(background.IsOk());
wxImage actual(background.GetSize());
actual.InitAlpha();
actual.Paste(background, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
@ -1717,6 +1757,9 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste fully transparent image")
{
const wxImage background("image/paste_input_background.png");
REQUIRE(background.IsOk());
wxImage actual = background.Copy();
wxImage transparent(actual.GetSize());
transparent.InitAlpha();
@ -1727,21 +1770,39 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste image with transparent region")
{
wxImage actual = background.Copy();
wxImage actual("image/paste_input_background.png");
REQUIRE(actual.IsOk());
const wxImage opaque_square("image/paste_input_overlay_transparent_border_opaque_square.png");
REQUIRE(opaque_square.IsOk());
actual.Paste(opaque_square, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
CHECK_THAT(actual, RGBSameAs(wxImage("image/paste_result_background_plus_overlay_transparent_border_opaque_square.png")));
CHECK_THAT(actual, CenterAlphaPixelEquals(wxALPHA_OPAQUE));
}
SECTION("Paste image with semi transparent region")
{
wxImage actual = background.Copy();
wxImage actual("image/paste_input_background.png");
REQUIRE(actual.IsOk());
const wxImage transparent_square("image/paste_input_overlay_transparent_border_semitransparent_square.png");
REQUIRE(transparent_square.IsOk());
actual.Paste(transparent_square, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
CHECK_THAT(actual, RGBSameAs(wxImage("image/paste_result_background_plus_overlay_transparent_border_semitransparent_square.png")));
CHECK_THAT(actual, CenterAlphaPixelEquals(wxALPHA_OPAQUE));
}
SECTION("Paste two semi transparent images on top of background")
{
wxImage actual = background.Copy();
wxImage actual("image/paste_input_background.png");
REQUIRE(actual.IsOk());
const wxImage transparent_square("image/paste_input_overlay_transparent_border_semitransparent_square.png");
REQUIRE(transparent_square.IsOk());
const wxImage transparent_circle("image/paste_input_overlay_transparent_border_semitransparent_circle.png");
REQUIRE(transparent_circle.IsOk());
actual.Paste(transparent_circle, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
actual.Paste(transparent_square, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
CHECK_THAT(actual, RGBSimilarTo(wxImage("image/paste_result_background_plus_circle_plus_square.png"), 1));
@ -1749,8 +1810,16 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste two semi transparent images together first, then on top of background")
{
wxImage actual("image/paste_input_background.png");
REQUIRE(actual.IsOk());
const wxImage transparent_square("image/paste_input_overlay_transparent_border_semitransparent_square.png");
REQUIRE(transparent_square.IsOk());
const wxImage transparent_circle("image/paste_input_overlay_transparent_border_semitransparent_circle.png");
REQUIRE(transparent_circle.IsOk());
wxImage circle = transparent_circle.Copy();
wxImage actual = background.Copy();
circle.Paste(transparent_square, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
actual.Paste(circle, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
// When applied in this order, two times a rounding difference is triggered.
@ -1759,6 +1828,12 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste semitransparent image over transparent image")
{
const wxImage transparent_square("image/paste_input_overlay_transparent_border_semitransparent_square.png");
REQUIRE(transparent_square.IsOk());
const wxImage transparent_circle("image/paste_input_overlay_transparent_border_semitransparent_circle.png");
REQUIRE(transparent_circle.IsOk());
wxImage actual(transparent_circle.GetSize());
actual.InitAlpha();
memset(actual.GetAlpha(), 0, actual.GetWidth() * actual.GetHeight());
@ -1770,28 +1845,6 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste fully transparent (masked) image over light image") // todo make test case for 'blend with mask'
{
const static char* transparent_image_xpm[] =
{
"5 5 2 1",
" c None", // Mask
"y c #FFFF00",
" ",
" ",
" ",
" ",
" ",
};
const static char* light_image_xpm[] =
{
"5 5 2 1",
" c None",
"y c #FFFF00",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
};
wxImage actual(light_image_xpm);
actual.InitAlpha();
wxImage paste(transparent_image_xpm);
@ -1801,28 +1854,6 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
}
SECTION("Paste fully black (masked) image over light image") // todo make test case for 'blend with mask'
{
const static char* black_image_xpm[] =
{
"5 5 2 1",
" c #000000",
"y c None", // Mask
" ",
" ",
" ",
" ",
" ",
};
const static char* light_image_xpm[] =
{
"5 5 2 1",
" c None",
"y c #FFFF00",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
"yyyyy",
};
wxImage actual(light_image_xpm);
actual.InitAlpha();
wxImage paste(black_image_xpm);

View File

@ -571,7 +571,7 @@ data:
data-images:
if not exist image mkdir image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png) do if not exist image\%f copy .\image\%f image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png) do if not exist image\%f copy .\image\%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr

View File

@ -556,7 +556,7 @@ data:
data-images:
if not exist image mkdir image
for %%f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png) do if not exist image\%%f copy .\image\%%f image
for %%f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png) do if not exist image\%%f copy .\image\%%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr

View File

@ -984,7 +984,7 @@ data:
data-images:
if not exist image mkdir image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png) do if not exist image\%f copy .\image\%f image
for %f in (horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png) do if not exist image\%f copy .\image\%f image
fr:
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr

View File

@ -360,6 +360,16 @@
cross_bilinear_256x256.png
cross_box_average_256x256.png
cross_nearest_neighb_256x256.png
paste_input_background.png
paste_input_black.png
paste_input_overlay_transparent_border_opaque_square.png
paste_input_overlay_transparent_border_semitransparent_circle.png
paste_input_overlay_transparent_border_semitransparent_square.png
paste_result_background_plus_circle_plus_square.png
paste_result_background_plus_overlay_transparent_border_opaque_square.png
paste_result_background_plus_overlay_transparent_border_semitransparent_square.png
paste_result_no_background_square_over_circle.png
</files>
</wx-data>