diff -r 000000000000 -r f453ebb75370 gfxconversion/bmconv_s60/src/MAINFUNC.CPP --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfxconversion/bmconv_s60/src/MAINFUNC.CPP Tue Feb 02 01:11:11 2010 +0200 @@ -0,0 +1,652 @@ +/* +* Copyright (c) 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__) || defined(__CW32__) +#include +#include +using namespace std; +#else //!__MSVCDOTNET__ && !__TOOLS2__ && !__CW32__ +#pragma warning(disable: 4100) +#pragma warning(disable: 4511) +#pragma warning(disable: 4512) +#pragma warning(disable: 4530) +#pragma warning(disable: 4663) +#pragma warning(disable: 4710) +#pragma warning(disable: 4786) +#pragma warning(disable: 4800) +#include +#endif //__MSVCDOTNET__ + +#include "TOOLSVER.H" +#include "BMCONV.H" +#include +#include +#include +#include + +const int KMaxPaletteFileLen = 256; + +#ifdef __linux__ +const char* DefaultPaletteFileSearchLocations[] = +{ + "/epoc32/include/mw/ThirdPartyBitmap.pal", + "/epoc32/include/middleware/ThirdPartyBitmap.pal", + "/epoc32/include/ThirdPartyBitmap.pal" +}; +#else +const char* DefaultPaletteFileSearchLocations[] = +{ + "\\epoc32\\include\\mw\\ThirdPartyBitmap.pal", + "\\epoc32\\include\\middleware\\ThirdPartyBitmap.pal", + "\\epoc32\\include\\ThirdPartyBitmap.pal" +}; +#endif + +/** +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 S60 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,TSourceFile* 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 && epocroot[rootLen-1] == '\\') + { + aBuf = std::string(epocroot, rootLen-1); + } + else if( rootLen > 0 ) + { + aBuf = std::string(epocroot); + } + } + } + aBuf += aName; + return aBuf.c_str(); + } + +bool FileExists( const char* aFileName ) +{ + struct stat fileInfo; + int retVal = 0; + + // Try to get file attributes to see if the file exists or not: + retVal = stat( aFileName, &fileInfo); + return retVal == 0; +} + +const char* DefaultPaletteFileName(std::string& aBuf) + { + const char* palettefilename = NULL; + int numOfSearchLocations = sizeof(DefaultPaletteFileSearchLocations)/sizeof(char*); + + for( int i = 0; i < numOfSearchLocations; ++i ) + { + palettefilename = AddEpocRootTo(aBuf, DefaultPaletteFileSearchLocations[i]); + if( FileExists( palettefilename)) + { + return palettefilename; + } + } + + return NULL; + } + +int Compile(int aNumArgs,int aArgArraySize, char** aArgPtrs) + { + TStoreType storeType = EFileStore; + int compression = 1; + int quiet = 0; + char* headerfilename = NULL; + char paletteBuf[KMaxPaletteFileLen]; + memset(paletteBuf, 0, KMaxPaletteFileLen); + std::string paletteStr; + const char* defaultPalettefile = DefaultPaletteFileName(paletteStr); + char* palettefilename = NULL; + char* destfilename = NULL; + int ret = OutOfRange; + bool aDestCreated = false; + + for(int argnum=0;argnum 0) + { + sources = new TSourceFile[numsources]; + for (int ii=0; ii 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