当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryReader::readRGB方法代码示例

本文整理汇总了C++中BinaryReader::readRGB方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryReader::readRGB方法的具体用法?C++ BinaryReader::readRGB怎么用?C++ BinaryReader::readRGB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryReader的用法示例。


在下文中一共展示了BinaryReader::readRGB方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

bool BmpImage::init()
{
	initValuesToDefault();

	BinaryReader* reader = new BinaryReader(this->image);
	reader->reset();

	/* read the file data header */
	// read the type of the file
	reader->seek(FILE_TYPE_OFFSET);
	fileType = reader->readWord();
	

	switch (fileType)
	{
	case BMPBITMAP:
		break;
	case BMPARRAY:
	case BMPCLRICON:
	case BMPCLRPOINTER:
	case BMPICON:
	case BMPPOINTER:
		return false;
	default:
		{
			fileType = NOT_BMP; // exception should be thrown
			return false;
		}
	}

	// read the file size in bytes
	fileSize = reader->readDword();

	// read the two hot spots, reserved 1 & reserved 2
	Xhot = reader->readWord();
	Yhot = reader->readWord();

	bitmapOffset = reader->readDword();

	/* read the bitmap header now */
	headerSize = reader->readDword();

	if (headerSize < BMPOLDANYHDRSIZE || 
		(headerSize > BMPNEWOS2HDRSIZE && headerSize != BMPNEWWINV4HDRSIZE))
	{
		fileType = NOT_BMP; // exception should be thrown
		return false;
	}

	// read the rest of the header and the palette if any
	if (headerSize == BMPOLDANYHDRSIZE) // we have an old BMP file format
	{
		version = BMPOLD;
		width = (word) reader->readWord();
		height = (word) reader->readWord();
		planes = reader->readWord();
		bitsPerPixel = reader->readWord();

		if (bitsPerPixel != 1 || bitsPerPixel != 4 || bitsPerPixel != 8 || 
			bitsPerPixel != 24)
		{
			fileType = NOT_BMP; // exception should be thrown
			return false;
		}

		colorPaletteSize = bitsPerPixel == 24 ? 0 : 1 << bitsPerPixel;
		
		int numberOfEntries = (bitmapOffset - BMPFILEHDRSIZE - 
			BMPOLDANYHDRSIZE) / BMPOLDPALETTESIZE;

		if (colorPaletteSize != numberOfEntries)
		{
			fileType = NOT_BMP; // exception should be thrown
			return false;
		}

		// read the palette
		if (colorPaletteSize != 0)
		{
			colorPalette = new unsigned long[colorPaletteSize];
			for (int i = 0; i < colorPaletteSize; i++)
			{
				colorPalette[i] = reader->readRGB();
			}
		}

		bitmapSize = rowBytes() * height;
	}
	else // new BMP file format
	{
		switch (headerSize)
		{
		case BMPNEWWINHDRSIZE:
			{
				version = BMPWINNEW;
				break;
			}
		case BMPNEWOS2HDRSIZE:
			{
				version = BMPOS2NEW;
//.........这里部分代码省略.........
开发者ID:bdumitriu,项目名称:playground,代码行数:101,代码来源:BmpImage.cpp


注:本文中的BinaryReader::readRGB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。