tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

modular_image.cc (3086B)


      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                            jxl::ThreadPool *pool) {
     22  while (!transform.empty()) {
     23    Transform t = transform.back();
     24    JXL_DEBUG_V(4, "Undoing transform");
     25    Status result = t.Inverse(*this, wp_header, pool);
     26    if (result == false) {
     27      JXL_NOTIFY_ERROR("Error while undoing transform.");
     28      error = true;
     29      return;
     30    }
     31    JXL_DEBUG_V(8, "Undoing transform: done");
     32    transform.pop_back();
     33  }
     34 }
     35 
     36 Image::Image(JxlMemoryManager *memory_manager, size_t iw, size_t ih,
     37             int bitdepth)
     38    : w(iw),
     39      h(ih),
     40      bitdepth(bitdepth),
     41      nb_meta_channels(0),
     42      error(false),
     43      memory_manager_(memory_manager) {}
     44 
     45 StatusOr<Image> Image::Create(JxlMemoryManager *memory_manager, size_t iw,
     46                              size_t ih, int bitdepth, int nb_chans) {
     47  Image result(memory_manager, iw, ih, bitdepth);
     48  for (int i = 0; i < nb_chans; i++) {
     49    JXL_ASSIGN_OR_RETURN(Channel c, Channel::Create(memory_manager, iw, ih));
     50    result.channel.emplace_back(std::move(c));
     51  }
     52  return result;
     53 }
     54 
     55 Image::Image(JxlMemoryManager *memory_manager)
     56    : w(0),
     57      h(0),
     58      bitdepth(8),
     59      nb_meta_channels(0),
     60      error(true),
     61      memory_manager_(memory_manager) {}
     62 
     63 Image &Image::operator=(Image &&other) noexcept {
     64  w = other.w;
     65  h = other.h;
     66  bitdepth = other.bitdepth;
     67  nb_meta_channels = other.nb_meta_channels;
     68  error = other.error;
     69  channel = std::move(other.channel);
     70  transform = std::move(other.transform);
     71  return *this;
     72 }
     73 
     74 StatusOr<Image> Image::Clone(const Image &that) {
     75  JxlMemoryManager *memory_manager = that.memory_manager();
     76  Image clone(memory_manager, that.w, that.h, that.bitdepth);
     77  clone.nb_meta_channels = that.nb_meta_channels;
     78  clone.error = that.error;
     79  clone.transform = that.transform;
     80  for (const Channel &ch : that.channel) {
     81    JXL_ASSIGN_OR_RETURN(Channel a, Channel::Create(memory_manager, ch.w, ch.h,
     82                                                    ch.hshift, ch.vshift));
     83    JXL_RETURN_IF_ERROR(CopyImageTo(ch.plane, &a.plane));
     84    clone.channel.push_back(std::move(a));
     85  }
     86  return clone;
     87 }
     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