Coverage Report

Created: 2026-02-14 07:42

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
2.88M
                                  size_t ih, int hsh, int vsh) {
28
2.88M
  JXL_ASSIGN_OR_RETURN(Plane<pixel_type> plane,
29
2.88M
                       Plane<pixel_type>::Create(memory_manager, iw, ih));
30
2.88M
  return Channel(std::move(plane), iw, ih, hsh, vsh);
31
2.88M
}
32
33
void Image::undo_transforms(const weighted::Header &wp_header,
34
169k
                            jxl::ThreadPool *pool) {
35
246k
  while (!transform.empty()) {
36
77.4k
    Transform t = transform.back();
37
77.4k
    JXL_DEBUG_V(4, "Undoing transform");
38
77.4k
    Status result = t.Inverse(*this, wp_header, pool);
39
77.4k
    if (result == false) {
40
4
      JXL_NOTIFY_ERROR("Error while undoing transform.");
41
4
      error = true;
42
4
      return;
43
4
    }
44
77.4k
    JXL_DEBUG_V(8, "Undoing transform: done");
45
77.4k
    transform.pop_back();
46
77.4k
  }
47
169k
}
48
49
Image::Image(JxlMemoryManager *memory_manager, size_t iw, size_t ih,
50
             int bitdepth)
51
496k
    : w(iw),
52
496k
      h(ih),
53
496k
      bitdepth(bitdepth),
54
496k
      nb_meta_channels(0),
55
496k
      error(false),
56
496k
      memory_manager_(memory_manager) {}
57
58
StatusOr<Image> Image::Create(JxlMemoryManager *memory_manager, size_t iw,
59
496k
                              size_t ih, int bitdepth, int nb_chans) {
60
496k
  Image result(memory_manager, iw, ih, bitdepth);
61
981k
  for (int i = 0; i < nb_chans; i++) {
62
485k
    JXL_ASSIGN_OR_RETURN(Channel c, Channel::Create(memory_manager, iw, ih));
63
485k
    result.channel.emplace_back(std::move(c));
64
485k
    result.channel.back().component = i;
65
485k
  }
66
496k
  return result;
67
496k
}
68
69
Image::Image(JxlMemoryManager *memory_manager)
70
486k
    : w(0),
71
486k
      h(0),
72
486k
      bitdepth(8),
73
486k
      nb_meta_channels(0),
74
486k
      error(true),
75
486k
      memory_manager_(memory_manager) {}
76
77
255k
Image &Image::operator=(Image &&other) noexcept {
78
255k
  w = other.w;
79
255k
  h = other.h;
80
255k
  bitdepth = other.bitdepth;
81
255k
  nb_meta_channels = other.nb_meta_channels;
82
255k
  error = other.error;
83
255k
  channel = std::move(other.channel);
84
255k
  transform = std::move(other.transform);
85
255k
  return *this;
86
255k
}
87
88
39
StatusOr<Image> Image::Clone(const Image &that) {
89
39
  JxlMemoryManager *memory_manager = that.memory_manager();
90
39
  Image clone(memory_manager, that.w, that.h, that.bitdepth);
91
39
  clone.nb_meta_channels = that.nb_meta_channels;
92
39
  clone.error = that.error;
93
39
  clone.transform = that.transform;
94
382
  for (const Channel &ch : that.channel) {
95
382
    JXL_ASSIGN_OR_RETURN(Channel a, Channel::Create(memory_manager, ch.w, ch.h,
96
382
                                                    ch.hshift, ch.vshift));
97
98
382
    JXL_RETURN_IF_ERROR(CopyImageTo(ch.plane, &a.plane));
99
382
    a.component = ch.component;
100
382
    clone.channel.push_back(std::move(a));
101
382
  }
102
39
  return clone;
103
39
}
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