Images/[Compressed]ImageData can be created using any Data, instead of just files or FileData.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-08-05 23:55:20 -03:00
parent 9654376bdd
commit 2dd6408d00
29 changed files with 130 additions and 72 deletions
@@ -23,6 +23,7 @@
#include "wrap_File.h" #include "wrap_File.h"
#include "wrap_DroppedFile.h" #include "wrap_DroppedFile.h"
#include "wrap_FileData.h" #include "wrap_FileData.h"
#include "common/wrap_Data.h"
#include "physfs/Filesystem.h" #include "physfs/Filesystem.h"
@@ -218,11 +219,49 @@ FileData *luax_getfiledata(lua_State *L, int idx)
return data; return data;
} }
Data *luax_getdata(lua_State *L, int idx)
{
Data *data = nullptr;
File *file = nullptr;
if (lua_isstring(L, idx) || luax_istype(L, idx, File::type))
{
file = luax_getfile(L, idx);
file->retain();
}
else if (luax_istype(L, idx, Data::type))
{
data = luax_checkdata(L, idx);
data->retain();
}
if (!data && !file)
{
luaL_argerror(L, idx, "filename, File, or Data expected");
return nullptr; // Never reached.
}
if (file)
{
luax_catchexcept(L,
[&]() { data = file->read(); },
[&](bool) { file->release(); }
);
}
return data;
}
bool luax_cangetfiledata(lua_State *L, int idx) bool luax_cangetfiledata(lua_State *L, int idx)
{ {
return lua_isstring(L, idx) || luax_istype(L, idx, File::type) || luax_istype(L, idx, FileData::type); return lua_isstring(L, idx) || luax_istype(L, idx, File::type) || luax_istype(L, idx, FileData::type);
} }
bool luax_cangetdata(lua_State *L, int idx)
{
return lua_isstring(L, idx) || luax_istype(L, idx, File::type) || luax_istype(L, idx, Data::type);
}
int w_newFileData(lua_State *L) int w_newFileData(lua_State *L)
{ {
// Single argument: treat as filepath or File. // Single argument: treat as filepath or File.
+3
View File
@@ -42,6 +42,9 @@ FileData *luax_getfiledata(lua_State *L, int idx);
bool luax_cangetfiledata(lua_State *L, int idx); bool luax_cangetfiledata(lua_State *L, int idx);
File *luax_getfile(lua_State *L, int idx); File *luax_getfile(lua_State *L, int idx);
Data *luax_getdata(lua_State *L, int idx);
bool luax_cangetdata(lua_State *L, int idx);
bool hack_setupWriteDirectory(); bool hack_setupWriteDirectory();
int loader(lua_State *L); int loader(lua_State *L);
int extloader(lua_State *L); int extloader(lua_State *L);
+15 -11
View File
@@ -631,10 +631,14 @@ int w_getStencilTest(lua_State *L)
return 2; return 2;
} }
static void parsePixelDensity(love::filesystem::FileData *d, float *pixeldensity) static void parsePixelDensity(Data *d, float *pixeldensity)
{ {
auto fd = dynamic_cast<love::filesystem::FileData *>(d);
if (fd == nullptr)
return;
// Parse a density scale of 2.0 from "image@2x.png". // Parse a density scale of 2.0 from "image@2x.png".
const std::string &fname = d->getName(); const std::string &fname = fd->getName();
size_t namelen = fname.length(); size_t namelen = fname.length();
size_t atpos = fname.rfind('@'); size_t atpos = fname.rfind('@');
@@ -664,20 +668,20 @@ static Image::Settings w__optImageSettings(lua_State *L, int idx, const Image::S
return settings; return settings;
} }
static std::pair<StrongRef<love::image::ImageData>, StrongRef<love::image::CompressedImageData>> static std::pair<StrongRef<image::ImageData>, StrongRef<image::CompressedImageData>>
getImageData(lua_State *L, int idx, bool allowcompressed, float *density) getImageData(lua_State *L, int idx, bool allowcompressed, float *density)
{ {
StrongRef<love::image::ImageData> idata; StrongRef<image::ImageData> idata;
StrongRef<love::image::CompressedImageData> cdata; StrongRef<image::CompressedImageData> cdata;
// Convert to ImageData / CompressedImageData, if necessary. // Convert to ImageData / CompressedImageData, if necessary.
if (lua_isstring(L, idx) || luax_istype(L, idx, love::filesystem::File::type) || luax_istype(L, idx, love::filesystem::FileData::type)) if (lua_isstring(L, idx) || luax_istype(L, idx, filesystem::File::type) || luax_istype(L, idx, Data::type))
{ {
auto imagemodule = Module::getInstance<love::image::Image>(Module::M_IMAGE); auto imagemodule = Module::getInstance<image::Image>(Module::M_IMAGE);
if (imagemodule == nullptr) if (imagemodule == nullptr)
luaL_error(L, "Cannot load images without the love.image module."); luaL_error(L, "Cannot load images without the love.image module.");
StrongRef<love::filesystem::FileData> fdata(love::filesystem::luax_getfiledata(L, idx), Acquire::NORETAIN); StrongRef<Data> fdata(filesystem::luax_getdata(L, idx), Acquire::NORETAIN);
if (density != nullptr) if (density != nullptr)
parsePixelDensity(fdata, density); parsePixelDensity(fdata, density);
@@ -688,10 +692,10 @@ getImageData(lua_State *L, int idx, bool allowcompressed, float *density)
luax_catchexcept(L, [&]() { idata.set(imagemodule->newImageData(fdata), Acquire::NORETAIN); }); luax_catchexcept(L, [&]() { idata.set(imagemodule->newImageData(fdata), Acquire::NORETAIN); });
} }
else if (luax_istype(L, idx, love::image::CompressedImageData::type)) else if (luax_istype(L, idx, image::CompressedImageData::type))
cdata.set(love::image::luax_checkcompressedimagedata(L, idx)); cdata.set(image::luax_checkcompressedimagedata(L, idx));
else else
idata.set(love::image::luax_checkimagedata(L, idx)); idata.set(image::luax_checkimagedata(L, idx));
return std::make_pair(idata, cdata); return std::make_pair(idata, cdata);
} }
+3 -3
View File
@@ -22,7 +22,7 @@
// LOVE // LOVE
#include "common/Object.h" #include "common/Object.h"
#include "filesystem/FileData.h" #include "common/Data.h"
#include "CompressedSlice.h" #include "CompressedSlice.h"
namespace love namespace love
@@ -46,7 +46,7 @@ public:
* CompressedImageData by this handler. * CompressedImageData by this handler.
* @param data The data to parse. * @param data The data to parse.
**/ **/
virtual bool canParse(const filesystem::FileData *data) = 0; virtual bool canParse(const Data *data) = 0;
/** /**
* Parses compressed image filedata into a list of sub-images and returns * Parses compressed image filedata into a list of sub-images and returns
@@ -60,7 +60,7 @@ public:
* *
* @return The single block of memory containing the parsed images. * @return The single block of memory containing the parsed images.
**/ **/
virtual StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, virtual StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) = 0; PixelFormat &format, bool &sRGB) = 0;
+1 -1
View File
@@ -27,7 +27,7 @@ namespace image
love::Type CompressedImageData::type("CompressedImageData", &Data::type); love::Type CompressedImageData::type("CompressedImageData", &Data::type);
CompressedImageData::CompressedImageData(const std::list<CompressedFormatHandler *> &formats, love::filesystem::FileData *filedata) CompressedImageData::CompressedImageData(const std::list<CompressedFormatHandler *> &formats, Data *filedata)
: format(PIXELFORMAT_UNKNOWN) : format(PIXELFORMAT_UNKNOWN)
, sRGB(false) , sRGB(false)
{ {
+1 -2
View File
@@ -25,7 +25,6 @@
#include "common/StringMap.h" #include "common/StringMap.h"
#include "common/int.h" #include "common/int.h"
#include "common/pixelformat.h" #include "common/pixelformat.h"
#include "filesystem/FileData.h"
#include "CompressedSlice.h" #include "CompressedSlice.h"
#include "CompressedFormatHandler.h" #include "CompressedFormatHandler.h"
@@ -49,7 +48,7 @@ public:
static love::Type type; static love::Type type;
CompressedImageData(const std::list<CompressedFormatHandler *> &formats, love::filesystem::FileData *filedata); CompressedImageData(const std::list<CompressedFormatHandler *> &formats, Data *filedata);
CompressedImageData(const CompressedImageData &c); CompressedImageData(const CompressedImageData &c);
virtual ~CompressedImageData(); virtual ~CompressedImageData();
+2 -2
View File
@@ -35,7 +35,7 @@ FormatHandler::~FormatHandler()
{ {
} }
bool FormatHandler::canDecode(love::filesystem::FileData* /*data*/) bool FormatHandler::canDecode(Data* /*data*/)
{ {
return false; return false;
} }
@@ -45,7 +45,7 @@ bool FormatHandler::canEncode(PixelFormat /*rawFormat*/, EncodedFormat /*encoded
return false; return false;
} }
FormatHandler::DecodedImage FormatHandler::decode(love::filesystem::FileData* /*data*/) FormatHandler::DecodedImage FormatHandler::decode(Data* /*data*/)
{ {
throw love::Exception("Image decoding is not implemented for this format backend."); throw love::Exception("Image decoding is not implemented for this format backend.");
} }
+3 -3
View File
@@ -23,7 +23,7 @@
// LOVE // LOVE
#include "common/Object.h" #include "common/Object.h"
#include "common/pixelformat.h" #include "common/pixelformat.h"
#include "filesystem/FileData.h" #include "common/Data.h"
namespace love namespace love
{ {
@@ -75,7 +75,7 @@ public:
/** /**
* Whether this format handler can decode a particular FileData. * Whether this format handler can decode a particular FileData.
**/ **/
virtual bool canDecode(love::filesystem::FileData *data); virtual bool canDecode(Data *data);
/** /**
* Whether this format handler can encode to a particular format. * Whether this format handler can encode to a particular format.
@@ -87,7 +87,7 @@ public:
* @param data The encoded data to decode. * @param data The encoded data to decode.
* @return The decoded pixel data. * @return The decoded pixel data.
**/ **/
virtual DecodedImage decode(love::filesystem::FileData *data); virtual DecodedImage decode(Data *data);
/** /**
* Encodes an image from raw pixel data into a particular format. * Encodes an image from raw pixel data into a particular format.
+3 -3
View File
@@ -76,7 +76,7 @@ const char *Image::getName() const
return "love.image.magpie"; return "love.image.magpie";
} }
love::image::ImageData *Image::newImageData(love::filesystem::FileData *data) love::image::ImageData *Image::newImageData(Data *data)
{ {
return new ImageData(data); return new ImageData(data);
} }
@@ -91,12 +91,12 @@ love::image::ImageData *Image::newImageData(int width, int height, PixelFormat f
return new ImageData(width, height, format, data, own); return new ImageData(width, height, format, data, own);
} }
love::image::CompressedImageData *Image::newCompressedData(love::filesystem::FileData *data) love::image::CompressedImageData *Image::newCompressedData(Data *data)
{ {
return new CompressedImageData(compressedFormatHandlers, data); return new CompressedImageData(compressedFormatHandlers, data);
} }
bool Image::isCompressed(love::filesystem::FileData *data) bool Image::isCompressed(Data *data)
{ {
for (CompressedFormatHandler *handler : compressedFormatHandlers) for (CompressedFormatHandler *handler : compressedFormatHandlers)
{ {
+3 -3
View File
@@ -61,7 +61,7 @@ public:
* @param data The FileData containing the encoded image data. * @param data The FileData containing the encoded image data.
* @return The new ImageData. * @return The new ImageData.
**/ **/
ImageData *newImageData(love::filesystem::FileData *data); ImageData *newImageData(Data *data);
/** /**
* Creates empty ImageData with the given size. * Creates empty ImageData with the given size.
@@ -87,13 +87,13 @@ public:
* @param data The FileData containing the compressed image data. * @param data The FileData containing the compressed image data.
* @return The new CompressedImageData. * @return The new CompressedImageData.
**/ **/
CompressedImageData *newCompressedData(love::filesystem::FileData *data); CompressedImageData *newCompressedData(Data *data);
/** /**
* Determines whether a FileData is Compressed image data or not. * Determines whether a FileData is Compressed image data or not.
* @param data The FileData to test. * @param data The FileData to test.
**/ **/
bool isCompressed(love::filesystem::FileData *data); bool isCompressed(Data *data);
std::vector<StrongRef<ImageData>> newCubeFaces(ImageData *src); std::vector<StrongRef<ImageData>> newCubeFaces(ImageData *src);
std::vector<StrongRef<ImageData>> newVolumeLayers(ImageData *src); std::vector<StrongRef<ImageData>> newVolumeLayers(ImageData *src);
+11 -4
View File
@@ -31,7 +31,7 @@ namespace image
love::Type ImageData::type("ImageData", &Data::type); love::Type ImageData::type("ImageData", &Data::type);
ImageData::ImageData(love::filesystem::FileData *data) ImageData::ImageData(Data *data)
{ {
decode(data); decode(data);
} }
@@ -108,7 +108,7 @@ void ImageData::create(int width, int height, PixelFormat format, void *data)
this->format = format; this->format = format;
} }
void ImageData::decode(love::filesystem::FileData *data) void ImageData::decode(Data *data)
{ {
FormatHandler *decoder = nullptr; FormatHandler *decoder = nullptr;
FormatHandler::DecodedImage decodedimage; FormatHandler::DecodedImage decodedimage;
@@ -132,8 +132,15 @@ void ImageData::decode(love::filesystem::FileData *data)
if (decodedimage.data == nullptr) if (decodedimage.data == nullptr)
{ {
const std::string &name = data->getFilename(); auto filedata = dynamic_cast<filesystem::FileData *>(data);
throw love::Exception("Could not decode file '%s' to ImageData: unsupported file format", name.c_str());
if (filedata != nullptr)
{
const std::string &name = filedata->getFilename();
throw love::Exception("Could not decode file '%s' to ImageData: unsupported file format", name.c_str());
}
else
throw love::Exception("Could not decode data to ImageData: unsupported encoded format");
} }
if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format)) if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format))
+2 -2
View File
@@ -55,7 +55,7 @@ public:
static love::Type type; static love::Type type;
ImageData(love::filesystem::FileData *data); ImageData(Data *data);
ImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8); ImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8);
ImageData(int width, int height, PixelFormat format, void *data, bool own); ImageData(int width, int height, PixelFormat format, void *data, bool own);
ImageData(const ImageData &c); ImageData(const ImageData &c);
@@ -132,7 +132,7 @@ private:
void create(int width, int height, PixelFormat format, void *data = nullptr); void create(int width, int height, PixelFormat format, void *data = nullptr);
// Decode and load an encoded format. // Decode and load an encoded format.
void decode(love::filesystem::FileData *data); void decode(Data *data);
// The actual data. // The actual data.
unsigned char *data = nullptr; unsigned char *data = nullptr;
+3 -2
View File
@@ -21,6 +21,7 @@
// LOVE // LOVE
#include "ASTCHandler.h" #include "ASTCHandler.h"
#include "common/int.h" #include "common/int.h"
#include "common/Exception.h"
namespace love namespace love
{ {
@@ -86,7 +87,7 @@ static PixelFormat convertFormat(uint32 blockX, uint32 blockY, uint32 blockZ)
} // Anonymous namespace. } // Anonymous namespace.
bool ASTCHandler::canParse(const filesystem::FileData *data) bool ASTCHandler::canParse(const Data *data)
{ {
if (data->getSize() <= sizeof(ASTCHeader)) if (data->getSize() <= sizeof(ASTCHeader))
return false; return false;
@@ -104,7 +105,7 @@ bool ASTCHandler::canParse(const filesystem::FileData *data)
return true; return true;
} }
StrongRef<CompressedMemory> ASTCHandler::parse(filesystem::FileData *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB) StrongRef<CompressedMemory> ASTCHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
{ {
if (!canParse(filedata)) if (!canParse(filedata))
throw love::Exception("Could not decode compressed data (not an .astc file?)"); throw love::Exception("Could not decode compressed data (not an .astc file?)");
+2 -2
View File
@@ -41,9 +41,9 @@ public:
virtual ~ASTCHandler() {} virtual ~ASTCHandler() {}
// Implements CompressedFormatHandler. // Implements CompressedFormatHandler.
bool canParse(const filesystem::FileData *data) override; bool canParse(const Data *data) override;
StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) override; PixelFormat &format, bool &sRGB) override;
+3 -2
View File
@@ -21,6 +21,7 @@
// LOVE // LOVE
#include "EXRHandler.h" #include "EXRHandler.h"
#include "common/halffloat.h" #include "common/halffloat.h"
#include "common/Exception.h"
// tinyexr // tinyexr
#define TINYEXR_IMPLEMENTATION #define TINYEXR_IMPLEMENTATION
@@ -36,7 +37,7 @@ namespace image
namespace magpie namespace magpie
{ {
bool EXRHandler::canDecode(love::filesystem::FileData *data) bool EXRHandler::canDecode(Data *data)
{ {
EXRVersion version; EXRVersion version;
return ParseEXRVersionFromMemory(&version, (const unsigned char *) data->getData(), data->getSize()) == TINYEXR_SUCCESS; return ParseEXRVersionFromMemory(&version, (const unsigned char *) data->getData(), data->getSize()) == TINYEXR_SUCCESS;
@@ -100,7 +101,7 @@ static T *loadEXRChannels(int width, int height, T *rgba[4], T one)
return data; return data;
} }
FormatHandler::DecodedImage EXRHandler::decode(love::filesystem::FileData *data) FormatHandler::DecodedImage EXRHandler::decode(Data *data)
{ {
const char *err = "unknown error"; const char *err = "unknown error";
auto mem = (const unsigned char *) data->getData(); auto mem = (const unsigned char *) data->getData();
+2 -2
View File
@@ -38,10 +38,10 @@ public:
// Implements FormatHandler. // Implements FormatHandler.
virtual bool canDecode(love::filesystem::FileData *data); virtual bool canDecode(Data *data);
virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat);
virtual DecodedImage decode(love::filesystem::FileData *data); virtual DecodedImage decode(Data *data);
virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format);
virtual void free(unsigned char *mem); virtual void free(unsigned char *mem);
+3 -2
View File
@@ -21,6 +21,7 @@
// LOVE // LOVE
#include "KTXHandler.h" #include "KTXHandler.h"
#include "common/int.h" #include "common/int.h"
#include "common/Exception.h"
// C // C
#include <string.h> #include <string.h>
@@ -280,7 +281,7 @@ PixelFormat convertFormat(uint32 glformat, bool &sRGB)
} // Anonymous namespace. } // Anonymous namespace.
bool KTXHandler::canParse(const filesystem::FileData *data) bool KTXHandler::canParse(const Data *data)
{ {
if (data->getSize() < sizeof(KTXHeader)) if (data->getSize() < sizeof(KTXHeader))
return false; return false;
@@ -297,7 +298,7 @@ bool KTXHandler::canParse(const filesystem::FileData *data)
return true; return true;
} }
StrongRef<CompressedMemory> KTXHandler::parse(filesystem::FileData *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB) StrongRef<CompressedMemory> KTXHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
{ {
if (!canParse(filedata)) if (!canParse(filedata))
throw love::Exception("Could not decode compressed data (not a KTX file?)"); throw love::Exception("Could not decode compressed data (not a KTX file?)");
+2 -2
View File
@@ -40,9 +40,9 @@ public:
virtual ~KTXHandler() {} virtual ~KTXHandler() {}
// Implements CompressedFormatHandler. // Implements CompressedFormatHandler.
bool canParse(const filesystem::FileData *data) override; bool canParse(const Data *data) override;
StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) override; PixelFormat &format, bool &sRGB) override;
+3 -2
View File
@@ -21,6 +21,7 @@
// LOVE // LOVE
#include "PKMHandler.h" #include "PKMHandler.h"
#include "common/int.h" #include "common/int.h"
#include "common/Exception.h"
namespace love namespace love
{ {
@@ -96,7 +97,7 @@ static PixelFormat convertFormat(uint16 texformat)
} // Anonymous namespace. } // Anonymous namespace.
bool PKMHandler::canParse(const filesystem::FileData *data) bool PKMHandler::canParse(const Data *data)
{ {
if (data->getSize() <= sizeof(PKMHeader)) if (data->getSize() <= sizeof(PKMHeader))
return false; return false;
@@ -113,7 +114,7 @@ bool PKMHandler::canParse(const filesystem::FileData *data)
return true; return true;
} }
StrongRef<CompressedMemory> PKMHandler::parse(filesystem::FileData *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB) StrongRef<CompressedMemory> PKMHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
{ {
if (!canParse(filedata)) if (!canParse(filedata))
throw love::Exception("Could not decode compressed data (not a PKM file?)"); throw love::Exception("Could not decode compressed data (not a PKM file?)");
+2 -2
View File
@@ -40,9 +40,9 @@ public:
virtual ~PKMHandler() {} virtual ~PKMHandler() {}
// Implements CompressedFormatHandler. // Implements CompressedFormatHandler.
bool canParse(const filesystem::FileData *data) override; bool canParse(const Data *data) override;
StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) override; PixelFormat &format, bool &sRGB) override;
+2 -2
View File
@@ -128,7 +128,7 @@ static unsigned zlibCompress(unsigned char **out, size_t *outsize, const unsigne
return 0; // Success. return 0; // Success.
} }
bool PNGHandler::canDecode(love::filesystem::FileData *data) bool PNGHandler::canDecode(Data *data)
{ {
unsigned int width = 0, height = 0; unsigned int width = 0, height = 0;
unsigned char *indata = (unsigned char *) data->getData(); unsigned char *indata = (unsigned char *) data->getData();
@@ -146,7 +146,7 @@ bool PNGHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
&& (rawFormat == PIXELFORMAT_RGBA8 || rawFormat == PIXELFORMAT_RGBA16); && (rawFormat == PIXELFORMAT_RGBA8 || rawFormat == PIXELFORMAT_RGBA16);
} }
PNGHandler::DecodedImage PNGHandler::decode(love::filesystem::FileData *fdata) PNGHandler::DecodedImage PNGHandler::decode(Data *fdata)
{ {
unsigned int width = 0, height = 0; unsigned int width = 0, height = 0;
unsigned char *indata = (unsigned char *) fdata->getData(); unsigned char *indata = (unsigned char *) fdata->getData();
+2 -2
View File
@@ -39,10 +39,10 @@ public:
// Implements FormatHandler. // Implements FormatHandler.
virtual bool canDecode(love::filesystem::FileData *data); virtual bool canDecode(Data *data);
virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat);
virtual DecodedImage decode(love::filesystem::FileData *data); virtual DecodedImage decode(Data *data);
virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format);
virtual void free(unsigned char *mem); virtual void free(unsigned char *mem);
+3 -2
View File
@@ -21,6 +21,7 @@
// LOVE // LOVE
#include "PVRHandler.h" #include "PVRHandler.h"
#include "common/int.h" #include "common/int.h"
#include "common/Exception.h"
// C++ // C++
#include <algorithm> #include <algorithm>
@@ -453,7 +454,7 @@ size_t getMipLevelSize(const PVRTexHeaderV3 &header, int miplevel)
} // Anonymous namespace. } // Anonymous namespace.
bool PVRHandler::canParse(const filesystem::FileData *data) bool PVRHandler::canParse(const Data *data)
{ {
if (data->getSize() < sizeof(PVRTexHeaderV2) || data->getSize() < sizeof(PVRTexHeaderV3)) if (data->getSize() < sizeof(PVRTexHeaderV2) || data->getSize() < sizeof(PVRTexHeaderV3))
return false; return false;
@@ -474,7 +475,7 @@ bool PVRHandler::canParse(const filesystem::FileData *data)
return false; return false;
} }
StrongRef<CompressedMemory> PVRHandler::parse(filesystem::FileData *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB) StrongRef<CompressedMemory> PVRHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
{ {
if (!canParse(filedata)) if (!canParse(filedata))
throw love::Exception("Could not decode compressed data (not a PVR file?)"); throw love::Exception("Could not decode compressed data (not a PVR file?)");
+2 -2
View File
@@ -38,9 +38,9 @@ public:
virtual ~PVRHandler() {} virtual ~PVRHandler() {}
// Implements CompressedFormatHandler. // Implements CompressedFormatHandler.
bool canParse(const filesystem::FileData *data) override; bool canParse(const Data *data) override;
StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) override; PixelFormat &format, bool &sRGB) override;
+3 -3
View File
@@ -20,7 +20,7 @@
// LOVE // LOVE
#include "STBHandler.h" #include "STBHandler.h"
#include "image/ImageData.h" #include "common/Exception.h"
#include "common/Color.h" #include "common/Color.h"
static void loveSTBIAssert(bool test, const char *teststr) static void loveSTBIAssert(bool test, const char *teststr)
@@ -52,7 +52,7 @@ namespace magpie
static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!"); static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!");
bool STBHandler::canDecode(love::filesystem::FileData *data) bool STBHandler::canDecode(Data *data)
{ {
int w = 0; int w = 0;
int h = 0; int h = 0;
@@ -69,7 +69,7 @@ bool STBHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
return encodedFormat == ENCODED_TGA && rawFormat == PIXELFORMAT_RGBA8; return encodedFormat == ENCODED_TGA && rawFormat == PIXELFORMAT_RGBA8;
} }
FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data) FormatHandler::DecodedImage STBHandler::decode(Data *data)
{ {
DecodedImage img; DecodedImage img;
+2 -2
View File
@@ -42,10 +42,10 @@ public:
// Implements FormatHandler. // Implements FormatHandler.
bool canDecode(love::filesystem::FileData *data) override; bool canDecode(Data *data) override;
bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat) override; bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat) override;
DecodedImage decode(love::filesystem::FileData *data) override; DecodedImage decode(Data *data) override;
EncodedImage encode(const DecodedImage &img, EncodedFormat format) override; EncodedImage encode(const DecodedImage &img, EncodedFormat format) override;
void free(unsigned char *mem) override; void free(unsigned char *mem) override;
+3 -2
View File
@@ -19,6 +19,7 @@
**/ **/
#include "ddsHandler.h" #include "ddsHandler.h"
#include "common/Exception.h"
namespace love namespace love
{ {
@@ -27,12 +28,12 @@ namespace image
namespace magpie namespace magpie
{ {
bool DDSHandler::canParse(const filesystem::FileData *data) bool DDSHandler::canParse(const Data *data)
{ {
return dds::isCompressedDDS(data->getData(), data->getSize()); return dds::isCompressedDDS(data->getData(), data->getSize());
} }
StrongRef<CompressedMemory> DDSHandler::parse(filesystem::FileData *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB) StrongRef<CompressedMemory> DDSHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
{ {
if (!dds::isDDS(filedata->getData(), filedata->getSize())) if (!dds::isDDS(filedata->getData(), filedata->getSize()))
throw love::Exception("Could not decode compressed data (not a DDS file?)"); throw love::Exception("Could not decode compressed data (not a DDS file?)");
+2 -2
View File
@@ -46,9 +46,9 @@ public:
virtual ~DDSHandler() {} virtual ~DDSHandler() {}
// Implements CompressedFormatHandler. // Implements CompressedFormatHandler.
bool canParse(const filesystem::FileData *data) override; bool canParse(const Data *data) override;
StrongRef<CompressedMemory> parse(filesystem::FileData *filedata, StrongRef<CompressedMemory> parse(Data *filedata,
std::vector<StrongRef<CompressedSlice>> &images, std::vector<StrongRef<CompressedSlice>> &images,
PixelFormat &format, bool &sRGB) override; PixelFormat &format, bool &sRGB) override;
+5 -5
View File
@@ -19,7 +19,7 @@
**/ **/
#include "wrap_Image.h" #include "wrap_Image.h"
#include "common/wrap_Data.h"
#include "common/Data.h" #include "common/Data.h"
#include "common/StringMap.h" #include "common/StringMap.h"
@@ -77,9 +77,9 @@ int w_newImageData(lua_State *L)
t->release(); t->release();
return 1; return 1;
} }
else if (filesystem::luax_cangetfiledata(L, 1)) // Case 2: File(Data). else if (filesystem::luax_cangetfiledata(L, 1) || luax_istype(L, 1, Data::type)) // Case 2: File(Data).
{ {
filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1); Data *data = love::filesystem::luax_getdata(L, 1);
ImageData *t = nullptr; ImageData *t = nullptr;
luax_catchexcept(L, luax_catchexcept(L,
@@ -99,7 +99,7 @@ int w_newImageData(lua_State *L)
int w_newCompressedData(lua_State *L) int w_newCompressedData(lua_State *L)
{ {
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1); Data *data = love::filesystem::luax_getdata(L, 1);
CompressedImageData *t = nullptr; CompressedImageData *t = nullptr;
luax_catchexcept(L, luax_catchexcept(L,
@@ -114,7 +114,7 @@ int w_newCompressedData(lua_State *L)
int w_isCompressed(lua_State *L) int w_isCompressed(lua_State *L)
{ {
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1); Data *data = love::filesystem::luax_getdata(L, 1);
bool compressed = instance()->isCompressed(data); bool compressed = instance()->isCompressed(data);
data->release(); data->release();