4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Brecht Van Lommel
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
32 #include "DNA_image_types.h"
33 #include "DNA_scene_types.h"
35 #include "BKE_context.h"
36 #include "BKE_image.h"
40 static EnumPropertyItem image_source_items[]= {
41 {IMA_SRC_FILE, "FILE", 0, "File", "Single image file"},
42 {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Sequence", "Multiple image files, as a sequence"},
43 {IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
44 {IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
45 {IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
46 {0, NULL, 0, NULL, NULL}};
50 #include "IMB_imbuf_types.h"
52 static void rna_Image_animated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
54 Image *ima= (Image*)ptr->data;
57 if(ima->flag & IMA_TWINANIM) {
58 nr= ima->xrep*ima->yrep;
59 if(ima->twsta>=nr) ima->twsta= 1;
60 if(ima->twend>=nr) ima->twend= nr-1;
61 if(ima->twsta>ima->twend) ima->twsta= 1;
65 static int rna_Image_dirty_get(PointerRNA *ptr)
67 Image *ima= (Image*)ptr->data;
70 for(ibuf=ima->ibufs.first; ibuf; ibuf=ibuf->next)
71 if(ibuf->userflags & IB_BITMAPDIRTY)
77 static void rna_Image_source_update(Main *bmain, Scene *scene, PointerRNA *ptr)
79 Image *ima= ptr->id.data;
80 BKE_image_signal(ima, NULL, IMA_SIGNAL_SRC_CHANGE);
83 static void rna_Image_fields_update(Main *bmain, Scene *scene, PointerRNA *ptr)
85 Image *ima= ptr->id.data;
89 ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
94 if(!(ima->flag & IMA_FIELDS) && (ibuf->flags & IB_fields)) nr= 1;
95 if((ima->flag & IMA_FIELDS) && !(ibuf->flags & IB_fields)) nr= 1;
98 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
101 BKE_image_release_ibuf(ima, lock);
104 static void rna_Image_reload_update(Main *bmain, Scene *scene, PointerRNA *ptr)
106 Image *ima= ptr->id.data;
107 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
108 printf("reload %p\n", ima);
111 static void rna_Image_generated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
113 Image *ima= ptr->id.data;
114 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
117 static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
119 ImageUser *iuser= ptr->data;
121 BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0);
124 static EnumPropertyItem *rna_Image_source_itemf(bContext *C, PointerRNA *ptr, int *free)
126 Image *ima= (Image*)ptr->data;
127 EnumPropertyItem *item= NULL;
130 if(ima->source == IMA_SRC_VIEWER) {
131 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_VIEWER);
134 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_FILE);
135 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_SEQUENCE);
136 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_MOVIE);
137 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_GENERATED);
140 RNA_enum_item_end(&item, &totitem);
146 static int rna_Image_has_data_get(PointerRNA *ptr)
148 Image *im= (Image*)ptr->data;
156 static int rna_Image_depth_get(PointerRNA *ptr)
158 Image *im= (Image*)ptr->data;
163 ibuf= BKE_image_acquire_ibuf(im, NULL, &lock);
167 else if(ibuf->rect_float)
172 BKE_image_release_ibuf(im, lock);
179 static void rna_def_imageuser(BlenderRNA *brna)
184 srna= RNA_def_struct(brna, "ImageUser", NULL);
185 RNA_def_struct_ui_text(srna, "Image User", "Parameters defining how an Image datablock is used by another datablock.");
187 prop= RNA_def_property(srna, "auto_refresh", PROP_BOOLEAN, PROP_NONE);
188 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS);
189 RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes.");
190 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
193 prop= RNA_def_property(srna, "cyclic", PROP_BOOLEAN, PROP_NONE);
194 RNA_def_property_boolean_sdna(prop, NULL, "cycl", 0);
195 RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie.");
196 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
198 prop= RNA_def_property(srna, "frames", PROP_INT, PROP_NONE);
199 RNA_def_property_range(prop, 0, MAXFRAMEF);
200 RNA_def_property_ui_text(prop, "Frames", "Sets the number of images of a movie to use.");
201 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
203 prop= RNA_def_property(srna, "offset", PROP_INT, PROP_NONE);
204 RNA_def_property_range(prop, -MAXFRAMEF, MAXFRAMEF);
205 RNA_def_property_ui_text(prop, "Offset", "Offsets the number of the frame to use in the animation.");
206 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
208 prop= RNA_def_property(srna, "start_frame", PROP_INT, PROP_TIME);
209 RNA_def_property_int_sdna(prop, NULL, "sfra");
210 RNA_def_property_range(prop, 1.0f, MAXFRAMEF);
211 RNA_def_property_ui_text(prop, "Start Frame", "Sets the global starting frame of the movie.");
212 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
214 prop= RNA_def_property(srna, "fields_per_frame", PROP_INT, PROP_NONE);
215 RNA_def_property_int_sdna(prop, NULL, "fie_ima");
216 RNA_def_property_range(prop, -MAXFRAMEF, MAXFRAMEF);
217 RNA_def_property_ui_text(prop, "Fields per Frame", "The number of fields per rendered frame (2 fields is 1 image).");
218 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
220 prop= RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
221 RNA_def_property_int_sdna(prop, NULL, "layer");
222 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
223 RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image.");
225 prop= RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
226 RNA_def_property_int_sdna(prop, NULL, "pass");
227 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
228 RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image.");
231 static void rna_def_image(BlenderRNA *brna)
235 static const EnumPropertyItem prop_type_items[]= {
236 {IMA_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
237 {IMA_TYPE_MULTILAYER, "MULTILAYER", 0, "Multilayer", ""},
238 {IMA_TYPE_UV_TEST, "UV_TEST", 0, "UV Test", ""},
239 {IMA_TYPE_R_RESULT, "RENDER_RESULT", 0, "Render Result", ""},
240 {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
241 {0, NULL, 0, NULL, NULL}};
242 static const EnumPropertyItem prop_generated_type_items[]= {
243 {0, "BLANK", 0, "Blank", "Generate a blank image"},
244 {1, "UVGRID", 0, "UV Grid", "Generated grid to test UV mappings"},
245 {0, NULL, 0, NULL, NULL}};
246 static const EnumPropertyItem prop_mapping_items[]= {
247 {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"},
248 {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"},
249 {0, NULL, 0, NULL, NULL}};
250 static const EnumPropertyItem prop_field_order_items[]= {
251 {0, "EVEN", 0, "Even", "Even Fields first"},
252 {IMA_STD_FIELD, "ODD", 0, "Odd", "Odd Fields first"},
253 {0, NULL, 0, NULL, NULL}};
255 srna= RNA_def_struct(brna, "Image", "ID");
256 RNA_def_struct_ui_text(srna, "Image", "Image datablock referencing an external or packed image.");
257 RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
259 prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
260 RNA_def_property_string_sdna(prop, NULL, "name");
261 RNA_def_property_ui_text(prop, "Filename", "Image/Movie file name.");
262 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update");
264 prop= RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
265 RNA_def_property_enum_items(prop, image_source_items);
266 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Image_source_itemf");
267 RNA_def_property_ui_text(prop, "Source", "Where the image comes from.");
268 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_source_update");
270 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
271 RNA_def_property_enum_items(prop, prop_type_items);
272 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
273 RNA_def_property_ui_text(prop, "Type", "How to generate the image.");
274 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
276 prop= RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
277 RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
278 RNA_def_property_ui_text(prop, "Packed File", "");
280 prop= RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
281 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
282 RNA_def_property_enum_items(prop, prop_field_order_items);
283 RNA_def_property_ui_text(prop, "Field Order", "Order of video fields. Select which lines are displayed first.");
284 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
287 prop= RNA_def_property(srna, "fields", PROP_BOOLEAN, PROP_NONE);
288 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_FIELDS);
289 RNA_def_property_ui_text(prop, "Fields", "Use fields of the image.");
290 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_fields_update");
292 prop= RNA_def_property(srna, "antialias", PROP_BOOLEAN, PROP_NONE);
293 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANTIALI);
294 RNA_def_property_ui_text(prop, "Anti-alias", "Toggles image anti-aliasing, only works with solid colors");
295 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
297 prop= RNA_def_property(srna, "premultiply", PROP_BOOLEAN, PROP_NONE);
298 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DO_PREMUL);
299 RNA_def_property_ui_text(prop, "Premultiply", "Convert RGB from key alpha to premultiplied alpha.");
300 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
302 prop= RNA_def_property(srna, "dirty", PROP_BOOLEAN, PROP_NONE);
303 RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL);
304 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
305 RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved.");
307 /* generated image (image_generated_change_cb) */
308 prop= RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
309 RNA_def_property_enum_sdna(prop, NULL, "gen_type");
310 RNA_def_property_enum_items(prop, prop_generated_type_items);
311 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type.");
312 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
314 prop= RNA_def_property(srna, "generated_width", PROP_INT, PROP_NONE);
315 RNA_def_property_int_sdna(prop, NULL, "gen_x");
316 RNA_def_property_range(prop, 1, 16384);
317 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width.");
318 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
320 prop= RNA_def_property(srna, "generated_height", PROP_INT, PROP_NONE);
321 RNA_def_property_int_sdna(prop, NULL, "gen_y");
322 RNA_def_property_range(prop, 1, 16384);
323 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height.");
324 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
326 /* realtime properties */
327 prop= RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
328 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
329 RNA_def_property_enum_items(prop, prop_mapping_items);
330 RNA_def_property_ui_text(prop, "Mapping", "Mapping type to use for this image in the game engine.");
331 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
333 prop= RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
334 RNA_def_property_float_sdna(prop, NULL, "aspx");
335 RNA_def_property_array(prop, 2);
336 RNA_def_property_range(prop, 0.1f, 5000.0f);
337 RNA_def_property_ui_text(prop, "Display Aspect", "Display Aspect for this image, does not affect rendering.");
338 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
340 prop= RNA_def_property(srna, "animated", PROP_BOOLEAN, PROP_NONE);
341 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TWINANIM);
342 RNA_def_property_ui_text(prop, "Animated", "Use as animated texture in the game engine.");
343 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
345 prop= RNA_def_property(srna, "animation_start", PROP_INT, PROP_NONE);
346 RNA_def_property_int_sdna(prop, NULL, "twsta");
347 RNA_def_property_range(prop, 0, 128);
348 RNA_def_property_ui_text(prop, "Animation Start", "Start frame of an animated texture.");
349 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
351 prop= RNA_def_property(srna, "animation_end", PROP_INT, PROP_NONE);
352 RNA_def_property_int_sdna(prop, NULL, "twend");
353 RNA_def_property_range(prop, 0, 128);
354 RNA_def_property_ui_text(prop, "Animation End", "End frame of an animated texture.");
355 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
357 prop= RNA_def_property(srna, "animation_speed", PROP_INT, PROP_NONE);
358 RNA_def_property_int_sdna(prop, NULL, "animspeed");
359 RNA_def_property_range(prop, 1, 100);
360 RNA_def_property_ui_text(prop, "Animation Speed", "Speed of the animation in frames per second.");
361 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
363 prop= RNA_def_property(srna, "tiles", PROP_BOOLEAN, PROP_NONE);
364 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TILES);
365 RNA_def_property_ui_text(prop, "Tiles", "Use of tilemode for faces (default shift-LMB to pick the tile for selected faces).");
366 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
368 prop= RNA_def_property(srna, "tiles_x", PROP_INT, PROP_NONE);
369 RNA_def_property_int_sdna(prop, NULL, "xrep");
370 RNA_def_property_range(prop, 1, 16);
371 RNA_def_property_ui_text(prop, "Tiles X", "Degree of repetition in the X direction.");
372 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
374 prop= RNA_def_property(srna, "tiles_y", PROP_INT, PROP_NONE);
375 RNA_def_property_int_sdna(prop, NULL, "yrep");
376 RNA_def_property_range(prop, 1, 16);
377 RNA_def_property_ui_text(prop, "Tiles Y", "Degree of repetition in the Y direction.");
378 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
380 prop= RNA_def_property(srna, "clamp_x", PROP_BOOLEAN, PROP_NONE);
381 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_U);
382 RNA_def_property_ui_text(prop, "Clamp X", "Disable texture repeating horizontally.");
383 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
385 prop= RNA_def_property(srna, "clamp_y", PROP_BOOLEAN, PROP_NONE);
386 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_V);
387 RNA_def_property_ui_text(prop, "Clamp Y", "Disable texture repeating vertically.");
388 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
391 Image.has_data and Image.depth are temporary,
392 Update import_obj.py when they are replaced (Arystan)
394 prop= RNA_def_property(srna, "has_data", PROP_BOOLEAN, PROP_NONE);
395 RNA_def_property_boolean_funcs(prop, "rna_Image_has_data_get", NULL);
396 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
397 RNA_def_property_ui_text(prop, "Has data", "True if this image has data.");
399 prop= RNA_def_property(srna, "depth", PROP_INT, PROP_NONE);
400 RNA_def_property_int_funcs(prop, "rna_Image_depth_get", NULL, NULL);
401 RNA_def_property_ui_text(prop, "Depth", "Image bit depth.");
402 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
407 void RNA_def_image(BlenderRNA *brna)
410 rna_def_imageuser(brna);