patch from Kevin Roy (kiniou), [#20584] get the image size in pixels in Python API
authorCampbell Barton <ideasman42@gmail.com>
Wed, 6 Jan 2010 10:46:49 +0000 (10:46 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 6 Jan 2010 10:46:49 +0000 (10:46 +0000)
source/blender/makesrna/intern/rna_image.c

index e0d8a6950deacb7dde2324ab3fed6bcfe051cce1..c4d7e772c58c06cea62e5b77fca10caa4729248e 100644 (file)
@@ -153,6 +153,26 @@ static int rna_Image_has_data_get(PointerRNA *ptr)
        return 0;
 }
 
        return 0;
 }
 
+static void rna_Image_size_get(PointerRNA *ptr,int *values)
+{
+       Image *im= (Image*)ptr->data;
+       ImBuf *ibuf;
+       void *lock;
+
+       ibuf = BKE_image_acquire_ibuf(im, NULL , &lock);
+       if (ibuf) {
+               values[0]= ibuf->x;
+               values[1]= ibuf->y;
+       }
+    else {
+               values[0]= 0;
+               values[1]= 0;
+       }
+
+       BKE_image_release_ibuf(im, lock);
+}
+
+
 static int rna_Image_depth_get(PointerRNA *ptr)
 {
        Image *im= (Image*)ptr->data;
 static int rna_Image_depth_get(PointerRNA *ptr)
 {
        Image *im= (Image*)ptr->data;
@@ -401,6 +421,10 @@ static void rna_def_image(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Depth", "Image bit depth.");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
        RNA_def_property_ui_text(prop, "Depth", "Image bit depth.");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       prop= RNA_def_int_vector(srna, "size" , 2 , NULL , 0, 0, "Size" , "Width and height in pixels, zero when image data cant be loaded." , 0 , 0);
+       RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
        RNA_api_image(srna);
 }
 
        RNA_api_image(srna);
 }