#include "stdafx.h" #include "CLodHandler.h" #include #include #include 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, maxx, maxy,i,y; bool check1, check2; unsigned char add; int it=0; std::stringstream out; fSize = readNormalNr(it,4,pcx);it+=4; maxx = readNormalNr(it,4,pcx);it+=4; maxy = readNormalNr(it,4,pcx);it+=4; if (fSize==maxx*maxy*3) check1=true; else check1=false; if (fSize==maxx*maxy) check2=true; else check2=false; if (check1) format=Epcxformat::PCX24B; else if (check2) format=Epcxformat::PCX8B; else return; bh.x=maxx; bh.y=maxy; add=(int)(4*(((float)1)-(((float)maxx/(float)4)-((int)((float)maxx/(float)4))))); if (add==4) add=0; if (format==Epcxformat::PCX8B) { bh._c1=0x436; bh._c2=0x28; bh._c3=1; bh._c4=8; bh.dataSize2=bh.dataSize1=maxx*maxy; bh.fullSize = bh.dataSize1+436; } else { bh._c1=0x36; bh._c2=0x28; bh._c3=1; bh._c4=0x18; bh.dataSize2=bh.dataSize1=0xB12; bh.fullSize=(maxx+add)*maxy*3+36; } 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)*maxx; for (int j=0;j0) { for (int j=0;j0; y--) { it=0xC+(y-1)*maxx*3; for (int j=0;j0) { for (int j=0;jformat->palette->colors+i)) = pr; } for(y=maxy; y>0; --y) { it = 0xc + (y-1)*maxx; for(int j=0; jpixels + ret->format->BytesPerPixel * (y*(maxx+add) + j)) = pcx[it+j]; for(int j=0; jpixels + ret->format->BytesPerPixel * (y*(maxx+add) + maxx + j)) = 0; } } else { for(int y=maxy; y>0; --y) { it = 0xc + (y-1)*maxx*3; for(int j=0; jpixels + (y*(maxx+add) + j)) = pcx[it+j]; } for(int j=0; jpixels + (y*(maxx+add) + j)) = 0; } } } return ret; } // if PFileType=pcx24bit then // for y:=MaxY downto 1 do // begin // FPcx.Seek($0C+(y-1)*(MaxX*3),spBegin); // Stream2Stream(FTemp,FPcx,MaxX*3); // if Add>0 then FTemp.Write(Buffer,Add*3); // end; // FTemp.Seek(0,spBegin); // BufferBitmap.LoadFromStream(FTemp); // FTemp.Free; // Result:=True; //end; /*int CLodHandler::decompress (unsigned char * source, int size, int realSize, std::ofstream & dest) { std::ofstream lb; lb.open("lodbuf\\buf.gz", std::ios::out|std::ios::binary); for(int i=0; i CLodHandler::extractManyFiles(std::vector defNamesIn, std::string lodName) { 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)); 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); /*std::ofstream destin; destin.open(bufff.c_str(), std::ios::binary); //int decRes = decompress(outp, entries[i].size, entries[i].realSize, bufff); int decRes = infs(outp, entries[i].size, entries[i].realSize, destin); destin.close(); if(decRes!=0) { std::cout<<"LOD Extraction error"<<" "<openFromMemory(decomp, entries[i].realSize, std::string((char*)entries[i].name)); ret[curDef] = nh; //delete decomp; } //for (int j=0; j=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