Ejemplo n.º 1
0
void ResContinuousSound::Serialize(Parcel::ObjStream &pArchive)
{
	if(pArchive.IsWriting()) {
		pArchive << mNbCopy;
		pArchive << mDataLen;
		pArchive.Write(mData, mDataLen);

	}
	else {
		SoundServer::DeleteContinuousSound(mSound);
		mSound = NULL;

		delete[]mData;
		mData = NULL;

		pArchive >> mNbCopy;
		pArchive >> mDataLen;

		mData = new char[mDataLen];

		pArchive.Read(mData, mDataLen);

		mSound = SoundServer::CreateContinuousSound(mData, mNbCopy);

	}
}
Ejemplo n.º 2
0
void TrackCompiler::AddBackgroundImage(std::istream &in, Parcel::ObjStream &archive)
{
	TrackSpecParser parser(in);

	if(parser.GetNextClass("HEADER") == NULL) {
		throw TrackCompileExn(_("Unable to find [HEADER] section"));
	}
	if(!parser.GetNextAttrib("Background")) {
		throw TrackCompileExn(_("Unable to find background image filename"));
	}
	std::string bgFilename = parser.GetParams();

	FILE *bgFile = fopen(bgFilename.c_str(), "rb");
	if (bgFile == NULL) {
		throw TrackCompileExn(boost::str(
			boost::format(_("Unable to find background image: %s")) %
				bgFilename));
	}

	// Extract the palette and image from the input file
	try {
		boost::scoped_array<MR_UInt8> bitmap(LoadBitmap(bgFile));
		boost::scoped_array<MR_UInt8> palette(LoadPalette(bgFile));

		archive << (int) MR_RAWBITMAP;
		archive.Write(palette.get(), MR_BACK_COLORS * 3);
		archive.Write(bitmap.get(), MR_BACK_X_RES * MR_BACK_Y_RES);
	}
	catch (...) {
		fclose(bgFile);
		throw;
	}

	fclose(bgFile);
}
Ejemplo n.º 3
0
void ResBitmap::SubBitmap::Serialize(Parcel::ObjStream &pArchive)
{
	if(pArchive.IsWriting()) {

		pArchive << mXRes;
		pArchive << mYRes;
		pArchive << mXResShiftFactor;
		pArchive << mYResShiftFactor;
		pArchive << mHaveTransparent;

		if (mXRes < 0 || mXRes > MAX_BITMAP_WIDTH ||
			mYRes < 0 || mYRes > MAX_BITMAP_HEIGHT)
		{
			throw Parcel::ObjStreamExn(
				pArchive.GetName(),
				boost::str(boost::format(
					"Writing invalid ResBitmap size: %dx%d") %
						mXRes % mYRes));
		}

		pArchive.Write(mBuffer, static_cast<size_t>(mXRes * mYRes));
	}
	else {
		delete[] mBuffer;
		delete[] mColumnPtr;

		pArchive >> mXRes;
		pArchive >> mYRes;
		pArchive >> mXResShiftFactor;
		pArchive >> mYResShiftFactor;
		pArchive >> mHaveTransparent;

		if (mXRes < 0 || mXRes > MAX_BITMAP_WIDTH ||
			mYRes < 0 || mYRes > MAX_BITMAP_HEIGHT)
		{
			throw Parcel::ObjStreamExn(
				pArchive.GetName(),
				boost::str(boost::format(
					"Writing invalid ResBitmap size: %dx%d") %
						mXRes % mYRes));
		}
		auto sz = static_cast<size_t>(mXRes * mYRes);

		mBuffer = new MR_UInt8[sz];
		mColumnPtr = new MR_UInt8 *[mXRes];

		MR_UInt8 *lPtr = mBuffer;

		for(int lCounter = 0; lCounter < mXRes; lCounter++) {
			mColumnPtr[lCounter] = lPtr;
			lPtr += mYRes;
		}
		pArchive.Read(mBuffer, sz);
	}
}