Blender V5.3
IMB_imbuf_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 * SPDX-FileCopyrightText: 2025 Blender Authors
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later */
5
6#pragma once
7
13
14#include "BLI_assert.hh"
15#include "BLI_enum_flags.hh"
17#include "BLI_mutex.hh"
18#include "BLI_string_ref.hh"
19
20#include "DNA_image_enums.h"
21#include "IMB_imbuf_enums.h"
22
23#include <atomic>
24#include <string>
25
26namespace blender {
27
28namespace gpu {
29class Texture;
30}
31struct IDProperty;
32
33namespace imbuf::partial_update {
34struct Tracker;
35}
36
37namespace imbuf {
39}
40
41namespace ocio {
42class ColorSpace;
43}
44using ColorSpace = ocio::ColorSpace;
45
52
57
58#define OPENEXR_HALF (1 << 8)
59#define OPENEXR_MULTIPART (1 << 9)
60/* Lowest bits of foptions.flag / exr_codec contain actual codec enum. */
61#define OPENEXR_CODEC_MASK (0xF)
62
63#ifdef WITH_IMAGE_CINEON
64# define CINEON_LOG (1 << 8)
65# define CINEON_16BIT (1 << 7)
66# define CINEON_12BIT (1 << 6)
67# define CINEON_10BIT (1 << 5)
68#endif
69
70#ifdef WITH_IMAGE_OPENJPEG
71# define JP2_12BIT (1 << 9)
72# define JP2_16BIT (1 << 8)
73# define JP2_YCC (1 << 7)
74# define JP2_CINE (1 << 6)
75# define JP2_CINE_48FPS (1 << 5)
76# define JP2_JP2 (1 << 4)
77# define JP2_J2K (1 << 3)
78#endif
79
80#define PNG_16BIT (1 << 10)
81
82#define RAWTGA 1
83
84#define TIF_16BIT (1 << 8)
85#define TIF_COMPRESS_NONE (1 << 7)
86#define TIF_COMPRESS_DEFLATE (1 << 6)
87#define TIF_COMPRESS_LZW (1 << 5)
88#define TIF_COMPRESS_PACKBITS (1 << 4)
89
90#define AVIF_10BIT (1 << 8)
91#define AVIF_12BIT (1 << 9)
92
93#define DDS_COMPRESSED_DXT1 (1 << 8)
94#define DDS_COMPRESSED_DXT3 (1 << 9)
95#define DDS_COMPRESSED_DXT5 (1 << 10)
96
98 short flag = 0;
100 char quality = 90;
101 /* Compression amount for PNG.
102 * Default to low compression ratio that is not time consuming. */
103 char compress = 15;
104};
105
106/* -------------------------------------------------------------------- */
109
110/* Different storage specialization.
111 *
112 * NOTE: Avoid direct access. Use the buffer utilities from the IMB_imbuf.hh instead
113 */
114
116 const uint8_t *data = nullptr;
118
119 const ColorSpace *colorspace = nullptr;
120};
121
123 const float *data = nullptr;
125
126 const ColorSpace *colorspace = nullptr;
127};
128
129enum ImBufGPUFlag : int {
135};
137
138struct ImBufGPU {
150 std::atomic<gpu::Texture *> texture = nullptr;
151
154
157
159 std::atomic<imbuf::ChangesetID> partial_update_changeset_id = -1;
160
163};
164
166
167/* -------------------------------------------------------------------- */
170
171struct ImBuf {
172 /* dimensions */
181 int x = 0;
182 int y = 0;
183
198
203 int channels = 0;
204
212
214
215 /* pixels */
216
223
232
235
239
243 std::atomic<imbuf::ChangesetID> full_update_changeset_id = -1;
244
246 double ppm[2] = {0.0, 0.0};
247
249 float dither = 0.0f;
250
254 int userflags = 0;
255
260
261 /* file information */
267 std::string filepath;
269 int fileframe = 0;
270
273
274 const uint8_t *byte_data() const;
276
277 const float *float_data() const;
278 float *float_data_for_write();
279
282 void assign_float_data(float *data);
283
285 void assign_byte_data(const uint8_t *data, ImplicitSharingPtr<> sharing_ptr);
286 void assign_float_data(const float *data, ImplicitSharingPtr<> sharing_ptr);
287
289 const IDProperty *metadata() const;
291 void assign_metadata(const IDProperty *metadata, ImplicitSharingPtr<> sharing_info);
292
293 [[nodiscard]] bool colorspace_is_data() const;
294
295 [[nodiscard]] const ColorSpace &byte_colorspace() const;
296 [[nodiscard]] const ColorSpace &float_colorspace() const;
297
298 [[nodiscard]] bool can_contain_alpha() const
299 {
301 }
302
303 [[nodiscard]] int color_mode_channels_get() const
304 {
305 switch (this->color_mode) {
306 case ImColorMode::BW:
307 return 1;
309 return 2;
310 case ImColorMode::RGB:
311 return 3;
313 return 4;
314 }
316 return 0;
317 }
318};
319
321[[nodiscard]] ImColorMode IMB_color_mode_from_channels(int channels);
322
324[[nodiscard]] bool IMB_chan_id_is_color(StringRef chan_id);
325
329enum {
331 IB_BITMAPDIRTY = (1 << 1),
333 IB_PERSISTENT = (1 << 2),
339};
340
342
349extern const char *imb_ext_image[];
350extern const char *imb_ext_movie[];
351extern const char *imb_ext_audio[];
352
353inline const uint8_t *ImBuf::byte_data() const
354{
355 return this->byte_buffer.data;
356}
357
358inline const float *ImBuf::float_data() const
359{
360 return this->float_buffer.data;
361}
362
363} // namespace blender
#define ENUM_OPERATORS(_enum_type)
#define BLI_assert_unreachable()
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
bool IMB_chan_id_is_color(StringRef chan_id)
ImColorMode IMB_color_mode_from_channels(int channels)
BMesh const char void * data
unsigned char uint8_t
Definition BKE_text.h:79
std::mutex Mutex
Definition BLI_mutex.hh:51
signed int int32_t
Definition BKE_text.h:78
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
ImplicitSharingPtr sharing_info
ImplicitSharingPtr sharing_info
std::atomic< imbuf::ChangesetID > partial_update_changeset_id
std::atomic< gpu::Texture * > texture
blender::Mutex mutex
ImbFormatOptions foptions
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
IDProperty * metadata_ptr
const ColorSpace & byte_colorspace() const
Definition allocimbuf.cc:98
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
std::atomic< imbuf::ChangesetID > full_update_changeset_id
IDProperty * metadata_for_write()
bool colorspace_is_data() const
ImplicitSharingPtr metadata_sharing_info
const IDProperty * metadata() const
const float * float_data() const
std::string filepath
ImColorMode color_mode
void assign_byte_data(uint8_t *data)
const ColorSpace & float_colorspace() const
eImbFileType ftype
float * float_data_for_write()
Definition allocimbuf.cc:79
imbuf::partial_update::Tracker * partial_update
void assign_metadata(const IDProperty *metadata, ImplicitSharingPtr<> sharing_info)
bool can_contain_alpha() const
int color_mode_channels_get() const
void assign_float_data(float *data)