Coverage Report

Created: 2025-11-16 07:22

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
654k
                                  size_t ih, int hsh, int vsh) {
28
654k
  JXL_ASSIGN_OR_RETURN(Plane<pixel_type> plane,
29
654k
                       Plane<pixel_type>::Create(memory_manager, iw, ih));
30
654k
  return Channel(std::move(plane), iw, ih, hsh, vsh);
31
654k
}
32
33
void Image::undo_transforms(const weighted::Header &wp_header,
34
46.1k
                            jxl::ThreadPool *pool) {
35
61.1k
  while (!transform.empty()) {
36
14.9k
    Transform t = transform.back();
37
14.9k
    JXL_DEBUG_V(4, "Undoing transform");
38
14.9k
    Status result = t.Inverse(*this, wp_header, pool);
39
14.9k
    if (result == false) {
40
0
      JXL_NOTIFY_ERROR("Error while undoing transform.");
41
0
      error = true;
42
0
      return;
43
0
    }
44
14.9k
    JXL_DEBUG_V(8, "Undoing transform: done");
45
14.9k
    transform.pop_back();
46
14.9k
  }
47
46.1k
}
48
49
Image::Image(JxlMemoryManager *memory_manager, size_t iw, size_t ih,
50
             int bitdepth)
51
196k
    : w(iw),
52
196k
      h(ih),
53
196k
      bitdepth(bitdepth),
54
196k
      nb_meta_channels(0),
55
196k
      error(false),
56
196k
      memory_manager_(memory_manager) {}
57
58
StatusOr<Image> Image::Create(JxlMemoryManager *memory_manager, size_t iw,
59
196k
                              size_t ih, int bitdepth, int nb_chans) {
60
196k
  Image result(memory_manager, iw, ih, bitdepth);
61
461k
  for (int i = 0; i < nb_chans; i++) {
62
264k
    JXL_ASSIGN_OR_RETURN(Channel c, Channel::Create(memory_manager, iw, ih));
63
264k
    result.channel.emplace_back(std::move(c));
64
264k
    result.channel.back().component = i;
65
264k
  }
66
196k
  return result;
67
196k
}
68
69
Image::Image(JxlMemoryManager *memory_manager)
70
329k
    : w(0),
71
329k
      h(0),
72
329k
      bitdepth(8),
73
329k
      nb_meta_channels(0),
74
329k
      error(true),
75
329k
      memory_manager_(memory_manager) {}
76
77
98.0k
Image &Image::operator=(Image &&other) noexcept {
78
98.0k
  w = other.w;
79
98.0k
  h = other.h;
80
98.0k
  bitdepth = other.bitdepth;
81
98.0k
  nb_meta_channels = other.nb_meta_channels;
82
98.0k
  error = other.error;
83
98.0k
  channel = std::move(other.channel);
84
98.0k
  transform = std::move(other.transform);
85
98.0k
  return *this;
86
98.0k
}
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