3 * Purpose: Platform Independent SKA Image Class Loader and Writer
4 * 25/Sep/2007 Davide Pizzolato - www.xdp.it
5 * CxImage version 6.0.0 02/Feb/2008
10 #if CXIMAGE_SUPPORT_SKA
12 ////////////////////////////////////////////////////////////////////////////////
13 #if CXIMAGE_SUPPORT_DECODE
14 ////////////////////////////////////////////////////////////////////////////////
15 bool CxImageSKA::Decode(CxFile *hFile)
22 hFile->Read(&ska_header,sizeof(SKAHEADER),1);
24 ska_header.Width = ntohs(ska_header.Width);
25 ska_header.Height = ntohs(ska_header.Height);
26 ska_header.dwUnknown = ntohl(ska_header.dwUnknown);
29 if (ska_header.dwUnknown != 0x01000000 ||
30 ska_header.Width > 0x7FFF || ska_header.Height > 0x7FFF ||
31 ska_header.BppExp != 3)
34 if (info.nEscape == -1){
35 head.biWidth = ska_header.Width ;
36 head.biHeight= ska_header.Height;
37 info.dwType = CXIMAGE_FORMAT_SKA;
41 int bpp = 1<<ska_header.BppExp;
43 Create(ska_header.Width,ska_header.Height,bpp,CXIMAGE_FORMAT_SKA);
49 rgb_color* ppal = (rgb_color*)malloc(nColors*sizeof(rgb_color));
50 if (!ppal) return false;
51 hFile->Read(ppal,nColors*sizeof(rgb_color),1);
52 SetPalette(ppal,nColors);
56 hFile->Read(GetBits(),ska_header.Width*ska_header.Height,1);
59 if (GetEffWidth() != ska_header.Width){
61 src = GetBits() + ska_header.Width*(ska_header.Height-1);
62 dst = GetBits(ska_header.Height-1);
63 for(int y=0;y<ska_header.Height;y++){
64 memcpy(dst,src,ska_header.Width);
65 src -= ska_header.Width;
74 ////////////////////////////////////////////////////////////////////////////////
75 #endif //CXIMAGE_SUPPORT_DECODE
76 ////////////////////////////////////////////////////////////////////////////////
77 #if CXIMAGE_SUPPORT_ENCODE
78 ////////////////////////////////////////////////////////////////////////////////
79 bool CxImageSKA::Encode(CxFile * hFile)
81 if (EncodeSafeCheck(hFile)) return false;
83 if(head.biBitCount > 8) {
84 strcpy(info.szLastError,"SKA Images must be 8 bit or less");
90 ska_header.Width = (unsigned short)GetWidth();
91 ska_header.Height = (unsigned short)GetHeight();
92 ska_header.BppExp = 3;
93 ska_header.dwUnknown = 0x01000000;
95 ska_header.Width = ntohs(ska_header.Width);
96 ska_header.Height = ntohs(ska_header.Height);
97 ska_header.dwUnknown = ntohl(ska_header.dwUnknown);
99 hFile->Write(&ska_header,sizeof(SKAHEADER),1);
101 ska_header.Width = ntohs(ska_header.Width);
102 ska_header.Height = ntohs(ska_header.Height);
103 ska_header.dwUnknown = ntohl(ska_header.dwUnknown);
105 if (head.biBitCount<8) IncreaseBpp(8);
108 for(int idx=0; idx<256; idx++){
109 GetPaletteColor(idx,&(pal[idx].r),&(pal[idx].g),&(pal[idx].b));
112 hFile->Write(pal,256*sizeof(rgb_color),1);
114 BYTE* src = GetBits(ska_header.Height-1);
115 for(int y=0;y<ska_header.Height;y++){
116 hFile->Write(src,ska_header.Width,1);
117 src -= GetEffWidth();
122 ////////////////////////////////////////////////////////////////////////////////
123 #endif // CXIMAGE_SUPPORT_ENCODE
124 ////////////////////////////////////////////////////////////////////////////////
125 #endif // CXIMAGE_SUPPORT_SKA