mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Improved performance and reduced temporary memory usage of love.graphics.newScreenshot and Canvas:getImageData
This commit is contained in:
@@ -652,10 +652,10 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||
for (int i = 0; i < height; ++i, dst -= row, src += row)
|
||||
memcpy(dst, src, row);
|
||||
|
||||
love::image::ImageData *img = image->newImageData(width, height, (void *)flipped);
|
||||
love::image::ImageData *img = image->newImageData(width, height, (void *)flipped, true);
|
||||
|
||||
// The new ImageData now owns the flipped data, so we don't delete it here.
|
||||
delete[] pixels;
|
||||
delete[] flipped;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
@@ -1201,7 +1201,9 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
||||
love::image::ImageData *img = 0;
|
||||
try
|
||||
{
|
||||
img = image->newImageData(w, h, (void *) screenshot);
|
||||
// Tell the new ImageData that it owns the screenshot data, so we don't
|
||||
// need to delete it here.
|
||||
img = image->newImageData(w, h, (void *) screenshot, true);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
@@ -1211,8 +1213,6 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
||||
throw;
|
||||
}
|
||||
|
||||
delete[] screenshot;
|
||||
|
||||
// Re-bind the active canvas, if necessary.
|
||||
if (curcanvas)
|
||||
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
||||
|
||||
Reference in New Issue
Block a user