From 4c5f5249d8375a5c7b1aab6a2aae4c2b802e84d1 Mon Sep 17 00:00:00 2001 From: David Thomas Date: Sat, 14 Jun 2025 14:37:36 +0100 Subject: [PATCH] Fix transposed arg, add consts --- src/app/commands/cmd_change_pixel_format.cpp | 12 +++++++----- src/render/error_diffusion.cpp | 11 ++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/app/commands/cmd_change_pixel_format.cpp b/src/app/commands/cmd_change_pixel_format.cpp index 3a216deb7..c902cb131 100644 --- a/src/app/commands/cmd_change_pixel_format.cpp +++ b/src/app/commands/cmd_change_pixel_format.cpp @@ -583,11 +583,13 @@ void ChangePixelFormatCommand::onExecute(Context* ctx) if (window.closer() != window.ok()) return; + const auto d = window.dithering(); + params().colorMode(window.selectedColorMode()); - params().dithering(window.dithering().algorithm()); - matrix = window.dithering().matrix(); - params().factor(window.dithering().factor()); - params().zigZag(window.dithering().zigzag()); + params().dithering(d.algorithm()); + matrix = d.matrix(); + params().factor(d.factor()); + params().zigZag(d.zigzag()); params().rgbmap(window.rgbMapAlgorithm()); params().fitCriteria(window.fitCriteria()); params().toGray(window.toGray()); @@ -634,7 +636,7 @@ void ChangePixelFormatCommand::onExecute(Context* ctx) tx(new cmd::SetPixelFormat( sprite, (PixelFormat)params().colorMode(), - render::Dithering(params().dithering(), matrix, params().factor(), params().zigZag()), + render::Dithering(params().dithering(), matrix, params().zigZag(), params().factor()), params().rgbmap(), get_gray_func(params().toGray()), &job, // SpriteJob is a render::TaskDelegate diff --git a/src/render/error_diffusion.cpp b/src/render/error_diffusion.cpp index c3fe905ba..a5aced534 100644 --- a/src/render/error_diffusion.cpp +++ b/src/render/error_diffusion.cpp @@ -142,7 +142,7 @@ void ErrorDiffusionDither::start(const doc::Image* srcImage, const int bufferRows = matrix.height; // Resize error buffers to accommodate the matrix height - std::vector::size_type bufferSize = m_width * bufferRows; + const std::vector::size_type bufferSize = m_width * bufferRows; for (int i = 0; i < kChannels; ++i) m_err[i].resize(bufferSize, 0); @@ -169,7 +169,7 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D(const int x, m_currentRowOffset = (m_currentRowOffset + 1) % matrix.height; // Clear only the row that will be used as the "last" row - int clearRowIndex = (m_currentRowOffset + matrix.height - 1) % matrix.height; + const int clearRowIndex = (m_currentRowOffset + matrix.height - 1) % matrix.height; for (int c = 0; c < kChannels; ++c) { int* rowToClear = &m_err[c][m_width * clearRowIndex]; std::fill(rowToClear, rowToClear + m_width, 0); @@ -215,8 +215,8 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D(const int x, for (int my = 0; my < matrix.height; ++my) { // Use circular buffer indexing - int bufferRow = (m_currentRowOffset + my) % matrix.height; - int bufferRowIndex = bufferRow * m_width; + const int bufferRow = (m_currentRowOffset + my) % matrix.height; + const int bufferRowIndex = bufferRow * m_width; for (int mx = 0; mx < matrix.width; ++mx) { const int coeff = direction > 0 ? matrix.coefficients[my][mx] : matrix.coefficients[my][matrix.width - 1 - mx]; @@ -234,9 +234,6 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D(const int x, // Calculate error as 16-bit fixed point const int errorValue = ((qerr * coeff) << 16) / matrix.divisor; - const int bufferRow = my; - const int bufferIndex = bufferRow * m_width + errorPixelX + 1; - m_err[c][bufferRowIndex + errorPixelX + 1] += errorValue; } }