Example #1
0
//******************
//	Main methods
//******************
MapObject PngUtil::mapObjectFromPng(const char* filename) {
	std::vector<unsigned char> rawImage; // Raw pixels & alpha's
	unsigned width,height;
	unsigned error = lodepng::decode(rawImage,width,height,filename);

	if (error) {
		std::cout << "decoder error " << error << ": "
						<< lodepng_error_text(error) << std::endl;
		throw "PNG decoding error ! " + error;
	}

	MapObject mapObject;
	mapObject.defineDimensions(width, height);

	// Convert the raw pixels to actual grid cells
	convertByteVectorToMapObject(rawImage,mapObject,width,height);

	// Return the loaded map as grid of cells
	return mapObject;
}