本文整理汇总了C++中StreamBuffer::Seek方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamBuffer::Seek方法的具体用法?C++ StreamBuffer::Seek怎么用?C++ StreamBuffer::Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamBuffer
的用法示例。
在下文中一共展示了StreamBuffer::Seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static status_t
convert_data_to_bits(pcx_header &header, StreamBuffer &source,
BPositionIO &target)
{
uint16 bitsPerPixel = header.bitsPerPixel;
uint16 bytesPerLine = header.bytesPerLine;
uint32 width = header.xMax - header.xMin + 1;
uint32 height = header.yMax - header.yMin + 1;
uint16 numPlanes = header.numPlanes;
uint32 scanLineLength = numPlanes * bytesPerLine;
// allocate buffers
TempAllocator scanLineAllocator;
TempAllocator paletteAllocator;
uint8 *scanLineData[height];
uint8 *palette = (uint8 *)paletteAllocator.Allocate(3 * 256);
status_t status = B_OK;
for (uint32 row = 0; row < height; row++) {
TRACE("scanline %ld\n", row);
scanLineData[row] = (uint8 *)scanLineAllocator.Allocate(scanLineLength);
if (scanLineData[row] == NULL)
return B_NO_MEMORY;
uint8 *line = scanLineData[row];
uint32 index = 0;
uint8 x;
do {
if (source.Read(&x, 1) != 1) {
status = B_IO_ERROR;
break;
}
if ((x & 0xc0) == 0xc0) {
uint32 count = x & 0x3f;
if (index + count - 1 > scanLineLength) {
status = B_BAD_DATA;
break;
}
if (source.Read(&x, 1) != 1) {
status = B_IO_ERROR;
break;
}
for (uint32 i = 0; i < count; i++)
line[index++] = x;
} else {
line[index++] = x;
}
} while (index < scanLineLength);
if (status != B_OK) {
// If we've already read more than a third of the file, display
// what we have, ie. ignore the error.
if (row < height / 3)
return status;
memset(scanLineData + row, 0, sizeof(uint8*) * (height - row));
break;
}
}
if (bitsPerPixel == 8 && numPlanes == 1) {
TRACE("palette reading %p 8\n", palette);
uint8 x;
if (status != B_OK || source.Read(&x, 1) != 1 || x != 12) {
// Try again by repositioning the file stream
if (source.Seek(-3 * 256 - 1, SEEK_END) < 0)
return B_BAD_DATA;
if (source.Read(&x, 1) != 1)
return B_IO_ERROR;
if (x != 12)
return B_BAD_DATA;
}
if (source.Read(palette, 256 * 3) != 256 * 3)
return B_IO_ERROR;
} else {
TRACE("palette reading %p palette\n", palette);
memcpy(palette, &header.paletteInfo, 48);
}
uint8 alpha = 255;
if (bitsPerPixel == 1 && numPlanes == 1) {
TRACE("target writing 1\n");
palette[0] = palette[1] = palette[2] = 0;
palette[3] = palette[4] = palette[5] = 0xff;
for (uint32 row = 0; row < height; row++) {
uint8 *line = scanLineData[row];
if (line == NULL)
break;
uint8 mask[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
for (uint32 i = 0; i < width; i++) {
bool isBit = ((line[i >> 3] & mask[i & 7]) != 0) ? true : false;
target.Write(&palette[!isBit ? 2 : 5], 1);
target.Write(&palette[!isBit ? 1 : 4], 1);
target.Write(&palette[!isBit ? 0 : 3], 1);
target.Write(&alpha, 1);
}
}
} else if (bitsPerPixel == 4 && numPlanes == 1) {