summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc')
-rw-r--r--third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc b/third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc
new file mode 100644
index 0000000000..2d22c1edb8
--- /dev/null
+++ b/third_party/jpeg-xl/lib/jxl/enc_dot_dictionary.cc
@@ -0,0 +1,71 @@
+// Copyright (c) the JPEG XL Project Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "lib/jxl/enc_dot_dictionary.h"
+
+#include <stddef.h>
+#include <string.h>
+
+#include <array>
+#include <utility>
+
+#include "lib/jxl/base/override.h"
+#include "lib/jxl/base/status.h"
+#include "lib/jxl/chroma_from_luma.h"
+#include "lib/jxl/dec_bit_reader.h"
+#include "lib/jxl/dec_xyb.h"
+#include "lib/jxl/enc_bit_writer.h"
+#include "lib/jxl/enc_detect_dots.h"
+#include "lib/jxl/enc_params.h"
+#include "lib/jxl/enc_xyb.h"
+#include "lib/jxl/image.h"
+
+namespace jxl {
+
+// Private implementation of Dictionary Encode/Decode
+namespace {
+
+/* Quantization constants for Ellipse dots */
+const size_t kEllipsePosQ = 2; // Quantization level for the position
+const double kEllipseMinSigma = 0.1; // Minimum sigma value
+const double kEllipseMaxSigma = 3.1; // Maximum Sigma value
+const size_t kEllipseSigmaQ = 16; // Number of quantization levels for sigma
+const size_t kEllipseAngleQ = 8; // Quantization level for the angle
+// TODO: fix these values.
+const std::array<double, 3> kEllipseMinIntensity{{-0.05, 0.0, -0.5}};
+const std::array<double, 3> kEllipseMaxIntensity{{0.05, 1.0, 0.4}};
+const std::array<size_t, 3> kEllipseIntensityQ{{10, 36, 10}};
+} // namespace
+
+std::vector<PatchInfo> FindDotDictionary(const CompressParams& cparams,
+ const Image3F& opsin,
+ const ColorCorrelationMap& cmap,
+ ThreadPool* pool) {
+ if (ApplyOverride(cparams.dots,
+ cparams.butteraugli_distance >= kMinButteraugliForDots)) {
+ GaussianDetectParams ellipse_params;
+ ellipse_params.t_high = 0.04;
+ ellipse_params.t_low = 0.02;
+ ellipse_params.maxWinSize = 5;
+ ellipse_params.maxL2Loss = 0.005;
+ ellipse_params.maxCustomLoss = 300;
+ ellipse_params.minIntensity = 0.12;
+ ellipse_params.maxDistMeanMode = 1.0;
+ ellipse_params.maxNegPixels = 0;
+ ellipse_params.minScore = 12.0;
+ ellipse_params.maxCC = 100;
+ ellipse_params.percCC = 100;
+ EllipseQuantParams qParams{
+ opsin.xsize(), opsin.ysize(), kEllipsePosQ,
+ kEllipseMinSigma, kEllipseMaxSigma, kEllipseSigmaQ,
+ kEllipseAngleQ, kEllipseMinIntensity, kEllipseMaxIntensity,
+ kEllipseIntensityQ, kEllipsePosQ <= 5, cmap.YtoXRatio(0),
+ cmap.YtoBRatio(0)};
+
+ return DetectGaussianEllipses(opsin, ellipse_params, qParams, pool);
+ }
+ return {};
+}
+} // namespace jxl