本文整理汇总了C++中common::DumpFile::write方法的典型用法代码示例。如果您正苦于以下问题:C++ DumpFile::write方法的具体用法?C++ DumpFile::write怎么用?C++ DumpFile::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::DumpFile
的用法示例。
在下文中一共展示了DumpFile::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: packData
void MadsM4Engine::dumpFile(const char* filename, bool uncompress) {
Common::DumpFile f;
byte buffer[DUMP_BUFFER_SIZE];
Common::SeekableReadStream *fileS = res()->get(filename);
if (!f.open(filename))
error("Could not open '%s' for writing", filename);
int bytesRead = 0;
warning("Dumping %s, size: %i\n", filename, fileS->size());
if (!uncompress) {
while (!fileS->eos()) {
bytesRead = fileS->read(buffer, DUMP_BUFFER_SIZE);
f.write(buffer, bytesRead);
}
} else {
MadsPack packData(fileS);
Common::SeekableReadStream *sourceUnc;
for (int i = 0; i < packData.getCount(); i++) {
sourceUnc = packData.getItemStream(i);
debugCN(kDebugCore, "Dumping compressed chunk %i of %i, size is %i\n", i + 1, packData.getCount(), sourceUnc->size());
while (!sourceUnc->eos()) {
bytesRead = sourceUnc->read(buffer, DUMP_BUFFER_SIZE);
f.write(buffer, bytesRead);
}
delete sourceUnc;
}
}
f.close();
res()->toss(filename);
res()->purge();
}
示例2: dumpBMP
void dumpBMP(const char *filename, int16 w, int16 h, const byte *bytes, const uint32 *palette) {
Common::DumpFile out;
byte my_hdr[sizeof(bmp_hdr)];
int i;
out.open(filename);
if (!out.isOpen())
return;
memcpy(my_hdr, bmp_hdr, sizeof(bmp_hdr));
*(uint32 *)(my_hdr + 2) = w * h + 1024 + sizeof(bmp_hdr);
*(uint32 *)(my_hdr + 18) = w;
*(uint32 *)(my_hdr + 22) = h;
out.write(my_hdr, sizeof(my_hdr));
for (i = 0; i != 256; i++, palette++) {
byte color[4];
color[0] = (byte)(*palette >> 16);
color[1] = (byte)(*palette >> 8);
color[2] = (byte)(*palette);
color[3] = 0;
out.write(color, 4);
}
while (--h >= 0) {
out.write(bytes + h * ((w + 3) & ~3), ((w + 3) & ~3));
}
}
示例3: writeBMP
static bool writeBMP(const Common::UString &filename, const byte *data,
int width, int height) {
if ((width <= 0) || (height <= 0) || !data)
return false;
Common::DumpFile file;
if (!file.open(filename))
return false;
// The pitch of the output has to be divisible by 4, so
// we output zeroes to make the pitch that far.
int extraDataSize = width & 3;
int imageSize = height * (width + extraDataSize) * 3;
// Main bitmap header
file.writeByte('B');
file.writeByte('M');
file.writeUint32LE(14 + 40 + imageSize); // Size
file.writeUint32LE(0); // reserved
file.writeUint32LE(14 + 40); // Image offset after both headers
// v3 header
file.writeUint32LE(40);
file.writeUint32LE(width);
file.writeUint32LE(height);
file.writeUint16LE(1);
file.writeUint16LE(24);
file.writeUint32LE(0);
file.writeUint32LE(imageSize);
file.writeUint32LE(72);
file.writeUint32LE(72);
file.writeUint32LE(0);
file.writeUint32LE(0);
if (extraDataSize != 0) {
// Dump, making sure the pitch is correct
while (height--) {
file.write(data, width * 3);
// Ensure we're on a 4-byte boundary
for (int i = 0; i < extraDataSize; i++)
file.writeByte(0);
data += width * 3;
}
} else {
// Dump directly (can do all at once here because the data
// is already good for BMP output)
file.write(data, width * height * 3);
}
if (!file.flush() || file.err())
return false;
file.close();
return true;
}
示例4: cacheFontData
bool BdfFont::cacheFontData(const BdfFont &font, const Common::String &filename) {
Common::DumpFile cacheFile;
if (!cacheFile.open(filename)) {
warning("BdfFont::cacheFontData: Couldn't open file '%s' for writing", filename.c_str());
return false;
}
const BdfFontData &data = font._data;
cacheFile.writeUint32BE(BDF_FONTCACHE_TAG);
cacheFile.writeUint32BE(BDF_FONTCACHE_VERSION);
cacheFile.writeUint16BE(data.maxAdvance);
cacheFile.writeByte(data.height);
cacheFile.writeByte(data.defaultBox.width);
cacheFile.writeByte(data.defaultBox.height);
cacheFile.writeSByte(data.defaultBox.xOffset);
cacheFile.writeSByte(data.defaultBox.yOffset);
cacheFile.writeByte(data.ascent);
cacheFile.writeUint16BE(data.firstCharacter);
cacheFile.writeSint16BE(data.defaultCharacter);
cacheFile.writeUint16BE(data.numCharacters);
for (int i = 0; i < data.numCharacters; ++i) {
const BdfBoundingBox &box = data.boxes ? data.boxes[i] : data.defaultBox;
if (data.bitmaps[i]) {
const int bytes = ((box.width + 7) / 8) * box.height;
cacheFile.writeUint32BE(bytes);
cacheFile.write(data.bitmaps[i], bytes);
} else {
cacheFile.writeUint32BE(0);
}
}
if (data.advances) {
cacheFile.writeByte(0xFF);
cacheFile.write(data.advances, data.numCharacters);
} else {
cacheFile.writeByte(0x00);
}
if (data.boxes) {
cacheFile.writeByte(0xFF);
for (int i = 0; i < data.numCharacters; ++i) {
const BdfBoundingBox &box = data.boxes[i];
cacheFile.writeByte(box.width);
cacheFile.writeByte(box.height);
cacheFile.writeSByte(box.xOffset);
cacheFile.writeSByte(box.yOffset);
}
} else {
cacheFile.writeByte(0x00);
}
return !cacheFile.err();
}
示例5: ExtractCdf
void GagEngine::ExtractCdf(const Common::String &a_fn)
{
CdfArchive archive(a_fn, true);
uint pos = a_fn.size();
for(uint i = 0; i < a_fn.size(); ++i)
{
if(a_fn[i] == '.')
pos = i;
}
//TODO: figure out how to create directory
Common::String dn(ConfMan.get("path") + '/' + Common::String(a_fn.c_str(), pos) + '/');
Common::ArchiveMemberList member_list;
archive.listMembers(member_list);
for(Common::ArchiveMemberList::iterator it = member_list.begin(); it != member_list.end(); ++it)
{
Common::ScopedPtr<Common::SeekableReadStream> stream((*it)->createReadStream());
if(stream)
{
uint8 *buffer = new uint8[stream->size()];
stream->read(buffer, stream->size());
Common::DumpFile file;
if(file.open(dn + (*it)->getName()))
file.write(buffer, stream->size());
delete [] buffer;
}
}
}
示例6: cmdDumpFile
bool Debugger::cmdDumpFile(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Format: dumpfile <resource name>\n");
return true;
}
Common::SeekableReadStream *s = _vm->_res->load(argv[1]);
if (!s) {
debugPrintf("Invalid resource.\n");
return true;
}
byte *buffer = new byte[s->size()];
s->read(buffer, s->size());
Common::DumpFile dumpFile;
dumpFile.open(argv[1]);
dumpFile.write(buffer, s->size());
dumpFile.flush();
dumpFile.close();
delete[] buffer;
debugPrintf("Resource %s has been dumped to disk.\n", argv[1]);
return true;
}
示例7: Cmd_DumpFile
bool Console::Cmd_DumpFile(int argc, const char **argv) {
if (argc != 3) {
debugPrintf("Usage: %s <file path> <output file name>\n", argv[0]);
return true;
}
Common::String filePath = argv[1];
Common::String outFileName = argv[2];
BaseFileManager *fileManager = BaseEngine::instance().getFileManager();
Common::SeekableReadStream *inFile = fileManager->openFile(filePath);
if (!inFile) {
debugPrintf("File '%s' not found\n", argv[1]);
return true;
}
Common::DumpFile *outFile = new Common::DumpFile();
outFile->open(outFileName);
byte *data = new byte[inFile->size()];
inFile->read(data, inFile->size());
outFile->write(data, inFile->size());
outFile->finalize();
outFile->close();
delete[] data;
delete outFile;
delete inFile;
debugPrintf("Resource file '%s' dumped to file '%s'\n", argv[1], argv[2]);
return true;
}
示例8: dumpMusic
// Dumps all of the game's music in external XMIDI *.xmi files
void dumpMusic() {
Common::File midiFile;
Common::DumpFile outFile;
char outName[20];
midiFile.open(MIDI_FILE);
int outFileSize = 0;
char buffer[20000];
const int total = 155; // maximum (SCN version)
for (int i = 0; i < total; i++) {
if (midiOffsets[i] == 0)
break;
sprintf(outName, "track%03d.xmi", i + 1);
outFile.open(outName);
if (i < total - 1)
outFileSize = midiOffsets[i + 1] - midiOffsets[i] - 4;
else
outFileSize = midiFile.size() - midiOffsets[i] - 4;
midiFile.seek(midiOffsets[i] + 4, SEEK_SET);
assert(outFileSize < 20000);
midiFile.read(buffer, outFileSize);
outFile.write(buffer, outFileSize);
outFile.close();
}
midiFile.close();
}
示例9: cmdDumpImage
bool Console::cmdDumpImage(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Use %s <TGA/TGZ name> to dump a Z-Vision TGA/TGZ image into a regular BMP image\n", argv[0]);
return true;
}
Common::String fileName = argv[1];
if (!fileName.hasSuffix(".tga")) {
debugPrintf("%s is not an image file", argv[1]);
}
Common::File f;
if (!_engine->getSearchManager()->openFile(f, argv[1])) {
warning("File not found: %s", argv[1]);
return true;
}
Graphics::Surface surface;
_engine->getRenderManager()->readImageToSurface(argv[1], surface, false);
// Open file
Common::DumpFile out;
fileName.setChar('b', fileName.size() - 3);
fileName.setChar('m', fileName.size() - 2);
fileName.setChar('p', fileName.size() - 1);
out.open(fileName);
// Write BMP header
out.writeByte('B');
out.writeByte('M');
out.writeUint32LE(surface.h * surface.pitch + 54);
out.writeUint32LE(0);
out.writeUint32LE(54);
out.writeUint32LE(40);
out.writeUint32LE(surface.w);
out.writeUint32LE(surface.h);
out.writeUint16LE(1);
out.writeUint16LE(16);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
// Write pixel data to BMP
out.write(surface.getPixels(), surface.pitch * surface.h);
out.flush();
out.close();
surface.free();
return true;
}
示例10: saveScreenshot
void OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const {
const uint width = _outputScreenWidth;
const uint height = _outputScreenHeight;
// A line of a BMP image must have a size divisible by 4.
// We calculate the padding bytes needed here.
// Since we use a 3 byte per pixel mode, we can use width % 4 here, since
// it is equal to 4 - (width * 3) % 4. (4 - (width * Bpp) % 4, is the
// usual way of computing the padding bytes required).
const uint linePaddingSize = width % 4;
const uint lineSize = width * 3 + linePaddingSize;
// Allocate memory for screenshot
uint8 *pixels = new uint8[lineSize * height];
// Get pixel data from OpenGL buffer
GLCALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels));
// BMP stores as BGR. Since we can't assume that GL_BGR is supported we
// will swap the components from the RGB we read to BGR on our own.
for (uint y = height; y-- > 0;) {
uint8 *line = pixels + y * lineSize;
for (uint x = width; x > 0; --x, line += 3) {
SWAP(line[0], line[2]);
}
}
// Open file
Common::DumpFile out;
out.open(filename);
// Write BMP header
out.writeByte('B');
out.writeByte('M');
out.writeUint32LE(height * lineSize + 54);
out.writeUint32LE(0);
out.writeUint32LE(54);
out.writeUint32LE(40);
out.writeUint32LE(width);
out.writeUint32LE(height);
out.writeUint16LE(1);
out.writeUint16LE(24);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
out.writeUint32LE(0);
// Write pixel data to BMP
out.write(pixels, lineSize * height);
// Free allocated memory
delete[] pixels;
}
示例11: dumpFaceMask
bool Node::dumpFaceMask(uint16 index, int face, DirectorySubEntry::ResourceType type) {
static const int32 kMaskSize = 640 * 640;
byte *mask = new byte[kMaskSize];
memset(mask, 0, kMaskSize);
uint32 headerOffset = 0;
uint32 dataOffset = 0;
const DirectorySubEntry *maskDesc = _vm->getFileDescription(0, index, face, type);
if (!maskDesc) {
delete[] mask;
return false;
}
Common::MemoryReadStream *maskStream = maskDesc->getData();
while (headerOffset < 400) {
int blockX = (headerOffset / sizeof(dataOffset)) % 10;
int blockY = (headerOffset / sizeof(dataOffset)) / 10;
maskStream->seek(headerOffset, SEEK_SET);
dataOffset = maskStream->readUint32LE();
headerOffset = maskStream->pos();
if (dataOffset != 0) {
maskStream->seek(dataOffset, SEEK_SET);
for(int i = 63; i >= 0; i--) {
int x = 0;
byte numValues = maskStream->readByte();
for (int j = 0; j < numValues; j++) {
byte repeat = maskStream->readByte();
byte value = maskStream->readByte();
for (int k = 0; k < repeat; k++) {
mask[((blockY * 64) + i) * 640 + blockX * 64 + x] = value;
x++;
}
}
}
}
}
delete maskStream;
Common::DumpFile outFile;
outFile.open(Common::String::format("dump/%d-%d.masku_%d", index, face, type));
outFile.write(mask, kMaskSize);
outFile.close();
delete[] mask;
return true;
}
示例12: dumpFile
void dumpFile(Common::SeekableReadStream *s, const char *outName) {
byte *buffer = new byte[s->size()];
s->read(buffer, s->size());
Common::DumpFile dumpFile;
dumpFile.open(outName);
dumpFile.write(buffer, s->size());
dumpFile.flush();
dumpFile.close();
delete[] buffer;
}
示例13: Cmd_DumpFile
bool Debugger::Cmd_DumpFile(int argc, const char **argv) {
if (argc < 2) {
debugPrintf("Usage: %s <resource> <unpack>\n", argv[0]);
debugPrintf(" resource: the resource name\n");
debugPrintf(" unpack: optional, when specified, the FAB/MADSPACK compressed resource is unpacked\n");
} else {
Common::DumpFile outFile;
Common::File inFile;
if (!inFile.open(argv[1])) {
debugPrintf("Specified resource does not exist\n");
} else {
outFile.open(argv[1]);
bool unpack = ((argc >= 3) && !scumm_stricmp(argv[2], "unpack"));
byte *data;
int totalSize = 0;
if (!unpack) {
totalSize = inFile.size();
data = new byte[totalSize];
inFile.read(data, totalSize);
} else {
MadsPack dataPack(&inFile);
int count = dataPack.getCount();
for (int i = 0; i < count; i++) {
totalSize += dataPack.getItem(i)._size;
}
data = new byte[totalSize];
byte *ptr = data;
for (int i = 0; i < count; i++) {
Common::SeekableReadStream *readStream = dataPack.getItemStream(i);
readStream->read(ptr, readStream->size());
ptr += readStream->size();
}
}
outFile.write(data, totalSize);
outFile.flush();
delete[] data;
inFile.close();
outFile.close();
debugPrintf("File written successfully.\n");
}
}
return true;
}
示例14: dumpRes
void ResMan::dumpRes(uint32 id) {
char outn[30];
sprintf(outn, "DUMP%08X.BIN", id);
Common::DumpFile outf;
if (outf.open(outn)) {
resOpen(id);
MemHandle *memHandle = resHandle(id);
if (memHandle) {
outf.write(memHandle->data, memHandle->size);
outf.close();
}
resClose(id);
}
}
示例15: cmdRawToWav
bool Console::cmdRawToWav(int argc, const char **argv) {
if (argc != 3) {
debugPrintf("Use %s <rawFilePath> <wavFileName> to dump a .RAW file to .WAV\n", argv[0]);
return true;
}
Common::File file;
if (!_engine->getSearchManager()->openFile(file, argv[1])) {
warning("File not found: %s", argv[1]);
return true;
}
Audio::AudioStream *audioStream = makeRawZorkStream(argv[1], _engine);
Common::DumpFile output;
output.open(argv[2]);
output.writeUint32BE(MKTAG('R', 'I', 'F', 'F'));
output.writeUint32LE(file.size() * 2 + 36);
output.writeUint32BE(MKTAG('W', 'A', 'V', 'E'));
output.writeUint32BE(MKTAG('f', 'm', 't', ' '));
output.writeUint32LE(16);
output.writeUint16LE(1);
uint16 numChannels;
if (audioStream->isStereo()) {
numChannels = 2;
output.writeUint16LE(2);
} else {
numChannels = 1;
output.writeUint16LE(1);
}
output.writeUint32LE(audioStream->getRate());
output.writeUint32LE(audioStream->getRate() * numChannels * 2);
output.writeUint16LE(numChannels * 2);
output.writeUint16LE(16);
output.writeUint32BE(MKTAG('d', 'a', 't', 'a'));
output.writeUint32LE(file.size() * 2);
int16 *buffer = new int16[file.size()];
audioStream->readBuffer(buffer, file.size());
#ifndef SCUMM_LITTLE_ENDIAN
for (int i = 0; i < file.size(); ++i)
buffer[i] = TO_LE_16(buffer[i]);
#endif
output.write(buffer, file.size() * 2);
delete[] buffer;
return true;
}