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