Skip to content

Commit

Permalink
Avoid loading current dithering matrix on each mouse move (related to a…
Browse files Browse the repository at this point in the history
…seprite#4174)

With this change we are reusing the cached/loaded matrix on each
DitheringMatrixInfo struct, calling the
load_dithering_matrix_from_sprite() function just one time (not on
each brush preview/mouse movement).
  • Loading branch information
dacap committed Aug 21, 2024
1 parent 29479cb commit e87f6df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/app/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,15 @@ const render::DitheringMatrix* Extensions::ditheringMatrix(const std::string& ma
return nullptr;
}

std::vector<Extension::DitheringMatrixInfo> Extensions::ditheringMatrices()
std::vector<Extension::DitheringMatrixInfo*> Extensions::ditheringMatrices()
{
std::vector<Extension::DitheringMatrixInfo> result;
std::vector<Extension::DitheringMatrixInfo*> result;
for (auto ext : m_extensions) {
if (!ext->isEnabled()) // Ignore disabled themes
continue;

for (auto it : ext->m_ditheringMatrices)
result.push_back(it.second);
for (auto& it : ext->m_ditheringMatrices)
result.push_back(&it.second);
}
return result;
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ namespace app {
std::string palettePath(const std::string& palId);
ExtensionItems palettes() const;
const render::DitheringMatrix* ditheringMatrix(const std::string& matrixId);
std::vector<Extension::DitheringMatrixInfo> ditheringMatrices();

// The returned collection can be used temporarily while
// extensions are not installed/uninstalled. Each element is
// pointing to the real matrix info owned by extensions, this is
// needed to cache the matrix because it is lazy loaded from an
// image file. These pointers cannot be deleted.
std::vector<Extension::DitheringMatrixInfo*> ditheringMatrices();

obs::signal<void(Extension*)> NewExtension;
obs::signal<void(Extension*)> KeysChange;
Expand Down
6 changes: 3 additions & 3 deletions src/app/ui/context_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,9 +1260,9 @@ class ContextBar::DynamicsField : public ButtonSet
bool found = false;
auto ditheringMatrices = App::instance()
->extensions().ditheringMatrices();
for (const auto& it : ditheringMatrices) {
if (it.name() == dynaPref.matrixName()) {
m_dynamics.ditheringMatrix = it.matrix();
for (const auto* it : ditheringMatrices) {
if (it->name() == dynaPref.matrixName()) {
m_dynamics.ditheringMatrix = it->matrix();
found = true;
break;
}
Expand Down
18 changes: 9 additions & 9 deletions src/app/ui/dithering_selector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -217,25 +217,25 @@ void DitheringSelector::regenerate(int selectedItemIndex)
addItem(new DitherItem(render::DitheringAlgorithm::None,
render::DitheringMatrix(),
Strings::dithering_selector_no_dithering()));
for (const auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(new DitherItem(
render::DitheringAlgorithm::Ordered,
it.matrix(),
Strings::dithering_selector_ordered_dithering() + it.name()));
it->matrix(),
Strings::dithering_selector_ordered_dithering() + it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());
Console::showException(e);
}
}
for (const auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(
new DitherItem(
render::DitheringAlgorithm::Old,
it.matrix(),
Strings::dithering_selector_old_dithering() + it.name()));
it->matrix(),
Strings::dithering_selector_old_dithering() + it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());
Expand All @@ -251,9 +251,9 @@ void DitheringSelector::regenerate(int selectedItemIndex)
case SelectMatrix:
addItem(new DitherItem(render::DitheringMatrix(),
Strings::dithering_selector_no_dithering()));
for (auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(new DitherItem(it.matrix(), it.name()));
addItem(new DitherItem(it->matrix(), it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());
Expand Down

0 comments on commit e87f6df

Please sign in to comment.