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
|
// 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.
#include "lib/jxl/modular/modular_image.h"
#include <sstream>
#include "lib/jxl/base/status.h"
#include "lib/jxl/image_ops.h"
#include "lib/jxl/modular/transform/transform.h"
namespace jxl {
void Image::undo_transforms(const weighted::Header &wp_header,
jxl::ThreadPool *pool) {
while (!transform.empty()) {
Transform t = transform.back();
JXL_DEBUG_V(4, "Undoing transform");
Status result = t.Inverse(*this, wp_header, pool);
if (result == false) {
JXL_NOTIFY_ERROR("Error while undoing transform.");
error = true;
return;
}
JXL_DEBUG_V(8, "Undoing transform: done");
transform.pop_back();
}
}
Image::Image(size_t iw, size_t ih, int bitdepth)
: w(iw), h(ih), bitdepth(bitdepth), nb_meta_channels(0), error(false) {}
StatusOr<Image> Image::Create(size_t iw, size_t ih, int bitdepth,
int nb_chans) {
Image result(iw, ih, bitdepth);
for (int i = 0; i < nb_chans; i++) {
StatusOr<Channel> channel_or = Channel::Create(iw, ih);
JXL_RETURN_IF_ERROR(channel_or.status());
result.channel.emplace_back(std::move(channel_or).value());
}
return result;
}
Image::Image() : w(0), h(0), bitdepth(8), nb_meta_channels(0), error(true) {}
Image &Image::operator=(Image &&other) noexcept {
w = other.w;
h = other.h;
bitdepth = other.bitdepth;
nb_meta_channels = other.nb_meta_channels;
error = other.error;
channel = std::move(other.channel);
transform = std::move(other.transform);
return *this;
}
StatusOr<Image> Image::Clone(const Image &that) {
Image clone(that.w, that.h, that.bitdepth);
clone.nb_meta_channels = that.nb_meta_channels;
clone.error = that.error;
clone.transform = that.transform;
for (const Channel &ch : that.channel) {
JXL_ASSIGN_OR_RETURN(Channel a,
Channel::Create(ch.w, ch.h, ch.hshift, ch.vshift));
CopyImageTo(ch.plane, &a.plane);
clone.channel.push_back(std::move(a));
}
return clone;
}
#if JXL_DEBUG_V_LEVEL >= 1
std::string Image::DebugString() const {
std::ostringstream os;
os << w << "x" << h << ", depth: " << bitdepth;
if (!channel.empty()) {
os << ", channels:";
for (size_t i = 0; i < channel.size(); ++i) {
os << " " << channel[i].w << "x" << channel[i].h
<< "(shift: " << channel[i].hshift << "," << channel[i].vshift << ")";
if (i < nb_meta_channels) os << "*";
}
}
return os.str();
}
#endif
} // namespace jxl
|