本文整理汇总了C++中FileReader::ReadUint8方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::ReadUint8方法的具体用法?C++ FileReader::ReadUint8怎么用?C++ FileReader::ReadUint8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::ReadUint8方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadUMXNameTableEntry
// Read an entry from the name table.
std::string ReadUMXNameTableEntry(FileReader &chunk, uint16 packageVersion)
{
std::string name;
if(packageVersion >= 64)
{
// String length
int32 length = ReadUMXIndex(chunk);
if(length <= 0)
{
return "";
}
name.reserve(length);
}
// Simple zero-terminated string
uint8 chr;
while((chr = chunk.ReadUint8()) != 0)
{
// Convert string to lower case
if(chr >= 'A' && chr <= 'Z')
{
chr = chr - 'A' + 'a';
}
name.append(1, static_cast<char>(chr));
}
chunk.Skip(4); // Object flags
return name;
}
示例2: 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);
//.........这里部分代码省略.........
示例3: ReadAMSPattern
// Read AMS or AMS2 (newVersion = true) pattern. At least this part of the format is more or less identical between the two trackers...
static void ReadAMSPattern(CPattern &pattern, bool newVersion, FileReader &patternChunk, CSoundFile &sndFile)
//-----------------------------------------------------------------------------------------------------------
{
enum
{
emptyRow = 0xFF, // No commands on row
endOfRowMask = 0x80, // If set, no more commands on this row
noteMask = 0x40, // If set, no note+instr in this command
channelMask = 0x1F, // Mask for extracting channel
// Note flags
readNextCmd = 0x80, // One more command follows
noteDataMask = 0x7F, // Extract note
// Command flags
volCommand = 0x40, // Effect is compressed volume command
commandMask = 0x3F, // Command or volume mask
};
// Effect translation table for extended (non-Protracker) effects
static const ModCommand::COMMAND effTrans[] =
{
CMD_S3MCMDEX, // Forward / Backward
CMD_PORTAMENTOUP, // Extra fine slide up
CMD_PORTAMENTODOWN, // Extra fine slide up
CMD_RETRIG, // Retrigger
CMD_NONE,
CMD_TONEPORTAVOL, // Toneporta with fine volume slide
CMD_VIBRATOVOL, // Vibrato with fine volume slide
CMD_NONE,
CMD_PANNINGSLIDE,
CMD_NONE,
CMD_VOLUMESLIDE, // Two times finder volume slide than Axx
CMD_NONE,
CMD_CHANNELVOLUME, // Channel volume (0...127)
CMD_PATTERNBREAK, // Long pattern break (in hex)
CMD_S3MCMDEX, // Fine slide commands
CMD_NONE, // Fractional BPM
CMD_KEYOFF, // Key off at tick xx
CMD_PORTAMENTOUP, // Porta up, but uses all octaves (?)
CMD_PORTAMENTODOWN, // Porta down, but uses all octaves (?)
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_NONE,
CMD_GLOBALVOLSLIDE, // Global volume slide
CMD_NONE,
CMD_GLOBALVOLUME, // Global volume (0... 127)
};
static ModCommand dummy;
for(ROWINDEX row = 0; row < pattern.GetNumRows(); row++)
{
PatternRow baseRow = pattern.GetRow(row);
while(patternChunk.AreBytesLeft())
{
const uint8 flags = patternChunk.ReadUint8();
if(flags == emptyRow)
{
break;
}
const CHANNELINDEX chn = (flags & channelMask);
ModCommand &m = chn < pattern.GetNumChannels() ? baseRow[chn] : dummy;
bool moreCommands = true;
if(!(flags & noteMask))
{
// Read note + instr
uint8 note = patternChunk.ReadUint8();
moreCommands = (note & readNextCmd) != 0;
note &= noteDataMask;
if(note == 1)
{
m.note = NOTE_KEYOFF;
} else if(note >= 2 && note <= 121 && newVersion)
{
m.note = note - 2 + NOTE_MIN;
} else if(note >= 12 && note <= 108 && !newVersion)
{
m.note = note + 12 + NOTE_MIN;
}
m.instr = patternChunk.ReadUint8();
}
while(moreCommands)
{
// Read one more effect command
ModCommand origCmd = m;
const uint8 command = patternChunk.ReadUint8(), effect = (command & commandMask);
moreCommands = (command & readNextCmd) != 0;
if(command & volCommand)
{
m.volcmd = VOLCMD_VOLUME;
//.........这里部分代码省略.........
示例4: ReadAMSString
// Read variable-length AMS string (we ignore the maximum text length specified by the AMS specs and accept any length).
static bool ReadAMSString(std::string &dest, FileReader &file)
//------------------------------------------------------------
{
const size_t length = file.ReadUint8();
return file.ReadString<mpt::String::spacePadded>(dest, length);
}
示例5: ReadITQ
//.........这里部分代码省略.........
PATTERNINDEX numPats = std::min(static_cast<PATTERNINDEX>(patPos.size()), GetModSpecifications().patternsMax);
if(numPats != patPos.size())
{
// Hack: Notify user here if file contains more patterns than what can be read.
AddToLog(mpt::String::Print(str_PatternSetTruncationNote, patPos.size(), numPats));
}
if(!(loadFlags & loadPatternData))
{
numPats = 0;
}
// Checking for number of used channels, which is not explicitely specified in the file.
for(PATTERNINDEX pat = 0; pat < numPats; pat++)
{
if(patPos[pat] == 0 || !file.Seek(patPos[pat]))
continue;
uint16 len = file.ReadUint16LE();
ROWINDEX numRows = file.ReadUint16LE();
if(numRows < GetModSpecifications().patternRowsMin
|| numRows > GetModSpecifications().patternRowsMax
|| !file.Skip(4))
continue;
FileReader patternData = file.GetChunk(len);
ROWINDEX row = 0;
std::vector<uint8> chnMask(GetNumChannels());
while(row < numRows && patternData.AreBytesLeft())
{
uint8 b = patternData.ReadUint8();
if(!b)
{
row++;
continue;
}
CHANNELINDEX ch = (b & IT_bitmask_patternChanField_c); // 0x7f We have some data grab a byte keeping only 7 bits
if(ch)
{
ch = (ch - 1);// & IT_bitmask_patternChanMask_c; // 0x3f mask of the byte again, keeping only 6 bits
}
if(ch >= chnMask.size())
{
chnMask.resize(ch + 1, 0);
}
if(b & IT_bitmask_patternChanEnabled_c) // 0x80 check if the upper bit is enabled.
{
chnMask[ch] = patternData.ReadUint8(); // set the channel mask for this channel.
}
// Channel used
if(chnMask[ch] & 0x0F) // if this channel is used set m_nChannels
{
if(ch >= GetNumChannels() && ch < MAX_BASECHANNELS)
{
m_nChannels = ch + 1;
}
}
// Now we actually update the pattern-row entry the note,instrument etc.
// Note
if(chnMask[ch] & 1) patternData.Skip(1);
示例6: void
OPENMPT_NAMESPACE_BEGIN
bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags)
//-------------------------------------------------------------------
{
file.Rewind();
// No valid MO3 file (magic bytes: "MO3")
if(!file.CanRead(8) || !file.ReadMagic("MO3"))
{
return false;
} else if(loadFlags == onlyVerifyHeader)
{
return true;
}
#ifdef NO_MO3
// As of November 2013, the format revision is 5; Versions > 31 are unlikely to exist in the next few years,
// so we will just ignore those if there's no UNMO3 library to tell us if the file is valid or not
// (avoid log entry with .MOD files that have a song name starting with "MO3".
if(file.ReadUint8() > 31)
{
return false;
}
AddToLog(GetStrI18N("The file appears to be a MO3 file, but this OpenMPT build does not support loading MO3 files."));
return false;
#else
bool result = false; // Result of trying to load the module, false == fail.
// Try to load unmo3 dynamically.
mpt::Library unmo3 = mpt::Library(mpt::LibraryPath::App(MPT_PATHSTRING("unmo3")));
if(!unmo3.IsValid())
{
// Didn't succeed.
AddToLog(GetStrI18N("Loading MO3 file failed because unmo3.dll could not be loaded."));
} else
{
// Library loaded successfully.
#if MPT_OS_WINDOWS
#define UNMO3_API __stdcall
#else
#define UNMO3_API
#endif
typedef uint32 (UNMO3_API * UNMO3_GETVERSION)();
// Decode a MO3 file (returns the same "exit codes" as UNMO3.EXE, eg. 0=success)
// IN: data/len = MO3 data/len
// OUT: data/len = decoded data/len (if successful)
// flags & 1: Don't load samples
typedef int32 (UNMO3_API * UNMO3_DECODE_OLD)(const void **data, uint32 *len);
typedef int32 (UNMO3_API * UNMO3_DECODE)(const void **data, uint32 *len, uint32 flags);
// Free the data returned by UNMO3_Decode
typedef void (UNMO3_API * UNMO3_FREE)(const void *data);
#undef UNMO3_API
UNMO3_GETVERSION UNMO3_GetVersion = nullptr;
UNMO3_DECODE_OLD UNMO3_Decode_Old = nullptr;
UNMO3_DECODE UNMO3_Decode = nullptr;
UNMO3_FREE UNMO3_Free = nullptr;
unmo3.Bind(UNMO3_GetVersion, "UNMO3_GetVersion");
if(UNMO3_GetVersion == nullptr)
{
// Old API version: No "flags" parameter.
unmo3.Bind(UNMO3_Decode_Old, "UNMO3_Decode");
} else
{
unmo3.Bind(UNMO3_Decode, "UNMO3_Decode");
}
unmo3.Bind(UNMO3_Free, "UNMO3_Free");
if((UNMO3_Decode != nullptr || UNMO3_Decode_Old != nullptr) && UNMO3_Free != nullptr)
{
file.Rewind();
const void *stream = file.GetRawData();
uint32 length = mpt::saturate_cast<uint32>(file.GetLength());
int32 unmo3result;
if(UNMO3_Decode != nullptr)
{
unmo3result = UNMO3_Decode(&stream, &length, (loadFlags & loadSampleData) ? 0 : 1);
} else
{
// Old API version: No "flags" parameter.
unmo3result = UNMO3_Decode_Old(&stream, &length);
}
if(unmo3result == 0)
{
// If decoding was successful, stream and length will keep the new pointers now.
FileReader unpackedFile(stream, length);
result = ReadXM(unpackedFile, loadFlags)
|| ReadIT(unpackedFile, loadFlags)
|| ReadS3M(unpackedFile, loadFlags)
|| ReadMTM(unpackedFile, loadFlags)
|| ReadMod(unpackedFile, loadFlags)
|| ReadM15(unpackedFile, loadFlags);
//.........这里部分代码省略.........