Ejemplo n.º 1
0
void PngUtil::mapObjectToPng(const char* filename, MapObject& mapObject) {
	// Get the measurements
	unsigned width = mapObject.getWidth();
	unsigned height = mapObject.getHeight();

	// Allocate a vector for the bytes array
	std::vector<unsigned char> rawPixels;
	rawPixels.resize(width * height * 4);

	// Convert the map object to raw pixels
	convertMapObjectToByteVector(mapObject,rawPixels);

	// Make a png from the raw pixels
	encodeOneStep(filename, rawPixels,width, height);
}
Ejemplo n.º 2
0
void PngUtil::convertMapObjectToByteVector(MapObject source,std::vector<unsigned char>& target) {
	unsigned height = source.getHeight();
	unsigned width = source.getWidth();
	for (unsigned y = 0; y < height; y++) {
			for (unsigned x = 0; x < width; x++) {
				unsigned pixelNumber = y * width + x;
				unsigned pixelBegining = 4 * pixelNumber;

				unsigned red = ClearPixel.red;
				unsigned green = ClearPixel.green;
				unsigned blue = ClearPixel.blue;
				unsigned alpha = 255;

				// Decide the color of the pixel
				switch(source.getCellAtPosition(x,y)){
				case Clear :
					break;
				case Occupied :
					red = OccupiedPixel.red;
					green = OccupiedPixel.green;
					blue = OccupiedPixel.blue;
					break;
				case Path:
					red = PathPixel.red;
					green = PathPixel.green;
					blue = PathPixel.blue;
					break;
				case Target:
					red = TargetPixel.red;
					green = TargetPixel.green;
					blue = TargetPixel.blue;
					break;
				case Source:
					red = SourcePixel.red;
					green = SourcePixel.green;
					blue = SourcePixel.blue;
					break;
			}

				// Fill the pixel color in the target
				target[pixelBegining + 0] = red;
				target[pixelBegining + 1] = green;
				target[pixelBegining + 2] = blue;
				target[pixelBegining + 3] = alpha;
			}
		}
}