Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/render/image.h')
-rw-r--r--intern/cycles/render/image.h217
1 files changed, 123 insertions, 94 deletions
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index ee60390d628..82f3e2759c6 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -22,7 +22,6 @@
#include "render/colorspace.h"
-#include "util/util_image.h"
#include "util/util_string.h"
#include "util/util_thread.h"
#include "util/util_unique_ptr.h"
@@ -31,91 +30,144 @@
CCL_NAMESPACE_BEGIN
class Device;
+class ImageHandle;
+class ImageKey;
+class ImageMetaData;
+class ImageManager;
class Progress;
class RenderStats;
class Scene;
class ColorSpaceProcessor;
-class ImageMetaData {
+/* Image Parameters */
+class ImageParams {
public:
- /* Must be set by image file or builtin callback. */
- bool is_float, is_half;
- int channels;
- size_t width, height, depth;
- bool builtin_free_cache;
-
- /* Automatically set. */
- ImageDataType type;
- ustring colorspace;
- bool compress_as_srgb;
-
- ImageMetaData()
- : is_float(false),
- is_half(false),
- channels(0),
- width(0),
- height(0),
- depth(0),
- builtin_free_cache(false),
- type((ImageDataType)0),
- colorspace(u_colorspace_raw),
- compress_as_srgb(false)
- {
- }
-
- bool operator==(const ImageMetaData &other) const
- {
- return is_float == other.is_float && is_half == other.is_half && channels == other.channels &&
- width == other.width && height == other.height && depth == other.depth &&
- type == other.type && colorspace == other.colorspace &&
- compress_as_srgb == other.compress_as_srgb;
- }
-};
-
-class ImageKey {
- public:
- string filename;
- void *builtin_data;
bool animated;
InterpolationType interpolation;
ExtensionType extension;
ImageAlphaType alpha_type;
ustring colorspace;
+ float frame;
- ImageKey()
- : builtin_data(NULL),
- animated(false),
+ ImageParams()
+ : animated(false),
interpolation(INTERPOLATION_LINEAR),
extension(EXTENSION_CLIP),
alpha_type(IMAGE_ALPHA_AUTO),
- colorspace(u_colorspace_raw)
+ colorspace(u_colorspace_raw),
+ frame(0.0f)
{
}
- bool operator==(const ImageKey &other) const
+ bool operator==(const ImageParams &other) const
{
- return (filename == other.filename && builtin_data == other.builtin_data &&
- animated == other.animated && interpolation == other.interpolation &&
+ return (animated == other.animated && interpolation == other.interpolation &&
extension == other.extension && alpha_type == other.alpha_type &&
- colorspace == other.colorspace);
+ colorspace == other.colorspace && frame == other.frame);
}
};
+/* Image MetaData
+ *
+ * Information about the image that is available before the image pixels are loaded. */
+class ImageMetaData {
+ public:
+ /* Set by ImageLoader.load_metadata(). */
+ int channels;
+ size_t width, height, depth;
+ ImageDataType type;
+
+ /* Optional color space, defaults to raw. */
+ ustring colorspace;
+ const char *colorspace_file_format;
+
+ /* Automatically set. */
+ bool compress_as_srgb;
+
+ ImageMetaData();
+ bool operator==(const ImageMetaData &other) const;
+ bool is_float() const;
+ void detect_colorspace();
+};
+
+/* Image loader base class, that can be subclassed to load image data
+ * from custom sources (file, memory, procedurally generated, etc). */
+class ImageLoader {
+ public:
+ ImageLoader();
+ virtual ~ImageLoader(){};
+
+ /* Load metadata without actual image yet, should be fast. */
+ virtual bool load_metadata(ImageMetaData &metadata) = 0;
+
+ /* Load actual image contents. */
+ virtual bool load_pixels(const ImageMetaData &metadata,
+ void *pixels,
+ const size_t pixels_size,
+ const bool associate_alpha) = 0;
+
+ /* Name for logs and stats. */
+ virtual string name() const = 0;
+
+ /* Optional for OSL texture cache. */
+ virtual ustring osl_filepath() const;
+
+ /* Free any memory used for loading metadata and pixels. */
+ virtual void cleanup(){};
+
+ /* Compare avoid loading the same image multiple times. */
+ virtual bool equals(const ImageLoader &other) const = 0;
+ static bool equals(const ImageLoader *a, const ImageLoader *b);
+
+ /* Work around for no RTTI. */
+};
+
+/* Image Handle
+ *
+ * Access handle for image in the image manager. Multiple shader nodes may
+ * share the same image, and this class handles reference counting for that. */
+class ImageHandle {
+ public:
+ ImageHandle();
+ ImageHandle(const ImageHandle &other);
+ ImageHandle &operator=(const ImageHandle &other);
+ ~ImageHandle();
+
+ bool operator==(const ImageHandle &other) const;
+
+ void clear();
+
+ bool empty();
+ int num_tiles();
+
+ ImageMetaData metadata();
+ int svm_slot(const int tile_index = 0) const;
+ device_memory *image_memory(const int tile_index = 0) const;
+
+ protected:
+ vector<int> tile_slots;
+ ImageManager *manager;
+
+ friend class ImageManager;
+};
+
+/* Image Manager
+ *
+ * Handles loading and storage of all images in the scene. This includes 2D
+ * texture images and 3D volume images. */
class ImageManager {
public:
explicit ImageManager(const DeviceInfo &info);
~ImageManager();
- int add_image(const ImageKey &key, float frame, ImageMetaData &metadata);
- void add_image_user(int flat_slot);
- void remove_image(int flat_slot);
- void remove_image(const ImageKey &key);
- void tag_reload_image(const ImageKey &key);
- bool get_image_metadata(const ImageKey &key, ImageMetaData &metadata);
- bool get_image_metadata(int flat_slot, ImageMetaData &metadata);
+ ImageHandle add_image(const string &filename, const ImageParams &params);
+ ImageHandle add_image(const string &filename,
+ const ImageParams &params,
+ const vector<int> &tiles);
+ ImageHandle add_image(ImageLoader *loader, const ImageParams &params);
void device_update(Device *device, Scene *scene, Progress &progress);
- void device_update_slot(Device *device, Scene *scene, int flat_slot, Progress *progress);
+ void device_update_slot(Device *device, Scene *scene, int slot, Progress *progress);
void device_free(Device *device);
void device_load_builtin(Device *device, Scene *scene, Progress &progress);
@@ -124,72 +176,49 @@ class ImageManager {
void set_osl_texture_system(void *texture_system);
bool set_animation_frame_update(int frame);
- device_memory *image_memory(int flat_slot);
-
void collect_statistics(RenderStats *stats);
bool need_update;
- /* NOTE: Here pixels_size is a size of storage, which equals to
- * width * height * depth.
- * Use this to avoid some nasty memory corruptions.
- */
- function<void(const string &filename, void *data, ImageMetaData &metadata)>
- builtin_image_info_cb;
- function<bool(const string &filename,
- void *data,
- int tile,
- unsigned char *pixels,
- const size_t pixels_size,
- const bool associate_alpha,
- const bool free_cache)>
- builtin_image_pixels_cb;
- function<bool(const string &filename,
- void *data,
- int tile,
- float *pixels,
- const size_t pixels_size,
- const bool associate_alpha,
- const bool free_cache)>
- builtin_image_float_pixels_cb;
-
struct Image {
- ImageKey key;
+ ImageParams params;
ImageMetaData metadata;
+ ImageLoader *loader;
float frame;
+ bool need_metadata;
bool need_load;
+ bool builtin;
string mem_name;
device_memory *mem;
int users;
+ thread_mutex mutex;
};
private:
- int tex_num_images[IMAGE_DATA_NUM_TYPES];
- int max_num_images;
bool has_half_images;
thread_mutex device_mutex;
int animation_frame;
- vector<Image *> images[IMAGE_DATA_NUM_TYPES];
+ vector<Image *> images;
void *osl_texture_system;
- bool file_load_image_generic(Image *img, unique_ptr<ImageInput> *in);
+ int add_image_slot(ImageLoader *loader, const ImageParams &params, const bool builtin);
+ void add_image_user(int slot);
+ void remove_image_user(int slot);
+
+ void load_image_metadata(Image *img);
template<TypeDesc::BASETYPE FileFormat, typename StorageType, typename DeviceType>
- bool file_load_image(Image *img,
- ImageDataType type,
- int texture_limit,
- device_vector<DeviceType> &tex_img);
+ bool file_load_image(Image *img, int texture_limit, device_vector<DeviceType> &tex_img);
- void metadata_detect_colorspace(ImageMetaData &metadata, const char *file_format);
+ void device_load_image(Device *device, Scene *scene, int slot, Progress *progress);
+ void device_free_image(Device *device, int slot);
- void device_load_image(
- Device *device, Scene *scene, ImageDataType type, int slot, Progress *progress);
- void device_free_image(Device *device, ImageDataType type, int slot);
+ friend class ImageHandle;
};
CCL_NAMESPACE_END