Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Rescale and copy area of source image into an area of dest image
Rescale and copy area of source image into an area of dest image [message #14547] |
Sun, 02 March 2008 20:32  |
mdelfede
Messages: 1308 Registered: September 2007
|
Ultimate Contributor |
|
|
I could not manage to do an apparently simple stuff : copy a rectangular area on source image, rescale it and put in another rectangular area on a destination imagebuffer.
This is my piece of code :
// extract and rescale image area
ImageEncoder t;
Rescale(t, destSize, page, sourceRect);
// copies rescaled image inside cache rectangle
const RGBA *rgba = t;
for(int iLine = 0 ; iLine < t.GetHeight(); iLine++)
{
Copy(imageCache[i+rect.top]+rect.left, rgba, t.GetWidth());
rgba += t.GetWidth();
}
or :
// extract and rescale image area
ImageEncoder t;
Rescale(t, destSize, page, sourceRect);
Image img = Image(t);
// copies rescaled image inside cache rectangle
const RGBA *rgba = img;
for(int iLine = 0 ; iLine < img.GetHeight(); iLine++)
{
memmove(imageCache[i+rect.top]+rect.left, rgba, img.GetWidth()* sizeof(RGBA));
rgba += img.GetWidth();
}
And many other options, but no way, destination stuff doesn't contain the required copy. I know that 't' contains a valid image because painting it directly is ok.
Any hint ?
Ah, last stuff.... ImageDraw class (which could be used for this purpose....) is documented in help with many member functions that it doesn't have in reality, first of them the constructor
Ciao
Max
[Updated on: Sun, 02 March 2008 22:50] Report message to a moderator
|
|
|
Re: Rescale and copy area of source image into an area of dest image [message #14554 is a reply to message #14547] |
Mon, 03 March 2008 17:52   |
mdelfede
Messages: 1308 Registered: September 2007
|
Ultimate Contributor |
|
|
well, partly solved... the bug was not here... for others interested in using Image and Imagebuffer, beware :
ImageBuffer buf;
Draw d = ........
...........
...........
d.DrawImage(buf, .....)
will *not* work, or better, it'll work ONCE.
DrawImage expects an Image& parameter, so buf is converted on the fly onto Image object, loosing its content due to destroy-on-copy behaviour.
The correct code is :
ImageBuffer buf;
Draw d = ........
...........
...........
Image img = buf;
d.DrawImage(img, .....)
buf = img;
quite un-intuitive, indeed. It would be much better to have a different version of DrawImage with an ImageBuffer & as first parameter. Also, allowing such automatic type conversion on objects that have the destroy-on-copy semantics can lead to subtle bugs...
Ciao
Max
|
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 15:05:04 CEST 2025
Total time taken to generate the page: 0.02670 seconds
|