Blender V5.3
image_metadata.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <cstdlib>
8
9#include <OpenImageIO/imageio.h>
10#include <OpenImageIO/string_view.h>
11
12#include "util/colorspace.h"
13#include "util/string.h"
14#include "util/types_image.h"
15
17
18/* Image MetaData
19 *
20 * Information about the image that is available before the image pixels are loaded.
21 * This can be filled by an image loaded through OpenImageIO, but is also used for
22 * custom image loaders that may e.g. load an image from memory or auto generate it. */
23
25 public:
26 /* Input image dimensions and format. */
27 int channels = 0;
30
31 /* Input colorspace hints. */
33 const char *colorspace_file_format = "";
34
35 /* Input tile info. */
37 uint32_t tile_size = 0;
39 bool tile_need_conform = true;
40
41 /* File is a valid tx file, but does not necessarily have mipmaps and tiles if it's
42 * small enough not to need them. */
43 bool is_tx_file = false;
44
45 /* Input NanoVDB data. */
47 bool use_transform_3d = false;
49
50 /* Auto determined by finalize. */
54 bool ignore_alpha = false;
55 bool is_channel_packed = false;
56
57 /* Constructor */
59 bool operator==(const ImageMetaData &other) const;
60
61 /* Finalize image metadata, with optional user provided alpha type and colorspace. */
62 void finalize(const ImageAlphaType alpha_type = IMAGE_ALPHA_AUTO);
63
64 /* Image info. */
65 bool is_float() const;
66 bool is_half() const;
67 bool is_rgba() const;
68 TypeDesc typedesc() const;
69
70 /* Memory stats. */
71 size_t memory_size() const;
72 size_t pixel_memory_size() const;
73
74 /* OpenImageIO metadata and pixel loading. */
75 bool oiio_load_metadata(OIIO::string_view filepath, OIIO::ImageSpec *r_spec = nullptr);
76 bool oiio_load_pixels(OIIO::string_view filepath, void *pixels, const bool flip_y = true) const;
77
78 /* Change data type to float. */
79 void make_float();
80
81 /* Modify pixel data to conform to formats known to the kernel. That means 1 or 4 channels,
82 * a known ImageDataType, associated alpha and no NaN or infinite values. */
83 void conform_pixels(void *pixels) const;
84 void conform_pixels(void *pixels,
85 const int64_t width,
86 const int64_t height,
87 const int64_t x_stride,
88 const int64_t in_y_stride,
89 const int64_t out_y_stride) const;
90
91 protected:
92 void detect_tiles(OIIO::ImageInput &input,
93 const OIIO::ImageSpec &spec,
94 OIIO::string_view filepath);
95};
96
long long int int64_t
ImageDataType type
string colorspace_file_hint
void finalize(const ImageAlphaType alpha_type=IMAGE_ALPHA_AUTO)
bool oiio_load_metadata(OIIO::string_view filepath, OIIO::ImageSpec *r_spec=nullptr)
bool is_half() const
bool has_tiles_and_mipmaps
bool oiio_load_pixels(OIIO::string_view filepath, void *pixels, const bool flip_y=true) const
bool is_float() const
TypeDesc typedesc() const
Transform transform_3d
bool is_rgba() const
int64_t nanovdb_byte_size
size_t memory_size() const
size_t pixel_memory_size() const
bool is_compressible_as_srgb
uint32_t tile_size
void conform_pixels(void *pixels) const
bool is_unassociated_alpha
void detect_tiles(OIIO::ImageInput &input, const OIIO::ImageSpec &spec, OIIO::string_view filepath)
bool operator==(const ImageMetaData &other) const
const char * colorspace_file_format
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
Definition math_float4.h:13
ccl_device_inline Transform transform_identity()
Definition transform.h:355
ImageDataType
Definition types_image.h:35
@ IMAGE_DATA_NUM_TYPES
Definition types_image.h:51
ImageAlphaType
Definition types_image.h:61
@ IMAGE_ALPHA_AUTO
Definition types_image.h:66
ustring u_colorspace_scene_linear