1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-03 23:19:22 +02:00

* faster decompression with infs2

* minor changes (unused code removed, a few additional consts)
This commit is contained in:
mateuszb
2009-09-27 11:37:15 +00:00
parent 974acb3907
commit 07a769601e
6 changed files with 50 additions and 198 deletions

View File

@@ -18,7 +18,7 @@
*/
boost::mutex bitmap_handler_mx;
int readNormalNr (int pos, int bytCon, unsigned char * str);
int readNormalNr (int pos, int bytCon, const unsigned char * str);
extern DLL_EXPORT CLodHandler *bitmaph;
@@ -56,6 +56,7 @@ void CPCXConv::fromFile(std::string path)
is.read((char*)pcx, pcxs); // read map file to buffer
is.close();
}
void CPCXConv::saveBMP(std::string path)
{
std::ofstream os;
@@ -63,120 +64,8 @@ void CPCXConv::saveBMP(std::string path)
os.write((char*)bmp,bmps);
os.close();
}
void CPCXConv::convert()
{
BMPHeader bh;
BMPPalette pal[256];
Epcxformat format;
int fSize,y;//,i; //TODO use me 'i'
bool check1, check2;
unsigned char add;
int it=0;
std::ostringstream out;
fSize = readNormalNr(it,4,pcx);it+=4;
bh.x = readNormalNr(it,4,pcx);it+=4;
bh.y = readNormalNr(it,4,pcx);it+=4;
if (fSize==bh.x*bh.y*3)
check1=true;
else
check1=false;
if (fSize==bh.x*bh.y)
check2=true;
else
check2=false;
if (check1)
format=PCX24B;
else if (check2)
format=PCX8B;
else
return;
add = 4 - bh.x%4;
if (add==4)
add=0;
bh._h3=bh.x*bh.y;
if (format==PCX8B)
{
bh._c1=0x436;
bh._c2=0x28;
bh._c3=1;
bh._c4=8;
//bh.dataSize2=bh.dataSize1=maxx*maxy;
bh.dataSize1=bh.x;
bh.dataSize2=bh.y;
bh.fullSize = bh.dataSize1+436;
}
else
{
bh._c1=0x36;
bh._c2=0x28;
bh._c3=1;
bh._c4=0x18;
//bh.dataSize2=bh.dataSize1=0xB12;
bh.dataSize1=bh.x;
bh.dataSize2=bh.y;
bh.fullSize=(bh.x+add)*bh.y*3+36+18;
bh._h3*=3;
}
if (format==PCX8B)
{
it = pcxs-256*3;
for (int i=0;i<256;i++)
{
pal[i].R=pcx[it++];
pal[i].G=pcx[it++];
pal[i].B=pcx[it++];
pal[i].F='\0';
}
}
out<<"BM";
bh.print(out);
if (format==PCX8B)
{
for (int i=0;i<256;i++)
{
out<<pal[i].B;
out<<pal[i].G;
out<<pal[i].R;
out<<pal[i].F;
}
for (y=bh.y;y>0;y--)
{
it=0xC+(y-1)*bh.x;
for (int j=0;j<bh.x;j++)
out<<pcx[it+j];
if (add>0)
{
for (int j=0;j<add;j++)
out<<'\0'; //bylo z buforu, ale onnie byl incjalizowany (?!)
}
}
}
else
{
for (y=bh.y; y>0; y--)
{
it=0xC+(y-1)*bh.x*3;
for (int j=0;j<bh.x*3;j++)
out<<pcx[it+j];
if (add>0)
{
for (int j=0;j<add*3;j++)
out<<'\0'; //bylo z buforu, ale onnie byl incjalizowany (?!)
}
}
}
std::string temp = out.str();
bmp = new unsigned char[temp.length()];
bmps=temp.length();
for (size_t a=0;a<temp.length();++a)
{
bmp[a]=temp[a];
}
}
SDL_Surface * CPCXConv::getSurface()
SDL_Surface * CPCXConv::getSurface() const
{
SDL_Surface * ret;
@@ -362,7 +251,7 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
delete [] pcd;
}
CPCXConv cp;
cp.openPCX((char*)pcx,e->realSize);
cp.openPCX((char*)pcx, e->realSize);
SDL_Surface * ret = cp.getSurface();
if(ret->format->BytesPerPixel == 1 && setKey)
{