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


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

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


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

示例1: toGrayscale

void BmpImage::toGrayscale()
{
	if (bitsPerPixel != 8 && bitsPerPixel != 24)
		return;

	int w = rowBytes();
	int avg;

	if (bitsPerPixel == 24)
	{
		ByteBuffer* bmpBuffer = new ByteBuffer(bitmapSize, bmpBits);
		BinaryReader* reader = new BinaryReader(bmpBuffer);

		byte blue, green, red;

		for (unsigned int i = 0; i < height; i++)
		{
			for (unsigned int j = 0; j < width; j++)
			{
				blue = reader->readByte(i*w+j*3);
				green = reader->readByte(i*w+j*3+1);
				red = reader->readByte(i*w+j*3+2);

				avg = (red + green + blue)/3;
				avg = (avg << 16) | (avg << 8) | (avg);

				bmpBuffer->seek(i*w+j*3);
				bmpBuffer->addRGB(avg);
			}
		}

		bmpBits = bmpBuffer->getBytes();
		return;
	}

	int colorTableIndex;

	for (unsigned int i = 0; i < height; i++)
	{
		for (unsigned int j = 0; j < width; j++)
		{
			colorTableIndex = bmpBits[i*w+j];
			avg = (colorPalette[colorTableIndex] & 0x00FF0000) >> 16;
			avg += (colorPalette[colorTableIndex] & 0x0000FF00) >> 8;
			avg += (colorPalette[colorTableIndex] & 0x000000FF);
			avg /= 3;

			bmpBits[i*w+j] = avg;
		}
	}

	for (int k = 0; k < colorPaletteSize; k++)
	{
		colorPalette[k] = (k << 16) | (k << 8) | (k);
	}
}
开发者ID:bdumitriu,项目名称:playground,代码行数:56,代码来源:BmpImage.cpp

示例2: getMessageLength

uint Packet::getMessageLength(ushort lengthType, BinaryReader& reader)
{
    uint length = 0;

    switch(lengthType)
    {
        case 1:
            length = static_cast<uint>(reader.readByte());
            break;
        case 2:
            length = reader.readUShort();
            break;
        case 3:
            length = static_cast<uint>(
                        ((reader.readByte() & 255) << 16) +
                        ((reader.readByte() & 255) << 8) +
                         (reader.readByte() & 255));
            break;
        default:
            break;
    }

    return length;
}
开发者ID:LuaxY,项目名称:CawotteSrv,代码行数:24,代码来源:packet.cpp


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