/* * Custom widget Demo * * * File : img2res.cpp * Purpose : Convert severals GIF images into a C++ resource file * Author : JLV * Creation : 10/19/04 * Last Update : 11/01/04 * * (C) hexaZen 2004 * * This file is part of a demo application for Zinzala. It can be * used, distributed and modified without limitation. * */ #include #include #include #include #include #include using namespace zSDK::Cincinella; using namespace zSDK::Farfalla; /* * Method : LoadBitmap * Purpose : Load a given image * Inputs : * * const tChar *aFilename, filename of the image to load * * Output : PhImage_t *, NULL if failed * Side Effects : none */ cBitmap *LoadBitmap(const tChar *aFilename) { PhImage_t* lImage = NULL; PiLoadInfo_t lInfo; PiIoHandler_t* lHandler; const tChar* lExt; tUint16 lPos; // extract extension of the image if(sStrTools::FindLast(aFilename,'.',&lPos)) { // get the handler for the image format lExt = &aFilename[lPos+1]; lHandler = PiIoGetHandlerByExt(lExt); if(lHandler) { memset(&lInfo,NULL,sizeof(PiLoadInfo_t)); lInfo.flags = Pi_IO_SHMEM; lInfo.shmem_threshold = 100; lInfo.handler = lHandler; lInfo.filename = aFilename; // load the image lImage = PiLoadImage(&lInfo); if(lImage) { cBitmap* lBitmap; // create a cBitmap and return it lBitmap = new cBitmap(lImage); if(!cBitmap::VerifyD(lBitmap)) return lBitmap; else return NULL; } else return NULL; } else return NULL; } else return NULL; } /* * Function : DumpBitmapToFile * Purpose : Dump a given bitmap into a .CPP & .H * Inputs : * * cFile &aHeader, open header file * cFile &aCode, open code file * cBitmap *aBitmap, bitmap to dump in the files * tColor *aPalette, bitmap's palette of colors * tUint16 aColors, number of colors in the palette * const tChar *aName, resource name to be used for this bitmap * * Output : none * Side Effects : none */ void DumpBitmapToFile(cFile &aHeader,cFile &aCode,cBitmap *aBitmap,tColor *aPalette, tUint16 aColors,const char *aName) { tUint16 lWidth,lHeight; tUint8 lIndex; tUint32 lLength; tUint8* lBits; PgColor_t lColor; aBitmap->GetTransparent(lIndex); aBitmap->GetSize(lWidth,lHeight); lLength = aBitmap->BitsLength(); lBits = aBitmap->GetBits(); aHeader.Write("extern const tBitmapResource kRscBitmap%s;\n\n",aName); aCode.Write("tUint8 kBitmap%sBits [] = {\n\n\t",aName); for(tUint16 k=0;k (