mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +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)
|
for (int i = 0; i < height; ++i, dst -= row, src += row)
|
||||||
memcpy(dst, 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[] pixels;
|
||||||
delete[] flipped;
|
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1201,7 +1201,9 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
|||||||
love::image::ImageData *img = 0;
|
love::image::ImageData *img = 0;
|
||||||
try
|
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 &)
|
catch (love::Exception &)
|
||||||
{
|
{
|
||||||
@@ -1211,8 +1213,6 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] screenshot;
|
|
||||||
|
|
||||||
// Re-bind the active canvas, if necessary.
|
// Re-bind the active canvas, if necessary.
|
||||||
if (curcanvas)
|
if (curcanvas)
|
||||||
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
curcanvas->startGrab(curcanvas->getAttachedCanvases());
|
||||||
|
|||||||
@@ -69,9 +69,11 @@ public:
|
|||||||
* @param The width of the ImageData.
|
* @param The width of the ImageData.
|
||||||
* @param The height of the ImageData.
|
* @param The height of the ImageData.
|
||||||
* @param The data to load into the ImageData.
|
* @param The data to load into the ImageData.
|
||||||
|
* @param Whether the new ImageData should take ownership of the data or
|
||||||
|
* copy it.
|
||||||
* @return The new ImageData.
|
* @return The new ImageData.
|
||||||
**/
|
**/
|
||||||
virtual ImageData *newImageData(int width, int height, void *data) = 0;
|
virtual ImageData *newImageData(int width, int height, void *data, bool own = false) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new CompressedData from FileData.
|
* Creates new CompressedData from FileData.
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ love::image::ImageData *Image::newImageData(int width, int height)
|
|||||||
return new ImageData(width, height);
|
return new ImageData(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::ImageData *Image::newImageData(int width, int height, void *data)
|
love::image::ImageData *Image::newImageData(int width, int height, void *data, bool own)
|
||||||
{
|
{
|
||||||
return new ImageData(width, height, data);
|
return new ImageData(width, height, data, own);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::CompressedData *Image::newCompressedData(love::filesystem::FileData *data)
|
love::image::CompressedData *Image::newCompressedData(love::filesystem::FileData *data)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
love::image::ImageData *newImageData(love::filesystem::FileData *data);
|
love::image::ImageData *newImageData(love::filesystem::FileData *data);
|
||||||
love::image::ImageData *newImageData(int width, int height);
|
love::image::ImageData *newImageData(int width, int height);
|
||||||
love::image::ImageData *newImageData(int width, int height, void *data);
|
love::image::ImageData *newImageData(int width, int height, void *data, bool own = false);
|
||||||
|
|
||||||
love::image::CompressedData *newCompressedData(love::filesystem::FileData *data);
|
love::image::CompressedData *newCompressedData(love::filesystem::FileData *data);
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,15 @@ ImageData::ImageData(int width, int height)
|
|||||||
memset(data, 0, width*height*sizeof(pixel));
|
memset(data, 0, width*height*sizeof(pixel));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageData::ImageData(int width, int height, void *data)
|
ImageData::ImageData(int width, int height, void *data, bool own)
|
||||||
{
|
{
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
create(width, height, data);
|
|
||||||
|
if (own)
|
||||||
|
this->data = (unsigned char *) data;
|
||||||
|
else
|
||||||
|
create(width, height, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageData::~ImageData()
|
ImageData::~ImageData()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
ImageData(love::filesystem::FileData *data);
|
ImageData(love::filesystem::FileData *data);
|
||||||
ImageData(int width, int height);
|
ImageData(int width, int height);
|
||||||
ImageData(int width, int height, void *data);
|
ImageData(int width, int height, void *data, bool own);
|
||||||
virtual ~ImageData();
|
virtual ~ImageData();
|
||||||
|
|
||||||
// Implements image::ImageData.
|
// Implements image::ImageData.
|
||||||
|
|||||||
Reference in New Issue
Block a user