Blender V5.0
OCIO_packed_image.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <cstddef>
8
9#include "BLI_assert.h"
10
11#if defined(WITH_OPENCOLORIO)
12# include "intern/opencolorio.hh"
13#endif
14
15namespace blender::ocio {
16
21
23#if defined(WITH_OPENCOLORIO)
24 OCIO_NAMESPACE::PackedImageDesc image_desc_;
25
26 static OCIO_NAMESPACE::BitDepth convert_bit_depth(const BitDepth bit_depth)
27 {
28 switch (bit_depth) {
30 return OCIO_NAMESPACE::BIT_DEPTH_UNKNOWN;
32 return OCIO_NAMESPACE::BIT_DEPTH_F32;
33 }
35 return OCIO_NAMESPACE::BIT_DEPTH_UNKNOWN;
36 }
37
38 static BitDepth convert_bit_depth(const OCIO_NAMESPACE::BitDepth bit_depth)
39 {
40 switch (bit_depth) {
41 case OCIO_NAMESPACE::BIT_DEPTH_UNKNOWN:
43 case OCIO_NAMESPACE::BIT_DEPTH_F32:
45 default:
46 /* Other bit depths are currently not supported. */
48 }
49 }
50
51#else
52 void *data_ = nullptr;
53 size_t width_ = 0;
54 size_t height_ = 0;
55 size_t num_channels_ = 0;
57 size_t chan_stride_in_bytes_ = 0;
58 size_t x_stride_in_bytes_ = 0;
59 size_t y_stride_in_bytes_ = 0;
60#endif
61
62 public:
64 const size_t width,
65 const size_t height,
66 const size_t num_channels,
67 const BitDepth bit_depth,
68 const size_t chan_stride_in_bytes,
69 const size_t x_stride_in_bytes,
70 const size_t y_stride_in_bytes)
71#if defined(WITH_OPENCOLORIO)
72 : image_desc_(data,
73 width,
74 height,
75 num_channels,
76 convert_bit_depth(bit_depth),
77 chan_stride_in_bytes,
78 x_stride_in_bytes,
79 y_stride_in_bytes)
80#else
81 : data_(data),
82 width_(width),
83 height_(height),
84 num_channels_(num_channels),
85 bit_depth_(bit_depth),
86 chan_stride_in_bytes_(chan_stride_in_bytes),
87 x_stride_in_bytes_(x_stride_in_bytes),
88 y_stride_in_bytes_(y_stride_in_bytes)
89#endif
90 {
91 }
92
93#if defined(WITH_OPENCOLORIO)
94 size_t get_width() const
95 {
96 return image_desc_.getWidth();
97 }
98 size_t get_height() const
99 {
100 return image_desc_.getHeight();
101 }
102
103 size_t get_num_channels() const
104 {
105 return image_desc_.getNumChannels();
106 }
107
108 void *get_data() const
109 {
110 return image_desc_.getData();
111 }
112
113 BitDepth get_bit_depth() const
114 {
115 return convert_bit_depth(image_desc_.getBitDepth());
116 }
117
118 size_t get_chan_stride_in_bytes() const
119 {
120 return image_desc_.getChanStrideBytes();
121 }
122 size_t get_x_stride_in_bytes() const
123 {
124 return image_desc_.getXStrideBytes();
125 }
126 size_t get_y_stride_in_bytes() const
127 {
128 return image_desc_.getYStrideBytes();
129 }
130
131 operator const OCIO_NAMESPACE::PackedImageDesc &() const
132 {
133 return image_desc_;
134 }
135#else
136 size_t get_width() const
137 {
138 return width_;
139 }
140 size_t get_height() const
141 {
142 return height_;
143 }
144
145 size_t get_num_channels() const
146 {
147 return num_channels_;
148 }
149
150 void *get_data() const
151 {
152 return data_;
153 }
154
156 {
157 return bit_depth_;
158 }
159
161 {
162 return chan_stride_in_bytes_;
163 }
165 {
166 return x_stride_in_bytes_;
167 }
169 {
170 return y_stride_in_bytes_;
171 }
172#endif
173};
174
175} // namespace blender::ocio
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
BMesh const char void * data
PackedImage(void *data, const size_t width, const size_t height, const size_t num_channels, const BitDepth bit_depth, const size_t chan_stride_in_bytes, const size_t x_stride_in_bytes, const size_t y_stride_in_bytes)