Exemple #1
0
static void writePixel(Common::WriteFile &file, const byte *&data, PixelFormat format) {
	if (format == kPixelFormatRGB) {
		file.writeByte(data[2]);
		file.writeByte(data[1]);
		file.writeByte(data[0]);
		file.writeByte(0xFF);
		data += 3;
	} else if (format == kPixelFormatBGR) {
		file.writeByte(data[0]);
		file.writeByte(data[1]);
		file.writeByte(data[2]);
		file.writeByte(0xFF);
		data += 3;
	} else if (format == kPixelFormatRGBA) {
		file.writeByte(data[2]);
		file.writeByte(data[1]);
		file.writeByte(data[0]);
		file.writeByte(data[3]);
		data += 4;
	} else if (format == kPixelFormatBGRA) {
		file.writeByte(data[0]);
		file.writeByte(data[1]);
		file.writeByte(data[2]);
		file.writeByte(data[3]);
		data += 4;
	} else
		throw Common::Exception("Unsupported pixel format: %d", (int) format);

}
Exemple #2
0
bool TwoDAFile::writeCSV(const Common::UString &fileName) const {
	Common::WriteFile file;
	if (!file.open(fileName))
		return false;

	writeCSV(file);
	file.close();

	return true;
}
Exemple #3
0
static Common::WriteStream *openTGA(const Common::UString &fileName, int width, int height) {
	Common::WriteFile *file = new Common::WriteFile(fileName);

	file->writeByte(0);     // ID Length
	file->writeByte(0);     // Palette size
	file->writeByte(2);     // Unmapped RGB
	file->writeUint32LE(0); // Color map
	file->writeByte(0);     // Color map
	file->writeUint16LE(0); // X
	file->writeUint16LE(0); // Y

	file->writeUint16LE(width);
	file->writeUint16LE(height);

	file->writeByte(32); // Pixel depths

	file->writeByte(0);

	return file;
}
Exemple #4
0
bool dumpStream(Common::SeekableReadStream &stream, const Common::UString &fileName) {
	Common::WriteFile file;
	if (!file.open(fileName))
		return false;

	size_t pos = stream.pos();
	try {
		stream.seek(0);

		file.writeStream(stream);
		stream.seek(pos);

		file.flush();

	} catch (...) {
		stream.seek(pos);
		return false;
	}

	file.close();
	return true;
}
Exemple #5
0
void dumpTGA(const Common::UString &fileName, const byte *data, int width, int height, PixelFormat format) {
	if ((width <= 0) || (height <= 0) || !data)
		throw Common::Exception("Invalid image data (%dx%d %d)", width, height, data != 0);

	Common::WriteFile file;

	if (!file.open(fileName))
		throw Common::Exception(Common::kOpenError);

	file.writeByte(0); // ID Length
	file.writeByte(0); // Palette size
	file.writeByte(2); // Unmapped RGB
	file.writeUint32LE(0); // Color map
	file.writeByte(0);     // Color map
	file.writeUint16LE(0); // X
	file.writeUint16LE(0); // Y

	file.writeUint16LE(width);
	file.writeUint16LE(height);

	file.writeByte(32); // Pixel depths

	file.writeByte(0);

	uint32 count = width * height;
	for (uint32 i = 0; i < count; i++)
		writePixel(file, data, format);

	file.close();
}