int PCXFile::LoadPCXFile(Byte* filebuff, Dword filesize) { memcpy((Byte*)&Pcx_head,(Byte*)filebuff,sizeof(PCXHeader)); int state=0; if (Pcx_head.bManufacturer==0x0a && Pcx_head.bVersion==0x05) { width=Pcx_head.dwWidth-Pcx_head.dwX+1; height=Pcx_head.dwHeight-Pcx_head.dwY+1; buffer=kos_GetMemory(width*height*3); Byte* pPal=filebuff+filesize-768; Byte* pImg=filebuff+128; Byte* cBuffer=(Byte*)buffer; if (Pcx_head.bNPlanes==1) { /* 8-bit decoding */ Dword y,i; Byte cur_byte,counter; Dword cWidth; for(y=0; y<height; y++) { cWidth=width; while(cWidth!=0) { cur_byte=*(pImg); pImg++; counter=1; if (cur_byte>=192) { counter=(cur_byte & 0x3F); cur_byte=*(pImg); pImg++; } for(i=0; i<counter; i++) { *(cBuffer+0)=(pPal[cur_byte*3+0]); *(cBuffer+1)=(pPal[cur_byte*3+1]); *(cBuffer+2)=(pPal[cur_byte*3+2]); cBuffer=cBuffer+3; cWidth--; } } } } else if (Pcx_head.bNPlanes==3) { /* 24-bit decoding */ state=1; } } else { state=1; } return state; }
int TGAFile::LoadTGAFile(Byte* filebuff, Dword filesize) { memcpy((Byte*)&Tga_head,(Byte*)filebuff,sizeof(sTGAHeader)); width=Tga_head.Width; height=Tga_head.Height; Byte* pImg=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin+(Tga_head.ColorMapLength*Tga_head.ColorMapEntrySize/8); Byte* pPal=filebuff+sizeof(sTGAHeader)+Tga_head.BytesInIdentField+Tga_head.ColorMapOrigin; Byte* cBuffer; int x,y; Byte r; int sm; int state=1; if (Tga_head.ImageDescByte >= 32) sm=height-1; else sm=0; // Изображение с палитрой (палитра 24 или 32-битная) if (Tga_head.ImageTypeCode==1) { if (Tga_head.ColorMapEntrySize>=24) { buffer=kos_GetMemory(width*height*3); int bpp=Tga_head.ColorMapEntrySize/8; for(y=height-1;y!=-1;y--) { for(x=0;x<width;x++) { r=*(pImg); pImg++; cBuffer=buffer+(abs(sm-y)*width*3)+x*3; *(cBuffer+0)=(Byte)(pPal[r*bpp+1]); *(cBuffer+1)=(Byte)(pPal[r*bpp+2]); *(cBuffer+2)=(Byte)(pPal[r*bpp+3]); } } state=0; } } // ЦВетное изображение без сжатия и палитры else if (Tga_head.ImageTypeCode==2) { switch (Tga_head.ImagePixelSize) { case 32: case 24: buffer=kos_GetMemory(width*height*3); for(y=height-1;y!=-1;y--) { for(x=0;x<width;x++) { cBuffer=buffer+(abs(sm-y)*width*3)+x*3; *(cBuffer+0)=*(pImg+0); *(cBuffer+1)=*(pImg+1); *(cBuffer+2)=*(pImg+2); pImg=pImg+Tga_head.ImagePixelSize/8; } } state=0; break; case 16: buffer=kos_GetMemory(width*height*3); for(y=height-1;y!=-1;y--) { for(x=0;x<width;x++) { cBuffer=buffer+(abs(sm-y)*width*3)+x*3; *(cBuffer+0)=(Byte)((*(Word*)(pImg)) & 31)<<3; *(cBuffer+1)=(Byte)((*(Word*)(pImg)>>5) & 31)<<3; *(cBuffer+2)=(Byte)((*(Word*)(pImg)>>10) & 31)<<3; pImg=pImg+2; } } state=0; break; } } // Монохромное изображение else if (Tga_head.ImageTypeCode==3)
*(cBuffer+1)=(Byte)((*(Word*)(pImg)>>5) & 31)<<3; *(cBuffer+2)=(Byte)((*(Word*)(pImg)>>10) & 31)<<3; pImg=pImg+2; } } state=0; break; } } // Монохромное изображение else if (Tga_head.ImageTypeCode==3) { switch (Tga_head.ImagePixelSize) { case 8: buffer=kos_GetMemory(width*height*3); for(y=height-1;y!=-1;y--) { for(x=0;x<width;x++) { cBuffer=buffer+(abs(sm-y)*width*3)+x*3; *(cBuffer+0)=*(pImg); *(cBuffer+1)=*(pImg); *(cBuffer+2)=*(pImg); pImg++; } } state=0; break; } }