Fix Un-replaceable transparent pixels created by resize

This commit is contained in:
lightovernight 2025-03-07 22:52:00 +08:00
parent fc63532fef
commit c25d6eb436
3 changed files with 11 additions and 4 deletions

View File

@ -38,7 +38,9 @@ doc::Image* resize_image(const doc::Image* image,
std::unique_ptr<doc::Image> newImage(doc::Image::create(spec));
newImage->setMaskColor(image->maskColor());
doc::algorithm::fixup_image_transparent_colors(newImage.get());
doc::algorithm::fixup_image_transparent_colors(
newImage.get(),
method == doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR);
doc::algorithm::resize_image(image, newImage.get(), method, pal, rgbmap, newImage->maskColor());
return newImage.release();
@ -77,7 +79,9 @@ void resize_cel_image(Tx& tx,
doc::Image::create(image->pixelFormat(), std::max(1, w), std::max(1, h)));
newImage->setMaskColor(image->maskColor());
doc::algorithm::fixup_image_transparent_colors(image);
doc::algorithm::fixup_image_transparent_colors(
image,
method == doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR);
doc::algorithm::resize_image(
image,
newImage.get(),

View File

@ -184,8 +184,10 @@ void resize_image(const Image* src,
}
}
void fixup_image_transparent_colors(Image* image)
void fixup_image_transparent_colors(Image* image, bool skip_for_nearest_neighbor)
{
if (skip_for_nearest_neighbor)
return;
int x, y;
switch (image->pixelFormat()) {

View File

@ -42,7 +42,8 @@ void resize_image(const Image* src,
// (alpha = 0) with the average of its 4-neighbors. Useful if you
// want to use resize_image() with images that contains
// transparent pixels.
void fixup_image_transparent_colors(Image* image);
void fixup_image_transparent_colors(Image* image, bool skip_for_nearest_neighbor);
} // namespace algorithm
} // namespace doc