2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IMAGE_H__
|
|
|
|
#define __IMAGE_H__
|
|
|
|
|
2014-05-11 01:38:39 +00:00
|
|
|
#include "device.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "device_memory.h"
|
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
#include "util_image.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_string.h"
|
2012-09-27 17:42:09 +00:00
|
|
|
#include "util_thread.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_vector.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
class DeviceScene;
|
|
|
|
class Progress;
|
|
|
|
|
|
|
|
class ImageManager {
|
|
|
|
public:
|
2016-05-11 14:50:10 +00:00
|
|
|
explicit ImageManager(const DeviceInfo& info);
|
2011-04-27 11:58:34 +00:00
|
|
|
~ImageManager();
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
enum ImageDataType {
|
2016-05-06 11:42:50 +00:00
|
|
|
IMAGE_DATA_TYPE_FLOAT4 = 0,
|
2016-05-08 18:18:52 +00:00
|
|
|
IMAGE_DATA_TYPE_BYTE4 = 1,
|
2016-08-11 20:30:03 +00:00
|
|
|
IMAGE_DATA_TYPE_HALF4 = 2,
|
|
|
|
IMAGE_DATA_TYPE_FLOAT = 3,
|
|
|
|
IMAGE_DATA_TYPE_BYTE = 4,
|
2016-06-19 15:31:16 +00:00
|
|
|
IMAGE_DATA_TYPE_HALF = 5,
|
2016-05-06 09:57:30 +00:00
|
|
|
|
|
|
|
IMAGE_DATA_NUM_TYPES
|
|
|
|
};
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
int add_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
bool animated,
|
|
|
|
float frame,
|
|
|
|
bool& is_float,
|
|
|
|
bool& is_linear,
|
|
|
|
InterpolationType interpolation,
|
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha);
|
2016-05-08 19:41:25 +00:00
|
|
|
void remove_image(int flat_slot);
|
2015-07-21 19:58:19 +00:00
|
|
|
void remove_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
|
|
|
ExtensionType extension);
|
|
|
|
void tag_reload_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
|
|
|
ExtensionType extension);
|
2016-05-09 10:51:42 +00:00
|
|
|
ImageDataType get_image_metadata(const string& filename, void *builtin_data, bool& is_linear);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
void device_update(Device *device, DeviceScene *dscene, Progress& progress);
|
2016-05-08 19:41:25 +00:00
|
|
|
void device_update_slot(Device *device, DeviceScene *dscene, int flat_slot, Progress *progress);
|
2011-04-27 11:58:34 +00:00
|
|
|
void device_free(Device *device, DeviceScene *dscene);
|
2014-05-19 12:45:52 +00:00
|
|
|
void device_free_builtin(Device *device, DeviceScene *dscene);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
void set_osl_texture_system(void *texture_system);
|
2012-05-13 12:32:44 +00:00
|
|
|
void set_pack_images(bool pack_images_);
|
2012-11-21 13:00:51 +00:00
|
|
|
bool set_animation_frame_update(int frame);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_update;
|
|
|
|
|
2015-03-29 20:12:22 +00:00
|
|
|
function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
|
|
|
|
function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
|
|
|
|
function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
struct Image {
|
|
|
|
string filename;
|
2013-01-30 13:42:12 +00:00
|
|
|
void *builtin_data;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
bool use_alpha;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_load;
|
2012-11-21 13:00:51 +00:00
|
|
|
bool animated;
|
2014-06-21 20:18:48 +00:00
|
|
|
float frame;
|
2014-03-07 22:16:09 +00:00
|
|
|
InterpolationType interpolation;
|
2015-07-21 19:58:19 +00:00
|
|
|
ExtensionType extension;
|
2014-03-07 22:16:09 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
int users;
|
|
|
|
};
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
private:
|
2016-05-06 09:57:30 +00:00
|
|
|
int tex_num_images[IMAGE_DATA_NUM_TYPES];
|
2016-05-27 21:35:29 +00:00
|
|
|
int tex_start_images[IMAGE_DATA_NUM_TYPES];
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
thread_mutex device_mutex;
|
|
|
|
int animation_frame;
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
vector<Image*> images[IMAGE_DATA_NUM_TYPES];
|
2011-05-31 16:21:30 +00:00
|
|
|
void *osl_texture_system;
|
2012-05-13 12:32:44 +00:00
|
|
|
bool pack_images;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
bool file_load_image_generic(Image *img, ImageInput **in, int &width, int &height, int &depth, int &components);
|
2016-05-22 21:24:26 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool file_load_byte_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool file_load_float_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-06-19 15:31:16 +00:00
|
|
|
template<typename T>
|
|
|
|
bool file_load_half_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
int type_index_to_flattened_slot(int slot, ImageDataType type);
|
2016-05-08 19:41:25 +00:00
|
|
|
int flattened_slot_to_type_index(int flat_slot, ImageDataType *type);
|
2016-05-06 09:57:30 +00:00
|
|
|
string name_from_type(int type);
|
|
|
|
|
2016-07-01 21:48:31 +00:00
|
|
|
uint8_t pack_image_options(ImageDataType type, size_t slot);
|
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
void device_load_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot, Progress *progess);
|
|
|
|
void device_free_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot);
|
2012-05-13 12:32:44 +00:00
|
|
|
|
|
|
|
void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __IMAGE_H__ */
|
|
|
|
|