diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_image.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_image.c | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 96d85cda5e7..df5bd9f27f3 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -22,6 +22,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/makesrna/intern/rna_image.c + * \ingroup RNA + */ + + #include <stdlib.h> #include "RNA_define.h" @@ -229,7 +234,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; @@ -238,6 +243,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) @@ -484,6 +557,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, 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); } |