diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc b/third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc index f5172aa126..24c64f5aad 100644 --- a/third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc +++ b/third_party/jpeg-xl/lib/jxl/modular/transform/enc_palette.cc @@ -10,8 +10,8 @@ #include <set> #include "lib/jxl/base/common.h" -#include "lib/jxl/base/data_parallel.h" #include "lib/jxl/base/status.h" +#include "lib/jxl/image_ops.h" #include "lib/jxl/modular/encoding/context_predict.h" #include "lib/jxl/modular/modular_image.h" #include "lib/jxl/modular/transform/enc_transform.h" @@ -34,7 +34,8 @@ float ColorDistance(const std::vector<float> &JXL_RESTRICT a, if (a.size() >= 3) { ave3 = (a[0] + b[0] + a[1] + b[1] + a[2] + b[2]) * (1.21f / 3.0f); } - float sum_a = 0, sum_b = 0; + float sum_a = 0; + float sum_b = 0; for (size_t c = 0; c < a.size(); ++c) { const float difference = static_cast<float>(a[c]) - static_cast<float>(b[c]); @@ -132,7 +133,8 @@ struct PaletteIterationData { delta_frequency.first[1], delta_frequency.first[2]}; float delta_distance = - sqrt(palette_internal::ColorDistance({0, 0, 0}, current_delta)) + 1; + std::sqrt(palette_internal::ColorDistance({0, 0, 0}, current_delta)) + + 1; delta_frequency.second *= delta_distance * delta_distance_multiplier; } @@ -174,7 +176,8 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, // Channel palette special case if (nb_colors == 0) return false; std::vector<pixel_type> lookup; - pixel_type minval, maxval; + pixel_type minval; + pixel_type maxval; compute_minmax(input.channel[begin_c], &minval, &maxval); size_t lookup_table_size = static_cast<int64_t>(maxval) - static_cast<int64_t>(minval) + 1; @@ -189,12 +192,12 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, const bool new_color = chpalette.insert(p[x]).second; if (new_color) { idx++; - if (idx > (int)nb_colors) return false; + if (idx > static_cast<int>(nb_colors)) return false; } } } JXL_DEBUG_V(6, "Channel %i uses only %i colors.", begin_c, idx); - Channel pch(idx, 1); + JXL_ASSIGN_OR_RETURN(Channel pch, Channel::Create(idx, 1)); pch.hshift = -1; pch.vshift = -1; nb_colors = idx; @@ -206,9 +209,12 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, for (size_t y = 0; y < h; y++) { pixel_type *p = input.channel[begin_c].Row(y); for (size_t x = 0; x < w; x++) { - for (idx = 0; p[x] != p_palette[idx] && idx < (int)nb_colors; idx++) { + for (idx = 0; + p[x] != p_palette[idx] && idx < static_cast<int>(nb_colors); + idx++) { + // no-op } - JXL_DASSERT(idx < (int)nb_colors); + JXL_DASSERT(idx < static_cast<int>(nb_colors)); p[x] = idx; } } @@ -226,12 +232,12 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, if (lookup[p[x] - minval] == 0) { lookup[p[x] - minval] = 1; idx++; - if (idx > (int)nb_colors) return false; + if (idx > static_cast<int>(nb_colors)) return false; } } } JXL_DEBUG_V(6, "Channel %i uses only %i colors.", begin_c, idx); - Channel pch(idx, 1); + JXL_ASSIGN_OR_RETURN(Channel pch, Channel::Create(idx, 1)); pch.hshift = -1; pch.vshift = -1; nb_colors = idx; @@ -256,7 +262,8 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, Image quantized_input; if (lossy) { - quantized_input = Image(w, h, input.bitdepth, nb); + JXL_ASSIGN_OR_RETURN(quantized_input, + Image::Create(w, h, input.bitdepth, nb)); for (size_t c = 0; c < nb; c++) { CopyImageTo(input.channel[begin_c + c].plane, &quantized_input.channel[c].plane); @@ -337,7 +344,7 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, JXL_DEBUG_V(6, "Channels %i-%i can be represented using a %i-color palette.", begin_c, end_c, nb_colors); - Channel pch(nb_colors, nb); + JXL_ASSIGN_OR_RETURN(Channel pch, Channel::Create(nb_colors, nb)); pch.hshift = -1; pch.vshift = -1; pixel_type *JXL_RESTRICT p_palette = pch.Row(0); @@ -361,7 +368,8 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, std::sort(candidate_palette_imageorder.begin(), candidate_palette_imageorder.end(), [](std::vector<pixel_type> ap, std::vector<pixel_type> bp) { - float ay, by; + float ay; + float by; ay = (0.299f * ap[0] + 0.587f * ap[1] + 0.114f * ap[2] + 0.1f); if (ap.size() > 3) ay *= 1.f + ap[3]; by = (0.299f * bp[0] + 0.587f * bp[1] + 0.114f * bp[2] + 0.1f); @@ -420,7 +428,7 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, for (int diffusion_index = 0; diffusion_index < 2; ++diffusion_index) { for (size_t c = 0; c < nb; c++) { color_with_error[c] = - p_in[c][x] + palette_iteration_data.final_run * + p_in[c][x] + (palette_iteration_data.final_run ? 1 : 0) * kDiffusionMultiplier[diffusion_index] * error_row[0][c][x + 2]; color[c] = Clamp1(lroundf(color_with_error[c]), 0l, @@ -503,7 +511,7 @@ Status FwdPaletteIteration(Image &input, uint32_t begin_c, uint32_t end_c, float local_error = color_with_error[c] - best_val[c]; len_error += local_error * local_error; } - len_error = sqrt(len_error); + len_error = std::sqrt(len_error); float modulate = 1.0; int len_limit = 38 << std::max(0, bit_depth - 8); if (len_error > len_limit) { |