diff --git a/src/app/cmd/set_pixel_format.cpp b/src/app/cmd/set_pixel_format.cpp index f9233d59e04..5c411061303 100644 --- a/src/app/cmd/set_pixel_format.cpp +++ b/src/app/cmd/set_pixel_format.cpp @@ -130,7 +130,8 @@ SetPixelFormat::SetPixelFormat(Sprite* sprite, false, // TODO is background? it depends of the layer where this tileset is used mapAlgorithm, toGray, - &superDel); + &superDel, + fitCriteria); } superDel.nextImage(); } diff --git a/src/app/cmd/set_pixel_format.h b/src/app/cmd/set_pixel_format.h index d02cc4db498..fcb239aaf57 100644 --- a/src/app/cmd/set_pixel_format.h +++ b/src/app/cmd/set_pixel_format.h @@ -39,7 +39,7 @@ namespace cmd { const doc::RgbMapAlgorithm mapAlgorithm, doc::rgba_to_graya_func toGray, render::TaskDelegate* delegate, - const doc::FitCriteria fitCriteria = doc::FitCriteria::DEFAULT); + const doc::FitCriteria fitCriteria); protected: void onExecute() override; diff --git a/src/app/commands/cmd_change_pixel_format.cpp b/src/app/commands/cmd_change_pixel_format.cpp index b065dab192d..072ce81b1a8 100644 --- a/src/app/commands/cmd_change_pixel_format.cpp +++ b/src/app/commands/cmd_change_pixel_format.cpp @@ -673,9 +673,10 @@ void ChangePixelFormatCommand::onExecute(Context* context) window.saveOptions(); } else { - // TO DO: in a first approach a simple conversion to indexed color mode - // it's just via the old fit criteria (Euclidean color distance). - m_fitCriteria = FitCriteria::DEFAULT; + if (m_format == IMAGE_INDEXED) { + m_rgbmap = Preferences::instance().quantization.rgbmapAlgorithm(); + m_fitCriteria = Preferences::instance().quantization.fitCriteria(); + } } #endif // ENABLE_UI diff --git a/src/app/commands/cmd_new_file.cpp b/src/app/commands/cmd_new_file.cpp index e0939145582..64952841d90 100644 --- a/src/app/commands/cmd_new_file.cpp +++ b/src/app/commands/cmd_new_file.cpp @@ -272,6 +272,11 @@ void NewFileCommand::onExecute(Context* ctx) else layer->setName(fmt::format("{} {}", Strings::commands_NewLayer_Layer(), 1)); } + if (sprite->pixelFormat() == IMAGE_INDEXED) { + sprite->rgbMap(0, Sprite::RgbMapFor(!layer->isBackground()), + Preferences::instance().quantization.rgbmapAlgorithm(), + Preferences::instance().quantization.fitCriteria()); + } // Show the sprite to the user std::unique_ptr doc(new Doc(sprite.get())); diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index d19579a50c7..dc072b6ffad 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2023 Igara Studio S.A. +// Copyright (C) 2018-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -1289,13 +1289,18 @@ void DocExporter::renderTexture(Context* ctx, // Make the sprite compatible with the texture so the render() // works correctly. if (sample.sprite()->pixelFormat() != textureImage->pixelFormat()) { + RgbMapAlgorithm rgbmapAlgo = + Preferences::instance().quantization.rgbmapAlgorithm(); + FitCriteria fc = + Preferences::instance().quantization.fitCriteria(); cmd::SetPixelFormat( sample.sprite(), textureImage->pixelFormat(), render::Dithering(), - Sprite::DefaultRgbMapAlgorithm(), // TODO add rgbmap algorithm preference + rgbmapAlgo, nullptr, // toGray is not needed because the texture is Indexed or RGB - nullptr) // TODO add a delegate to show progress + nullptr, // TODO add a delegate to show progress + fc) .execute(ctx); } diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index ad19b5cdc2e..c2e62d84206 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -290,6 +290,12 @@ bool AseFormat::onLoad(FileOp* fop) return false; Sprite* sprite = delegate.sprite(); + // Assign RgbMap +// if (sprite->pixelFormat() == IMAGE_INDEXED && +// fop->context()->isUIAvailable()) +// sprite->rgbMap(0, Sprite::RgbMapFor(sprite->isOpaque()), +// Preferences::instance().quantization.rgbmapAlgorithm(), +// Preferences::instance().quantization.fitCriteria()); fop->createDocument(sprite); if (sprite->colorSpace() != nullptr && diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index 1a8c4c46cfc..574345b0020 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -1372,6 +1372,13 @@ ImageRef FileOp::sequenceImageToLoad( // Add the layer sprite->root()->addLayer(layer); + // Assign RgbMap +// if (sprite->pixelFormat() == IMAGE_INDEXED) { +// sprite->rgbMap(0, Sprite::RgbMapFor(sprite->isOpaque()), +// Preferences::instance().quantization.rgbmapAlgorithm(), +// Preferences::instance().quantization.fitCriteria()); +// } + // Done createDocument(sprite); m_seq.layer = layer; diff --git a/src/app/pref/preferences.cpp b/src/app/pref/preferences.cpp index 53d9c9a4619..30bb1044620 100644 --- a/src/app/pref/preferences.cpp +++ b/src/app/pref/preferences.cpp @@ -67,14 +67,6 @@ Preferences::Preferences() load(); - // Create a connection with the default RgbMapAlgorithm preferences - // to change the default algorithm in the "doc" layer. - quantization.rgbmapAlgorithm.AfterChange.connect( - [](const doc::RgbMapAlgorithm& newValue){ - doc::Sprite::SetDefaultRgbMapAlgorithm(newValue); - }); - doc::Sprite::SetDefaultRgbMapAlgorithm(quantization.rgbmapAlgorithm()); - // Create a connection with the default document preferences grid // bounds to sync the default grid bounds for new sprites in the // "doc" layer. diff --git a/src/doc/sprite.cpp b/src/doc/sprite.cpp index b14538ba91a..fc2a60fed01 100644 --- a/src/doc/sprite.cpp +++ b/src/doc/sprite.cpp @@ -36,7 +36,6 @@ namespace doc { -static RgbMapAlgorithm g_rgbMapAlgorithm = RgbMapAlgorithm::DEFAULT; static gfx::Rect g_defaultGridBounds(0, 0, 16, 16); // static @@ -51,18 +50,6 @@ void Sprite::SetDefaultGridBounds(const gfx::Rect& defGridBounds) g_defaultGridBounds = defGridBounds; } -// static -RgbMapAlgorithm Sprite::DefaultRgbMapAlgorithm() -{ - return g_rgbMapAlgorithm; -} - -// static -void Sprite::SetDefaultRgbMapAlgorithm(const RgbMapAlgorithm mapAlgo) -{ - g_rgbMapAlgorithm = mapAlgo; -} - ////////////////////////////////////////////////////////////////////// // Constructors/Destructor @@ -436,7 +423,7 @@ RgbMap* Sprite::rgbMap(const frame_t frame, const RgbMapFor forLayer) const { FitCriteria fc = FitCriteria::DEFAULT; - RgbMapAlgorithm algo = g_rgbMapAlgorithm; + RgbMapAlgorithm algo = RgbMapAlgorithm::DEFAULT; if (m_rgbMap) { fc = m_rgbMap->fitCriteria(); algo = m_rgbMap->rgbmapAlgorithm();