[Bf-committers] Blender.Image Question

Alexander Ewering blender at instinctive.de
Sat Feb 19 22:16:17 CET 2005


On Sat, 19 Feb 2005, Austin Benesh wrote:

> This is the code I have so far for the getPixelColor function in
> Blender.Image, but when I try to write the color to the console just to
> test, it gives some non-sense hex code. Could anyone tell me the problem
> with my code (I copied much of it from Image_GetDepth)? Much appreciations!

Dear Austin!

The "non-sense hex code" you are seeing is the address in memory, in hex,
of a certain pixel you are addressing.

>From the manpage of printf() you've probably read:

        %p      The void * pointer argument is printed in hexadecimal (as if by %#x or %#lx).

To print the content of memory locations, you need to dereference the pointer.

There are other problems in your code. From what I remember, rect is an int*, 
so it already points to whole RGBA groups. Though, you are multiplying the
address by 4, which is certainly not what you want, as you will access every
4th pixel.

These are generic C questions though, not related to Blender code.
Getting a K&R book is probably the better solution than asking on a 
mailing list dealing with a specific application - you will get more answers faster.

> static PyObject *Image_getPixels_g(BPy_Image * self, PyObject *args)
>
> {
>
>
>
>      PyObject *attr;
>
>      Image *image = self->image;
>
>      char* p;
>
>      int ptr;
>
>      int x=0;
>
>      int y=0;
>
>
>
>      if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
>
>            return EXPP_ReturnPyObjError( PyExc_TypeError,
>
>                                    "expected 2 integers" );
>
>
>
>      if( !image->ibuf )      /* if no image data available */
>
>            load_image( image, IB_rect, "", 0 );      /* loading it */
>
>
>
>      if( !image->ibuf )      /* didn't work */
>
>            return EXPP_ReturnPyObjError( PyExc_RuntimeError,
>
>                                    "couldn't load image data in Blender" );
>
>
>
>
>
>      ptr=(x + y * image->ibuf->x) * 4;
>
>
>
> attr = Py_BuildValue( "h", image->ibuf->rect[ptr+1] );
>
>
>
>      p=(char*)image->ibuf->rect[ptr+1];
>
>      printf("%p");
>
>      if( attr )
>
>            return attr;
>
>
>
>      return EXPP_ReturnPyObjError( PyExc_RuntimeError,
>
>                              "couldn't get Image.depth attribute" );
>
> };
>
>


| alexander ewering              instinctive mediaworks
| ae[@]instinctive[.]de   http://www[.]instinctive[.]de


More information about the Bf-committers mailing list