Blender V4.3
cycles/scene/image.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __IMAGE_H__
6#define __IMAGE_H__
7
8#include "device/memory.h"
9
10#include "scene/colorspace.h"
11
12#include "util/string.h"
13#include "util/thread.h"
14#include "util/transform.h"
15#include "util/unique_ptr.h"
16#include "util/vector.h"
17
19
20class Device;
21class DeviceInfo;
22class ImageHandle;
23class ImageKey;
24class ImageMetaData;
25class ImageManager;
26class Progress;
27class RenderStats;
28class Scene;
29class ColorSpaceProcessor;
30class VDBImageLoader;
31
32/* Image Parameters */
34 public:
39 ustring colorspace;
40 float frame;
41
51
52 bool operator==(const ImageParams &other) const
53 {
54 return (animated == other.animated && interpolation == other.interpolation &&
55 extension == other.extension && alpha_type == other.alpha_type &&
56 colorspace == other.colorspace && frame == other.frame);
57 }
58};
59
60/* Image MetaData
61 *
62 * Information about the image that is available before the image pixels are loaded. */
64 public:
65 /* Set by ImageLoader.load_metadata(). */
67 size_t width, height, depth;
68 size_t byte_size;
70
71 /* Optional color space, defaults to raw. */
72 ustring colorspace;
75
76 /* Optional transform for 3D images. */
79
80 /* Automatically set. */
82
84 bool operator==(const ImageMetaData &other) const;
85 bool is_float() const;
86 void detect_colorspace();
87};
88
89/* Information about supported features that Image loaders can use. */
91 public:
93};
94
95/* Image loader base class, that can be subclassed to load image data
96 * from custom sources (file, memory, procedurally generated, etc). */
98 public:
100 virtual ~ImageLoader(){};
101
102 /* Load metadata without actual image yet, should be fast. */
103 virtual bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) = 0;
104
105 /* Load actual image contents. */
106 virtual bool load_pixels(const ImageMetaData &metadata,
107 void *pixels,
108 const size_t pixels_size,
109 const bool associate_alpha) = 0;
110
111 /* Name for logs and stats. */
112 virtual string name() const = 0;
113
114 /* Optional for OSL texture cache. */
115 virtual ustring osl_filepath() const;
116
117 /* Optional for tiled textures loaded externally. */
118 virtual int get_tile_number() const;
119
120 /* Free any memory used for loading metadata and pixels. */
121 virtual void cleanup(){};
122
123 /* Compare avoid loading the same image multiple times. */
124 virtual bool equals(const ImageLoader &other) const = 0;
125 static bool equals(const ImageLoader *a, const ImageLoader *b);
126
127 virtual bool is_vdb_loader() const;
128
129 /* Work around for no RTTI. */
130};
131
132/* Image Handle
133 *
134 * Access handle for image in the image manager. Multiple shader nodes may
135 * share the same image, and this class handles reference counting for that. */
137 public:
138 ImageHandle();
139 ImageHandle(const ImageHandle &other);
140 ImageHandle &operator=(const ImageHandle &other);
141 ~ImageHandle();
142
143 bool operator==(const ImageHandle &other) const;
144
145 void clear();
146
147 bool empty() const;
148 int num_tiles() const;
149
151 int svm_slot(const int tile_index = 0) const;
153 device_texture *image_memory(const int tile_index = 0) const;
154
155 VDBImageLoader *vdb_loader(const int tile_index = 0) const;
156
157 ImageManager *get_manager() const;
158
159 protected:
162
163 friend class ImageManager;
164};
165
166/* Image Manager
167 *
168 * Handles loading and storage of all images in the scene. This includes 2D
169 * texture images and 3D volume images. */
171 public:
172 explicit ImageManager(const DeviceInfo &info);
174
175 ImageHandle add_image(const string &filename, const ImageParams &params);
176 ImageHandle add_image(const string &filename,
177 const ImageParams &params,
178 const array<int> &tiles);
179 ImageHandle add_image(ImageLoader *loader, const ImageParams &params, const bool builtin = true);
181
182 void device_update(Device *device, Scene *scene, Progress &progress);
183 void device_update_slot(Device *device, Scene *scene, size_t slot, Progress *progress);
184 void device_free(Device *device);
185
186 void device_load_builtin(Device *device, Scene *scene, Progress &progress);
187 void device_free_builtin(Device *device);
188
189 void set_osl_texture_system(void *texture_system);
190 bool set_animation_frame_update(int frame);
191
192 void collect_statistics(RenderStats *stats);
193
194 void tag_update();
195
196 bool need_update() const;
197
214
215 private:
216 bool need_update_;
217
218 ImageDeviceFeatures features;
219
220 thread_mutex device_mutex;
221 thread_mutex images_mutex;
222 int animation_frame;
223
224 vector<Image *> images;
225 void *osl_texture_system;
226
227 size_t add_image_slot(ImageLoader *loader, const ImageParams &params, const bool builtin);
228 void add_image_user(size_t slot);
229 void remove_image_user(size_t slot);
230
231 void load_image_metadata(Image *img);
232
233 template<TypeDesc::BASETYPE FileFormat, typename StorageType>
234 bool file_load_image(Image *img, int texture_limit);
235
236 void device_load_image(Device *device, Scene *scene, size_t slot, Progress *progress);
237 void device_free_image(Device *device, size_t slot);
238
239 friend class ImageHandle;
240};
241
243
244#endif /* __IMAGE_H__ */
int num_tiles() const
vector< size_t > tile_slots
ImageManager * get_manager() const
bool operator==(const ImageHandle &other) const
VDBImageLoader * vdb_loader(const int tile_index=0) const
device_texture * image_memory(const int tile_index=0) const
bool empty() const
ImageManager * manager
ImageHandle & operator=(const ImageHandle &other)
ImageMetaData metadata()
int svm_slot(const int tile_index=0) const
vector< int4 > get_svm_slots() const
virtual bool load_pixels(const ImageMetaData &metadata, void *pixels, const size_t pixels_size, const bool associate_alpha)=0
virtual bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata)=0
virtual void cleanup()
virtual bool equals(const ImageLoader &other) const =0
virtual ~ImageLoader()
virtual ustring osl_filepath() const
virtual int get_tile_number() const
virtual string name() const =0
virtual bool is_vdb_loader() const
bool set_animation_frame_update(int frame)
ImageManager(const DeviceInfo &info)
void device_update(Device *device, Scene *scene, Progress &progress)
bool need_update() const
void device_free(Device *device)
void device_update_slot(Device *device, Scene *scene, size_t slot, Progress *progress)
void device_load_builtin(Device *device, Scene *scene, Progress &progress)
void device_free_builtin(Device *device)
ImageHandle add_image(const string &filename, const ImageParams &params)
void collect_statistics(RenderStats *stats)
void set_osl_texture_system(void *texture_system)
ImageDataType type
bool is_float() const
void detect_colorspace()
bool operator==(const ImageMetaData &other) const
const char * colorspace_file_format
bool operator==(const ImageParams &other) const
ImageAlphaType alpha_type
InterpolationType interpolation
ExtensionType extension
ustring u_colorspace_raw
local_group_size(16, 16) .push_constant(Type b
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
const int tile_index
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29
ImageDataType
ImageAlphaType
@ IMAGE_ALPHA_AUTO
InterpolationType
@ INTERPOLATION_LINEAR
ExtensionType
@ EXTENSION_CLIP