Hi Renaud, 

QImage is limited to a maximum of 8 bits per channel, with a very limited list 
of pixelformats.. as such you will probably have to do all your operations 
(especially OCIO ops) in full 32 bit floating point, and finally resample the 
image into an 8 bit per channel RGB/RGBA format with oiio, which you can then 
wrap in a QImage. 

Assuming you end up with an 8bpc RGB ImageBuf already, you should be able to 
directly construct a QImage from this, using 
myImageBuf.pixelAddr(xmin,ymin,zmin) as the pointer to the QImages raw data in 
the constructor e.g. 

QImage myImage( myImageBuf.pixeladdr( myImageBuf.xmin(), myImageBuf.ymin(), 
myImageBuf.zmin() ), myImageBuf.width(), myImageBuf.height(), QImage :: 
Format_RGB888 ); 

or similar. Note some formats (particularly exr where dataWindow does not match 
displayWindow) will have their pixel data starting at some other location than 
0,0 which is why I have used xmin()/ymin()/zmin() but in most cases 
pixeladdr(0,0,0) would work fine. 

In the case your 'final' processed ImageBuf is something with > 8 bits per 
channel, you can also use ImageBuf.get_pixels() to dump the pixels from a float 
ImageBuf into a specified format - this is probably a nicer way to do it, and 
in this case you would probably allocate a buffer of the correct size using 
malloc, and the width/height/nchans info from the ImageBuf - and call 
myImageBuf.get_pixels() to copy the image data into it and then wrap a QImage 
around it. 

e.g. 

unsigned char* myBuffer = 
malloc(myImageBuf.width()*myImageBuf.height()*myImageBuf.nchans()); 
myImageBuf.get_pixels(myImageBuf.roi_full(),TypeDesc::UINT8,myBuffer); 

QImage::Format QIFormat = QImage::Format_RGB888 //default case is 3 channels 
if (myImageBuf.nchans == 4) 
{ 
QIFormat = QImage::Format_ARGB32; 
} 

QImage myQImage(myBuffer,myImageBuf.width(),myImageBuf.height(),QIFormat); 

Note if your ImageBuf has more than 4 channels of data, you will likely need to 
extract the R,G,B,A channels to a new ImageBuf, and wrap that in a QImage using 
one of the above techniques, as QImage cannot 'wrap' anything other than 3/4 
channel RGB image data (unless you need 1 bit masks or 8-bit indexed colour, 
which is unlikely). 


All this code is straight off the top of my head, and may not compile as-is - 
but these are the approaches I would use. 

Hopefully that helps? 

-Pete 







PETER BLACK l PARK ROAD POST PRODUCTION LTD 
TELEPHONE +64 4 909 7800 l WWW.PARKROAD.CO.NZ 

----- Original Message -----

From: "Renaud" <[email protected]> 
To: [email protected] 
Sent: Wednesday, February 3, 2016 7:15:39 PM 
Subject: [Oiio-dev] ImgBuff to Qimage 

Hi ! 

I've been trying to load an image using the ImgBuff approach for a while now 
but I can't quite figure out how to dump the ImgBuff back into a QImage. 

Would anyone be kind enough to provide a simple example on how to do that ? 

I was able to load images into a QImage using the following method : 
http://permalink.gmane.org/gmane.comp.lib.openimageio.devel/140 

but I would like to be able to process the image using OCIO: LUT, colorpsace 
changes, ... before dumping the result into a QImage. 

Any help would be greatly appreciated. 
Thanks. 

_______________________________________________ 
Oiio-dev mailing list 
[email protected] 
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 

_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to