Fix Cycles OpenCL not taking Extend and Clip extension types into account.
[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.h"
21 #include "device_memory.h"
22
23 #include "util_image.h"
24 #include "util_string.h"
25 #include "util_thread.h"
26 #include "util_vector.h"
27
28 CCL_NAMESPACE_BEGIN
29
30 class Device;
31 class DeviceScene;
32 class Progress;
33
34 class ImageManager {
35 public:
36         explicit ImageManager(const DeviceInfo& info);
37         ~ImageManager();
38
39         enum ImageDataType {
40                 IMAGE_DATA_TYPE_FLOAT4 = 0,
41                 IMAGE_DATA_TYPE_BYTE4 = 1,
42                 IMAGE_DATA_TYPE_FLOAT = 2,
43                 IMAGE_DATA_TYPE_BYTE = 3,
44                 IMAGE_DATA_TYPE_HALF4 = 4,
45                 IMAGE_DATA_TYPE_HALF = 5,
46
47                 IMAGE_DATA_NUM_TYPES
48         };
49
50         int add_image(const string& filename,
51                       void *builtin_data,
52                       bool animated,
53                       float frame,
54                       bool& is_float,
55                       bool& is_linear,
56                       InterpolationType interpolation,
57                       ExtensionType extension,
58                       bool use_alpha);
59         void remove_image(int flat_slot);
60         void remove_image(const string& filename,
61                           void *builtin_data,
62                           InterpolationType interpolation,
63                           ExtensionType extension);
64         void tag_reload_image(const string& filename,
65                               void *builtin_data,
66                               InterpolationType interpolation,
67                               ExtensionType extension);
68         ImageDataType get_image_metadata(const string& filename, void *builtin_data, bool& is_linear);
69
70         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
71         void device_update_slot(Device *device, DeviceScene *dscene, int flat_slot, Progress *progress);
72         void device_free(Device *device, DeviceScene *dscene);
73         void device_free_builtin(Device *device, DeviceScene *dscene);
74
75         void set_osl_texture_system(void *texture_system);
76         void set_pack_images(bool pack_images_);
77         bool set_animation_frame_update(int frame);
78
79         bool need_update;
80
81         function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
82         function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
83         function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
84
85         struct Image {
86                 string filename;
87                 void *builtin_data;
88
89                 bool use_alpha;
90                 bool need_load;
91                 bool animated;
92                 float frame;
93                 InterpolationType interpolation;
94                 ExtensionType extension;
95
96                 int users;
97         };
98
99 private:
100         int tex_num_images[IMAGE_DATA_NUM_TYPES];
101         int tex_start_images[IMAGE_DATA_NUM_TYPES];
102
103         thread_mutex device_mutex;
104         int animation_frame;
105
106         vector<Image*> images[IMAGE_DATA_NUM_TYPES];
107         void *osl_texture_system;
108         bool pack_images;
109
110         bool file_load_image_generic(Image *img, ImageInput **in, int &width, int &height, int &depth, int &components);
111
112         template<typename T>
113         bool file_load_byte_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
114
115         template<typename T>
116         bool file_load_float_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
117
118         template<typename T>
119         bool file_load_half_image(Image *img, ImageDataType type, device_vector<T>& tex_img);
120
121         int type_index_to_flattened_slot(int slot, ImageDataType type);
122         int flattened_slot_to_type_index(int flat_slot, ImageDataType *type);
123         string name_from_type(int type);
124
125         uint8_t pack_image_options(ImageDataType type, size_t slot);
126
127         void device_load_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot, Progress *progess);
128         void device_free_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot);
129
130         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
131 };
132
133 CCL_NAMESPACE_END
134
135 #endif /* __IMAGE_H__ */
136