Exemple #1
0
MR_UInt8 *LoadBitmap(const char *lFileName, int &pXRes, int &pYRes, bool pReverse)
{
	MR_UInt8 *lReturnValue = NULL;

	FILE *lFile = fopen(lFileName, "rb");

	if(lFile == NULL) {
		std::cerr << _("ERROR") << ": " << _("Unable to open input file") <<
			std::endl;
	}
	else {
		const char *lExtension = strrchr(lFileName, '.');

		try {
			if(!_stricmp(lExtension, ".PCX")) {
				lReturnValue = PCXRead(lFile, pXRes, pYRes);
			}
			else if(!_stricmp(lExtension, ".BMP")) {
				lReturnValue = BMPRead(lFile, pXRes, pYRes);
			}
			else if(!_stricmp(lExtension, ".IMG")) {
				lReturnValue = IMGRead(lFile, pXRes, pYRes);
			}
			else {
				std::cerr << _("ERROR") << ": " <<  _("Invalid file type") <<
					std::endl;
			}
		}
		catch (...) {
			fclose(lFile);
			throw;
		}

		fclose(lFile);
	}

	if((lReturnValue != NULL) && pReverse) {
		// Make the invertion of the image pixels
		MR_UInt8 *lOldBuffer = lReturnValue;

		lReturnValue = new MR_UInt8[pXRes * pYRes];

		int lDestIndex = 0;

		for(int lX = 0; lX < pXRes; lX++) {
			MR_UInt8 *lSource = lOldBuffer + lX;

			for(int lY = 0; lY < pYRes; lY++) {
				lReturnValue[lDestIndex] = *lSource;
				lSource += pXRes;
				lDestIndex++;
			}
		}
		delete lOldBuffer;
	}

	return lReturnValue;
}
MR_UInt8 *TrackCompiler::LoadBitmap(FILE * pFile)
{
	MR_UInt8 *lReturnValue = NULL;

	int pXRes;
	int pYRes;

	lReturnValue = PCXRead(pFile, pXRes, pYRes);

	if(lReturnValue) {
		if((pXRes != MR_BACK_X_RES) || (pYRes != MR_BACK_Y_RES)) {
			throw TrackCompileExn(_("Incorrect background resolution"));
		}
	}

	if(lReturnValue != NULL) {
		// Make the invertion of the image pixels and add the pixel offset
		MR_UInt8 *lOldBuffer = lReturnValue;

		lReturnValue = new MR_UInt8[pXRes * pYRes];

		int lDestIndex = 0;

		for(int lX = 0; lX < pXRes; lX++) {
			MR_UInt8 *lSource = lOldBuffer + lX;

			for(int lY = pYRes - 1; lY >= 0; lY--) {
				if(*lSource >= 128) {
					// To correct a bug of Paint Shop Pro
					*lSource = 0;
				}
				lReturnValue[lDestIndex + lY] = (*lSource) + MR_RESERVED_COLORS_BEGINNING + MR_BASIC_COLORS;
				lSource += pXRes;
			}
			lDestIndex += pYRes;
		}
		delete lOldBuffer;
	}
	return lReturnValue;
}