libjxl

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

enc_toc.cc (1632B)


      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_toc.h"
      7 
      8 #include <stdint.h>
      9 
     10 #include "lib/jxl/base/common.h"
     11 #include "lib/jxl/coeff_order.h"
     12 #include "lib/jxl/enc_aux_out.h"
     13 #include "lib/jxl/enc_coeff_order.h"
     14 #include "lib/jxl/field_encodings.h"
     15 #include "lib/jxl/fields.h"
     16 #include "lib/jxl/toc.h"
     17 
     18 namespace jxl {
     19 Status WriteGroupOffsets(const std::vector<BitWriter>& group_codes,
     20                          const std::vector<coeff_order_t>& permutation,
     21                          BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) {
     22   BitWriter::Allotment allotment(writer, MaxBits(group_codes.size()));
     23   if (!permutation.empty() && !group_codes.empty()) {
     24     // Don't write a permutation at all for an empty group_codes.
     25     writer->Write(1, 1);  // permutation
     26     JXL_DASSERT(permutation.size() == group_codes.size());
     27     EncodePermutation(permutation.data(), /*skip=*/0, permutation.size(),
     28                       writer, /* layer= */ 0, aux_out);
     29 
     30   } else {
     31     writer->Write(1, 0);  // no permutation
     32   }
     33   writer->ZeroPadToByte();  // before TOC entries
     34 
     35   for (size_t i = 0; i < group_codes.size(); i++) {
     36     JXL_ASSERT(group_codes[i].BitsWritten() % kBitsPerByte == 0);
     37     const size_t group_size = group_codes[i].BitsWritten() / kBitsPerByte;
     38     JXL_RETURN_IF_ERROR(U32Coder::Write(kTocDist, group_size, writer));
     39   }
     40   writer->ZeroPadToByte();  // before first group
     41   allotment.ReclaimAndCharge(writer, kLayerTOC, aux_out);
     42   return true;
     43 }
     44 
     45 }  // namespace jxl