mirror of
https://github.com/love2d/love.git
synced 2026-08-17 02:58:31 +02:00
Simplified some compressed image parsing code.
--HG-- branch : minor
This commit is contained in:
@@ -87,7 +87,7 @@ static PixelFormat convertFormat(uint32 blockX, uint32 blockY, uint32 blockZ)
|
||||
|
||||
} // Anonymous namespace.
|
||||
|
||||
bool ASTCHandler::canParse(const Data *data)
|
||||
bool ASTCHandler::canParseCompressed(Data *data)
|
||||
{
|
||||
if (data->getSize() <= sizeof(ASTCHeader))
|
||||
return false;
|
||||
@@ -105,9 +105,9 @@ bool ASTCHandler::canParse(const Data *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
StrongRef<CompressedMemory> ASTCHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
StrongRef<CompressedMemory> ASTCHandler::parseCompressed(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
{
|
||||
if (!canParse(filedata))
|
||||
if (!canParseCompressed(filedata))
|
||||
throw love::Exception("Could not decode compressed data (not an .astc file?)");
|
||||
|
||||
ASTCHeader header = *(const ASTCHeader *) filedata->getData();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/config.h"
|
||||
#include "image/CompressedFormatHandler.h"
|
||||
#include "image/FormatHandler.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -34,16 +34,16 @@ namespace magpie
|
||||
* Handles simple .astc files (generated by ARM's astcenc tool) with compressed
|
||||
* ASTC data inside.
|
||||
**/
|
||||
class ASTCHandler : public CompressedFormatHandler
|
||||
class ASTCHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~ASTCHandler() {}
|
||||
|
||||
// Implements CompressedFormatHandler.
|
||||
bool canParse(const Data *data) override;
|
||||
// Implements FormatHandler.
|
||||
bool canParseCompressed(Data *data) override;
|
||||
|
||||
StrongRef<CompressedMemory> parse(Data *filedata,
|
||||
StrongRef<CompressedMemory> parseCompressed(Data *filedata,
|
||||
std::vector<StrongRef<CompressedSlice>> &images,
|
||||
PixelFormat &format, bool &sRGB) override;
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ FormatHandler::EncodedImage EXRHandler::encode(const DecodedImage & /*img*/, Enc
|
||||
throw love::Exception("Invalid format.");
|
||||
}
|
||||
|
||||
void EXRHandler::free(unsigned char *mem)
|
||||
void EXRHandler::freeRawPixels(unsigned char *mem)
|
||||
{
|
||||
delete[] mem;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
virtual DecodedImage decode(Data *data);
|
||||
virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format);
|
||||
|
||||
virtual void free(unsigned char *mem);
|
||||
virtual void freeRawPixels(unsigned char *mem);
|
||||
|
||||
}; // EXRHandler
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ PixelFormat convertFormat(uint32 glformat, bool &sRGB)
|
||||
|
||||
} // Anonymous namespace.
|
||||
|
||||
bool KTXHandler::canParse(const Data *data)
|
||||
bool KTXHandler::canParseCompressed(Data *data)
|
||||
{
|
||||
if (data->getSize() < sizeof(KTXHeader))
|
||||
return false;
|
||||
@@ -298,9 +298,9 @@ bool KTXHandler::canParse(const Data *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
StrongRef<CompressedMemory> KTXHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
StrongRef<CompressedMemory> KTXHandler::parseCompressed(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
{
|
||||
if (!canParse(filedata))
|
||||
if (!canParseCompressed(filedata))
|
||||
throw love::Exception("Could not decode compressed data (not a KTX file?)");
|
||||
|
||||
KTXHeader header = *(KTXHeader *) filedata->getData();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/config.h"
|
||||
#include "image/CompressedFormatHandler.h"
|
||||
#include "image/FormatHandler.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -33,16 +33,16 @@ namespace magpie
|
||||
/**
|
||||
* Handles KTX files with compressed image data inside.
|
||||
**/
|
||||
class KTXHandler : public CompressedFormatHandler
|
||||
class KTXHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~KTXHandler() {}
|
||||
|
||||
// Implements CompressedFormatHandler.
|
||||
bool canParse(const Data *data) override;
|
||||
// Implements FormatHandler.
|
||||
bool canParseCompressed(Data *data) override;
|
||||
|
||||
StrongRef<CompressedMemory> parse(Data *filedata,
|
||||
StrongRef<CompressedMemory> parseCompressed(Data *filedata,
|
||||
std::vector<StrongRef<CompressedSlice>> &images,
|
||||
PixelFormat &format, bool &sRGB) override;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ static PixelFormat convertFormat(uint16 texformat)
|
||||
|
||||
} // Anonymous namespace.
|
||||
|
||||
bool PKMHandler::canParse(const Data *data)
|
||||
bool PKMHandler::canParseCompressed(Data *data)
|
||||
{
|
||||
if (data->getSize() <= sizeof(PKMHeader))
|
||||
return false;
|
||||
@@ -114,9 +114,9 @@ bool PKMHandler::canParse(const Data *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
StrongRef<CompressedMemory> PKMHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
StrongRef<CompressedMemory> PKMHandler::parseCompressed(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
{
|
||||
if (!canParse(filedata))
|
||||
if (!canParseCompressed(filedata))
|
||||
throw love::Exception("Could not decode compressed data (not a PKM file?)");
|
||||
|
||||
PKMHeader header = *(const PKMHeader *) filedata->getData();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/config.h"
|
||||
#include "image/CompressedFormatHandler.h"
|
||||
#include "image/FormatHandler.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -33,16 +33,16 @@ namespace magpie
|
||||
/**
|
||||
* Handles PKM files with compressed ETC data inside.
|
||||
**/
|
||||
class PKMHandler : public CompressedFormatHandler
|
||||
class PKMHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~PKMHandler() {}
|
||||
|
||||
// Implements CompressedFormatHandler.
|
||||
bool canParse(const Data *data) override;
|
||||
// Implements FormatHandler.
|
||||
bool canParseCompressed(Data *data) override;
|
||||
|
||||
StrongRef<CompressedMemory> parse(Data *filedata,
|
||||
StrongRef<CompressedMemory> parseCompressed(Data *filedata,
|
||||
std::vector<StrongRef<CompressedSlice>> &images,
|
||||
PixelFormat &format, bool &sRGB) override;
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ FormatHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, EncodedF
|
||||
return encimg;
|
||||
}
|
||||
|
||||
void PNGHandler::free(unsigned char *mem)
|
||||
void PNGHandler::freeRawPixels(unsigned char *mem)
|
||||
{
|
||||
// LodePNG uses malloc, realloc, and free.
|
||||
if (mem)
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
virtual DecodedImage decode(Data *data);
|
||||
virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format);
|
||||
|
||||
virtual void free(unsigned char *mem);
|
||||
virtual void freeRawPixels(unsigned char *mem);
|
||||
|
||||
}; // PNGHandler
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ size_t getMipLevelSize(const PVRTexHeaderV3 &header, int miplevel)
|
||||
} // Anonymous namespace.
|
||||
|
||||
|
||||
bool PVRHandler::canParse(const Data *data)
|
||||
bool PVRHandler::canParseCompressed(Data *data)
|
||||
{
|
||||
if (data->getSize() < sizeof(PVRTexHeaderV2) || data->getSize() < sizeof(PVRTexHeaderV3))
|
||||
return false;
|
||||
@@ -475,9 +475,9 @@ bool PVRHandler::canParse(const Data *data)
|
||||
return false;
|
||||
}
|
||||
|
||||
StrongRef<CompressedMemory> PVRHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
StrongRef<CompressedMemory> PVRHandler::parseCompressed(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
{
|
||||
if (!canParse(filedata))
|
||||
if (!canParseCompressed(filedata))
|
||||
throw love::Exception("Could not decode compressed data (not a PVR file?)");
|
||||
|
||||
PVRTexHeaderV3 header3 = *(PVRTexHeaderV3 *) filedata->getData();
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "image/CompressedFormatHandler.h"
|
||||
#include "image/FormatHandler.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -31,16 +31,16 @@ namespace image
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
class PVRHandler : public CompressedFormatHandler
|
||||
class PVRHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~PVRHandler() {}
|
||||
|
||||
// Implements CompressedFormatHandler.
|
||||
bool canParse(const Data *data) override;
|
||||
// Implements FormatHandler.
|
||||
bool canParseCompressed(Data *data) override;
|
||||
|
||||
StrongRef<CompressedMemory> parse(Data *filedata,
|
||||
StrongRef<CompressedMemory> parseCompressed(Data *filedata,
|
||||
std::vector<StrongRef<CompressedSlice>> &images,
|
||||
PixelFormat &format, bool &sRGB) override;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, EncodedF
|
||||
return encimg;
|
||||
}
|
||||
|
||||
void STBHandler::free(unsigned char *mem)
|
||||
void STBHandler::freeRawPixels(unsigned char *mem)
|
||||
{
|
||||
// The STB decoder gave memory allocated directly by stb_image to the
|
||||
// ImageData, so we use stb_image_free to delete it.
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
DecodedImage decode(Data *data) override;
|
||||
EncodedImage encode(const DecodedImage &img, EncodedFormat format) override;
|
||||
|
||||
void free(unsigned char *mem) override;
|
||||
void freeRawPixels(unsigned char *mem) override;
|
||||
|
||||
}; // STBHandler
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace image
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
bool DDSHandler::canParse(const Data *data)
|
||||
bool DDSHandler::canParseCompressed(Data *data)
|
||||
{
|
||||
return dds::isCompressedDDS(data->getData(), data->getSize());
|
||||
}
|
||||
|
||||
StrongRef<CompressedMemory> DDSHandler::parse(Data *filedata, std::vector<StrongRef<CompressedSlice>> &images, PixelFormat &format, bool &sRGB)
|
||||
StrongRef<CompressedMemory> DDSHandler::parseCompressed(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?)");
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
// LOVE
|
||||
#include "image/CompressedFormatHandler.h"
|
||||
#include "image/FormatHandler.h"
|
||||
|
||||
// dds parser
|
||||
#include "ddsparse/ddsparse.h"
|
||||
@@ -39,16 +39,16 @@ namespace magpie
|
||||
/**
|
||||
* Interface between CompressedImageData and the ddsparse library.
|
||||
**/
|
||||
class DDSHandler : public CompressedFormatHandler
|
||||
class DDSHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~DDSHandler() {}
|
||||
|
||||
// Implements CompressedFormatHandler.
|
||||
bool canParse(const Data *data) override;
|
||||
// Implements FormatHandler.
|
||||
bool canParseCompressed(Data *data) override;
|
||||
|
||||
StrongRef<CompressedMemory> parse(Data *filedata,
|
||||
StrongRef<CompressedMemory> parseCompressed(Data *filedata,
|
||||
std::vector<StrongRef<CompressedSlice>> &images,
|
||||
PixelFormat &format, bool &sRGB) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user