本文整理汇总了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);
}
}
示例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;
}