Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-04-03 20:17:39 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-04-03 20:17:39 +0400
commit993e9d4c463406acf81abe8f17a0cac587afd180 (patch)
treeaf1da3e1d3e4d5961495dd5b5bbc6b4e690cf74e /source/blender/makesrna/intern/rna_image.c
parent480b9dca64abd85622c28d195733f3915752636e (diff)
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_image.c')
-rw-r--r--source/blender/makesrna/intern/rna_image.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 64b7e589ecb..2b6349a3877 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -243,6 +243,76 @@ 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;
+ 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 @@ 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_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);
}