tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

enc_dot_dictionary.cc (2807B)


      1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style
      4 // license that can be found in the LICENSE file.
      5 
      6 #include "lib/jxl/enc_dot_dictionary.h"
      7 
      8 #include <array>
      9 #include <cstddef>
     10 #include <cstring>
     11 
     12 #include "lib/jxl/base/override.h"
     13 #include "lib/jxl/base/rect.h"
     14 #include "lib/jxl/base/status.h"
     15 #include "lib/jxl/chroma_from_luma.h"
     16 #include "lib/jxl/enc_detect_dots.h"
     17 #include "lib/jxl/enc_params.h"
     18 #include "lib/jxl/image.h"
     19 
     20 namespace jxl {
     21 
     22 // Private implementation of Dictionary Encode/Decode
     23 namespace {
     24 
     25 /* Quantization constants for Ellipse dots */
     26 const size_t kEllipsePosQ = 2;        // Quantization level for the position
     27 const double kEllipseMinSigma = 0.1;  // Minimum sigma value
     28 const double kEllipseMaxSigma = 3.1;  // Maximum Sigma value
     29 const size_t kEllipseSigmaQ = 16;     // Number of quantization levels for sigma
     30 const size_t kEllipseAngleQ = 8;      // Quantization level for the angle
     31 // TODO(user): fix these values.
     32 const std::array<double, 3> kEllipseMinIntensity{{-0.05, 0.0, -0.5}};
     33 const std::array<double, 3> kEllipseMaxIntensity{{0.05, 1.0, 0.4}};
     34 const std::array<size_t, 3> kEllipseIntensityQ{{10, 36, 10}};
     35 }  // namespace
     36 
     37 StatusOr<std::vector<PatchInfo>> FindDotDictionary(
     38    const CompressParams& cparams, const Image3F& opsin, const Rect& rect,
     39    const ColorCorrelation& color_correlation, ThreadPool* pool) {
     40  if (ApplyOverride(cparams.dots,
     41                    cparams.butteraugli_distance >= kMinButteraugliForDots)) {
     42    GaussianDetectParams ellipse_params;
     43    ellipse_params.t_high = 0.04;
     44    ellipse_params.t_low = 0.02;
     45    ellipse_params.maxWinSize = 5;
     46    ellipse_params.maxL2Loss = 0.005;
     47    ellipse_params.maxCustomLoss = 300;
     48    ellipse_params.minIntensity = 0.12;
     49    ellipse_params.maxDistMeanMode = 1.0;
     50    ellipse_params.maxNegPixels = 0;
     51    ellipse_params.minScore = 12.0;
     52    ellipse_params.maxCC = 100;
     53    ellipse_params.percCC = 100;
     54    EllipseQuantParams qParams{rect.xsize(),
     55                               rect.ysize(),
     56                               kEllipsePosQ,
     57                               kEllipseMinSigma,
     58                               kEllipseMaxSigma,
     59                               kEllipseSigmaQ,
     60                               kEllipseAngleQ,
     61                               kEllipseMinIntensity,
     62                               kEllipseMaxIntensity,
     63                               kEllipseIntensityQ,
     64                               kEllipsePosQ <= 5,
     65                               color_correlation.YtoXRatio(0),
     66                               color_correlation.YtoBRatio(0)};
     67 
     68    return DetectGaussianEllipses(opsin, rect, ellipse_params, qParams, pool);
     69  }
     70  std::vector<PatchInfo> nothing;
     71  return nothing;
     72 }
     73 }  // namespace jxl