Update of /cvsroot/babylonlib/_SrcPool/Cpp/Samples/Images/Src In directory sc8-pr-cvs1:/tmp/cvs-serv24634/Cpp/Samples/Images/Src Added Files: TestGifViewer.cpp TestBasicBarsBmp.c TestGifConversion.cpp TestGifCreate.cpp ImagesTest.cpp Log Message: Created --- NEW FILE: TestGifViewer.cpp --- /*$Workfile: TestGifViewer.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:14:23 $ $Author: ddarko $ Test of GIF image decoder Mar 2k2 D. Kolakovic */ // Group=Examples #include <iostream> #include <iomanip.h> #include "KGifViewer.h" //CGifViewer class #include "KTrace.h" //TRACE macros #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //TestGifViewer()--------------------------------------------------------------- /*Test of GIF image decoder Returns: true if successful, otherwise returns false */ bool TestGifViewer(char* szImageFileName, int iColors //[in] number of colors in the test image //palette or -1 to skip testing of palette //size ) { cout << "TestGifViewer(" << szImageFileName << ')' <<endl; bool bRes = false; //Create empty GIF object cout << " Read GIF file" << endl; CGifViewer gifImage; if (gifImage.Load(szImageFileName)) { gifImage.Dump(); if (gifImage.HasGlobalColorTable()) { if ( (iColors < 0) || //Skip test (gifImage.GetGlobalColorTable().GetSize() == (uint32)iColors) ) bRes = true; } } cout << endl << "======================" << endl; return bRes; } // Get File Size long GetFileSize(char* pszFile) { long lRes = 0; FILE* fileStream; #ifdef __MSDOS__ #define OPEN_FLAGS "rb" #else #define OPEN_FLAGS "r" #endif if( (fileStream=fopen(pszFile, OPEN_FLAGS)) != NULL ) { fseek(fileStream,0,SEEK_END); //Move pointer to end of file lRes = ftell(fileStream); //Get current file position fclose(fileStream); } return lRes; } //caller deletest the buffer BYTE* Load(char* pszFile) { BYTE* pResult = NULL; long lSize = GetFileSize(pszFile); if (lSize > 0) { FILE* fileStream = fopen(pszFile, "rb"); if (fileStream != NULL) { pResult = new BYTE[lSize]; if(pResult != NULL) { //Copy the filr to the buffer if(fread(pResult, sizeof(BYTE), lSize, fileStream) != (size_t)lSize) { //Failure delete[] pResult; pResult = NULL; perror(pszFile); } } fclose (fileStream); } else perror(pszFile); } return pResult; } //TestGifDecoder()------------------------------------------------------------- /*Test of decoding a GIF image. An image is stored complete in a continuous block in memory. Returns: true if successful, otherwise returns false */ bool TestGifDecoder(char* szImageFileName) { cout << "TestGifDecoder(" << szImageFileName << ')' <<endl; BYTE* pGifStream = Load(szImageFileName); if (pGifStream == NULL) return false; //Failed to open or read the file long lSize = GetFileSize(szImageFileName); CGifViewer gifDecoder; bool bRes = gifDecoder.Decode(pGifStream, lSize); delete pGifStream; //Free allocated memory cout << endl << "======================" << endl; return bRes; } /////////////////////////////////////////////////////////////////////////////// /****************************************************************************** *$Log: * 4 Biblioteka1.3 05/08/2002 10:33:46 AMDarko Fixed bug in * SeekImagePos * 3 Biblioteka1.2 31/07/2002 4:30:21 PMDarko Kolakovic * SeekImageDescriptor inserted * 2 Biblioteka1.1 16/07/2002 7:57:08 PMDarko Kolakovic Added * TestGifCreate() * 1 Biblioteka1.0 16/07/2002 12:48:21 AMDarko *$ *****************************************************************************/ --- NEW FILE: TestBasicBarsBmp.c --- /*$Workfile: TestBasicBarsBmp.c$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:14:23 $ $Author: ddarko $ Microsoft DIB bitmap example June 2k2 D. Kolakovic */ /* Group=Images */ #include "KTypedef.h" //BYTE definition /*Monochrome bitmap that contains black and white horizontal strips. Size of bitmap stream is 142 bytes. Size of the image is 20 by 20 pixels. */ BYTE g_bmpBasicBars[] = { /*BITMAPFILEHEADER 14 bytes */ 0x42, 0x4D, /*bfType 'B','M'. Specifies the type of file */ 0x8E, 0x00, 0x00, 0x00, /*bfSize 142 bytes. Specifies the size of the file */ 0x00, 0x00, /*bfReserved1. Must be set to zero */ 0x00, 0x00, /*bfReserved2. Must be set to zero */ 0x3E, 0x00, 0x00, 0x00, /*bfOffBits 62 bytes Offset to image data bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD[]) */ /*BITMAPINFOHEADER 40 bytes */ 0x28, 0x00, 0x00, 0x00, /*biSize sizeof(BITMAPINFOHEADER) = 40 bytes */ 0x14, 0x00, 0x00, 0x00, /*biWidth 20 pixels. Image width */ 0x14, 0x00, 0x00, 0x00, /*biHeight 20 pixels. Image height */ 0x01, 0x00, /*biPlanes must be set to 1. Number of planes */ 0x01, 0x00, /*biBitCount 1 bit. Number of bits per pixel */ 0x00, 0x00, 0x00, 0x00, /*biCompression 0 = none. Compression type */ 0x50, 0x00, 0x00, 0x00, /*biSizeImage 80 bytes. Size of the image */ 0x13, 0x0B, 0x00, 0x00, /*biXPelsPerMeter 2835 px/m. Horizontal resolution */ 0x13, 0x0B, 0x00, 0x00, /*biYPelsPerMeter 2835 pixel/m. Vertical resolution*/ 0x02, 0x00, 0x00, 0x00, /*biClrUsed 2. Number of colors actually used */ 0x02, 0x00, 0x00, 0x00, /*biClrImportant 2. Number of important colors */ /*RGBQUAD[] 8 bytes. Pallete */ 0x00, 0x00, 0x00, 0x00, /*0. ( 0, 0, 0) black */ 0xFF, 0xFF, 0xFF, 0x00, /*1. (255,255,255) white */ /*BYTE[] 80 bytes. Image data */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00, /*0000 0000 0000 0000 0000 */ 0xFF, 0xFF, 0xF0, 0x00, /*1111 1111 1111 1111 1111 */ 0x00, 0x00, 0x00, 0x00 /*0000 0000 0000 0000 0000 */ }; /* ///////////////////////////////////////////////////////////////////////// */ /*Monochrome bitmap that contains black triangle. Size of bitmap stream is 446 bytes. Size of the image is 48 by 48 pixels. */ BYTE g_bmpDiagonal[] = { /*BITMAPFILEHEADER 14 bytes */ 0x42, 0x4D, 0xBE, 0x01, 0x00, 0x00, //446 bytes 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, //62 bytes 0x28, 0x00, 0x00, 0x00, //40 0x30, 0x00, 0x00, 0x00, //48 0x30, 0x00, 0x00, 0x00, //48 0x01, 0x00, //1 0x01, 0x00, // 1 bits/pixel 0x00, 0x00, 0x00, 0x00, // 0 compression 0x00, 0x00, 0x00, 0x00, //calculate image size 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //black 0xFF, 0xFF, 0xFF, 0x00, //white /*BYTE[] 384 bytes. Image data */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, /* 0. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, /* 1. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, /* 2. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, /* 3. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, /* 4. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, /* 5. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, /* 6. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, /* 7. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, /* 8. */ 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, /* 9. */ 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFF, /*10. */ 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFF, /*11. */ 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFF, /*12. */ 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFF, /*13. */ 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, /*14. */ 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, /*15. */ 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /*16. */ 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, /*17. */ 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, /*18. */ 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, /*19. */ 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, /*20. */ 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, /*21. */ 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0x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FF, 0xFF, 0xFF, 0xFF, /*42. */ 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /*43. */ 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /*44. */ 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /*45. */ 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /*46. */ 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF /*47. */ }; --- NEW FILE: TestGifConversion.cpp --- /*$Workfile: TestGifConversion.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:14:23 $ $Author: ddarko $ Test GIF primitive conversons Mar 2k2 D. Kolakovic */ // Group=Examples #include <iostream> #include <iomanip.h> #include "KProgCst.h" //_ENDIAN_ORDER_ #include "KGif.h" //CGif class #include "KTrace.h" //TRACE macros #if (_ENDIAN_ORDER_ == _ENDIAN_BIG_) #pragma message ("Include Big Endian Swap files") #include "KSwpByte.h" #endif #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //TestGifConversion()--------------------------------------------------------------- /*Test of GIF primitive conversions Returns: true if successful, otherwise returns false */ bool TestGifConversion() { cout << "TestGifConversion()" << endl; bool bRes = false; //Convert CGifColor to RGBQUAD cout << "Convert CGifColor to RGBQUAD" << endl; CGifColor gifColor(0x10, 0x20, 0x30); DWORD dwColorQ = (DWORD)gifColor; if (bRes = (dwColorQ == 0x00102030)) { #if (_ENDIAN_ORDER_ == _ENDIAN_BIG_) dwColorQ = SwapByteOrder(dwColorQ); #endif RGBQUAD* rgbColor = (RGBQUAD*)&dwColorQ; if (bRes = (rgbColor->rgbRed == gifColor.m_cRed)) if (bRes = (rgbColor->rgbBlue == gifColor.m_cBlue)) bRes = (rgbColor->rgbGreen == gifColor.m_cGreen); } cout << endl << "======================" << endl; return bRes; } /////////////////////////////////////////////////////////////////////////////// /****************************************************************************** *$Log: * 2 Biblioteka1.1 05/08/2002 10:33:43 AMDarko Fixed bug in * SeekImagePos * 1 Biblioteka1.0 02/08/2002 9:25:18 PMDarko Kolakovic *$ *****************************************************************************/ --- NEW FILE: TestGifCreate.cpp --- /*$Workfile: TestGifCreate.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:14:23 $ $Author: ddarko $ Test GIF object initialization Mar 2k2 D. Kolakovic */ // Group=Examples #include "KGif.h" //CGif class #include "KTrace.h" //TRACE macros #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //TestGifCreate()--------------------------------------------------------------- /*Test of GIF object initialization Returns: true if successful, otherwise returns false */ bool TestGifCreate() { TRACE0("TestGifCreate()\n"); bool bRes = false; //Create empty GIF object TRACE0(" Create empty GIF container\n"); CGif gifImage; if (gifImage.IsValid()) { if (!gifImage.HasGlobalColorTable()) { if (gifImage.GetGlobalColorTable().GetSize() == 0) bRes = true; } } if (!bRes) gifImage.Dump(); return bRes; } /////////////////////////////////////////////////////////////////////////////// /****************************************************************************** *$Log: * 1 Biblioteka1.0 16/07/2002 7:55:57 PMDarko Kolakovic *$ *****************************************************************************/ --- NEW FILE: ImagesTest.cpp --- /*$Workfile: ImagesTest.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:14:23 $ $Author: ddarko $ Test of image decoders and viewers Copyright: CommonSoft Inc Mar 2k2 D. Kolakovic */ // Group=Examples #include <stdlib.h> //EXIT_SUCCESS definition #include <fstream.h> #include "KTrace.h" //TRACE0 macros #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern bool TestGifCreate(); extern bool TestGifConversion(); extern bool TestGifViewer(char* szImageFileName, int iColors); extern bool TestGifDecoder(char* szImageFileName); extern "C" const char* gifscan (FILE* infp /* infp = stdin;*/ ); //Image Test results struct TestImages { char* m_szImagePath; //file directory int m_iColorNo; //number of colors in color palette, table or map; //if -1, any number of colors is valid bool m_bTestResult; //result of successful test }; //Table of test images TestImages g_testImages[] = { {".\\Res\\TestBasicBars.gif" , 2, true}, // 0 {".\\Res\\TestRedWhite.gif" , 2, true}, // 1 {".\\Res\\TestTriangle.gif" , 2, true}, // 2 {".\\Res\\TestDiagonalGray.gif" , 16, true}, // 3 {".\\Res\\TestDiagonal.gif" , 16, true}, // 4 {".\\Res\\TestFourSeasons.gif" , 4, true}, // 5 {".\\Res\\TestInterlace.gif" , 4, true}, // 6 {".\\Res\\TestRainbow.gif" ,256, true}, // 7 {".\\Res\\TestBars.gif" , 16, true}, // 8 {".\\Res\\TestColor.gif" ,256, true}, // 9 {".\\Res\\TestGlobeAni.gif" ,256, true}, //10 {".\\Res\\TestTrueColor.gif" ,256, true}, //11 {".\\Res\\TestCorruptedBlock.gif", 2, false}, //12 {".\\Res\\TestAntialiasing.gif" ,256, true}, //13 {NULL , 0, false} //end of automated test }; //main()----------------------------------------------------------------------- /*Defines the entry point for the console application. Test of decoding and encoding various image formats. Returns: EXIT_SUCCESS if successful, otherwise returns EXIT_FAILURE. */ int main(int argc, char* argv[] //[in] 1st argument: file name ) { cout << "Validation of image decoding and converting\n\n" << endl; const int ARG_FILENAME = 1; //index of 'file name' argument if(argc <= ARG_FILENAME) { cerr << "Usage: Images [file_name]" << endl; cerr << "Proceeding with sample " << g_testImages[0].m_szImagePath << endl; } else { g_testImages[0].m_szImagePath = argv[ARG_FILENAME]; g_testImages[0].m_iColorNo = -1; g_testImages[1].m_szImagePath = NULL; g_testImages[1].m_iColorNo = 0; } if(!TestGifCreate()) { cout << " Failure!" << endl; return EXIT_FAILURE; } else cout << " Success." << endl; if(!TestGifConversion()) { cout << " Failure!" << endl; return EXIT_FAILURE; } else cout << " Success." << endl; //Test all images form a table int i = 0; while (g_testImages[i].m_szImagePath != NULL) { FILE *file; file = fopen(g_testImages[i].m_szImagePath, "rb"); if (file == NULL) return EXIT_FAILURE; cout << endl << i << ". " << g_testImages[i].m_szImagePath << " -------------------------" << endl; gifscan(file); cout << i << ". -------------------------" << endl; fclose(file); if(TestGifViewer(g_testImages[i].m_szImagePath, g_testImages[i].m_iColorNo) != true) { cout << " Failure!" << endl; return EXIT_FAILURE; } else cout << " Success." << endl; if( TestGifDecoder(g_testImages[i].m_szImagePath) != g_testImages[i].m_bTestResult) { cout << " Failure!" << endl; return EXIT_FAILURE; } else cout << " Success." << endl; i++; } cout << endl << "======================" << endl; return EXIT_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// /****************************************************************************** *$Log: * 8 Biblioteka1.7 19/08/2002 9:45:15 AMDarko Kolakovic * 7 Biblioteka1.6 13/08/2002 8:12:42 AMDarko Kolakovic * 6 Biblioteka1.5 06/08/2002 3:36:10 PMDarko Kolakovic Added more * diagnostic information * 5 Biblioteka1.4 05/08/2002 10:33:30 AMDarko Fixed bug in * SeekImagePos * 4 Biblioteka1.3 02/08/2002 9:26:14 PMDarko Kolakovic * 3 Biblioteka1.2 31/07/2002 4:30:02 PMDarko Kolakovic * SeekImageDescriptor inserted * 2 Biblioteka1.1 16/07/2002 7:57:04 PMDarko Kolakovic Added * TestGifCreate() * 1 Biblioteka1.0 16/07/2002 12:48:19 AMDarko *$ *****************************************************************************/ |