#include "../stdafx.h" #include "CDefHandler.h" #include "SDL_image.h" #include long long pow(long long a, int b) { if (!b) return 1; long c = a; while (--b) a*=c; return a; } void BMPHeader::print(std::ostream & out) { CDefHandler::print(out,fullSize,4); CDefHandler::print(out,_h1,4); CDefHandler::print(out,_c1,4); CDefHandler::print(out,_c2,4); CDefHandler::print(out,x,4); CDefHandler::print(out,y,4); CDefHandler::print(out,_c3,2); CDefHandler::print(out,_c4,2); CDefHandler::print(out,_h2,4); CDefHandler::print(out,_h3,4); CDefHandler::print(out,dataSize1,4); CDefHandler::print(out,dataSize2,4); for (int i=0;i<8;i++) out << _c5[i]; out.flush(); } CDefHandler::CDefHandler() { //FDef = NULL; RWEntries = NULL; RLEntries = NULL; notFreeImgs = false; } CDefHandler::~CDefHandler() { //if (FDef) //delete [] FDef; if (RWEntries) delete [] RWEntries; if (RLEntries) delete [] RLEntries; if (notFreeImgs) return; for (int i=0; i open(name.c_str(),std::ios::binary); is->seekg(0,std::ios::end); // na koniec andame = is->tellg(); // read length is->seekg(0,std::ios::beg); // wracamy na poczatek unsigned char * FDef = new unsigned char[andame]; // allocate memory is->read((char*)FDef, andame); // read map file to buffer is->close(); delete is; i = 0; DEFType = readNormalNr(i,4,FDef); i+=4; fullWidth = readNormalNr(i,4,FDef); i+=4; fullHeight = readNormalNr(i,4,FDef); i+=4; i=0xc; totalBlocks = readNormalNr(i,4,FDef); i+=4; i=0x10; for (int it=0;it<256;it++) { palette[it].R = FDef[i++]; palette[it].G = FDef[i++]; palette[it].B = FDef[i++]; palette[it].F = 0; } i=0x310; totalEntries=0; for (int z=0; z=0;i--) { int test2 = nr/(amp); ret[i]=test2; nr -= (nr/(amp))*amp; amp/=256; } return ret; } void CDefHandler::expand(unsigned char N,unsigned char & BL, unsigned char & BR) { BL = (N & 0xE0) >> 5; BR = N & 0x1F; } int CDefHandler::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic) { int ret=0; int amp=1; if (str) { for (int i=0; i=amp/2) { ret = ret-amp; } return ret; } void CDefHandler::print (std::ostream & stream, int nr, int bytcon) { unsigned char * temp = writeNormalNr(nr,bytcon); for (int i=0;iformat->palette->colors+i))=pr; } if (defType2==0) { if (TopMargin>0) { for (int i=0;i0) { for (int j=0;j0) { for (int j=0;j0) { for (int i=0;i0) { for (int i=0;i0) { for (int j=0;j=SpriteWidth) break; } BaseOffset+=SegmentLength+1;//// TotalRowLength+=SegmentLength+1; } else { for (int k=0;k0) { for (int j=0;j0) { for (int j=0;j0) { for (int i=0;i0) { for (int i=0;i0) { for (int j=0;j0) { for (int j=0;j0) { for (int j=0;j0) { for (int i=0;i0) { for (int i=0;i0) { for (int j=0;j=SpriteWidth) break; FTemp[ftcp++]=FDef[BaseOffset++]; } } else { for(int h=0; h=SpriteWidth) break; FTemp[ftcp++]=code; } } TotalRowLength+=( LeftMargin>=0 ? value : value+LeftMargin ); }while(TotalRowLength0) { for (int j=0;j0) { for (int j=0;j0) { for (int i=0;ipixels + ret->format->BytesPerPixel * (i*(fullWidth+add) + j)) = FTemp[i*(FullWidth+add)+j]; } } SDL_Color ttcol = ret->format->palette->colors[0]; Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused); SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol); delete [] FTemp; return ret; }; CDefEssential * CDefHandler::essentialize() { CDefEssential * ret = new CDefEssential; ret->ourImages = ourImages; notFreeImgs = true; return ret; }