/src/libjxl/lib/jxl/modular/modular_image.cc
Line | Count | Source (jump to first uncovered line) |
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 | | #include "lib/jxl/modular/modular_image.h" |
7 | | |
8 | | #include <jxl/memory_manager.h> |
9 | | |
10 | | #if JXL_DEBUG_V_LEVEL >= 1 |
11 | | #include <sstream> |
12 | | #endif |
13 | | |
14 | | #include "lib/jxl/base/status.h" |
15 | | #include "lib/jxl/image_ops.h" |
16 | | #include "lib/jxl/modular/transform/transform.h" |
17 | | |
18 | | namespace jxl { |
19 | | |
20 | | void Image::undo_transforms(const weighted::Header &wp_header, |
21 | 59.4k | jxl::ThreadPool *pool) { |
22 | 92.0k | while (!transform.empty()) { |
23 | 32.6k | Transform t = transform.back(); |
24 | 32.6k | JXL_DEBUG_V(4, "Undoing transform"); |
25 | 32.6k | Status result = t.Inverse(*this, wp_header, pool); |
26 | 32.6k | if (result == false) { |
27 | 0 | JXL_NOTIFY_ERROR("Error while undoing transform."); |
28 | 0 | error = true; |
29 | 0 | return; |
30 | 0 | } |
31 | 32.6k | JXL_DEBUG_V(8, "Undoing transform: done"); |
32 | 32.6k | transform.pop_back(); |
33 | 32.6k | } |
34 | 59.4k | } |
35 | | |
36 | | Image::Image(JxlMemoryManager *memory_manager, size_t iw, size_t ih, |
37 | | int bitdepth) |
38 | 151k | : w(iw), |
39 | 151k | h(ih), |
40 | 151k | bitdepth(bitdepth), |
41 | 151k | nb_meta_channels(0), |
42 | 151k | error(false), |
43 | 151k | memory_manager_(memory_manager) {} |
44 | | |
45 | | StatusOr<Image> Image::Create(JxlMemoryManager *memory_manager, size_t iw, |
46 | 151k | size_t ih, int bitdepth, int nb_chans) { |
47 | 151k | Image result(memory_manager, iw, ih, bitdepth); |
48 | 342k | for (int i = 0; i < nb_chans; i++) { |
49 | 191k | JXL_ASSIGN_OR_RETURN(Channel c, Channel::Create(memory_manager, iw, ih)); |
50 | 191k | result.channel.emplace_back(std::move(c)); |
51 | 191k | } |
52 | 151k | return result; |
53 | 151k | } |
54 | | |
55 | | Image::Image(JxlMemoryManager *memory_manager) |
56 | 137k | : w(0), |
57 | 137k | h(0), |
58 | 137k | bitdepth(8), |
59 | 137k | nb_meta_channels(0), |
60 | 137k | error(true), |
61 | 137k | memory_manager_(memory_manager) {} |
62 | | |
63 | 65.9k | Image &Image::operator=(Image &&other) noexcept { |
64 | 65.9k | w = other.w; |
65 | 65.9k | h = other.h; |
66 | 65.9k | bitdepth = other.bitdepth; |
67 | 65.9k | nb_meta_channels = other.nb_meta_channels; |
68 | 65.9k | error = other.error; |
69 | 65.9k | channel = std::move(other.channel); |
70 | 65.9k | transform = std::move(other.transform); |
71 | 65.9k | return *this; |
72 | 65.9k | } |
73 | | |
74 | 0 | StatusOr<Image> Image::Clone(const Image &that) { |
75 | 0 | JxlMemoryManager *memory_manager = that.memory_manager(); |
76 | 0 | Image clone(memory_manager, that.w, that.h, that.bitdepth); |
77 | 0 | clone.nb_meta_channels = that.nb_meta_channels; |
78 | 0 | clone.error = that.error; |
79 | 0 | clone.transform = that.transform; |
80 | 0 | for (const Channel &ch : that.channel) { |
81 | 0 | JXL_ASSIGN_OR_RETURN(Channel a, Channel::Create(memory_manager, ch.w, ch.h, |
82 | 0 | ch.hshift, ch.vshift)); |
83 | 0 | JXL_RETURN_IF_ERROR(CopyImageTo(ch.plane, &a.plane)); |
84 | 0 | clone.channel.push_back(std::move(a)); |
85 | 0 | } |
86 | 0 | return clone; |
87 | 0 | } |
88 | | |
89 | | #if JXL_DEBUG_V_LEVEL >= 1 |
90 | | std::string Image::DebugString() const { |
91 | | std::ostringstream os; |
92 | | os << w << "x" << h << ", depth: " << bitdepth; |
93 | | if (!channel.empty()) { |
94 | | os << ", channels:"; |
95 | | for (size_t i = 0; i < channel.size(); ++i) { |
96 | | os << " " << channel[i].w << "x" << channel[i].h |
97 | | << "(shift: " << channel[i].hshift << "," << channel[i].vshift << ")"; |
98 | | if (i < nb_meta_channels) os << "*"; |
99 | | } |
100 | | } |
101 | | return os.str(); |
102 | | } |
103 | | #endif |
104 | | |
105 | | } // namespace jxl |