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_MODULAR_MODULAR_IMAGE_H_ 7 #define LIB_JXL_MODULAR_MODULAR_IMAGE_H_ 8 9 #include <stddef.h> 10 #include <stdint.h> 11 #include <stdio.h> 12 #include <string.h> 13 14 #include <utility> 15 #include <vector> 16 17 #include "lib/jxl/base/compiler_specific.h" 18 #include "lib/jxl/base/data_parallel.h" 19 #include "lib/jxl/base/status.h" 20 #include "lib/jxl/image.h" 21 #include "lib/jxl/image_ops.h" 22 23 namespace jxl { 24 25 typedef int32_t pixel_type; // can use int16_t if it's only for 8-bit images. 26 // Need some wiggle room for YCoCg / Squeeze etc 27 28 typedef int64_t pixel_type_w; 29 30 namespace weighted { 31 struct Header; 32 } 33 34 class Channel { 35 public: 36 jxl::Plane<pixel_type> plane; 37 size_t w, h; 38 int hshift, vshift; // w ~= image.w >> hshift; h ~= image.h >> vshift 39 Channel(size_t iw, size_t ih, int hsh = 0, int vsh = 0) plane(iw,ih)40 : plane(iw, ih), w(iw), h(ih), hshift(hsh), vshift(vsh) {} 41 42 Channel(const Channel& other) = delete; 43 Channel& operator=(const Channel& other) = delete; 44 45 // Move assignment 46 Channel& operator=(Channel&& other) noexcept { 47 w = other.w; 48 h = other.h; 49 hshift = other.hshift; 50 vshift = other.vshift; 51 plane = std::move(other.plane); 52 return *this; 53 } 54 55 // Move constructor 56 Channel(Channel&& other) noexcept = default; 57 shrink()58 void shrink() { 59 if (plane.xsize() == w && plane.ysize() == h) return; 60 jxl::Plane<pixel_type> resizedplane(w, h); 61 plane = std::move(resizedplane); 62 } shrink(int nw,int nh)63 void shrink(int nw, int nh) { 64 w = nw; 65 h = nh; 66 shrink(); 67 } 68 Row(const size_t y)69 JXL_INLINE pixel_type* Row(const size_t y) { return plane.Row(y); } Row(const size_t y)70 JXL_INLINE const pixel_type* Row(const size_t y) const { 71 return plane.Row(y); 72 } 73 }; 74 75 class Transform; 76 77 class Image { 78 public: 79 // image data, transforms can dramatically change the number of channels and 80 // their semantics 81 std::vector<Channel> channel; 82 // transforms that have been applied (and that have to be undone) 83 std::vector<Transform> transform; 84 85 // image dimensions (channels may have different dimensions due to transforms) 86 size_t w, h; 87 int bitdepth; 88 size_t nb_meta_channels; // first few channels might contain palette(s) 89 bool error; // true if a fatal error occurred, false otherwise 90 91 Image(size_t iw, size_t ih, int bitdepth, int nb_chans); 92 Image(); 93 94 Image(const Image& other) = delete; 95 Image& operator=(const Image& other) = delete; 96 97 Image& operator=(Image&& other) noexcept; 98 Image(Image&& other) noexcept = default; 99 100 // undo all except the first 'keep' transforms 101 void undo_transforms(const weighted::Header& wp_header, int keep = 0, 102 jxl::ThreadPool* pool = nullptr); 103 }; 104 105 } // namespace jxl 106 107 #endif // LIB_JXL_MODULAR_MODULAR_IMAGE_H_ 108