[Oiio-dev] "ImageBufAlgo::resize" and "ImageBufAlgo::resample" cropsimage instead of scaling down to new size

Larry Gritz lg at larrygritz.com
Sun Mar 5 21:38:14 PST 2017


I think "silence" was just because it's the weekend.

Glad you got your problem figured out.

I'll point out that it is possible to improve performance by avoiding extra copies and allocations -- you have one copy in the ImageBuf itself, then you allocate myBuffer and copy into it with resizedBuf.get_pxels().

It's possible to make an ImageBuf "wrap" an existing buffer, so you could do:

// First, allocate the memory just once
unsigned char* myBuffer = (unsigned char*)malloc(thumbSpecSpec.width*thumbSpecSpec.height*thumbSpecSpec.nchannels );
// Construct an ImageBuf that wraps your buffer -- it will not allocate separate pixel memory
ImageBuf resizedBuf (thumbSpecSpec, myBuffer);
// Now do the resize, right into your buffer
ImageBufAlgo::resample ( resizedBuf, srcImageBuf );

... and then carry on with the QImage.



> On Mar 5, 2017, at 7:47 PM, talonrenaud at me.com wrote:
> 
> I understand why I’m getting a silence treatment. I was reading the pixels from my source image instead of my resized (resampled) image.
> I waited half a day on a stupid typo. See working code below:
>  
> Code:
> ImageBuf srcImageBuf("C:/someImage.dpx”);
>  
> int thumbWidth = 480;
> int thumbHeight = 270;
> int thumbChans = 3;
>  
> ImageSpec thumbSpecSpec( thumbWidth, thumbHeight, thumbChans, TypeDesc::UINT8 );
> ImageBuf resizedBuf( thumbSpecSpec );
> ImageBufAlgo::resample ( resizedBuf, srcImageBuf );
>  
> unsigned char* myBuffer = (unsigned char*)malloc(thumbSpecSpec.width*thumbSpecSpec.height*thumbSpecSpec.nchannels );
> resizedBuf.get_pixels(resizedBuf.roi_full(), TypeDesc::UINT8, myBuffer);
>  
> // Create QImage
> QImage::Format QIFormat = QImage::Format_RGB888;
> QImage *newQImage = new QImage(myBuffer, resizedBuf.spec().width, resizedBuf.spec().height, QIFormat);
>  
> Renaud
>  
>  
> From: talonrenaud at me.com <mailto:talonrenaud at me.com>
> Sent: Sunday, March 5, 2017 1:09 AM
> To: OpenImageIO developers <mailto:oiio-dev at lists.openimageio.org>
> Subject: [Oiio-dev] "ImageBufAlgo::resize" and "ImageBufAlgo::resample" cropsimage instead of scaling down to new size
>  
> Hi !
>  
> I was able to get my get my image loaded and converted to a QImage using code that Larry and Peter Black helped with a little while back, that said for some reason when I try to scale down my image (to generate a thumbnail) both ImageBufAlgo::resize and ImageBufAlgo::resample crop the original image (using a portion of the source image from what seems to be a roi of 0, 480, 0, 270) instead of using the full ROI from the source and scaling it down into a smaller thumbnail ImgBuf.
> I am pulling my hair off on this. I have used both resize and resample with pyOpenImageIO with no issue, it’s pretty much the same code here so I’m not sure what I am doing wrong.
> As usual, any help would be greatly appreciated. (I’m using OIIO 1.7 on Windows 10, compiled with VS2015)
>  
> Thanks,
>  
> Renaud
>  
> Code:
> 
> ImageBuf srcImageBuf("C:/someImage.dpx”);
>  
> int thumbWidth = 480;
> int thumbHeight = 270;
> int thumbChans = 3;
>  
> ImageSpec thumbSpecSpec( thumbWidth, thumbHeight, thumbChans, TypeDesc::UINT8 );
> ImageBuf resizedBuf( thumbSpecSpec );
> ImageBufAlgo::resample ( resizedBuf, srcImageBuf );
>  
> unsigned char* myBuffer = (unsigned char*)malloc(thumbSpecSpec.width*thumbSpecSpec.height*thumbSpecSpec.nchannels );
> srcImageBuf.get_pixels(resizedBuf.roi_full(), TypeDesc::UINT8, myBuffer);
>  
> // Create QImage
> QImage::Format QIFormat = QImage::Format_RGB888;
> QImage *newQImage = new QImage(myBuffer, resizedBuf.spec().width, resizedBuf.spec().height, QIFormat);
>  
> _______________________________________________
> Oiio-dev mailing list
> Oiio-dev at lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
lg at larrygritz.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openimageio.org/pipermail/oiio-dev-openimageio.org/attachments/20170305/5bf38a10/attachment-0001.html>


More information about the Oiio-dev mailing list