Kaynağa Gözat

Cosmetic code improvements

--HG--
branch : image-CompressedData
Alex Szpakowski 12 yıl önce
ebeveyn
işleme
7403245715

+ 1 - 1
src/modules/filesystem/physfs/wrap_FileData.cpp

@@ -52,7 +52,7 @@ static const luaL_Reg w_FileData_functions[] =
 {
 
 	// Data
-	{ "getPointer", w_Data_getPointer },
+//	{ "getPointer", w_Data_getPointer },
 	{ "getSize", w_Data_getSize },
 
 	{ "getFilename", w_FileData_getFilename },

+ 1 - 1
src/modules/font/wrap_GlyphData.cpp

@@ -32,7 +32,7 @@ GlyphData *luax_checkglyphdata(lua_State *L, int idx)
 
 static const luaL_Reg functions[] =
 {
-	{ "getPointer", w_Data_getPointer },
+//	{ "getPointer", w_Data_getPointer },
 	{ "getSize", w_Data_getSize },
 	{ 0, 0 }
 };

+ 5 - 2
src/modules/graphics/opengl/Image.h

@@ -146,10 +146,13 @@ private:
 	{
 		return texture;
 	}
-	// The ImageData from which the texture is created.
+
+	// The ImageData from which the texture is created. May be null if
+	// Compressed image data was used to create the texture.
 	love::image::ImageData *data;
 
-	// Or the Compressed Image Data from which the texture is created.
+	// Or the Compressed Image Data from which the texture is created. May be
+	// null if raw ImageData was used to create the texture.
 	love::image::CompressedData *cdata;
 
 	// Width and height of the hardware texture.

+ 3 - 1
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -418,7 +418,7 @@ int w_newImageFont(lua_State *L)
 	int startIndex = 2;
 
 	// Convert to ImageData if necessary.
-	if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T)))
+	if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
 		luax_convobj(L, 1, "image", "newImageData");
 	else if (luax_istype(L, 1, GRAPHICS_IMAGE_T))
 	{
@@ -426,6 +426,8 @@ int w_newImageFont(lua_State *L)
 		img_filter = i->getFilter();
 		setFilter = true;
 		love::image::ImageData *id = i->getData();
+		if (!id)
+			return luaL_argerror(L, 1, "image cannot be compressed");
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)id, false);
 		lua_replace(L, 1);
 	}

+ 1 - 1
src/modules/image/CompressedData.h

@@ -62,8 +62,8 @@ public:
 	// by a sub-image.
 	struct SubImage
 	{
-		size_t size;
 		int width, height;
+		size_t size;
 		std::vector<unsigned char> data;
 	};
 

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

@@ -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
src/modules/image/magpie/DevilHandler.cpp

@@ -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 - 0
src/modules/image/magpie/DevilHandler.h

@@ -32,6 +32,9 @@ namespace image
 namespace magpie
 {
 
+/**
+ * Interface between ImageData and DevIL.
+ **/
 class DevilHandler : public FormatHandler
 {
 public:

+ 8 - 8
src/modules/image/magpie/ImageData.cpp

@@ -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
src/modules/image/magpie/ddsHandler.cpp

@@ -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
src/modules/image/magpie/ddsHandler.h

@@ -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

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

@@ -109,7 +109,7 @@ int w_CompressedData_getType(lua_State *L)
 static const luaL_Reg functions[] =
 {
 	// Data
-	{ "getPointer", w_Data_getPointer },
+//	{ "getPointer", w_Data_getPointer },
 	{ "getSize", w_Data_getSize },
 
 	{ "getWidth", w_CompressedData_getWidth },

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

@@ -118,7 +118,7 @@ int w_isCompressed(lua_State *L)
 	{
 		return luaL_error(L, "%s", e.what());
 	}
-	luax_pushboolean(L,	compressed);
+	luax_pushboolean(L, compressed);
 	return 1;
 }
 

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

@@ -191,7 +191,7 @@ int w_ImageData_encode(lua_State *L)
 static const luaL_Reg functions[] =
 {
 	// Data
-	{ "getPointer", w_Data_getPointer },
+//	{ "getPointer", w_Data_getPointer },
 	{ "getSize", w_Data_getSize },
 
 	{ "getWidth", w_ImageData_getWidth },

+ 1 - 1
src/modules/sound/wrap_SoundData.cpp

@@ -81,7 +81,7 @@ static const luaL_Reg functions[] =
 {
 
 	// Data
-	{ "getPointer", w_Data_getPointer },
+//	{ "getPointer", w_Data_getPointer },
 	{ "getSize", w_Data_getSize },
 
 	{ "getChannels", w_SoundData_getChannels },