fs/_tests/fsRle8/main.cpp

Go to the documentation of this file.
00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/ras/fsRle8Enc.h>
00004 #include <fs/ras/fsRle8Blt.h>
00005 
00006 #include <stdio.h> // printf
00007 #include <memory.h> // memset, memcmp
00008 #include <cassert>
00009 //---------------------------------------------------------------------------
00011 const fs::ras::nsRle8Blt::PxFmt8888_t *
00012 Conv(const fs::ras::Rle8Enc_t::PxFmt8888_t *pFrom)
00013 {
00014     // put a static assert here to ensure the types are equal in size
00015     return reinterpret_cast<const fs::ras::nsRle8Blt::PxFmt8888_t *>(pFrom);
00016 }
00017 //---------------------------------------------------------------------------
00018 int main()
00019 {
00020     using namespace fs::ras;
00021 
00022     // input RGBA-8888 image data
00023     const Rle8Enc_t::PxFmt8888_t aIn[] = {
00024      {0,0,0,0},       {0,0,255,128},   {0,0,0,0},
00025      {0,255,0,128},   {255,0,0,255},   {0,255,0,128},
00026      {0,0,255,128},   {0,0,255,128},   {0,0,0,0},
00027     };
00028     
00029     // encode RGBA-8888 image data into RLE8 data stream
00030     Rle8Enc_t Rle(aIn, 3, 3);
00031     assert(Rle.IsValid() && "Couldn't encode image data!");
00032         
00033     // get image dimensions
00034     int nW = 0, nH = 0;
00035     Rle.GetSize(nW, nH);
00036     ::printf("image width = %d, image height = %d\n", nW, nH);
00037         
00038     // get RLE8 data stream
00039     const unsigned char *pRle = 0;
00040     int nRleNum = 0;
00041     Rle.GetRle(pRle, nRleNum);
00042     ::printf("RLE8 data stream: ");
00043     for(int i = 0; i < nRleNum; ++i)
00044     {
00045         bool bTr = (pRle[i] & 1) == 0;
00046         int nNum = pRle[i] >> 1;
00047 
00048         ::printf("%d{%d/%d} ", pRle[i], !bTr, nNum);
00049 
00050         if(!bTr)
00051             for(int j = 0; j < nNum; ++i, ++j)
00052                 ::printf("%d ", pRle[i + 1]);
00053 
00054     }
00055     ::printf("\n");
00056     
00057     // get palette items
00058     const Rle8Enc_t::PxFmt8888_t *pPal = 0;
00059     int nPalNum = 0;
00060     Rle.GetPal(pPal, nPalNum);
00061     ::printf("palette items: ");
00062     for(int i = 0; i < nPalNum; ++i)
00063     {
00064         ::printf("%d-%d-%d-%d ",
00065          pPal[i].r, pPal[i].g, pPal[i].b, pPal[i].a);
00066     }
00067     ::printf("\n");
00068     
00069     // get line offsets
00070     const Rle8Enc_t::uint32 *pOff = 0;
00071     int nOffNum = 0;
00072     Rle.GetOff(pOff, nOffNum);
00073     ::printf("line offsets: ");
00074     for(int i = 0; i < nOffNum; ++i)
00075         ::printf("%d ", pOff[i]);
00076     ::printf("\n---\n");
00077 
00078     // decode RLE8 data stream back to RGBA-8888 image data
00079     nsRle8Blt::PxFmt8888_t aOut[sizeof(aIn)];
00080     ::memset(aOut, 0, sizeof(aOut));
00081     
00082     Rle8Blt<nsRle8Blt::Cl8888TrCpPcy_t>(
00083      pRle, Conv(pPal), pOff,
00084      3, 3,
00085      3, 3,
00086      aOut,
00087      3, 3,
00088      0, 0
00089     );
00090     
00091     // compare the input with the output
00092     ::printf("aIn %s aOut\n", ::memcmp(aIn, aOut, sizeof(aIn)) == 0 ?
00093      "==" : "!=");
00094     
00095     return 0;
00096 }
00097 //---------------------------------------------------------------------------
00098 // image width = 3, image height = 3
00099 // RLE8 data stream: 2{0/1} 3{1/1} 0 2{0/1} 7{1/3} 1 2 1 5{1/2} 0 0 2{0/1}
00100 // palette items: 0-0-255-128 0-255-0-128 255-0-0-255
00101 // line offsets: 0 4 8
00102 // ---
00103 // aIn == aOut
00104 //---------------------------------------------------------------------------

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