Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include "..\kosSyst.h"
  2. #include "tga.h"
  3.  
  4. int TGAFile::LoadTGAFile(Byte* filebuff, Dword filesize)
  5. {
  6.  
  7.   memcpy((Byte*)&Tga_head,(Byte*)filebuff,sizeof(sTGAHeader));
  8.   width=Tga_head.Width;
  9.   height=Tga_head.Height;
  10.  
  11.   Byte* pImg=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin+(Tga_head.ColorMapLength*Tga_head.ColorMapEntrySize/8);
  12.   Byte* pPal=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin;
  13.   Byte* cBuffer;
  14.   int x,y;
  15.   Byte  r;
  16.   int sm;
  17.      
  18.   int state=1;
  19.  
  20.     if (Tga_head.ImageDescByte >= 32) sm=height-1; else sm=0;
  21.     // Èçîáðàæåíèå ñ ïàëèòðîé (ïàëèòðà 24 èëè 32-áèòíàÿ)
  22.     if (Tga_head.ImageTypeCode==1)
  23.     {
  24.       if (Tga_head.ColorMapEntrySize>=24)
  25.       {
  26.         buffer=kos_GetMemory(width*height*3);
  27.         int bpp=Tga_head.ColorMapEntrySize/8;
  28.         for(y=height-1;y!=-1;y--)
  29.         {
  30.           for(x=0;x<width;x++)
  31.           {
  32.             r=*(pImg); pImg++;
  33.             cBuffer=buffer+(abs(sm-y)*width*3)+x*3;
  34.             *(cBuffer+0)=(Byte)(pPal[r*bpp+1]);
  35.             *(cBuffer+1)=(Byte)(pPal[r*bpp+2]);
  36.             *(cBuffer+2)=(Byte)(pPal[r*bpp+3]);
  37.           }
  38.         }
  39.         state=0;
  40.       }
  41.     }
  42.     // ÖÂåòíîå èçîáðàæåíèå áåç ñæàòèÿ è ïàëèòðû
  43.     else if (Tga_head.ImageTypeCode==2)
  44.     {
  45.       switch (Tga_head.ImagePixelSize)
  46.       {
  47.         case 32:
  48.         case 24:
  49.           buffer=kos_GetMemory(width*height*3);
  50.           for(y=height-1;y!=-1;y--)
  51.           {
  52.             for(x=0;x<width;x++)
  53.             {
  54.               cBuffer=buffer+(abs(sm-y)*width*3)+x*3;
  55.               *(cBuffer+0)=*(pImg+0);
  56.               *(cBuffer+1)=*(pImg+1);
  57.               *(cBuffer+2)=*(pImg+2);
  58.               pImg=pImg+Tga_head.ImagePixelSize/8;
  59.             }
  60.           }
  61.           state=0;
  62.         break;
  63.         case 16:
  64.           buffer=kos_GetMemory(width*height*3);
  65.           for(y=height-1;y!=-1;y--)
  66.           {
  67.             for(x=0;x<width;x++)
  68.             {
  69.               cBuffer=buffer+(abs(sm-y)*width*3)+x*3;
  70.               *(cBuffer+0)=(Byte)((*(Word*)(pImg)) & 31)<<3;
  71.               *(cBuffer+1)=(Byte)((*(Word*)(pImg)>>5) & 31)<<3;
  72.               *(cBuffer+2)=(Byte)((*(Word*)(pImg)>>10) & 31)<<3;      
  73.               pImg=pImg+2;
  74.             }
  75.           }
  76.           state=0;
  77.         break;
  78.       }
  79.     }
  80.     // Ìîíîõðîìíîå èçîáðàæåíèå
  81.     else if (Tga_head.ImageTypeCode==3)
  82.     {
  83.       switch (Tga_head.ImagePixelSize)
  84.       {
  85.         case 8:
  86.           buffer=kos_GetMemory(width*height*3);
  87.           for(y=height-1;y!=-1;y--)
  88.           {
  89.             for(x=0;x<width;x++)
  90.             {
  91.               cBuffer=buffer+(abs(sm-y)*width*3)+x*3;
  92.               *(cBuffer+0)=*(pImg);
  93.               *(cBuffer+1)=*(pImg);
  94.               *(cBuffer+2)=*(pImg);
  95.               pImg++;
  96.             }
  97.           }
  98.           state=0;
  99.         break;
  100.       }
  101.     }
  102.   return state;
  103. }