tor-browser

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

headers.h (2419B)


      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_HEADERS_H_
      7 #define LIB_JXL_HEADERS_H_
      8 
      9 // Codestream headers.
     10 
     11 #include <stddef.h>
     12 #include <stdint.h>
     13 
     14 #include "lib/jxl/base/compiler_specific.h"
     15 #include "lib/jxl/base/status.h"
     16 #include "lib/jxl/dec_bit_reader.h"
     17 #include "lib/jxl/field_encodings.h"
     18 
     19 namespace jxl {
     20 
     21 // Reserved by ISO/IEC 10918-1. LF causes files opened in text mode to be
     22 // rejected because the marker changes to 0x0D instead. The 0xFF prefix also
     23 // ensures there were no 7-bit transmission limitations.
     24 static constexpr uint8_t kCodestreamMarker = 0x0A;
     25 
     26 // Compact representation of image dimensions (best case: 9 bits) so decoders
     27 // can preallocate early.
     28 class SizeHeader : public Fields {
     29 public:
     30  SizeHeader();
     31  JXL_FIELDS_NAME(SizeHeader)
     32 
     33  Status VisitFields(Visitor* JXL_RESTRICT visitor) override;
     34 
     35  Status Set(size_t xsize, size_t ysize);
     36 
     37  size_t xsize() const;
     38  size_t ysize() const {
     39    return small_ ? ((ysize_div8_minus_1_ + 1) * 8) : ysize_;
     40  }
     41 
     42 private:
     43  bool small_;  // xsize and ysize <= 256 and divisible by 8.
     44 
     45  uint32_t ysize_div8_minus_1_;
     46  uint32_t ysize_;
     47 
     48  uint32_t ratio_;
     49  uint32_t xsize_div8_minus_1_;
     50  uint32_t xsize_;
     51 };
     52 
     53 // (Similar to SizeHeader but different encoding because previews are smaller)
     54 class PreviewHeader : public Fields {
     55 public:
     56  PreviewHeader();
     57  JXL_FIELDS_NAME(PreviewHeader)
     58 
     59  Status VisitFields(Visitor* JXL_RESTRICT visitor) override;
     60 
     61  Status Set(size_t xsize, size_t ysize);
     62 
     63  size_t xsize() const;
     64  size_t ysize() const { return div8_ ? (ysize_div8_ * 8) : ysize_; }
     65 
     66 private:
     67  bool div8_;  // xsize and ysize divisible by 8.
     68 
     69  uint32_t ysize_div8_;
     70  uint32_t ysize_;
     71 
     72  uint32_t ratio_;
     73  uint32_t xsize_div8_;
     74  uint32_t xsize_;
     75 };
     76 
     77 struct AnimationHeader : public Fields {
     78  AnimationHeader();
     79  JXL_FIELDS_NAME(AnimationHeader)
     80 
     81  Status VisitFields(Visitor* JXL_RESTRICT visitor) override;
     82 
     83  // Ticks per second (expressed as rational number to support NTSC)
     84  uint32_t tps_numerator;
     85  uint32_t tps_denominator;
     86 
     87  uint32_t num_loops;  // 0 means to repeat infinitely.
     88 
     89  bool have_timecodes;
     90 };
     91 
     92 Status ReadSizeHeader(BitReader* JXL_RESTRICT reader,
     93                      SizeHeader* JXL_RESTRICT size);
     94 
     95 }  // namespace jxl
     96 
     97 #endif  // LIB_JXL_HEADERS_H_