Revision: 35976
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35976
Author:   blendix
Date:     2011-04-03 16:17:39 +0000 (Sun, 03 Apr 2011)
Log Message:
-----------
Image pixel acces, through Image.pixels as floating point values.

It's not the most efficient solution, but this can be optimized later. It's
best to copy out all the pixels at once into a list, rather than accessing
them one by one.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_image.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_image.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_image.c    2011-04-03 
16:11:21 UTC (rev 35975)
+++ trunk/blender/source/blender/makesrna/intern/rna_image.c    2011-04-03 
16:17:39 UTC (rev 35976)
@@ -243,6 +243,76 @@
        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;
+               length[1]= ibuf->channels;
+       }
+       else {
+               length[0]= 0;
+               length[1]= 0;
+       }
+
+       BKE_image_release_ibuf(ima, lock);
+
+       return length[0]*length[1];
+}
+
+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]);
+               }
+       }
+
+       BKE_image_release_ibuf(ima, lock);
+}
+
 #else
 
 static void rna_def_imageuser(BlenderRNA *brna)
@@ -489,6 +559,13 @@
        RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       prop= RNA_def_property(srna, "pixels", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_DYNAMIC);
+       RNA_def_property_multi_array(prop, 2, 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);
 }
 

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to