#include "../stdafx.h" #include "CLodHandler.h" #include "../SDL_Extensions.h" #include "CDefHandler.h" #include #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); // to the end 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=PCX24B; else if (check2) format=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==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<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;ioffset,std::ios_base::beg); unsigned char * outp; if (ourEntry->size==0) //file is not compressed { outp = new unsigned char[ourEntry->realSize]; FLOD.read((char*)outp, ourEntry->realSize); CDefHandler * nh = new CDefHandler; nh->openFromMemory(outp, ourEntry->realSize, std::string((char*)ourEntry->name)); nh->alphaTransformed = false; ret = nh; } else //we will decompress file { outp = new unsigned char[ourEntry->size]; FLOD.read((char*)outp, ourEntry->size); FLOD.seekg(0, std::ios_base::beg); unsigned char * decomp = NULL; int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp); CDefHandler * nh = new CDefHandler; nh->openFromMemory(decomp, ourEntry->realSize, std::string((char*)ourEntry->name)); nh->alphaTransformed = false; ret = nh; } delete[] outp; return ret; } CDefEssential * CLodHandler::giveDefEss(std::string defName) { CDefEssential * ret; CDefHandler * temp = giveDef(defName); ret = temp->essentialize(); delete temp; return ret; } 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) { std::string Ts; FLOD.open(lodFile.c_str(),std::ios::binary); 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); for (int i=0; i