mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Fixed detection of PNG images.
--HG-- branch : minor
This commit is contained in:
@@ -128,10 +128,14 @@ static unsigned zlibCompress(unsigned char **out, size_t *outsize, const unsigne
|
|||||||
|
|
||||||
bool PNGHandler::canDecode(love::filesystem::FileData *data)
|
bool PNGHandler::canDecode(love::filesystem::FileData *data)
|
||||||
{
|
{
|
||||||
std::string ext = data->getExtension();
|
unsigned int width = 0, height = 0;
|
||||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
unsigned char *indata = (unsigned char *) data->getData();
|
||||||
|
size_t insize = data->getSize();
|
||||||
|
|
||||||
return ext.compare("png") == 0;
|
lodepng::State state;
|
||||||
|
unsigned status = lodepng_inspect(&width, &height, &state, indata, insize);
|
||||||
|
|
||||||
|
return status == 0 && width > 0 && height > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PNGHandler::canEncode(ImageData::Format format)
|
bool PNGHandler::canEncode(ImageData::Format format)
|
||||||
@@ -147,8 +151,7 @@ PNGHandler::DecodedImage PNGHandler::decode(love::filesystem::FileData *fdata)
|
|||||||
|
|
||||||
DecodedImage img;
|
DecodedImage img;
|
||||||
|
|
||||||
LodePNGState state;
|
lodepng::State state;
|
||||||
lodepng_state_init(&state);
|
|
||||||
|
|
||||||
state.info_raw.colortype = LCT_RGBA;
|
state.info_raw.colortype = LCT_RGBA;
|
||||||
state.info_raw.bitdepth = 8;
|
state.info_raw.bitdepth = 8;
|
||||||
@@ -158,8 +161,6 @@ PNGHandler::DecodedImage PNGHandler::decode(love::filesystem::FileData *fdata)
|
|||||||
unsigned status = lodepng_decode(&img.data, &width, &height,
|
unsigned status = lodepng_decode(&img.data, &width, &height,
|
||||||
&state, indata, insize);
|
&state, indata, insize);
|
||||||
|
|
||||||
lodepng_state_cleanup(&state);
|
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
const char *err = lodepng_error_text(status);
|
const char *err = lodepng_error_text(status);
|
||||||
@@ -180,8 +181,7 @@ PNGHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, ImageData::
|
|||||||
|
|
||||||
EncodedImage encimg;
|
EncodedImage encimg;
|
||||||
|
|
||||||
LodePNGState state;
|
lodepng::State state;
|
||||||
lodepng_state_init(&state);
|
|
||||||
|
|
||||||
state.info_raw.colortype = LCT_RGBA;
|
state.info_raw.colortype = LCT_RGBA;
|
||||||
state.info_raw.bitdepth = 8;
|
state.info_raw.bitdepth = 8;
|
||||||
@@ -195,8 +195,6 @@ PNGHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, ImageData::
|
|||||||
unsigned status = lodepng_encode(&encimg.data, &encimg.size,
|
unsigned status = lodepng_encode(&encimg.data, &encimg.size,
|
||||||
img.data, img.width, img.height, &state);
|
img.data, img.width, img.height, &state);
|
||||||
|
|
||||||
lodepng_state_cleanup(&state);
|
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
const char *err = lodepng_error_text(status);
|
const char *err = lodepng_error_text(status);
|
||||||
|
|||||||
Reference in New Issue
Block a user