Fix build error on Windows 32 bit.
[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/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 Progress;
32 class Scene;
33
34 class ImageMetaData {
35 public:
36         /* Must be set by image file or builtin callback. */
37         bool is_float, is_half;
38         int channels;
39         size_t width, height, depth;
40         bool builtin_free_cache;
41
42         /* Automatically set. */
43         ImageDataType type;
44         bool is_linear;
45 };
46
47 class ImageManager {
48 public:
49         explicit ImageManager(const DeviceInfo& info);
50         ~ImageManager();
51
52         int add_image(const string& filename,
53                       void *builtin_data,
54                       bool animated,
55                       float frame,
56                       InterpolationType interpolation,
57                       ExtensionType extension,
58                       bool use_alpha,
59                       ImageMetaData& metadata);
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         bool get_image_metadata(const string& filename,
72                                 void *builtin_data,
73                                 ImageMetaData& metadata);
74
75         void device_update(Device *device,
76                            Scene *scene,
77                            Progress& progress);
78         void device_update_slot(Device *device,
79                                 Scene *scene,
80                                 int flat_slot,
81                                 Progress *progress);
82         void device_free(Device *device);
83         void device_free_builtin(Device *device);
84
85         void set_osl_texture_system(void *texture_system);
86         bool set_animation_frame_update(int frame);
87
88         device_memory *image_memory(int flat_slot);
89
90         bool need_update;
91
92         /* NOTE: Here pixels_size is a size of storage, which equals to
93          *       width * height * depth.
94          *       Use this to avoid some nasty memory corruptions.
95          */
96         function<void(const string &filename,
97                       void *data,
98                       ImageMetaData& metadata)> builtin_image_info_cb;
99         function<bool(const string &filename,
100                       void *data,
101                       unsigned char *pixels,
102                       const size_t pixels_size,
103                       const bool free_cache)> builtin_image_pixels_cb;
104         function<bool(const string &filename,
105                       void *data,
106                       float *pixels,
107                       const size_t pixels_size,
108                       const bool free_cache)> builtin_image_float_pixels_cb;
109
110         struct Image {
111                 string filename;
112                 void *builtin_data;
113                 bool builtin_free_cache;
114
115                 bool use_alpha;
116                 bool need_load;
117                 bool animated;
118                 float frame;
119                 InterpolationType interpolation;
120                 ExtensionType extension;
121
122                 string mem_name;
123                 device_memory *mem;
124
125                 int users;
126         };
127
128 private:
129         int tex_num_images[IMAGE_DATA_NUM_TYPES];
130         int max_num_images;
131         bool has_half_images;
132
133         thread_mutex device_mutex;
134         int animation_frame;
135
136         vector<Image*> images[IMAGE_DATA_NUM_TYPES];
137         void *osl_texture_system;
138
139         bool file_load_image_generic(Image *img,
140                                      ImageInput **in,
141                                      int &width,
142                                      int &height,
143                                      int &depth,
144                                      int &components);
145
146         template<TypeDesc::BASETYPE FileFormat,
147                  typename StorageType,
148                  typename DeviceType>
149         bool file_load_image(Image *img,
150                              ImageDataType type,
151                              int texture_limit,
152                              device_vector<DeviceType>& tex_img);
153
154         int max_flattened_slot(ImageDataType type);
155         int type_index_to_flattened_slot(int slot, ImageDataType type);
156         int flattened_slot_to_type_index(int flat_slot, ImageDataType *type);
157         string name_from_type(int type);
158
159         void device_load_image(Device *device,
160                                Scene *scene,
161                                ImageDataType type,
162                                int slot,
163                                Progress *progess);
164         void device_free_image(Device *device,
165                                ImageDataType type,
166                                int slot);
167 };
168
169 CCL_NAMESPACE_END
170
171 #endif /* __IMAGE_H__ */
172