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


C++ Stream::GetOffset方法代码示例

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


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

示例1: ras_decode

static bool ras_decode(Bitmap& target, Stream& stream)
{
	// reset stream
	stream.Seek(0,Stream::START);

	// streamsize - headersize
	int size = stream.GetSize() - 32;
	if ( size < 1 )
		return false;

	// read header
	uint32 magic		= ReadBigEndian<uint32>(stream);
	uint32 width		= ReadBigEndian<uint32>(stream);
	uint32 height		= ReadBigEndian<uint32>(stream);
	uint32 bits			= ReadBigEndian<uint32>(stream);
/*	uint32 length = */	  ReadBigEndian<uint32>(stream);
	uint32 type			= ReadBigEndian<uint32>(stream);
	uint32 maptype		= ReadBigEndian<uint32>(stream);
	uint32 maplength	= ReadBigEndian<uint32>(stream);

	// verify header
	if ( magic != 0x59a66a95 )
		return false;

	if ( bits != 1 && bits != 8 && bits != 24 && bits != 32 )
		return false;

	if ( type != 0 && type != 1 && type != 2 && type != 3 )
		return false;

	// create bitmap
	switch ( bits )
	{
		case 1:  target = Bitmap(width,height,PIXELFORMAT_INTENSITY8); break;
		case 8:  target = Bitmap(width,height,PIXELFORMAT_PALETTE8(NULL)); break;
		case 24: target = Bitmap(width,height,PIXELFORMAT_RGB888); break;
		case 32: target = Bitmap(width,height,PIXELFORMAT_ARGB8888); break;
		default: return false;
	}

	// read colormap
	switch ( maptype )
	{
		// "none" - no palette
		case 0:
		{
			stream.Seek(maplength,Stream::CURRENT);
			break;
		}

		// "equal rgb" -mode palette
		case 1:
		{
			if ( bits != 8 || maplength > 768 )
				return false;

			const PixelFormat& pxf = target.GetPixelFormat();
			Color32* palette = pxf.GetPalette();
			int count = static_cast<int>(maplength / 3);

			int i;
			for ( i=0; i<count; ++i ) palette[i].r = ReadBigEndian<uint8>(stream);
			for ( i=0; i<count; ++i ) palette[i].g = ReadBigEndian<uint8>(stream);
			for ( i=0; i<count; ++i ) palette[i].b = ReadBigEndian<uint8>(stream);
			for ( i=0; i<count; ++i ) palette[i].a = 0xff;

			break;
		}

		// "raw" -mode palette
		// TODO: this code has not been tested
		//       (couldn't find files to test with or specification)
		//       this is my best guess how the "raw" mode works!
		case 2:
		{
			if ( bits != 8 || maplength > 768 )
				return false;

			const PixelFormat& pxf = target.GetPixelFormat();
			Color32* palette = pxf.GetPalette();
			int count = static_cast<int>(maplength / 3);

			for ( int i=0; i<count; ++i )
			{
				palette[i].r = ReadBigEndian<uint8>(stream);
				palette[i].g = ReadBigEndian<uint8>(stream);
				palette[i].b = ReadBigEndian<uint8>(stream);
				palette[i].a = 0xff;
			}
		}

		// unknown fileformat
		default: return false;
	}

	// decode buffer
	int buffersize = stream.GetSize() - stream.GetOffset();
	uint8* buffer = new uint8[buffersize];
	stream.Read(buffer,buffersize);

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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