tor-browser

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

pnm.h (1659B)


      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_EXTRAS_DEC_PNM_H_
      7 #define LIB_EXTRAS_DEC_PNM_H_
      8 
      9 // Decodes PBM/PGM/PPM/PFM pixels in memory.
     10 
     11 #include <stddef.h>
     12 #include <stdint.h>
     13 
     14 // TODO(janwas): workaround for incorrect Win64 codegen (cause unknown)
     15 #include <hwy/highway.h>
     16 
     17 #include "lib/extras/dec/color_hints.h"
     18 #include "lib/extras/mmap.h"
     19 #include "lib/extras/packed_image.h"
     20 #include "lib/jxl/base/span.h"
     21 #include "lib/jxl/base/status.h"
     22 
     23 namespace jxl {
     24 
     25 struct SizeConstraints;
     26 
     27 namespace extras {
     28 
     29 // Decodes `bytes` into `ppf`. color_hints may specify "color_space", which
     30 // defaults to sRGB.
     31 Status DecodeImagePNM(Span<const uint8_t> bytes, const ColorHints& color_hints,
     32                      PackedPixelFile* ppf,
     33                      const SizeConstraints* constraints = nullptr);
     34 
     35 struct HeaderPNM {
     36  size_t xsize;
     37  size_t ysize;
     38  bool is_gray;    // PGM
     39  bool has_alpha;  // PAM
     40  size_t bits_per_sample;
     41  bool floating_point;
     42  bool big_endian;
     43  std::vector<JxlExtraChannelType> ec_types;  // PAM
     44 };
     45 
     46 class ChunkedPNMDecoder {
     47 public:
     48  static StatusOr<ChunkedPNMDecoder> Init(const char* file_path);
     49  // Initializes `ppf` with a pointer to this `ChunkedPNMDecoder`.
     50  jxl::Status InitializePPF(const ColorHints& color_hints,
     51                            PackedPixelFile* ppf);
     52 
     53 private:
     54  HeaderPNM header_ = {};
     55  size_t data_start_ = 0;
     56  MemoryMappedFile pnm_;
     57 
     58  friend struct PNMChunkedInputFrame;
     59 };
     60 
     61 }  // namespace extras
     62 }  // namespace jxl
     63 
     64 #endif  // LIB_EXTRAS_DEC_PNM_H_