mirror of https://github.com/aseprite/aseprite.git
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().
This commit is contained in:
parent
6aabfef0b8
commit
06d3bbf953
|
@ -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<doc::Image> 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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue