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