#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(); } void CDefHandler::openDef(std::string name) { int i,j, totalInBlock; char Buffer[13]; defName=name; int andame; std::ifstream * is = new std::ifstream(); is -> 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 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); i+=4; fullWidth = readNormalNr(i,4); i+=4; fullHeight = readNormalNr(i,4); i+=4; i=0xc; totalBlocks = readNormalNr(i,4); 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 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 FDef = new unsigned char[andame]; // allocate memory is->read((char*)FDef, andame); // read map file to buffer is->close(); delete is;*/ //FDef = new unsigned char[size]; // allocate memory while (!(FDef = (unsigned char *)malloc((sizeof(unsigned char))*size))); for (int i=0;i=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; } for (int i=0;i<800;i++) fbuffer[i]=0; if (defType2==0) { if (add==4) add=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;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); return ret; }; CDefEssential * CDefHandler::essentialize() { CDefEssential * ret = new CDefEssential; ret->ourImages = ourImages; return ret; }