fs/_tests/fsTgaLdr/main.cpp

Go to the documentation of this file.
00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/ras/fsTgaLdr.h>
00004 
00005 #include <stdio.h> // printf
00006 #include <memory.h> // memset, memcmp
00007 #include <cassert>
00008 //---------------------------------------------------------------------------
00009 int main()
00010 {
00011     using namespace fs::ras;
00012         
00013     //--- TEST1 RGB-888 ---
00014     
00015     TgaLdr_t Tga1("test_rgb.tga");
00016     assert(Tga1.IsValid() && "Couldn't load the TGA file!");
00017 
00018     ::printf("---> IMAGE 1:\n");
00019     ::printf("width: %d\n", Tga1.GetW());
00020     ::printf("height: %d\n", Tga1.GetH());
00021     ::printf("is RGB-888 : %s\n", Tga1.GetData888() ? "true" : "false");
00022     ::printf("is RGBA-8888 : %s\n", Tga1.GetData8888() ? "true" : "false");
00023     
00024     // expected RGB-888 data
00025     const unsigned char aExpRgbData[] = {
00026      255, 255, 255,   255, 0, 0,   255, 255, 255,
00027      255, 255, 255,   0, 255, 0,   255, 255, 255,
00028      0,   0,   0,     0, 0, 255,   0,   0,   0,
00029     };
00030 
00031     // compare loaded and expected RGB-888 data
00032     assert(Tga1.GetData888());
00033     ::printf("aExpRgbData %s TGA Data\n", ::memcmp(Tga1.GetData888(),
00034      aExpRgbData, sizeof(aExpRgbData)) == 0 ? "==" : "!=");
00035     
00036     //--- TEST2 RGBA-8888 ---
00037     
00038     TgaLdr_t Tga2("test_rgba.tga");
00039     assert(Tga2.IsValid() && "Couldn't load the TGA file!");
00040         
00041     ::printf("---> IMAGE 2:\n");
00042     ::printf("width: %d\n", Tga2.GetW());
00043     ::printf("height: %d\n", Tga2.GetH());
00044     ::printf("is RGB-888 : %s\n", Tga2.GetData888() ? "true" : "false");
00045     ::printf("is RGBA-8888 : %s\n", Tga2.GetData8888() ? "true" : "false");
00046                 
00047     // expected RGBA-8888 data
00048     const unsigned char aExpRgbaData [] = {
00049      255, 255, 255, 63,   255, 0, 0, 255,   255, 255, 255, 127,
00050      255, 255, 255, 63,   0, 255, 0, 255,   255, 255, 255, 127,
00051      0,   0,   0,   63,   0, 0, 255, 255,   0,   0,   0,   127,
00052     };
00053                     
00054     // compare loaded and expected RGBA-8888 data
00055     assert(Tga2.GetData8888());
00056     ::printf("aExpRgbaData %s TGA Data\n---\n", ::memcmp(Tga2.GetData8888(),
00057      aExpRgbaData, sizeof(aExpRgbaData)) == 0 ? "==" : "!=");
00058      
00059     //---
00060 
00061     return 0;
00062 }
00063 //---------------------------------------------------------------------------
00064 // ---> IMAGE 1:
00065 // width: 3
00066 // height: 3
00067 // is RGB-888 : true
00068 // is RGBA-8888 : false
00069 // aExpRgbData == TGA Data
00070 // ---> IMAGE 2:
00071 // width: 3
00072 // height: 3
00073 // is RGB-888 : false
00074 // is RGBA-8888 : true
00075 // aExpRgbaData == TGA Data
00076 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]