libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

toc.h (1834B)


      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 #ifndef LIB_JXL_TOC_H_
      7 #define LIB_JXL_TOC_H_
      8 
      9 #include <stddef.h>
     10 #include <stdint.h>
     11 
     12 #include <vector>
     13 
     14 #include "lib/jxl/base/compiler_specific.h"
     15 #include "lib/jxl/base/status.h"
     16 #include "lib/jxl/coeff_order_fwd.h"
     17 #include "lib/jxl/dec_bit_reader.h"
     18 #include "lib/jxl/field_encodings.h"
     19 
     20 namespace jxl {
     21 
     22 // (2+bits) = 2,3,4 bytes so encoders can patch TOC after encoding.
     23 // 30 is sufficient for 4K channels of uncompressed 16-bit samples.
     24 constexpr U32Enc kTocDist(Bits(10), BitsOffset(14, 1024), BitsOffset(22, 17408),
     25                           BitsOffset(30, 4211712));
     26 
     27 size_t MaxBits(size_t num_sizes);
     28 
     29 // TODO(veluca): move these to FrameDimensions.
     30 static JXL_INLINE size_t AcGroupIndex(size_t pass, size_t group,
     31                                       size_t num_groups, size_t num_dc_groups) {
     32   return 2 + num_dc_groups + pass * num_groups + group;
     33 }
     34 
     35 static JXL_INLINE size_t NumTocEntries(size_t num_groups, size_t num_dc_groups,
     36                                        size_t num_passes) {
     37   if (num_groups == 1 && num_passes == 1) return 1;
     38   return AcGroupIndex(0, 0, num_groups, num_dc_groups) +
     39          num_groups * num_passes;
     40 }
     41 
     42 Status ReadToc(size_t toc_entries, BitReader* JXL_RESTRICT reader,
     43                std::vector<uint32_t>* JXL_RESTRICT sizes,
     44                std::vector<coeff_order_t>* JXL_RESTRICT permutation);
     45 
     46 Status ReadGroupOffsets(size_t toc_entries, BitReader* JXL_RESTRICT reader,
     47                         std::vector<uint64_t>* JXL_RESTRICT offsets,
     48                         std::vector<uint32_t>* JXL_RESTRICT sizes,
     49                         uint64_t* total_size);
     50 
     51 }  // namespace jxl
     52 
     53 #endif  // LIB_JXL_TOC_H_