tor-browser

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

chroma_from_luma.cc (1939B)


      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/chroma_from_luma.h"
      7 
      8 #include <jxl/memory_manager.h>
      9 
     10 #include <cstddef>
     11 #include <cstdlib>  // abs
     12 #include <limits>
     13 
     14 #include "lib/jxl/base/common.h"
     15 #include "lib/jxl/fields.h"
     16 #include "lib/jxl/image_ops.h"
     17 
     18 namespace jxl {
     19 
     20 Status ColorCorrelation::DecodeDC(BitReader* br) {
     21  if (br->ReadFixedBits<1>() == 1) {
     22    // All default.
     23    return true;
     24  }
     25  SetColorFactor(U32Coder::Read(kColorFactorDist, br));
     26  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_x_));
     27  if (std::abs(base_correlation_x_) > 4.0f) {
     28    return JXL_FAILURE("Base X correlation is out of range");
     29  }
     30  JXL_RETURN_IF_ERROR(F16Coder::Read(br, &base_correlation_b_));
     31  if (std::abs(base_correlation_b_) > 4.0f) {
     32    return JXL_FAILURE("Base B correlation is out of range");
     33  }
     34  ytox_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
     35             std::numeric_limits<int8_t>::min();
     36  ytob_dc_ = static_cast<int>(br->ReadFixedBits<kBitsPerByte>()) +
     37             std::numeric_limits<int8_t>::min();
     38  RecomputeDCFactors();
     39  return true;
     40 }
     41 
     42 StatusOr<ColorCorrelationMap> ColorCorrelationMap::Create(
     43    JxlMemoryManager* memory_manager, size_t xsize, size_t ysize, bool XYB) {
     44  ColorCorrelationMap result;
     45  size_t xblocks = DivCeil(xsize, kColorTileDim);
     46  size_t yblocks = DivCeil(ysize, kColorTileDim);
     47  JXL_ASSIGN_OR_RETURN(result.ytox_map,
     48                       ImageSB::Create(memory_manager, xblocks, yblocks));
     49  JXL_ASSIGN_OR_RETURN(result.ytob_map,
     50                       ImageSB::Create(memory_manager, xblocks, yblocks));
     51  ZeroFillImage(&result.ytox_map);
     52  ZeroFillImage(&result.ytob_map);
     53  if (!XYB) {
     54    result.base_.base_correlation_b_ = 0;
     55  }
     56  result.base_.RecomputeDCFactors();
     57  return result;
     58 }
     59 
     60 }  // namespace jxl