Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor video driver sprite creation

CreateSprite8() now enforces 8bpp as the name implies and also takes a Palette* instead of void* (Color*)
A new method CreatePalettedSprite() will fill in for creating non 8bpp paletted sprites using an array of Colors
  • Loading branch information...
commit d7a6a404f8dbc4cb02ede0622256cc181f06ac57 1 parent a1fdb4b
@bradallred bradallred authored
View
6 gemrb/core/Video.h
@@ -134,8 +134,10 @@ class GEM_EXPORT Video : public Plugin {
virtual Sprite2D* CreateSprite(int w, int h, int bpp, ieDword rMask,
ieDword gMask, ieDword bMask, ieDword aMask, void* pixels,
bool cK = false, int index = 0) = 0;
- virtual Sprite2D* CreateSprite8(int w, int h, int bpp, void* pixels,
- void* palette, bool cK = false, int index = 0) = 0;
+ virtual Sprite2D* CreateSprite8(int w, int h, void* pixels,
+ Palette* palette, bool cK = false, int index = 0) = 0;
+ virtual Sprite2D* CreatePalettedSprite(int w, int h, int bpp, void* pixels,
+ Color* palette, bool cK = false, int index = 0) = 0;
virtual bool SupportsBAMSprites() { return false; }
virtual void FreeSprite(Sprite2D* &spr) = 0;
virtual Sprite2D* DuplicateSprite(const Sprite2D* spr) = 0;
View
2  gemrb/plugins/BAMImporter/BAMFont.cpp
@@ -55,7 +55,7 @@ BAMFont::BAMFont(AnimationFactory* af, int* baseline)
pal->release();
first->release();
- blank = core->GetVideoDriver()->CreateSprite8(0, 0, 8, NULL, palette->col);
+ blank = core->GetVideoDriver()->CreateSprite8(0, 0, NULL, palette);
}
BAMFont::~BAMFont()
View
6 gemrb/plugins/BAMImporter/BAMImporter.cpp
@@ -153,8 +153,8 @@ Sprite2D* BAMImporter::GetFrameInternal(unsigned short findex, unsigned char mod
} else {
void* pixels = GetFramePixels(findex);
spr = core->GetVideoDriver()->CreateSprite8(
- frames[findex].Width, frames[findex].Height, 8,
- pixels, palette->col, true, 0 );
+ frames[findex].Width, frames[findex].Height,
+ pixels, palette, true, 0 );
}
spr->XPos = (ieWordSigned)frames[findex].XPos;
@@ -287,7 +287,7 @@ Sprite2D* BAMImporter::GetPalette()
for (int i = 0; i < 256; i++) {
*p++ = ( unsigned char ) i;
}
- return core->GetVideoDriver()->CreateSprite8( 16, 16, 8, pixels, palette->col, false );
+ return core->GetVideoDriver()->CreateSprite8( 16, 16, pixels, palette );
}
#include "BAMFontManager.h"
View
4 gemrb/plugins/BMPImporter/BMPImporter.cpp
@@ -234,8 +234,8 @@ Sprite2D* BMPImporter::GetSprite2D()
} else if (BitCount == 8) {
void* p = malloc( Width* Height );
memcpy( p, pixels, Width * Height );
- spr = core->GetVideoDriver()->CreateSprite8( Width, Height, NumColors==16?4:8,
- p, Palette, true, 0 );
+ spr = core->GetVideoDriver()->CreatePalettedSprite(Width, Height, NumColors == 16 ? 4 : 8,
+ p, Palette, true, 0);
}
return spr;
}
View
3  gemrb/plugins/PNGImporter/PNGImporter.cpp
@@ -180,8 +180,7 @@ Sprite2D* PNGImporter::GetSprite2D()
Color pal[256];
GetPalette(256, pal);
// TODO: colorkey
- spr = core->GetVideoDriver()->CreateSprite8(Width, Height, 8,
- buffer, pal, false, 0);
+ spr = core->GetVideoDriver()->CreatePalettedSprite(Width, Height, 8, buffer, pal);
} else {
spr = core->GetVideoDriver()->CreateSprite(Width, Height, 32,
red_mask, green_mask,
View
25 gemrb/plugins/SDLVideo/SDLVideo.cpp
@@ -393,29 +393,28 @@ void SDLVideoDriver::AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly
}
}
-
Sprite2D* SDLVideoDriver::CreateSprite(int w, int h, int bpp, ieDword rMask,
ieDword gMask, ieDword bMask, ieDword aMask, void* pixels, bool cK, int index)
{
SDL_Surface* p = SDL_CreateRGBSurfaceFrom( pixels, w, h, bpp, w*( bpp / 8 ),
- rMask, gMask, bMask, aMask );
+ rMask, gMask, bMask, aMask );
if (cK) {
SDL_SetColorKey( p, SDL_SRCCOLORKEY | SDL_RLEACCEL, index );
}
return new Sprite2D(w, h, bpp, p, pixels);
}
-Sprite2D* SDLVideoDriver::CreateSprite8(int w, int h, int bpp, void* pixels,
- void* palette, bool cK, int index)
+Sprite2D* SDLVideoDriver::CreateSprite8(int w, int h, void* pixels,
+ Palette* palette, bool cK, int index)
+{
+ return CreatePalettedSprite(w, h, 8, pixels, palette->col, cK, index);
+}
+
+Sprite2D* SDLVideoDriver::CreatePalettedSprite(int w, int h, int bpp, void* pixels,
+ Color* palette, bool cK, int index)
{
SDL_Surface* p = SDL_CreateRGBSurfaceFrom( pixels, w, h, 8, w, 0, 0, 0, 0 );
- int colorcount;
- if (bpp == 8) {
- colorcount = 256;
- } else {
- colorcount = 16;
- }
- SetSurfacePalette( p, ( SDL_Color * ) palette, colorcount );
+ SetSurfacePalette( p, (SDL_Color*)palette, 0x01 << bpp );
if (cK) {
SDL_SetColorKey( p, SDL_SRCCOLORKEY, index );
}
@@ -457,8 +456,8 @@ Sprite2D* SDLVideoDriver::DuplicateSprite(const Sprite2D* sprite)
SDL_LockSurface( tmp );
memcpy(newpixels, sprite->pixels, sprite->Width*sprite->Height);
- dest = CreateSprite8(sprite->Width, sprite->Height, 8,
- newpixels, tmp->format->palette->colors, true, 0);
+ dest = CreatePalettedSprite(sprite->Width, sprite->Height, 8, newpixels,
+ (Color*)tmp->format->palette->colors, true, 0);
SDL_UnlockSurface( tmp );
} else {
dest = sprite->copy();
View
6 gemrb/plugins/SDLVideo/SDLVideo.h
@@ -87,8 +87,10 @@ class SDLVideoDriver : public Video {
Sprite2D* CreateSprite(int w, int h, int bpp, ieDword rMask,
ieDword gMask, ieDword bMask, ieDword aMask, void* pixels,
bool cK = false, int index = 0);
- Sprite2D* CreateSprite8(int w, int h, int bpp, void* pixels,
- void* palette, bool cK = false, int index = 0);
+ Sprite2D* CreateSprite8(int w, int h, void* pixels,
+ Palette* palette, bool cK, int index);
+ Sprite2D* CreatePalettedSprite(int w, int h, int bpp, void* pixels,
+ Color* palette, bool cK = false, int index = 0);
bool SupportsBAMSprites() { return true; }
void FreeSprite(Sprite2D* &spr);
Sprite2D* DuplicateSprite(const Sprite2D* spr);
View
4 gemrb/plugins/TISImporter/TISImporter.cpp
@@ -107,7 +107,7 @@ Sprite2D* TISImporter::GetTile(int index)
memset(pixels, 0, 4096);
memset(Palette, 0, 256 * sizeof(Color));
Palette[0].g = 200;
- Sprite2D* spr = core->GetVideoDriver()->CreateSprite8( 64, 64, 8, pixels, Palette, false, 0 );
+ Sprite2D* spr = core->GetVideoDriver()->CreatePalettedSprite( 64, 64, 8, pixels, Palette );
spr->XPos = spr->YPos = 0;
return spr;
}
@@ -130,7 +130,7 @@ Sprite2D* TISImporter::GetTile(int index)
}
}
str->Read( pixels, 4096 );
- Sprite2D* spr = core->GetVideoDriver()->CreateSprite8( 64, 64, 8, pixels, Palette, transparent, transindex );
+ Sprite2D* spr = core->GetVideoDriver()->CreatePalettedSprite( 64, 64, 8, pixels, Palette, transparent, transindex );
spr->XPos = spr->YPos = 0;
return spr;
}
View
8 gemrb/plugins/TTFImporter/TTFFont.cpp
@@ -158,7 +158,7 @@ const Sprite2D* TTFFont::GetCharSprite(ieWord chr) const
// TODO: do an underline if requested
- Sprite2D* spr = core->GetVideoDriver()->CreateSprite8(sprWidth, sprHeight, 8, pixels, palette, true, 0);
+ Sprite2D* spr = core->GetVideoDriver()->CreateSprite8(sprWidth, sprHeight, pixels, palette, true, 0);
// for some reason BAM fonts are all based of a YPos of 13
spr->YPos = 13 - yoffset;
// cache the glyph
@@ -266,11 +266,11 @@ TTFFont::TTFFont(FT_Face face, ieWord ptSize, FontStyle style, Palette* pal)
SetPalette(pal);
// TODO: ttf fonts have a "box" glyph they use for this
- blank = core->GetVideoDriver()->CreateSprite8(0, 0, 8, NULL, palette->col);
+ blank = core->GetVideoDriver()->CreateSprite8(0, 0, NULL, palette);
// ttf fonts dont produce glyphs for whitespace
int SpaceWidth = core->TLKEncoding.zerospace ? 1 : (ptSize * 0.25);
- Sprite2D* space = core->GetVideoDriver()->CreateSprite8(SpaceWidth, 0, 8, NULL, palette->col);;
- Sprite2D* tab = core->GetVideoDriver()->CreateSprite8((space->Width)*4, 0, 8, NULL, palette->col);
+ Sprite2D* space = core->GetVideoDriver()->CreateSprite8(SpaceWidth, 0, NULL, palette);
+ Sprite2D* tab = core->GetVideoDriver()->CreateSprite8((space->Width)*4, 0, NULL, palette);
// now cache these glyphs for quick access
// WARNING: if we ever did something to purge the cache these would be lost
Please sign in to comment.
Something went wrong with that request. Please try again.