#include "stdafx.h" #include "CLodHandler.h" #include #include #include #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations int readNormalNr (int pos, int bytCon, unsigned char * str) { int ret=0; int amp=1; if (str) { for (int i=0; i open(path.c_str(),std::ios::binary); is->seekg(0,std::ios::end); // na koniec pcxs = is->tellg(); // read length is->seekg(0,std::ios::beg); // wracamy na poczatek pcx = new unsigned char[pcxs]; // allocate memory is->read((char*)pcx, pcxs); // read map file to buffer is->close(); delete is; } void CPCXConv::saveBMP(std::string path) { std::ofstream os; os.open(path.c_str(), std::ios::binary); os.write((char*)bmp,bmps); os.close(); } void CPCXConv::convert() { BMPHeader bh; BMPPalette pal[256]; Epcxformat format; int fSize,i,y; bool check1, check2; unsigned char add; int it=0; std::stringstream 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=Epcxformat::PCX24B; else if (check2) format=Epcxformat::PCX8B; else return; add=(int)(4*(((float)1)-(((float)bh.x/(float)4)-((int)((float)bh.x/(float)4))))); if (add==4) add=0; bh._h3=bh.x*bh.y; if (format==Epcxformat::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==Epcxformat::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==Epcxformat::PCX8B) { for (int i=0;i<256;i++) { out<0;y--) { it=0xC+(y-1)*bh.x; for (int j=0;j0) { for (int j=0;j0; y--) { it=0xC+(y-1)*bh.x*3; for (int j=0;j0) { for (int j=0;jformat->palette->colors+i) = tp; } for (y=bh.y;y>0;y--) { it=0xC+(y-1)*bh.x; for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j]; } if (add>0) { for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+bh.x)) = 0; } } } } else { for (y=bh.y; y>0; y--) { it=0xC+(y-1)*bh.x*3; for (int j=0;jpixels + ret->pitch * (y-1) + j) = pcx[it+j]; } if (add>0) { for (int j=0;jpixels + ret->pitch * (y-1) + (j+bh.x*3)) = 0; } } } } return ret; } SDL_Surface * CLodHandler::loadBitmap(std::string fname) { unsigned char * pcx; std::transform(fname.begin(),fname.end(),fname.begin(),toupper); fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); int index=-1; for (int i=0;i pom; pom.push_back(defName); return extractManyFiles(pom)[0]; } std::vector CLodHandler::extractManyFiles(std::vector defNamesIn) { std::vector ret(defNamesIn.size()); for(int hh=0; hh found(defNamesIn.size(), 0); for (int i=0;iopenFromMemory(outp, entries[i].realSize, std::string((char*)entries[i].name)); nh->alphaTransformed = false; ret[curDef] = nh; } else //we will decompressing file { outp = new unsigned char[entries[i].size]; FLOD.read((char*)outp, entries[i].size); FLOD.seekg(0, std::ios_base::beg); unsigned char * decomp = NULL; int decRes = infs2(outp, entries[i].size, entries[i].realSize, decomp); CDefHandler * nh = new CDefHandler; nh->openFromMemory(decomp, entries[i].realSize, std::string((char*)entries[i].name)); nh->alphaTransformed = false; ret[curDef] = nh; } delete outp; } //std::cout<<'\r'<<"Reading defs: 100% "<=amp/2) { ret = ret-amp; } return ret; } void CLodHandler::init(std::string lodFile) { FLOD; std::string Ts; //std::cout<<"*** Loading FAT ... \n"; FLOD.open(lodFile.c_str(),std::ios::binary); //std::cout<<"*** Archive: "+FName+" loaded\n"; FLOD.seekg(8,std::ios_base::beg); unsigned char temp[4]; FLOD.read((char*)temp,4); totalFiles = readNormalNr(temp,4); FLOD.seekg(0x5c,std::ios_base::beg); entries.reserve(totalFiles); //std::cout<<"*** Loading FAT ...\n"; for (int i=0; i