Fix crash in wxImage::Paste() when using images without alpha
Check for the presence of alpha channel before using it in the fallback code. Also add a unit test exercising this branch of the code and which crashed before.
This commit is contained in:
@@ -1786,13 +1786,14 @@ wxImage::Paste(const wxImage & image, int x, int y,
|
|||||||
{
|
{
|
||||||
// Copy the non masked pixel
|
// Copy the non masked pixel
|
||||||
memcpy(target_data + i, source_data + i, 3);
|
memcpy(target_data + i, source_data + i, 3);
|
||||||
// Make the copied pixel fully opaque
|
if (alpha_target_data != NULL) // Make the copied pixel fully opaque
|
||||||
alpha_target_data[i / 3] = wxALPHA_OPAQUE;
|
alpha_target_data[i / 3] = wxALPHA_OPAQUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
source_data += source_step;
|
source_data += source_step;
|
||||||
target_data += target_step;
|
target_data += target_step;
|
||||||
alpha_target_data += target_alpha_step;
|
if (alpha_target_data != NULL)
|
||||||
|
alpha_target_data += target_alpha_step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1540,6 +1540,10 @@ TEST_CASE("wxImage::Paste", "[image][paste]")
|
|||||||
wxImage expected(toggle_equal_size_xpm);
|
wxImage expected(toggle_equal_size_xpm);
|
||||||
actual.Paste(paste, 0, 0);
|
actual.Paste(paste, 0, 0);
|
||||||
CHECK_THAT(actual, RGBSameAs(expected));
|
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")
|
SECTION("Paste larger image")
|
||||||
|
Reference in New Issue
Block a user