Pyqt maya convert .iff to .jpeg

hi there

is it possible to convert .iff image in maya into .jpeg using QImage class? :?:

import maya.OpenMaya as mom

mayaImage = mom.MImage()
mayaImage.readFromFile(“someIffImage.iff”)
# get image dimensions
scriptUtilw = mom.MScriptUtil()
scriptUtilh = mom.MScriptUtil()
wPtr = scriptUtilw.asUintPtr()
hPtr = scriptUtilh.asUintPtr()
mayaImage.getSize( wPtr, hPtr )
twidth = scriptUtilw.getUint(wPtr)
theight = scriptUtilh.getUint(hPtr)
# get a byte-pointer to the image data in the memory
pixelPtr = mayaImage.pixels()
pA = ctypes.cast( pixelPtr.long(), ctypes.POINTER( ctypes.c_char ) )
# get the image data as string
pAstring=ctypes.string_at(pA, twidththeight4)

pAstring is holds your picture - 32 bit RGBA in this case
You should be able to construct a QImage with QImage(pAstring,twidth,theight,Qt.QImage.Format_ARGB32)

you might also have to use QImages .mirrored() function if the IFF ends up being upside down. If the colors are wrong then it’s just a case of R and B being swapped - QT has a function for this as well (.rgbSwapped()).

Some versions of Maya (x64?) are missing ctypes though - but you can install it yourself by downloading them and adding them to the pythonpath and then import them.

thanks robert for quick reply

is it possible to crop perticular region?

crop it in Qt. I haven’t done this but my guess is that you need to create a new QBitmap or QImage and then use it as paint device and paint the bigger bitmap into it.

But if you’re lucky, maybe QImage has a crop function somewhere…

hi all

can i implement iff into qt ?

is there any method to add new file format into qt

thanks and regards

mossin

Could try this…
http://blarg.robertkist.com/?p=16

It’s an IFF loader module, based on Gimp’s code (might want to check the license). I turned it into a module. It can only read though. You can then pass the RGB/RGBA image buffer to PIL or Qt and make an image.