Cycles: Make all #include statements relative to cycles source directory
[blender.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/device.h"
21 #include "device/device_memory.h"
22
23 #include "util/util_image.h"
24 #include "util/util_string.h"
25 #include "util/util_thread.h"
26 #include "util/util_vector.h"
27
28 CCL_NAMESPACE_BEGIN
29
30 class Device;
31 class DeviceScene;
32 class Progress;
33 class Scene;
34
35 class ImageManager {
36 public:
37         explicit ImageManager(const DeviceInfo& info);
38         ~ImageManager();
39
40         enum ImageDataType {
41                 IMAGE_DATA_TYPE_FLOAT4 = 0,
42                 IMAGE_DATA_TYPE_BYTE4 = 1,
43                 IMAGE_DATA_TYPE_HALF4 = 2,
44                 IMAGE_DATA_TYPE_FLOAT = 3,
45                 IMAGE_DATA_TYPE_BYTE = 4,
46                 IMAGE_DATA_TYPE_HALF = 5,
47
48                 IMAGE_DATA_NUM_TYPES
49         };
50
51         int add_image(const string& filename,
52                       void *builtin_data,
53                       bool animated,
54                       float frame,
55                       bool& is_float,
56                       bool& is_linear,
57                       InterpolationType interpolation,
58                       ExtensionType extension,
59                       bool use_alpha);
60         void remove_image(int flat_slot);
61         void remove_image(const string& filename,
62                           void *builtin_data,
63                           InterpolationType interpolation,
64                           ExtensionType extension,
65                           bool use_alpha);
66         void tag_reload_image(const string& filename,
67                               void *builtin_data,
68                               InterpolationType interpolation,
69                               ExtensionType extension,
70                               bool use_alpha);
71         ImageDataType get_image_metadata(const string& filename, void *builtin_data, bool& is_linear);
72
73         void device_update(Device *device,
74                            DeviceScene *dscene,
75                            Scene *scene,
76                            Progress& progress);
77         void device_update_slot(Device *device,
78                                 DeviceScene *dscene,
79                                 Scene *scene,
80                                 int flat_slot,
81                                 Progress *progress);
82         void device_free(Device *device, DeviceScene *dscene);
83         void device_free_builtin(Device *device, DeviceScene *dscene);
84
85         void set_osl_texture_system(void *texture_system);
86         void set_pack_images(bool pack_images_);
87         bool set_animation_frame_update(int frame);
88
89         bool need_update;
90
91         /* NOTE: Here pixels_size is a size of storage, which equals to
92          *       width * height * depth.
93          *       Use this to avoid some nasty memory corruptions.
94          */
95         function<void(const string &filename,
96                       void *data,
97                       bool &is_float,
98                       int &width,
99                       int &height,
100                       int &depth,
101                       int &channels)> builtin_image_info_cb;
102         function<bool(const string &filename,
103                       void *data,
104                       unsigned char *pixels,
105                       const size_t pixels_size)> builtin_image_pixels_cb;
106         function<bool(const string &filename,
107                       void *data,
108                       float *pixels,
109                       const size_t pixels_size)> builtin_image_float_pixels_cb;
110
111         struct Image {
112                 string filename;
113                 void *builtin_data;
114
115                 bool use_alpha;
116                 bool need_load;
117                 bool animated;
118                 float frame;
119                 InterpolationType interpolation;
120                 ExtensionType extension;
121
122                 int users;
123         };
124
125 private:
126         int tex_num_images[IMAGE_DATA_NUM_TYPES];
127         int tex_start_images[IMAGE_DATA_NUM_TYPES];
128
129         thread_mutex device_mutex;
130         int animation_frame;
131
132         vector<Image*> images[IMAGE_DATA_NUM_TYPES];
133         void *osl_texture_system;
134         bool pack_images;
135
136         bool file_load_image_generic(Image *img, ImageInput **in, int &width, int &height, int &depth, int &components);
137
138         template<TypeDesc::BASETYPE FileFormat,
139                  typename StorageType,
140                  typename DeviceType>
141         bool file_load_image(Image *img,
142                              ImageDataType type,
143                              int texture_limit,
144                              device_vector<DeviceType>& tex_img);
145
146         int type_index_to_flattened_slot(int slot, ImageDataType type);
147         int flattened_slot_to_type_index(int flat_slot, ImageDataType *type);
148         string name_from_type(int type);
149
150         uint8_t pack_image_options(ImageDataType type, size_t slot);
151
152         void device_load_image(Device *device,
153                                DeviceScene *dscene,
154                                Scene *scene,
155                                ImageDataType type,
156                                int slot,
157                                Progress *progess);
158         void device_free_image(Device *device,
159                                DeviceScene *dscene,
160                                ImageDataType type,
161                                int slot);
162
163         void device_pack_images(Device *device,
164                                 DeviceScene *dscene,
165                                 Progress& progess);
166 };
167
168 CCL_NAMESPACE_END
169
170 #endif /* __IMAGE_H__ */
171