b4097d624b8c34db8a7d15826f9a58c8f95ac87e
[blender-staging.git] / intern / cycles / render / image.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __IMAGE_H__
18 #define __IMAGE_H__
19
20 #include "device.h"
21 #include "device_memory.h"
22
23 #include "util_string.h"
24 #include "util_thread.h"
25 #include "util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 class Device;
30 class DeviceScene;
31 class Progress;
32
33 class ImageManager {
34 public:
35         ImageManager(const DeviceInfo& info);
36         ~ImageManager();
37
38         enum ImageDataType {
39                 IMAGE_DATA_TYPE_FLOAT4 = 0,
40                 IMAGE_DATA_TYPE_BYTE = 1,
41
42                 IMAGE_DATA_NUM_TYPES
43         };
44
45         int add_image(const string& filename,
46                       void *builtin_data,
47                       bool animated,
48                       float frame,
49                       bool& is_float,
50                       bool& is_linear,
51                       InterpolationType interpolation,
52                       ExtensionType extension,
53                       bool use_alpha);
54         void remove_image(int slot);
55         void remove_image(const string& filename,
56                           void *builtin_data,
57                           InterpolationType interpolation,
58                           ExtensionType extension);
59         void tag_reload_image(const string& filename,
60                               void *builtin_data,
61                               InterpolationType interpolation,
62                               ExtensionType extension);
63         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
64
65         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
66         void device_update_slot(Device *device, DeviceScene *dscene, int slot, Progress *progress);
67         void device_free(Device *device, DeviceScene *dscene);
68         void device_free_builtin(Device *device, DeviceScene *dscene);
69
70         void set_osl_texture_system(void *texture_system);
71         void set_pack_images(bool pack_images_);
72         bool set_animation_frame_update(int frame);
73
74         bool need_update;
75
76         function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
77         function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
78         function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
79
80         struct Image {
81                 string filename;
82                 void *builtin_data;
83
84                 bool use_alpha;
85                 bool need_load;
86                 bool animated;
87                 float frame;
88                 InterpolationType interpolation;
89                 ExtensionType extension;
90
91                 int users;
92         };
93
94 private:
95         int tex_num_images[IMAGE_DATA_NUM_TYPES];
96         int tex_image_byte_start;
97         thread_mutex device_mutex;
98         int animation_frame;
99
100         vector<Image*> images[IMAGE_DATA_NUM_TYPES];
101         void *osl_texture_system;
102         bool pack_images;
103
104         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
105         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
106
107         int type_index_to_flattened_slot(int slot, ImageDataType type);
108         int flattened_slot_to_type_index(int slot, ImageDataType *type);
109         string name_from_type(int type);
110
111         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
112         void device_free_image(Device *device, DeviceScene *dscene, int slot);
113
114         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
115 };
116
117 CCL_NAMESPACE_END
118
119 #endif /* __IMAGE_H__ */
120