Blender V5.3
image_loader.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <atomic>
8
9#include "util/param.h"
10#include "util/string.h"
11#include "util/types_image.h"
12
14
15class Progress;
16class ImageMetaData;
17
18/* Parameters for image loading. */
20 bool use_texture_cache = true;
21 bool auto_texture_cache = true;
23 ustring colorspace;
25
26 /* Error reporting. */
27 std::atomic<int> &load_failure_num;
28 std::atomic<int> &tx_failure_num;
29};
30
31/* Image loader base class, that can be subclassed to load image data
32 * from custom sources (file, memory, procedurally generated, etc). */
34 public:
36 virtual ~ImageLoader() = default;
37
38 /* Load metadata without actual image yet, should be fast. */
39 virtual bool load_metadata(ImageMetaData &metadata,
40 const ImageLoaderParams &params,
41 Progress &progress) = 0;
42
43 /* Load full image pixels.
44 * This is expected to call metadata.conform_pixels(). */
45 virtual bool load_pixels(const ImageMetaData &metadata, void *pixels) = 0;
46
47 /* Load pixels for a single tile, if ImageMetaData.tile_size is set.
48 * This is expected to call metadata.conform_pixels(). */
49 virtual bool load_pixels_tile(const ImageMetaData & /*metadata*/,
50 const int /*miplevel*/,
51 const int64_t /*x*/,
52 const int64_t /*y*/,
53 const int64_t /*w*/,
54 const int64_t /*h*/,
55 const int64_t /*x_stride*/,
56 const int64_t /*y_stride*/,
57 const int64_t /*padding*/,
58 const ExtensionType /*extension*/,
59 uint8_t * /*pixels*/)
60 {
61 return false;
62 }
63
64 /* Name for logs and stats. */
65 virtual string name() const = 0;
66
67 /* Optional for tiled textures loaded externally. */
68 virtual int get_tile_number() const;
69
70 /* Free any memory used for loading metadata and pixels. */
71 virtual void cleanup() {};
72
73 /* Compare avoid loading the same image multiple times. */
74 virtual bool equals(const ImageLoader &other) const = 0;
75 static bool equals(const ImageLoader *a, const ImageLoader *b);
76
77 /* Test if this loader will load NanoVDB. */
78 virtual bool is_vdb_loader() const;
79};
80
long long int int64_t
virtual ~ImageLoader()=default
virtual bool load_pixels_tile(const ImageMetaData &, const int, const int64_t, const int64_t, const int64_t, const int64_t, const int64_t, const int64_t, const int64_t, const ExtensionType, uint8_t *)
virtual void cleanup()
virtual bool equals(const ImageLoader &other) const =0
virtual bool load_pixels(const ImageMetaData &metadata, void *pixels)=0
virtual bool load_metadata(ImageMetaData &metadata, const ImageLoaderParams &params, Progress &progress)=0
virtual int get_tile_number() const
virtual string name() const =0
virtual bool is_vdb_loader() const
#define CCL_NAMESPACE_END
string texture_cache_path
std::atomic< int > & tx_failure_num
std::atomic< int > & load_failure_num
ImageAlphaType alpha_type
ImageAlphaType
Definition types_image.h:61
ExtensionType
Definition types_image.h:80