Browse Source

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

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
2dd6408d00

+ 39 - 0
src/modules/filesystem/wrap_Filesystem.cpp

@@ -23,6 +23,7 @@
 #include "wrap_File.h"
 #include "wrap_DroppedFile.h"
 #include "wrap_FileData.h"
+#include "common/wrap_Data.h"
 
 #include "physfs/Filesystem.h"
 
@@ -218,11 +219,49 @@ FileData *luax_getfiledata(lua_State *L, int idx)
 	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)
 {
 	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)
 {
 	// Single argument: treat as filepath or File.

+ 3 - 0
src/modules/filesystem/wrap_Filesystem.h

@@ -42,6 +42,9 @@ FileData *luax_getfiledata(lua_State *L, int idx);
 bool luax_cangetfiledata(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();
 int loader(lua_State *L);
 int extloader(lua_State *L);

+ 15 - 11
src/modules/graphics/wrap_Graphics.cpp

@@ -631,10 +631,14 @@ int w_getStencilTest(lua_State *L)
 	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 "[email protected]".
-	const std::string &fname = d->getName();
+	const std::string &fname = fd->getName();
 
 	size_t namelen = fname.length();
 	size_t atpos = fname.rfind('@');
@@ -664,20 +668,20 @@ static Image::Settings w__optImageSettings(lua_State *L, int idx, const Image::S
 	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)
 {
-	StrongRef<love::image::ImageData> idata;
-	StrongRef<love::image::CompressedImageData> cdata;
+	StrongRef<image::ImageData> idata;
+	StrongRef<image::CompressedImageData> cdata;
 
 	// 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)
 			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)
 			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); });
 
 	}
-	else if (luax_istype(L, idx, love::image::CompressedImageData::type))
-		cdata.set(love::image::luax_checkcompressedimagedata(L, idx));
+	else if (luax_istype(L, idx, image::CompressedImageData::type))
+		cdata.set(image::luax_checkcompressedimagedata(L, idx));
 	else
-		idata.set(love::image::luax_checkimagedata(L, idx));
+		idata.set(image::luax_checkimagedata(L, idx));
 
 	return std::make_pair(idata, cdata);
 }

+ 3 - 3
src/modules/image/CompressedFormatHandler.h

@@ -22,7 +22,7 @@
 
 // LOVE
 #include "common/Object.h"
-#include "filesystem/FileData.h"
+#include "common/Data.h"
 #include "CompressedSlice.h"
 
 namespace love
@@ -46,7 +46,7 @@ public:
 	 * CompressedImageData by this handler.
 	 * @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
@@ -60,7 +60,7 @@ public:
 	 *
 	 * @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,
 	               PixelFormat &format, bool &sRGB) = 0;
 

+ 1 - 1
src/modules/image/CompressedImageData.cpp

@@ -27,7 +27,7 @@ namespace image
 
 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)
 	, sRGB(false)
 {

+ 1 - 2
src/modules/image/CompressedImageData.h

@@ -25,7 +25,6 @@
 #include "common/StringMap.h"
 #include "common/int.h"
 #include "common/pixelformat.h"
-#include "filesystem/FileData.h"
 #include "CompressedSlice.h"
 #include "CompressedFormatHandler.h"
 
@@ -49,7 +48,7 @@ public:
 
 	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);
 	virtual ~CompressedImageData();
 

+ 2 - 2
src/modules/image/FormatHandler.cpp

@@ -35,7 +35,7 @@ FormatHandler::~FormatHandler()
 {
 }
 
-bool FormatHandler::canDecode(love::filesystem::FileData* /*data*/)
+bool FormatHandler::canDecode(Data* /*data*/)
 {
 	return false;
 }
@@ -45,7 +45,7 @@ bool FormatHandler::canEncode(PixelFormat /*rawFormat*/, EncodedFormat /*encoded
 	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.");
 }

+ 3 - 3
src/modules/image/FormatHandler.h

@@ -23,7 +23,7 @@
 // LOVE
 #include "common/Object.h"
 #include "common/pixelformat.h"
-#include "filesystem/FileData.h"
+#include "common/Data.h"
 
 namespace love
 {
@@ -75,7 +75,7 @@ public:
 	/**
 	 * 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.
@@ -87,7 +87,7 @@ public:
 	 * @param data The encoded data to decode.
 	 * @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.

+ 3 - 3
src/modules/image/Image.cpp

@@ -76,7 +76,7 @@ const char *Image::getName() const
 	return "love.image.magpie";
 }
 
-love::image::ImageData *Image::newImageData(love::filesystem::FileData *data)
+love::image::ImageData *Image::newImageData(Data *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);
 }
 
-love::image::CompressedImageData *Image::newCompressedData(love::filesystem::FileData *data)
+love::image::CompressedImageData *Image::newCompressedData(Data *data)
 {
 	return new CompressedImageData(compressedFormatHandlers, data);
 }
 
-bool Image::isCompressed(love::filesystem::FileData *data)
+bool Image::isCompressed(Data *data)
 {
 	for (CompressedFormatHandler *handler : compressedFormatHandlers)
 	{

+ 3 - 3
src/modules/image/Image.h

@@ -61,7 +61,7 @@ public:
 	 * @param data The FileData containing the encoded image data.
 	 * @return The new ImageData.
 	 **/
-	ImageData *newImageData(love::filesystem::FileData *data);
+	ImageData *newImageData(Data *data);
 
 	/**
 	 * Creates empty ImageData with the given size.
@@ -87,13 +87,13 @@ public:
 	 * @param data The FileData containing the compressed image data.
 	 * @return The new CompressedImageData.
 	 **/
-	CompressedImageData *newCompressedData(love::filesystem::FileData *data);
+	CompressedImageData *newCompressedData(Data *data);
 
 	/**
 	 * Determines whether a FileData is Compressed image data or not.
 	 * @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>> newVolumeLayers(ImageData *src);

+ 11 - 4
src/modules/image/ImageData.cpp

@@ -31,7 +31,7 @@ namespace image
 
 love::Type ImageData::type("ImageData", &Data::type);
 
-ImageData::ImageData(love::filesystem::FileData *data)
+ImageData::ImageData(Data *data)
 {
 	decode(data);
 }
@@ -108,7 +108,7 @@ void ImageData::create(int width, int height, PixelFormat format, void *data)
 	this->format = format;
 }
 
-void ImageData::decode(love::filesystem::FileData *data)
+void ImageData::decode(Data *data)
 {
 	FormatHandler *decoder = nullptr;
 	FormatHandler::DecodedImage decodedimage;
@@ -132,8 +132,15 @@ void ImageData::decode(love::filesystem::FileData *data)
 
 	if (decodedimage.data == nullptr)
 	{
-		const std::string &name = data->getFilename();
-		throw love::Exception("Could not decode file '%s' to ImageData: unsupported file format", name.c_str());
+		auto filedata = dynamic_cast<filesystem::FileData *>(data);
+
+		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))

+ 2 - 2
src/modules/image/ImageData.h

@@ -55,7 +55,7 @@ public:
 
 	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, void *data, bool own);
 	ImageData(const ImageData &c);
@@ -132,7 +132,7 @@ private:
 	void create(int width, int height, PixelFormat format, void *data = nullptr);
 
 	// Decode and load an encoded format.
-	void decode(love::filesystem::FileData *data);
+	void decode(Data *data);
 
 	// The actual data.
 	unsigned char *data = nullptr;

+ 3 - 2
src/modules/image/magpie/ASTCHandler.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "ASTCHandler.h"
 #include "common/int.h"
+#include "common/Exception.h"
 
 namespace love
 {
@@ -86,7 +87,7 @@ static PixelFormat convertFormat(uint32 blockX, uint32 blockY, uint32 blockZ)
 
 } // Anonymous namespace.
 
-bool ASTCHandler::canParse(const filesystem::FileData *data)
+bool ASTCHandler::canParse(const Data *data)
 {
 	if (data->getSize() <= sizeof(ASTCHeader))
 		return false;
@@ -104,7 +105,7 @@ bool ASTCHandler::canParse(const filesystem::FileData *data)
 	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))
 		throw love::Exception("Could not decode compressed data (not an .astc file?)");

+ 2 - 2
src/modules/image/magpie/ASTCHandler.h

@@ -41,9 +41,9 @@ public:
 	virtual ~ASTCHandler() {}
 
 	// 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,
 	        PixelFormat &format, bool &sRGB) override;
 

+ 3 - 2
src/modules/image/magpie/EXRHandler.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "EXRHandler.h"
 #include "common/halffloat.h"
+#include "common/Exception.h"
 
 // tinyexr
 #define TINYEXR_IMPLEMENTATION
@@ -36,7 +37,7 @@ namespace image
 namespace magpie
 {
 
-bool EXRHandler::canDecode(love::filesystem::FileData *data)
+bool EXRHandler::canDecode(Data *data)
 {
 	EXRVersion version;
 	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;
 }
 
-FormatHandler::DecodedImage EXRHandler::decode(love::filesystem::FileData *data)
+FormatHandler::DecodedImage EXRHandler::decode(Data *data)
 {
 	const char *err = "unknown error";
 	auto mem = (const unsigned char *) data->getData();

+ 2 - 2
src/modules/image/magpie/EXRHandler.h

@@ -38,10 +38,10 @@ public:
 
 	// Implements FormatHandler.
 
-	virtual bool canDecode(love::filesystem::FileData *data);
+	virtual bool canDecode(Data *data);
 	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 void free(unsigned char *mem);

+ 3 - 2
src/modules/image/magpie/KTXHandler.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "KTXHandler.h"
 #include "common/int.h"
+#include "common/Exception.h"
 
 // C
 #include <string.h>
@@ -280,7 +281,7 @@ PixelFormat convertFormat(uint32 glformat, bool &sRGB)
 
 } // Anonymous namespace.
 
-bool KTXHandler::canParse(const filesystem::FileData *data)
+bool KTXHandler::canParse(const Data *data)
 {
 	if (data->getSize() < sizeof(KTXHeader))
 		return false;
@@ -297,7 +298,7 @@ bool KTXHandler::canParse(const filesystem::FileData *data)
 	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))
 		throw love::Exception("Could not decode compressed data (not a KTX file?)");

+ 2 - 2
src/modules/image/magpie/KTXHandler.h

@@ -40,9 +40,9 @@ public:
 	virtual ~KTXHandler() {}
 
 	// 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,
 	        PixelFormat &format, bool &sRGB) override;
 

+ 3 - 2
src/modules/image/magpie/PKMHandler.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "PKMHandler.h"
 #include "common/int.h"
+#include "common/Exception.h"
 
 namespace love
 {
@@ -96,7 +97,7 @@ static PixelFormat convertFormat(uint16 texformat)
 
 } // Anonymous namespace.
 
-bool PKMHandler::canParse(const filesystem::FileData *data)
+bool PKMHandler::canParse(const Data *data)
 {
 	if (data->getSize() <= sizeof(PKMHeader))
 		return false;
@@ -113,7 +114,7 @@ bool PKMHandler::canParse(const filesystem::FileData *data)
 	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))
 		throw love::Exception("Could not decode compressed data (not a PKM file?)");

+ 2 - 2
src/modules/image/magpie/PKMHandler.h

@@ -40,9 +40,9 @@ public:
 	virtual ~PKMHandler() {}
 
 	// 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,
 	        PixelFormat &format, bool &sRGB) override;
 

+ 2 - 2
src/modules/image/magpie/PNGHandler.cpp

@@ -128,7 +128,7 @@ static unsigned zlibCompress(unsigned char **out, size_t *outsize, const unsigne
 	return 0; // Success.
 }
 
-bool PNGHandler::canDecode(love::filesystem::FileData *data)
+bool PNGHandler::canDecode(Data *data)
 {
 	unsigned int width = 0, height = 0;
 	unsigned char *indata = (unsigned char *) data->getData();
@@ -146,7 +146,7 @@ bool PNGHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
 		&& (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 char *indata = (unsigned char *) fdata->getData();

+ 2 - 2
src/modules/image/magpie/PNGHandler.h

@@ -39,10 +39,10 @@ public:
 
 	// Implements FormatHandler.
 
-	virtual bool canDecode(love::filesystem::FileData *data);
+	virtual bool canDecode(Data *data);
 	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 void free(unsigned char *mem);

+ 3 - 2
src/modules/image/magpie/PVRHandler.cpp

@@ -21,6 +21,7 @@
 // LOVE
 #include "PVRHandler.h"
 #include "common/int.h"
+#include "common/Exception.h"
 
 // C++
 #include <algorithm>
@@ -453,7 +454,7 @@ size_t getMipLevelSize(const PVRTexHeaderV3 &header, int miplevel)
 } // Anonymous namespace.
 
 
-bool PVRHandler::canParse(const filesystem::FileData *data)
+bool PVRHandler::canParse(const Data *data)
 {
 	if (data->getSize() < sizeof(PVRTexHeaderV2) || data->getSize() < sizeof(PVRTexHeaderV3))
 		return false;
@@ -474,7 +475,7 @@ bool PVRHandler::canParse(const filesystem::FileData *data)
 	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))
 		throw love::Exception("Could not decode compressed data (not a PVR file?)");

+ 2 - 2
src/modules/image/magpie/PVRHandler.h

@@ -38,9 +38,9 @@ public:
 	virtual ~PVRHandler() {}
 
 	// 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,
 	        PixelFormat &format, bool &sRGB) override;
 

+ 3 - 3
src/modules/image/magpie/STBHandler.cpp

@@ -20,7 +20,7 @@
 
 // LOVE
 #include "STBHandler.h"
-#include "image/ImageData.h"
+#include "common/Exception.h"
 #include "common/Color.h"
 
 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!");
 
-bool STBHandler::canDecode(love::filesystem::FileData *data)
+bool STBHandler::canDecode(Data *data)
 {
 	int w = 0;
 	int h = 0;
@@ -69,7 +69,7 @@ bool STBHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
 	return encodedFormat == ENCODED_TGA && rawFormat == PIXELFORMAT_RGBA8;
 }
 
-FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data)
+FormatHandler::DecodedImage STBHandler::decode(Data *data)
 {
 	DecodedImage img;
 

+ 2 - 2
src/modules/image/magpie/STBHandler.h

@@ -42,10 +42,10 @@ public:
 
 	// Implements FormatHandler.
 
-	bool canDecode(love::filesystem::FileData *data) override;
+	bool canDecode(Data *data) 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;
 
 	void free(unsigned char *mem) override;

+ 3 - 2
src/modules/image/magpie/ddsHandler.cpp

@@ -19,6 +19,7 @@
  **/
 
 #include "ddsHandler.h"
+#include "common/Exception.h"
 
 namespace love
 {
@@ -27,12 +28,12 @@ namespace image
 namespace magpie
 {
 
-bool DDSHandler::canParse(const filesystem::FileData *data)
+bool DDSHandler::canParse(const Data *data)
 {
 	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()))
 		throw love::Exception("Could not decode compressed data (not a DDS file?)");

+ 2 - 2
src/modules/image/magpie/ddsHandler.h

@@ -46,9 +46,9 @@ public:
 	virtual ~DDSHandler() {}
 
 	// 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,
 	        PixelFormat &format, bool &sRGB) override;
 

+ 5 - 5
src/modules/image/wrap_Image.cpp

@@ -19,7 +19,7 @@
  **/
 
 #include "wrap_Image.h"
-
+#include "common/wrap_Data.h"
 #include "common/Data.h"
 #include "common/StringMap.h"
 
@@ -77,9 +77,9 @@ int w_newImageData(lua_State *L)
 		t->release();
 		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;
 		luax_catchexcept(L,
@@ -99,7 +99,7 @@ int w_newImageData(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;
 	luax_catchexcept(L,
@@ -114,7 +114,7 @@ int w_newCompressedData(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);
 	data->release();