mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
Reworked ImageData:encode:
- It now returns a FileData containing the encoded ImageData. - The first argument is now the format to encode to. - The second argument is now the filename to write to, and is optional. No file will be written if a filename is not given.
This commit is contained in:
@@ -144,7 +144,7 @@ void ImageData::decode(love::filesystem::FileData *data)
|
||||
decodeHandler = decoder;
|
||||
}
|
||||
|
||||
void ImageData::encode(love::filesystem::File *f, ImageData::EncodedFormat format)
|
||||
love::filesystem::FileData *ImageData::encode(EncodedFormat format, const char *filename)
|
||||
{
|
||||
FormatHandler *encoder = nullptr;
|
||||
FormatHandler::EncodedImage encodedimage;
|
||||
@@ -174,14 +174,14 @@ void ImageData::encode(love::filesystem::File *f, ImageData::EncodedFormat forma
|
||||
{
|
||||
const char *fname = "unknown";
|
||||
getConstant(format, fname);
|
||||
throw love::Exception("no suitable image encoder for %s format.", fname);
|
||||
throw love::Exception("No suitable image encoder for %s format.", fname);
|
||||
}
|
||||
|
||||
love::filesystem::FileData *filedata = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
f->open(love::filesystem::File::MODE_WRITE);
|
||||
f->write(encodedimage.data, encodedimage.size);
|
||||
f->close();
|
||||
filedata = new love::filesystem::FileData(encodedimage.size, filename);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
@@ -189,7 +189,10 @@ void ImageData::encode(love::filesystem::File *f, ImageData::EncodedFormat forma
|
||||
throw;
|
||||
}
|
||||
|
||||
memcpy(filedata->getData(), encodedimage.data, encodedimage.size);
|
||||
encoder->free(encodedimage.data);
|
||||
|
||||
return filedata;
|
||||
}
|
||||
|
||||
} // magpie
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
// LOVE
|
||||
#include "FormatHandler.h"
|
||||
#include "filesystem/File.h"
|
||||
#include "image/ImageData.h"
|
||||
|
||||
// C++
|
||||
@@ -46,7 +45,7 @@ public:
|
||||
virtual ~ImageData();
|
||||
|
||||
// Implements image::ImageData.
|
||||
virtual void encode(love::filesystem::File *f, ImageData::EncodedFormat format);
|
||||
virtual love::filesystem::FileData *encode(EncodedFormat format, const char *filename);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user