libjxl

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

pnm.h (1738B)


      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 #include <mutex>
     17 
     18 #include "lib/extras/dec/color_hints.h"
     19 #include "lib/extras/mmap.h"
     20 #include "lib/extras/packed_image.h"
     21 #include "lib/jxl/base/data_parallel.h"
     22 #include "lib/jxl/base/span.h"
     23 #include "lib/jxl/base/status.h"
     24 
     25 namespace jxl {
     26 
     27 struct SizeConstraints;
     28 
     29 namespace extras {
     30 
     31 // Decodes `bytes` into `ppf`. color_hints may specify "color_space", which
     32 // defaults to sRGB.
     33 Status DecodeImagePNM(Span<const uint8_t> bytes, const ColorHints& color_hints,
     34                       PackedPixelFile* ppf,
     35                       const SizeConstraints* constraints = nullptr);
     36 
     37 void TestCodecPNM();
     38 
     39 struct HeaderPNM {
     40   size_t xsize;
     41   size_t ysize;
     42   bool is_gray;    // PGM
     43   bool has_alpha;  // PAM
     44   size_t bits_per_sample;
     45   bool floating_point;
     46   bool big_endian;
     47   std::vector<JxlExtraChannelType> ec_types;  // PAM
     48 };
     49 
     50 class ChunkedPNMDecoder {
     51  public:
     52   static StatusOr<ChunkedPNMDecoder> Init(const char* file_path);
     53   // Initializes `ppf` with a pointer to this `ChunkedPNMDecoder`.
     54   jxl::Status InitializePPF(const ColorHints& color_hints,
     55                             PackedPixelFile* ppf);
     56 
     57  private:
     58   HeaderPNM header_ = {};
     59   size_t data_start_ = 0;
     60   MemoryMappedFile pnm_;
     61 
     62   friend struct PNMChunkedInputFrame;
     63 };
     64 
     65 }  // namespace extras
     66 }  // namespace jxl
     67 
     68 #endif  // LIB_EXTRAS_DEC_PNM_H_