Cleanup: include the type of data in function name
[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         int add_image(const string& filename,
41                       void *builtin_data,
42                       bool animated,
43                       float frame,
44                       bool& is_float,
45                       bool& is_linear,
46                       InterpolationType interpolation,
47                       ExtensionType extension,
48                       bool use_alpha);
49         void remove_image(int flat_slot);
50         void remove_image(const string& filename,
51                           void *builtin_data,
52                           InterpolationType interpolation,
53                           ExtensionType extension,
54                           bool use_alpha);
55         void tag_reload_image(const string& filename,
56                               void *builtin_data,
57                               InterpolationType interpolation,
58                               ExtensionType extension,
59                               bool use_alpha);
60         ImageDataType get_image_metadata(const string& filename, void *builtin_data, bool& is_linear);
61
62         void device_update(Device *device,
63                            DeviceScene *dscene,
64                            Scene *scene,
65                            Progress& progress);
66         void device_update_slot(Device *device,
67                                 DeviceScene *dscene,
68                                 Scene *scene,
69                                 int flat_slot,
70                                 Progress *progress);
71         void device_free(Device *device, DeviceScene *dscene);
72         void device_free_builtin(Device *device, DeviceScene *dscene);
73
74         void set_osl_texture_system(void *texture_system);
75         void set_pack_images(bool pack_images_);
76         bool set_animation_frame_update(int frame);
77
78         bool need_update;
79
80         /* NOTE: Here pixels_size is a size of storage, which equals to
81          *       width * height * depth.
82          *       Use this to avoid some nasty memory corruptions.
83          */
84         function<void(const string &filename,
85                       void *data,
86                       bool &is_float,
87                       int &width,
88                       int &height,
89                       int &depth,
90                       int &channels)> builtin_image_info_cb;
91         function<bool(const string &filename,
92                       void *data,
93                       unsigned char *pixels,
94                       const size_t pixels_size)> builtin_image_pixels_cb;
95         function<bool(const string &filename,
96                       void *data,
97                       float *pixels,
98                       const size_t pixels_size)> builtin_image_float_pixels_cb;
99
100         struct Image {
101                 string filename;
102                 void *builtin_data;
103
104                 bool use_alpha;
105                 bool need_load;
106                 bool animated;
107                 float frame;
108                 InterpolationType interpolation;
109                 ExtensionType extension;
110
111                 int users;
112         };
113
114 private:
115         int tex_num_images[IMAGE_DATA_NUM_TYPES];
116         int max_num_images;
117         bool has_half_images;
118         bool cuda_fermi_limits;
119
120         thread_mutex device_mutex;
121         int animation_frame;
122
123         vector<Image*> images[IMAGE_DATA_NUM_TYPES];
124         void *osl_texture_system;
125         bool pack_images;
126
127         bool file_load_image_generic(Image *img, ImageInput **in, int &width, int &height, int &depth, int &components);
128
129         template<TypeDesc::BASETYPE FileFormat,
130                  typename StorageType,
131                  typename DeviceType>
132         bool file_load_image(Image *img,
133                              ImageDataType type,
134                              int texture_limit,
135                              device_vector<DeviceType>& tex_img);
136
137         int max_flattened_slot(ImageDataType type);
138         int type_index_to_flattened_slot(int slot, ImageDataType type);
139         int flattened_slot_to_type_index(int flat_slot, ImageDataType *type);
140         string name_from_type(int type);
141
142         uint8_t pack_image_options(ImageDataType type, size_t slot);
143
144         void device_load_image(Device *device,
145                                DeviceScene *dscene,
146                                Scene *scene,
147                                ImageDataType type,
148                                int slot,
149                                Progress *progess);
150         void device_free_image(Device *device,
151                                DeviceScene *dscene,
152                                ImageDataType type,
153                                int slot);
154
155         template<typename T>
156         void device_pack_images_type(
157                 ImageDataType type,
158                 const vector<device_vector<T>*>& cpu_textures,
159                 device_vector<T> *device_image,
160                 uint4 *info);
161
162         void device_pack_images(Device *device,
163                                 DeviceScene *dscene,
164                                 Progress& progess);
165 };
166
167 CCL_NAMESPACE_END
168
169 #endif /* __IMAGE_H__ */
170