From 06d3bbf953b9bb2ff08d33c7f4e8198f4885af57 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 24 Apr 2025 20:35:57 -0300 Subject: [PATCH] Integrate fixup_image_transparent_colors() in resize_image() (#5048) With this patch we've even fixed a couple of bugs: 1. In resize_image() where fixup_image_transparent_colors() was being called in the new image instead of the source image. 2. When a bilinear resize was done to a tileset in SpriteSizeCommand, each tile was being resized directly without calling fixup_image_transparent_colors(). --- src/app/util/resize_image.cpp | 10 ++-------- src/app/util/resize_image.h | 7 +++++-- src/doc/algorithm/resize_image.cpp | 13 ++++++++----- src/doc/algorithm/resize_image.h | 15 ++++++++------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/app/util/resize_image.cpp b/src/app/util/resize_image.cpp index bf44f2e6f..c8d0b652c 100644 --- a/src/app/util/resize_image.cpp +++ b/src/app/util/resize_image.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (c) 2019-2022 Igara Studio S.A. +// Copyright (c) 2019-2025 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -26,7 +26,7 @@ namespace app { -doc::Image* resize_image(const doc::Image* image, +doc::Image* resize_image(doc::Image* image, const gfx::SizeF& scale, const doc::algorithm::ResizeMethod method, const Palette* pal, @@ -38,9 +38,6 @@ doc::Image* resize_image(const doc::Image* image, std::unique_ptr newImage(doc::Image::create(spec)); newImage->setMaskColor(image->maskColor()); - 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(); @@ -79,9 +76,6 @@ 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, - method == doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR); doc::algorithm::resize_image( image, newImage.get(), diff --git a/src/app/util/resize_image.h b/src/app/util/resize_image.h index 5d6ab9249..163c263f2 100644 --- a/src/app/util/resize_image.h +++ b/src/app/util/resize_image.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (c) 2019-2021 Igara Studio S.A. +// Copyright (c) 2019-2025 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -23,7 +23,10 @@ class RgbMap; namespace app { class Tx; -doc::Image* resize_image(const doc::Image* image, +// The "image" parameter can be modified with +// doc::algorithm::fixup_image_transparent_colors() function if +// it's needed. +doc::Image* resize_image(doc::Image* image, const gfx::SizeF& scale, const doc::algorithm::ResizeMethod method, const doc::Palette* pal, diff --git a/src/doc/algorithm/resize_image.cpp b/src/doc/algorithm/resize_image.cpp index 8c5b0f198..e66961812 100644 --- a/src/doc/algorithm/resize_image.cpp +++ b/src/doc/algorithm/resize_image.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2019 Igara Studio S.A. +// Copyright (c) 2019-2025 Igara Studio S.A. // Copyright (c) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -41,13 +41,18 @@ void resize_image_nearest(const Image* src, Image* dst) } } -void resize_image(const Image* src, +void resize_image(Image* src, Image* dst, const ResizeMethod method, const Palette* pal, const RgbMap* rgbmap, const color_t maskColor) { + // For resize methods that will merge neighbor pixels, we have to + // call fixup_image_transparent_colors(). + if (method != RESIZE_METHOD_NEAREST_NEIGHBOR) + fixup_image_transparent_colors(src); + switch (method) { // TODO optimize this case RESIZE_METHOD_NEAREST_NEIGHBOR: { @@ -184,10 +189,8 @@ void resize_image(const Image* src, } } -void fixup_image_transparent_colors(Image* image, bool skip_for_nearest_neighbor) +void fixup_image_transparent_colors(Image* image) { - if (skip_for_nearest_neighbor) - return; int x, y; switch (image->pixelFormat()) { diff --git a/src/doc/algorithm/resize_image.h b/src/doc/algorithm/resize_image.h index 9057fb065..85f634666 100644 --- a/src/doc/algorithm/resize_image.h +++ b/src/doc/algorithm/resize_image.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2019 Igara Studio S.A. +// Copyright (c) 2019-2025 Igara Studio S.A. // Copyright (c) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -25,12 +25,13 @@ enum ResizeMethod { RESIZE_METHOD_ROTSPRITE, }; -// Resizes the source image 'src' to the destination image 'dst'. +// Resizes the source image "src" to the destination image "dst". // -// Warning: If you are using the RESIZE_METHOD_BILINEAR, it is -// recommended to use 'fixup_image_transparent_colors' function -// over the source image 'src' BEFORE using this routine. -void resize_image(const Image* src, +// Warning: If you are using the RESIZE_METHOD_BILINEAR, the "src" +// image will be first filtered with the +// fixup_image_transparent_colors() function, which modifies the +// transparent pixels of the "src" image. +void resize_image(Image* src, Image* dst, const ResizeMethod method, const Palette* palette, @@ -42,7 +43,7 @@ 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, bool skip_for_nearest_neighbor); +void fixup_image_transparent_colors(Image* image); } // namespace algorithm } // namespace doc