Пример #1
0
bool Bitmap::readXml(TiXmlElement* e)
{
	TiXmlElement* child = Xml::getElement(e, "frame");
	if(child != NULL)
	{    
		stringstream frame(Xml::getText(child));
		string line;
		unsigned int numPix = 0;

		// read through all the chars
		while(!frame.eof())
		{
			frame >> line;
			LOG << "       " << line << endl;

			stringstream chars(line);

			char c;
			chars >> c;
			while(!chars.eof())
			{
				switch(c)
				{
					case '*':   // filled
						bitmap.push_back(true);
						numPix++;
						break;
					case '-':   // empty
						bitmap.push_back(false);
						numPix++;
						break;
					default: // ignore
						break;
				}
				chars >> c;
			}
		}

		// correct size?
		if(bitmapWidth == 0)	bitmapWidth = 1;
		if(bitmapHeight == 0)	bitmapHeight = 1;
		if(numPix < bitmapWidth*bitmapHeight)
		{
			LOG_WARN << "Bitmap: Not enough pixels in frame: " << numPix
					 << ", need " << bitmapWidth*bitmapHeight << std::endl;
			bitmap.clear();
			return false;
		}
		
		computePixelSize();
	}
Пример #2
0
void Bitmap::setSize(unsigned int w, unsigned int h)
{
	width = w;
	height = h;
	computePixelSize();
}
Пример #3
0
Image *allocate(int rows, int cols) {
	int width, height;
	computePixelSize(&width, &height, rows, cols);
	return new Image(width, height);
}