Fix transposed arg, add consts

This commit is contained in:
David Thomas 2025-06-14 14:37:36 +01:00
parent 484f8d69bf
commit 4c5f5249d8
No known key found for this signature in database
GPG Key ID: 553E822E460EE293
2 changed files with 11 additions and 12 deletions

View File

@ -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

View File

@ -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<int>::size_type bufferSize = m_width * bufferRows;
const std::vector<int>::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;
}
}