mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
lepszy CPCXConv i zmiana klasy CSDL_Ext na przestrzeń nazw
This commit is contained in:
parent
69e206346f
commit
895d4f4da8
111
CLodHandler.cpp
111
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; j<maxx; ++j)
|
||||
*((char*)ret->pixels + ret->format->BytesPerPixel * (y*(maxx+add) + j)) = pcx[it+j];
|
||||
for(int j=0; j<add; ++j)
|
||||
*((char*)ret->pixels + 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; j<maxx*3; ++j)
|
||||
{
|
||||
*((char*)ret->pixels + (y*(maxx+add) + j)) = pcx[it+j];
|
||||
}
|
||||
for(int j=0; j<add*3; ++j)
|
||||
{
|
||||
*((char*)ret->pixels + (y*(maxx+add) + j)) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if PFileType=pcx24bit then
|
||||
// for y:=MaxY downto 1 do
|
||||
|
@ -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;}
|
||||
};
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user