本文整理汇总了C++中FileReader::ReadArray方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::ReadArray方法的具体用法?C++ FileReader::ReadArray怎么用?C++ FileReader::ReadArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::ReadArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
OPENMPT_NAMESPACE_BEGIN
PNG::Bitmap *PNG::ReadPNG(FileReader &file)
//-----------------------------------------
{
file.Rewind();
if(!file.ReadMagic("\211PNG\r\n\032\n"))
{
return nullptr;
}
uint32_t width = 0;
uint32_t height = 0;
uint8_t bitDepth;
uint8_t colorType;
uint8_t compressionMethod;
uint8_t filterMethod;
uint8_t interlaceMethod;
std::vector<uint8_t> dataIn;
std::vector<Pixel> palette;
while(file.AreBytesLeft())
{
uint32_t chunkLength = file.ReadUint32BE();
char magic[4];
file.ReadArray(magic);
FileReader chunk = file.ReadChunk(chunkLength);
file.Skip(4); // CRC32
if(!memcmp(magic, "IHDR", 4))
{
// Image header
width = chunk.ReadUint32BE();
height = chunk.ReadUint32BE();
bitDepth = chunk.ReadUint8();
colorType = chunk.ReadUint8();
compressionMethod = chunk.ReadUint8();
filterMethod = chunk.ReadUint8();
interlaceMethod = chunk.ReadUint8();
ASSERT(!filterMethod && !interlaceMethod);
} else if(!memcmp(magic, "IDAT", 4))
{
// Data block(s)
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = static_cast<uInt>(chunk.GetLength());
strm.next_in = (Bytef *)(chunk.GetRawData());
if(inflateInit2(&strm, 15) != Z_OK)
{
break;
}
int retVal;
do
{
dataIn.resize(dataIn.size() + 4096);
strm.avail_out = 4096;
strm.next_out = (Bytef *)&dataIn[dataIn.size() - 4096];
retVal = inflate(&strm, Z_NO_FLUSH);
} while(retVal == Z_OK);
inflateEnd(&strm);
} else if(!memcmp(magic, "PLTE", 4))
{
// Palette for <= 8-bit images
palette.resize(256);
size_t numEntries = std::min<size_t>(256u, chunk.GetLength() / 3u);
for(size_t i = 0; i < numEntries; i++)
{
uint8_t p[3];
chunk.ReadArray(p);
palette[i] = Pixel(p[0], p[1], p[2], 255);
}
}
}
// LUT for translating the color type into a number of color samples
const uint32_t sampleTable[] =
{
1, // 0: Grayscale
0,
3, // 2: RGB
1, // 3: Palette bitmap
2, // 4: Grayscale + Alpha
0,
4 // 6: RGBA
};
const uint32_t bitsPerPixel = colorType < CountOf(sampleTable) ? sampleTable[colorType] * bitDepth : 0;
if(!width || !height || !bitsPerPixel
|| (colorType != 2 && colorType != 3 && colorType != 6) || bitDepth != 8 // Only RGB(A) and 8-bit palette PNGs for now.
|| compressionMethod || interlaceMethod
|| (colorType == 3 && palette.empty())
|| dataIn.size() < (bitsPerPixel * width * height) / 8 + height) // Enough data present?
{
return nullptr;
}
Bitmap *bitmap = new (std::nothrow) Bitmap(width, height);
//.........这里部分代码省略.........
示例2: ReadSample
//.........这里部分代码省略.........
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<littleEndian32>(1.0f / static_cast<float>(1<<15)))
);
} else
{
bytesRead = CopyMonoSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<bigEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<bigEndian32>(1.0f / static_cast<float>(1<<15)))
);
}
}
//////////////////////////////////////////////////////
// 32-Bit / Float / Stereo Interleaved / PCM / full scale 2^15
else if(GetBitDepth() == 32 && GetChannelFormat() == stereoInterleaved && GetEncoding() == floatPCM15)
{
if(GetEndianness() == littleEndian)
{
bytesRead = CopyStereoInterleavedSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<littleEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<littleEndian32>(1.0f / static_cast<float>(1<<15)))
);
} else
{
bytesRead = CopyStereoInterleavedSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<bigEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<bigEndian32>(1.0f / static_cast<float>(1<<15)))
);
}
}
//////////////////////////////////////////////////////
// 32-Bit / Float / Stereo Interleaved / PCM / full scale 2^23
else if(GetBitDepth() == 32 && GetChannelFormat() == mono && GetEncoding() == floatPCM23)
{
if(GetEndianness() == littleEndian)
{
bytesRead = CopyMonoSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<littleEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<littleEndian32>(1.0f / static_cast<float>(1<<23)))
);
} else
{
bytesRead = CopyMonoSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<bigEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<bigEndian32>(1.0f / static_cast<float>(1<<23)))
);
}
}
//////////////////////////////////////////////////////
// 32-Bit / Float / Stereo Interleaved / PCM / full scale 2^23
else if(GetBitDepth() == 32 && GetChannelFormat() == stereoInterleaved && GetEncoding() == floatPCM23)
{
if(GetEndianness() == littleEndian)
{
bytesRead = CopyStereoInterleavedSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<littleEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<littleEndian32>(1.0f / static_cast<float>(1<<23)))
);
} else
{
bytesRead = CopyStereoInterleavedSample
(sample, sourceBuf, fileSize,
SC::ConversionChain<SC::Convert<int16, float32>, SC::DecodeScaledFloat32<bigEndian32> >
(SC::Convert<int16, float32>(), SC::DecodeScaledFloat32<bigEndian32>(1.0f / static_cast<float>(1<<23)))
);
}
}
//////////////////////////////////////////////////////
// Compressed samples
if(*this == SampleIO(_8bit, mono, littleEndian, ADPCM))
{
// 4-Bit ADPCM data
int8 compressionTable[16]; // ADPCM Compression LUT
if(file.ReadArray(compressionTable))
{
size_t readLength = (sample.nLength + 1) / 2;
LimitMax(readLength, file.BytesLeft());
const uint8 *inBuf = reinterpret_cast<const uint8*>(sourceBuf) + sizeof(compressionTable);
int8 *outBuf = static_cast<int8 *>(sample.pSample);
int8 delta = 0;
for(size_t i = readLength; i != 0; i--)
{
delta += compressionTable[*inBuf & 0x0F];
*(outBuf++) = delta;
delta += compressionTable[(*inBuf >> 4) & 0x0F];
*(outBuf++) = delta;
inBuf++;
}
bytesRead = sizeof(compressionTable) + readLength;
}