From 895d4f4da8e01e6acd211f65fdf3e00d4b1166a5 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 8 Jul 2007 15:19:00 +0000 Subject: [PATCH] =?UTF-8?q?lepszy=20CPCXConv=20i=20zmiana=20klasy=20CSDL?= =?UTF-8?q?=5FExt=20na=20przestrze=C5=84=20nazw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLodHandler.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++++ CLodHandler.h | 1 + SDL_Extensions.h | 27 ++++++------ 3 files changed, 125 insertions(+), 14 deletions(-) diff --git a/CLodHandler.cpp b/CLodHandler.cpp index b643f3404..d8050611b 100644 --- a/CLodHandler.cpp +++ b/CLodHandler.cpp @@ -154,6 +154,117 @@ void CPCXConv::convert() } } +SDL_Surface * CPCXConv::getSurface() +{ + SDL_Surface * ret; + BMPHeader bh; + BMPPalette pal[256]; + Epcxformat format; + int fSize, maxx, maxy,i,y; + bool check1, check2; + unsigned char add; + int it=0; + + 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 NULL; + 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'; + } + } +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int rmask = 0xff000000; + int gmask = 0x00ff0000; + int bmask = 0x0000ff00; + int amask = 0x000000ff; +#else + int rmask = 0x000000ff; + int gmask = 0x0000ff00; + int bmask = 0x00ff0000; + int amask = 0xff000000; +#endif + ret = SDL_CreateRGBSurface(SDL_SWSURFACE, maxx, maxy, (format==Epcxformat::PCX8B ? 8 : 24), rmask, gmask, bmask, amask); + if (format==Epcxformat::PCX8B) + { + for(int i=0; i<256; ++i) + { + SDL_Color pr; + pr.r = pal[i].R; + pr.g = pal[i].G; + pr.b = pal[i].B; + pr.unused = pal[i].F; + (*(ret->format->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 diff --git a/CLodHandler.h b/CLodHandler.h index 0b9949470..ad93f81ee 100644 --- a/CLodHandler.h +++ b/CLodHandler.h @@ -43,6 +43,7 @@ public: void openPCX(char * PCX, int len); void openPCX(); void convert(); + SDL_Surface * getSurface(); CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; ~CPCXConv(){if (pcxs) delete pcx; if(bmps) delete bmp;} }; diff --git a/SDL_Extensions.h b/SDL_Extensions.h index d83bc83c8..24e6d2f7b 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -6,21 +6,20 @@ extern SDL_Surface * ekran; extern SDL_Color tytulowy, tlo, zwykly ; -class CSDL_Ext +namespace CSDL_Ext { -public: - static void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels - static SDL_Surface * rotate01(SDL_Surface * toRot, int myC = 2); //vertical flip - static SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip - static SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left - static SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees - static SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy); - static Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte = false); - static SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); - static SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) - static SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to - static Uint32 colorToUint32(const SDL_Color * color); //little endian only - static void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest + void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels + SDL_Surface * rotate01(SDL_Surface * toRot, int myC = 2); //vertical flip + SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip + SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left + SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees + SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy); + Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte = false); + SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); + SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) + SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to + Uint32 colorToUint32(const SDL_Color * color); //little endian only + void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest }; #endif // SDL_EXTENSIONS_H \ No newline at end of file