Coverage Report

Created: 2025-11-16 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/modular/modular_image.h
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
#ifndef LIB_JXL_MODULAR_MODULAR_IMAGE_H_
7
#define LIB_JXL_MODULAR_MODULAR_IMAGE_H_
8
9
#include <jxl/memory_manager.h>
10
11
#include <cstddef>
12
#include <cstdint>
13
#include <cstring>
14
#include <string>
15
#include <utility>
16
#include <vector>
17
18
#include "lib/jxl/base/compiler_specific.h"
19
#include "lib/jxl/base/data_parallel.h"
20
#include "lib/jxl/base/status.h"
21
#include "lib/jxl/image.h"
22
23
namespace jxl {
24
25
typedef int32_t pixel_type;  // can use int16_t if it's only for 8-bit images.
26
                             // Need some wiggle room for YCoCg / Squeeze etc
27
28
typedef int64_t pixel_type_w;
29
30
namespace weighted {
31
struct Header;
32
}
33
34
class Channel {
35
 public:
36
  jxl::Plane<pixel_type> plane;
37
  size_t w, h;
38
  int hshift, vshift;  // w ~= image.w >> hshift;  h ~= image.h >> vshift
39
  int component = -1;
40
  Channel(const Channel& other) = delete;
41
  Channel& operator=(const Channel& other) = delete;
42
43
  static StatusOr<Channel> Create(JxlMemoryManager* memory_manager, size_t iw,
44
                                  size_t ih, int hsh = 0, int vsh = 0);
45
46
  // Move assignment
47
191M
  Channel& operator=(Channel&& other) noexcept {
48
191M
    w = other.w;
49
191M
    h = other.h;
50
191M
    hshift = other.hshift;
51
191M
    vshift = other.vshift;
52
191M
    component = other.component;
53
191M
    plane = std::move(other.plane);
54
191M
    return *this;
55
191M
  }
56
57
  // Move constructor
58
7.92M
  Channel(Channel&& other) noexcept = default;
59
60
937k
  JxlMemoryManager* memory_manager() const { return plane.memory_manager(); };
61
62
1.11M
  Status shrink() {
63
1.11M
    if (plane.xsize() == w && plane.ysize() == h) return true;
64
936k
    JXL_ASSIGN_OR_RETURN(plane,
65
936k
                         Plane<pixel_type>::Create(memory_manager(), w, h));
66
936k
    return true;
67
936k
  }
68
153k
  Status shrink(int nw, int nh) {
69
153k
    w = nw;
70
153k
    h = nh;
71
153k
    return shrink();
72
153k
  }
73
74
874M
  JXL_INLINE pixel_type* Row(const size_t y) { return plane.Row(y); }
75
650M
  JXL_INLINE const pixel_type* Row(const size_t y) const {
76
650M
    return plane.Row(y);
77
650M
  }
78
79
 private:
80
  Channel(jxl::Plane<pixel_type>&& p, size_t iw, size_t ih, int hsh, int vsh)
81
2.32M
      : plane(std::move(p)), w(iw), h(ih), hshift(hsh), vshift(vsh) {}
82
};
83
84
class Transform;
85
86
class Image {
87
 public:
88
  // image data, transforms can dramatically change the number of channels and
89
  // their semantics
90
  std::vector<Channel> channel;
91
  // transforms that have been applied (and that have to be undone)
92
  std::vector<Transform> transform;
93
94
  // image dimensions (channels may have different dimensions due to transforms)
95
  size_t w, h;
96
  int bitdepth;
97
  size_t nb_meta_channels;  // first few channels might contain palette(s)
98
  bool error;               // true if a fatal error occurred, false otherwise
99
100
  explicit Image(JxlMemoryManager* memory_manager);
101
102
  Image(const Image& other) = delete;
103
  Image& operator=(const Image& other) = delete;
104
105
  Image& operator=(Image&& other) noexcept;
106
727k
  Image(Image&& other) noexcept = default;
107
108
  static StatusOr<Image> Create(JxlMemoryManager* memory_manager, size_t iw,
109
                                size_t ih, int bitdepth, int nb_chans);
110
111
2.12M
  JxlMemoryManager* memory_manager() const { return memory_manager_; }
112
113
11.7k
  bool empty() const {
114
11.7k
    for (const auto& ch : channel) {
115
1.57k
      if (ch.w && ch.h) return false;
116
1.56k
    }
117
10.2k
    return true;
118
11.7k
  }
119
120
  static StatusOr<Image> Clone(const Image& that);
121
122
  void undo_transforms(const weighted::Header& wp_header,
123
                       jxl::ThreadPool* pool = nullptr);
124
125
  std::string DebugString() const;
126
127
 private:
128
  Image(JxlMemoryManager* memory_manager, size_t iw, size_t ih, int bitdepth);
129
  JxlMemoryManager* memory_manager_;
130
};
131
132
}  // namespace jxl
133
134
#endif  // LIB_JXL_MODULAR_MODULAR_IMAGE_H_