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
+3 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;