[Bf-committers] Question about Image RNA/DNA + Patch

Kevin ROY kiniou at gmail.com
Wed Jan 6 11:01:28 CET 2010


Hi,

Thanks to Campbell, I push the following patch in the tracker to get
Image size in pixels accessible in Python. This new property is an array
of two integer called size (ex: bpy.data.images['name'].size[0] and
bpy.data.images['name'].size[1] )

Cheers ;)

Le mardi 05 janvier 2010 à 15:37 +0100, Kevin ROY a écrit : 
> I've thought about doing that (before sending my patch) by making a
> rna_Image_size_get function which return an array like
> Image.Image.GetSize() did in 2.4x but so far I didn't find how to return
> an array without DNA stuff. I have already read about RNA on
> http://wiki.blender.org/index.php/Dev:Doc/Blender_Source/RNA and search
> some snippets inside svn code and so far, no luck.
> 
> Actually I did 2 functions for size_x and size_y similar to
> rna_Image_depth_get but I think it may be better to have the 2.4x
> behaviour with a returned array (along with a dictionnary).
> 
> Le mardi 05 janvier 2010 à 15:04 +0100, Campbell Barton a écrit : 
> > since the image's imbuf stores the width and the height this could be
> > done by adding RNA access to the ImBuf (But I'd prefer not to do that)
> > 
> > So it can be done by making a size or width/height prop. These would
> > be readonly and have _get functions.
> > 
> > See:
> > ./source/blender/makesrna/intern/rna_image.c:400:	RNA_def_property_int_funcs(prop,
> > "rna_Image_depth_get", NULL, NULL);
> > 
> > Rather then depth, just get the ibuf's ->x/y
> > 
> > On 1/5/10, Kevin ROY <kiniou at gmail.com> wrote:
> > > Hi,
> > >
> > > I'm looking for some help or good directions to make the size in pixels
> > > from an image available through RNA. For the use case, I need these 2
> > > props in a script that export meshes for NintendoDS CallList and more
> > > particularly when it exports UV coordinates ( e.g. [0.0,1.0[ become
> > > [0,128[ according to a 128x128 texture) .
> > >
> > > In the 2.4x Python API, we can get the size from Image.Image.getSize()
> > > but i didn't found any clue on how to do it in 2.5 API .
> > >
> > > On the other hand, I did found the generated_width and generated_height
> > > properties in the Image structure but I think they might be bound to
> > > images generated by blender itself and they are not used when texture
> > > images are loaded from file. So I modify the function called
> > > image_initialize_after_load where we can update these 2 properties (c.f.
> > > the "quick-and-dirty" patch joined in the mail) and now I can access
> > > them in python .
> > >
> > > I think there is a better way to do that and I'll take a look into 2.4x
> > > code to found how it was done .
> > >
> > > Cheers,
> > >
> > > --
> > > Kevin Roy
> > > http://blog.knokorpo.fr
> > >
> > >
> > 
> > 
> 
> 


-- 
Kevin Roy
http://blog.knokorpo.fr

-------------- next part --------------
Index: source/blender/makesrna/intern/rna_image.c
===================================================================
--- source/blender/makesrna/intern/rna_image.c	(révision 25732)
+++ source/blender/makesrna/intern/rna_image.c	(copie de travail)
@@ -153,6 +153,27 @@ static int rna_Image_has_data_get(PointerRNA *ptr)
 	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]=0;
+		values[1]=0;
+	} else {
+		values[0] = ibuf->x;
+		values[1] = ibuf->y;
+	}
+
+	BKE_image_release_ibuf(im, lock);
+
+}
+
+
 static int rna_Image_depth_get(PointerRNA *ptr)
 {
 	Image *im= (Image*)ptr->data;
@@ -401,6 +422,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);
 
+	prop= RNA_def_int_vector(srna, "size" , 2 , NULL , 0, 0, "Size" , "Size in pixels" , 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);
 }
 


More information about the Bf-committers mailing list