svn merge ^/trunk/blender -r40720:40872
[blender.git] / source / blender / makesrna / intern / rna_image.c
index 92c860a80743a94458c873d3de5d1e3a0105decb..eac4932ac43af333391cebc583fcecb40910710b 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/makesrna/intern/rna_image.c
+ *  \ingroup RNA
+ */
+
+
 #include <stdlib.h>
 
 #include "RNA_define.h"
@@ -39,9 +44,9 @@
 #include "WM_types.h"
 
 static EnumPropertyItem image_source_items[]= {
-       {IMA_SRC_FILE, "FILE", 0, "File", "Single image file"},
-       {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Sequence", "Multiple image files, as a sequence"},
-       {IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
+       {IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"},
+       {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"},
+       {IMA_SRC_MOVIE, "MOVIE", 0, "Movie File", "Movie file"},
        {IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
        {IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
        {0, NULL, 0, NULL, NULL}};
@@ -50,7 +55,7 @@ static EnumPropertyItem image_source_items[]= {
 
 #include "IMB_imbuf_types.h"
 
-static void rna_Image_animated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Image_animated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Image *ima= (Image*)ptr->data;
        int  nr;
@@ -75,14 +80,14 @@ static int rna_Image_dirty_get(PointerRNA *ptr)
        return 0;
 }
 
-static void rna_Image_source_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Image_source_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Image *ima= ptr->id.data;
        BKE_image_signal(ima, NULL, IMA_SIGNAL_SRC_CHANGE);
-       DAG_id_flush_update(&ima->id, 0);
+       DAG_id_tag_update(&ima->id, 0);
 }
 
-static void rna_Image_fields_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Image_fields_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Image *ima= ptr->id.data;
        ImBuf *ibuf;
@@ -103,20 +108,20 @@ static void rna_Image_fields_update(Main *bmain, Scene *scene, PointerRNA *ptr)
        BKE_image_release_ibuf(ima, lock);
 }
 
-static void rna_Image_reload_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Image_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Image *ima= ptr->id.data;
        BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
-       DAG_id_flush_update(&ima->id, 0);
+       DAG_id_tag_update(&ima->id, 0);
 }
 
-static void rna_Image_generated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Image_generated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Image *ima= ptr->id.data;
        BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
 }
 
-static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_ImageUser_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
 {
        ImageUser *iuser= ptr->data;
 
@@ -138,7 +143,7 @@ char *rna_ImageUser_path(PointerRNA *ptr)
        return BLI_strdup("");
 }
 
-static EnumPropertyItem *rna_Image_source_itemf(bContext *C, PointerRNA *ptr, int *free)
+static EnumPropertyItem *rna_Image_source_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
 {
        Image *ima= (Image*)ptr->data;
        EnumPropertyItem *item= NULL;
@@ -171,9 +176,19 @@ static void rna_Image_file_format_set(PointerRNA *ptr, int value)
 {
        Image *image= (Image*)ptr->data;
        if(BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */
-               ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
+               ImBuf *ibuf;
+               int ftype= BKE_imtype_to_ftype(value);
+
+               /*
+               ibuf= BKE_image_get_ibuf(image, NULL);
                if(ibuf)
-                       ibuf->ftype= BKE_imtype_to_ftype(value);
+                       ibuf->ftype= ftype;
+               */
+
+               /* to be safe change all buffer file types */
+               for(ibuf= image->ibufs.first; ibuf; ibuf= ibuf->next) {
+                       ibuf->ftype= ftype;
+               }
        }
 }
 
@@ -206,6 +221,39 @@ static void rna_Image_size_get(PointerRNA *ptr,int *values)
        BKE_image_release_ibuf(im, lock);
 }
 
+static void rna_Image_resolution_get(PointerRNA *ptr, float *values)
+{
+       Image *im= (Image*)ptr->data;
+       ImBuf *ibuf;
+       void *lock;
+
+       ibuf = BKE_image_acquire_ibuf(im, NULL , &lock);
+       if (ibuf) {
+               values[0]= ibuf->ppm[0];
+               values[1]= ibuf->ppm[1];
+       }
+       else {
+               values[0]= 0;
+               values[1]= 0;
+       }
+
+       BKE_image_release_ibuf(im, lock);
+}
+
+static void rna_Image_resolution_set(PointerRNA *ptr, const float *values)
+{
+       Image *im= (Image*)ptr->data;
+       ImBuf *ibuf;
+       void *lock;
+
+       ibuf = BKE_image_acquire_ibuf(im, NULL , &lock);
+       if (ibuf) {
+               ibuf->ppm[0]= values[0];
+               ibuf->ppm[1]= values[1];
+       }
+
+       BKE_image_release_ibuf(im, lock);
+}
 
 static int rna_Image_depth_get(PointerRNA *ptr)
 {
@@ -219,7 +267,7 @@ static int rna_Image_depth_get(PointerRNA *ptr)
        if(!ibuf)
                depth= 0;
        else if(ibuf->rect_float)
-               depth= 128;
+               depth= ibuf->depth * 4;
        else
                depth= ibuf->depth;
 
@@ -228,6 +276,74 @@ static int rna_Image_depth_get(PointerRNA *ptr)
        return depth;
 }
 
+static int rna_Image_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
+{
+       Image *ima= ptr->id.data;
+       ImBuf *ibuf;
+       void *lock;
+
+       ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+       if(ibuf)
+               length[0]= ibuf->x*ibuf->y*ibuf->channels;
+       else
+               length[0]= 0;
+
+       BKE_image_release_ibuf(ima, lock);
+
+       return length[0];
+}
+
+static void rna_Image_pixels_get(PointerRNA *ptr, float *values)
+{
+       Image *ima= ptr->id.data;
+       ImBuf *ibuf;
+       void *lock;
+       int i, size;
+
+       ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+       if(ibuf) {
+               size= ibuf->x*ibuf->y*ibuf->channels;
+
+               if(ibuf->rect_float) {
+                       memcpy(values, ibuf->rect_float, sizeof(float)*size);
+               }
+               else {
+                       for(i = 0; i < size; i++)
+                               values[i] = ((unsigned char*)ibuf->rect)[i]*(1.0f/255.0f);
+               }
+       }
+
+       BKE_image_release_ibuf(ima, lock);
+}
+
+static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
+{
+       Image *ima= ptr->id.data;
+       ImBuf *ibuf;
+       void *lock;
+       int i, size;
+
+       ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+       if(ibuf) {
+               size= ibuf->x*ibuf->y*ibuf->channels;
+
+               if(ibuf->rect_float) {
+                       memcpy(ibuf->rect_float, values, sizeof(float)*size);
+               }
+               else {
+                       for(i = 0; i < size; i++)
+                               ((unsigned char*)ibuf->rect)[i] = FTOCHAR(values[i]);
+               }
+
+               ibuf->userflags |= IB_BITMAPDIRTY;
+       }
+
+       BKE_image_release_ibuf(ima, lock);
+}
+
 #else
 
 static void rna_def_imageuser(BlenderRNA *brna)
@@ -265,12 +381,12 @@ static void rna_def_imageuser(BlenderRNA *brna)
        prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
        RNA_def_property_int_sdna(prop, NULL, "sfra");
        RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
-       RNA_def_property_ui_text(prop, "Start Frame", "Sets the global starting frame of the movie");
+       RNA_def_property_ui_text(prop, "Start Frame", "Sets the global starting frame of the movie/sequence, assuming first picture has a #1");
        RNA_def_property_update(prop, 0, "rna_ImageUser_update");
 
        prop= RNA_def_property(srna, "fields_per_frame", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "fie_ima");
-       RNA_def_property_range(prop, 1, MAXFRAMEF);
+       RNA_def_property_range(prop, 1, 200);
        RNA_def_property_ui_text(prop, "Fields per Frame", "The number of fields per rendered frame (2 fields is 1 image)");
        RNA_def_property_update(prop, 0, "rna_ImageUser_update");
 
@@ -386,6 +502,11 @@ static void rna_def_image(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
        RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
 
+       prop= RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "gen_flag", IMA_GEN_FLOAT);
+       RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating point buffer");
+       RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
+
        /* realtime properties */
        prop= RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
@@ -474,6 +595,16 @@ static void rna_def_image(BlenderRNA *brna)
        RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       prop= RNA_def_float_vector(srna, "resolution" , 2 , NULL , 0, 0, "Resolution" , "X/Y pixels per meter" , 0 , 0);
+       RNA_def_property_float_funcs(prop, "rna_Image_resolution_get" , "rna_Image_resolution_set", NULL);
+
+       prop= RNA_def_property(srna, "pixels", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_DYNAMIC);
+       RNA_def_property_multi_array(prop, 1, NULL);
+       RNA_def_property_ui_text(prop, "Pixels", "Image pixels in floating point values");
+       RNA_def_property_dynamic_array_funcs(prop, "rna_Image_pixels_get_length");
+       RNA_def_property_float_funcs(prop, "rna_Image_pixels_get", "rna_Image_pixels_set", NULL);
+
        RNA_api_image(srna);
 }