Maybe the MScriptUtil class can help you here? It's a python wrapper
for pointers/references.

On Mon, Feb 23, 2009 at 4:06 PM, jbrav...@gmail.com <jbrav...@gmail.com> wrote:
>
> I'm trying to execute this bit of code I found in one of the devkit
> examples. (customImagePlane.py)
>
> image = OpenMaya.MImage()
> image.readFromFile(filenameStr)
>
> scriptUtil = OpenMaya.MScriptUtil()
> widthPtr = scriptUtil.asUintPtr()
> heightPtr = scriptUtil.asUintPtr()
> scriptUtil.setUint( widthPtr, 0 )
> scriptUtil.setUint( heightPtr, 0 )
> image.getSize( widthPtr, heightPtr )
>
> pWidth = scriptUtil.getUint(widthPtr)
> pHeight = scriptUtil.getUint(heightPtr)
>
> print 'readBandedImageNode: ', pWidth, pHeight
>
>
> size = pWidth * pHeight
> # Implement transparency
> charPixelPtr = image.pixels()
> for i in range( 0, size, 4 ):
>        alphaIndex = (i*4)+3
>        alpha = OpenMayaScript.getCharArrayItem(charPixelPtr,alphaIndex)
>        OpenMayaScript.setCharArray( alpha * (1.0 - self.fTransparency),
> alphaIndex )
>
>
> First off, what is OpenMayaScript? It doesn't declare it or import it
> anywhere, so I'm assuming they meant MScriptUtil() as those are
> functions of it being used.
>
> Secondly, this isn't working =P. I'm getting this error:
>
> # TypeError: argument number 1: a 'char *' is expected, 'PySwigObject
> (_p_unsigned_char)' is received #
>
> I'm really not having much luck learning the python api as it seems
> all these expected types that C++ requires are getting lost in
> pythonese. image.pixels() is supposed to return a constant unsigned
> char... so why is piping that into that variable above breaking it?
>
> This is sample code so it should work? What is a PySwigObject?
>
> I've also tried using image.floatPixels from the MImage class and it
> returns None every time.
>
> I'm trying to get pixel value information at given coordinates. I
> found another C++ example of what I want to do but I'm a little lost
> on the c++ to python syntax change.
>
> C++ exmaple:
> const unsigned char* pix = image.pixels() + (w*py*4 + 4*px);
>
> Can anyone tell me what I'm doing wrong, or is this another bug?
>
>
> >
>



-- 
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to