Coverage Report

Created: 2025-12-31 07:53

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