本文整理汇总了C++中IReader::read方法的典型用法代码示例。如果您正苦于以下问题:C++ IReader::read方法的具体用法?C++ IReader::read怎么用?C++ IReader::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReader
的用法示例。
在下文中一共展示了IReader::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decode
Image ImageFormat_JPEG::decode(IReader& reader) const
{
const int64 size = reader.size();
uint8* buffer = static_cast<uint8*>(::malloc(static_cast<size_t>(size)));
reader.read(buffer, size);
int width, height;
tjhandle tj = ::tjInitDecompress();
::tjDecompressHeader(tj, buffer, static_cast<unsigned long>(size), &width, &height);
Image image(width, height);
::tjDecompress(
tj,
buffer,
static_cast<unsigned long>(size),
image.dataAsUint8(),
image.width(),
image.stride(),
image.height(),
sizeof(Color),
0);
::tjDestroy(tj);
::free(buffer);
return image;
}
示例2: program
void Flash::program(const QString &filename)
{
#if 0
QFile file(filename);
uint32_t len;
uint32_t addr;
int32_t response;
if (!file.open(QIODevice::ReadOnly))
throw std::runtime_error((QString("Cannot open file ") + filename + QString(".")).toStdString());
for(addr=0x14000000; !file.atEnd(); addr+=len)
{
len =(uint32_t)file.read(m_buf, m_sectorSize);
m_chirp.callSync(m_programProc, UINT32(addr), UINTS8(len, m_buf), END_OUT_ARGS,
&response, END_IN_ARGS);
if (response==-1)
throw std::runtime_error("Invalid address range.");
else if (response==-3)
throw std::runtime_error("Error during verify.");
else if (response<0)
throw std::runtime_error("Error during programming.");
}
#else
IReader *reader;
unsigned long addr, len;
int32_t res, response;
reader = createReader(filename);
while(1)
{
res = reader->read((unsigned char *)m_buf, m_sectorSize, &addr, &len);
if (len)
{
if (m_chirp.callSync(m_programProc, UINT32(addr), UINTS8(len, m_buf), END_OUT_ARGS,
&response, END_IN_ARGS)<0)
throw std::runtime_error("communication error during programming.");
if (response==-1)
throw std::runtime_error("invalid address range.");
else if (response==-3)
throw std::runtime_error("during verify.");
else if (response<-100)
{
QString str = "I/O: " + QString::number(-response-100) + ".";
throw std::runtime_error(str.toStdString());
}
else if (response<0)
{
QString str = "programming: " + QString::number(response) + ".";
throw std::runtime_error(str.toStdString());
}
}
if (res<0)
break;
}
#endif
// reset Pixy
if (m_chirp.callSync(m_reset, END_OUT_ARGS,
&response, END_IN_ARGS)<0)
throw std::runtime_error("Unable to reset.");
destroyReader(reader);
}
示例3: decode
Wave AudioFormat_WAVE::decode(IReader& reader) const
{
RiffHeader riffHeader;
if (!reader.read(riffHeader))
{
return Wave();
}
if (!detail::MemEqual(riffHeader.riff, detail::RIFF_SIGN) || !detail::MemEqual(riffHeader.type, detail::WAVE_SIGN))
{
return Wave();
}
ChunkHeader chunkHeader;
for (;;)
{
if (!reader.read(chunkHeader))
{
return Wave();
}
if (detail::MemEqual(chunkHeader.chunkID, detail::FMT_CHUNK))
{
break;
}
else
{
reader.setPos(reader.getPos() + chunkHeader.chunkSize);
}
}
FormatHeader formatHeader;
if (!reader.read(formatHeader))
{
return Wave();
}
if (chunkHeader.chunkSize > sizeof(formatHeader))
{
reader.skip(chunkHeader.chunkSize - sizeof(formatHeader));
}
for (;;)
{
if (!reader.read(chunkHeader))
{
return Wave();
}
if (detail::MemEqual(chunkHeader.chunkID, detail::DATA_CHUNK))
{
break;
}
else
{
reader.setPos(reader.getPos() + chunkHeader.chunkSize);
}
}
const uint32 size_bytes = chunkHeader.chunkSize;
const size_t num_samples = size_bytes / (formatHeader.channels * (formatHeader.bitsWidth / 8));
Wave wave(num_samples, Arg::samplingRate = formatHeader.samplerate);
if (formatHeader.bitsWidth == 8 && formatHeader.channels == 1)
{
// PCM 8bit 1ch
Array<uint8> samples(num_samples);
reader.read(samples.data(), size_bytes);
for (size_t i = 0; i < num_samples; ++i)
{
wave[i].set(samples[i] / 127.5f - 1.0f);
}
}
else if (formatHeader.bitsWidth == 8 && formatHeader.channels == 2)
{
// PCM 8bit 2ch
Array<WS8bit> samples(num_samples);
reader.read(samples.data(), size_bytes);
for (uint32 i = 0; i < num_samples; ++i)
{
wave[i].set(samples[i].left / 127.5f - 1.0f, samples[i].right / 127.5f - 1.0f);
}
}
else if (formatHeader.bitsWidth == 16 && formatHeader.channels == 1)
{
// PCM 16bit 1ch
Array<int16> samples(num_samples);
reader.read(samples.data(), size_bytes);
for (uint32 i = 0; i < num_samples; ++i)
{
//.........这里部分代码省略.........