diff -r 000000000000 -r 5d03bc08d59c graphicstools/gdi_tools/bmconv/MAINFUNC.CPP --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graphicstools/gdi_tools/bmconv/MAINFUNC.CPP Tue Feb 02 01:47:50 2010 +0200 @@ -0,0 +1,532 @@ +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#if defined(__MSVCDOTNET__) || defined(__TOOLS2__) +#include +#include +using namespace std; +#else //!__MSVCDOTNET__ && !__TOOLS2__ +#include +#endif //__MSVCDOTNET__ + +#include "TOOLSVER.H" +#include "BMCONV.H" +#include +#include +#include + + +/** +Returns an informative error message, the result of the program actions performed. +@return Informative error string +@param aErrorNumber The error returned from the actions performed +@param aDestfile The multiple bitmap store file name +@param aDestCreated True if the multiple bitmap store has been created/modified +*/ + +char* ErrorMessage(int aErrorNumber, char* aDestfile=NULL, bool aDestCreated=false) + { + // Remove the multiple bitmap store if it has been created/modified during an fstream session and there has been an error + if(aDestfile && (aErrorNumber != NoError) && (aDestCreated == true)) + { + remove(aDestfile); + } + + switch(aErrorNumber) + { + case NoError: + return "Success."; + case NoMemory: + return "Out of memory."; + case Arg: + return "Bad argument."; + case Files: + return "File does not exist"; + case SourceFile: + return "Bad source file(s)."; + case DestFile: + return "Bad destination file(s)."; + case CommandFile: + return "Bad command file."; + case OutOfRange: + return "Number of sources/targets mismatch."; + case TooManyArgs: + return "Too many arguments."; + case UnknownCompression: + return "Unknown source compression type."; + case CompressionError: + return "Compression error."; + case DecompressionError: + return "Decompression error."; + case Bpp: + return "Invalid bitmap mode specified."; + case PaletteFile: + return "Bad palette file."; + case PaletteSupportNotImplemented: + return "Palettes not supported"; + case AlphaFiles: + return "Alpha bitmap file does not exist"; + case AlphaDimensions: + return "Alpha channel bitmap's dimensions don't match pixel bitmap's dimensions."; + case AlphaBpp: + return "Alpha channel bitmap must be 8bpp."; + default: + return "Unknown error!"; + }; + } + +void Header() + { + cout << "\n"; + cout << "\n"; + cout << "BMCONV version "<< version << ".\n"; + } + +void Report(int aError) + { + Header(); + cout << ErrorMessage(aError) << "\n"; + } + +/** +Compiliation information to print to the user at the end of the program. +@param aQuiet Flag if the user selected quiet output mode +@param aError The error returned from the actions performed +@param aType The multiple bitmap store type created +@param aDestfile The multiple bitmap store file name +@param aBitmapFiles The array of bitmaps used +@param aNumFiles The amount of bitmaps used +@param aDestCreated True if the multiple bitmap store has been created/modified +*/ + +void CompilationReport(int aQuiet,int aError,TStoreType aType,char* aDestfile,char** aBitmapFiles,int aNumFiles, bool aDestCreated) + { + if(!aQuiet || aError) + { + Header(); + cout << "Compiling...\n"; + if(aType!=ENoStore) + cout << "Multiple bitmap store type: "; + if(aType==EFileStore) + cout << "File store" << "\n"; + else if(aType==ERomStore) + cout << "ROM image store" << "\n"; + else if(aType==ECompressedRomStore) + cout << "Compressed ROM image store" << "\n"; + if(aDestfile!=NULL) + cout << "Epoc file: " << aDestfile << "\n\n"; + for(int count=0;count=4 || aArgc==2) + { + for(int count=2;count 0) + { + BitmapCompiler mp(&aArgPtrs[firstsource],numsources); + ret = mp.Compile(storeType,compression,destfilename,headerfilename,palettefilename); + aDestCreated = true; // The multiple bitmap store has been created/modified + } + + CompilationReport(quiet,ret,storeType,destfilename,&aArgPtrs[firstsource],aNumArgs-firstsource,aDestCreated); + + return ret; + } + +void GetInfo(char* aSourceFile) + { + Header(); + + EpocLoader pl; + int numSources=-1; + int romFormat=0; + int ret = pl.EpocBitmapCount(aSourceFile, numSources, romFormat); + if (ret) + { + cout << "Problem reading number of bitmaps \n"; + cout << ErrorMessage(ret) << "\n"; + return; + } + + cout << aSourceFile << " is a " << (romFormat? "ROM image":"File store") + << " containing " << numSources << ((numSources==1)? " bitmap\n":" bitmaps\n"); + + for (int count = 0;count 0) + cout << "Palette entries " << h.iPaletteEntries; + + int byteSize = BitmapUtils::ByteWidth(h.iWidthInPixels,h.iBitsPerPixel) * h.iHeightInPixels; + int compressionRatio = 0; + if (byteSize > 0) + compressionRatio = (h.iBitmapSize - sizeof(SEpocBitmapHeader)) * 100 / byteSize; + + switch (h.iCompression) + { + case ENoBitmapCompression: + cout << "No compression\n"; + break; + case EByteRLECompression: + cout << "Bytewise RLE compression " << compressionRatio << "%\n"; + break; + case ETwelveBitRLECompression: + cout << "12 bit RLE compression " << compressionRatio << "%\n"; + break; + case ESixteenBitRLECompression: + cout << "16 bit RLE compression " << compressionRatio << "%\n"; + break; + case ETwentyFourBitRLECompression: + cout << "24 bit RLE compression " << compressionRatio << "%\n"; + break; + case EThirtyTwoUBitRLECompression: + cout << "unsigned 32 bit RLE compression (no alpha channel) " << compressionRatio << "%\n"; + break; + case EThirtyTwoABitRLECompression: + cout << "unsigned 32 bit RLE compression (with alpha channel) " << compressionRatio << "%\n"; + break; + // case ERLECompressionLast: // Added to supress unhandled switch warning + default: + break; + } + } + } + + cout << "\n"; + } + +class TAutoPtr + { +public: + TAutoPtr(char** aPtr) : + iPtr(aPtr) + { + } + ~TAutoPtr() + { + delete iPtr; + } +private: + char** iPtr; + }; + +int main(int argc,char* argv[],char* []) + { + if (argc <= 1) + { + Usage(); + return 0; + } + + int optMaxCnt = argc; + + if(argc==2) // The single argument must be a command file name + { + struct stat fileinfo; + if (stat(argv[1],&fileinfo)==-1) + { + Report(CommandFile); + return 0; + } + optMaxCnt = fileinfo.st_size; + } + + char** argptrs = new char*[optMaxCnt]; + if(!argptrs) + { + Report(NoMemory); + return 0; + } + TAutoPtr autoPtr(argptrs); + memset(argptrs, 0, optMaxCnt * sizeof(char*)); + + int numargs = 0; + if(argc>2) // Explicit arguments are present + { + for(int count=0;count