Cosmetic code improvements

--HG--
branch : image-CompressedData
This commit is contained in:
Alex Szpakowski
2013-04-07 22:58:08 -03:00
parent 88d64954a4
commit 7403245715
15 changed files with 39 additions and 48 deletions
+3 -3
View File
@@ -40,16 +40,16 @@ CompressedData::~CompressedData()
void CompressedData::load(love::filesystem::FileData *data)
{
std::vector<SubImage> imageMipmaps;
std::vector<SubImage> parsedImages;
TextureType textype = TYPE_UNKNOWN;
if (ddsHandler::canParse(data))
textype = ddsHandler::parse(data, imageMipmaps);
textype = ddsHandler::parse(data, parsedImages);
if (textype == TYPE_UNKNOWN)
throw (love::Exception("Could not parse compressed data: Unknown format."));
dataImages = imageMipmaps;
dataImages = parsedImages;
type = textype;
}
+7 -7
View File
@@ -145,7 +145,7 @@ DevilHandler::EncodedImage DevilHandler::encode(const DecodedImage &img, ImageDa
ilBindImage(tempimage);
ilxClearErrors();
EncodedImage encodedimg;
EncodedImage encodedimage;
try
{
@@ -194,32 +194,32 @@ DevilHandler::EncodedImage DevilHandler::encode(const DecodedImage &img, ImageDa
break;
}
encodedimg.size = ilSaveL(ilFormat, NULL, 0);
if (!encodedimg.size)
encodedimage.size = ilSaveL(ilFormat, NULL, 0);
if (!encodedimage.size)
throw love::Exception("Could not encode image!");
try
{
encodedimg.data = new ILubyte[encodedimg.size];
encodedimage.data = new ILubyte[encodedimage.size];
}
catch(std::bad_alloc &)
{
throw love::Exception("Out of memory");
}
ilSaveL(ilFormat, encodedimg.data, encodedimg.size);
ilSaveL(ilFormat, encodedimage.data, encodedimage.size);
}
catch (std::exception &e)
{
// catches love and std exceptions
ilDeleteImage(tempimage);
delete[] encodedimg.data;
delete[] encodedimage.data;
throw love::Exception("%s", e.what());
}
ilDeleteImage(tempimage);
return encodedimg;
return encodedimage;
}
} // magpie
+3
View File
@@ -32,6 +32,9 @@ namespace image
namespace magpie
{
/**
* Interface between ImageData and DevIL.
**/
class DevilHandler : public FormatHandler
{
public:
+8 -8
View File
@@ -74,26 +74,26 @@ void ImageData::create(int width, int height, void *data)
void ImageData::decode(love::filesystem::FileData *data)
{
FormatHandler::DecodedImage decodedimg;
FormatHandler::DecodedImage decodedimage;
if (DevilHandler::canDecode(data))
decodedimg = DevilHandler::decode(data);
decodedimage = DevilHandler::decode(data);
else
throw love::Exception("Image format has no suitable decoder.");
throw love::Exception("Could not decode image: unrecognized format.");
// The decoder *must* output a 32 bits-per-pixel image.
if (decodedimg.size != decodedimg.width*decodedimg.height*sizeof(pixel))
if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel))
{
delete[] decodedimg.data;
delete[] decodedimage.data;
throw love::Exception("Coult not convert image!");
}
if (this->data)
delete[] this->data;
this->width = decodedimg.width;
this->height = decodedimg.height;
this->data = decodedimg.data;
this->width = decodedimage.width;
this->height = decodedimage.height;
this->data = decodedimage.data;
}
void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
+1 -17
View File
@@ -29,28 +29,12 @@ namespace magpie
bool ddsHandler::canParse(const filesystem::FileData *data)
{
if (!accepts(data->getExtension()))
if (data->getExtension().compare("dds") != 0)
return false;
return dds::Parser::isCompressedDDS(data->getData(), data->getSize());
}
bool ddsHandler::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"dds", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
CompressedData::TextureType ddsHandler::parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images)
{
if (!dds::Parser::isDDS(data->getData(), data->getSize()))
+2 -3
View File
@@ -55,15 +55,14 @@ public:
/**
* Parses Compressed image data into a list of sub-images.
* @param[in] data The data to parse.
* @param[out] images The list of sub-images (including byte data for each)
* outputted by the parser.
* @param[out] images The list of sub-images (including byte data for each),
* created by the parser.
* @return The type of CompressedData.
**/
static CompressedData::TextureType parse(filesystem::FileData *data, std::vector<CompressedData::SubImage> &images);
private:
static bool accepts(const std::string &ext);
static CompressedData::TextureType convertFormat(dds::Format ddsformat);
}; // ddsHandler