diff --git a/src/common/ResourceManager.cpp b/src/common/ResourceManager.cpp index a8722d98..ced9640f 100644 --- a/src/common/ResourceManager.cpp +++ b/src/common/ResourceManager.cpp @@ -251,7 +251,6 @@ void CResourceManager::LoadAllSprites() { gfx_loadimage(spr_awardkillsinrow, convertPath("gfx/packs/awards/killsinrownumbers.png", graphicspack), true); - //gfx_loadteamcoloredimage(&spr_flagbases, convertPath("gfx/packs/modeobjects/flagbases.png", graphicspack), 255, 0, 255, 160, false, false); gfx_loadimage(spr_flagbases, convertPath("gfx/packs/modeobjects/flagbases.png", graphicspack), 160, true); gfx_loadimage(spr_ownedtags, convertPath("gfx/packs/modeobjects/ownedtags.png", graphicspack), 160, true); diff --git a/src/common/gfx.cpp b/src/common/gfx.cpp index a911096d..cc980157 100644 --- a/src/common/gfx.cpp +++ b/src/common/gfx.cpp @@ -270,173 +270,6 @@ bool gfx_loadfullskin(gfxSprite ** gSprites, const std::string& filename, const return true; } -SDL_Surface * gfx_createteamcoloredsurface(SDL_Surface * sImage, short iColor, const RGB& key, Uint8 alpha) -{ - SDL_Surface * sTempImage = SDL_CreateRGBSurface(sImage->flags, iColor == -2 ? sImage->w << 2 : sImage->w, iColor == -1 ? sImage->h << 2 : sImage->h, sImage->format->BitsPerPixel, sImage->format->Rmask, sImage->format->Gmask, sImage->format->Bmask, sImage->format->Amask); - - //Take the loaded image and colorize it - if (SDL_MUSTLOCK(sTempImage)) - SDL_LockSurface(sTempImage); - - if (SDL_MUSTLOCK(sImage)) - SDL_LockSurface(sImage); - - //Need two counters because the pitch of the surfaces could be different - int iSrcPixelCounter = 0; - int iDstPixelCounter = 0; - - int iNextImageOffset = 0; - - if (iColor == -1) - iNextImageOffset = sImage->pitch * sImage->h; - else if (iColor == -2) - iNextImageOffset = sImage->w * 3; - - Uint8 * pixels = (Uint8*)sImage->pixels; - Uint8 * temppixels = (Uint8*)sTempImage->pixels; - - //Adjust what order we grab the pixels based on where R, G and B are - short iRedOffset = sImage->format->Rshift >> 3; - short iGreenOffset = sImage->format->Gshift >> 3; - short iBlueOffset = sImage->format->Bshift >> 3; - - for (unsigned short j = 0; j < sImage->w; j++) { - for (unsigned short i = 0; i < sImage->h; i++) { - Uint8 iColorByte1 = pixels[iSrcPixelCounter + iRedOffset]; - Uint8 iColorByte2 = pixels[iSrcPixelCounter + iGreenOffset]; - Uint8 iColorByte3 = pixels[iSrcPixelCounter + iBlueOffset]; - - bool fFoundColor = false; - for (unsigned short m = 0; m < gfx.getPalette().colorCount(); m++) { - if (gfx.getPalette().matchesColorAtID(m, iColorByte1, iColorByte2, iColorByte3)) { - if (iColor < 0) { - for (unsigned short iTeam = 0; iTeam < 4; iTeam++) { - unsigned short base = iDstPixelCounter + iNextImageOffset * iTeam; - gfx.getPalette().copyColorSchemeTo( - iTeam, 0, m, - temppixels[base + iRedOffset], - temppixels[base + iGreenOffset], - temppixels[base + iBlueOffset]); - } - } else { - gfx.getPalette().copyColorSchemeTo( - iColor, 0, m, - temppixels[iDstPixelCounter + iRedOffset], - temppixels[iDstPixelCounter + iGreenOffset], - temppixels[iDstPixelCounter + iBlueOffset]); - } - - fFoundColor = true; - break; - } - } - - if (!fFoundColor) { - if (iColor < 0) { - for (short iTeam = 0; iTeam < 4; iTeam++) { - temppixels[iDstPixelCounter + iRedOffset + iNextImageOffset * iTeam] = iColorByte1; - temppixels[iDstPixelCounter + iGreenOffset + iNextImageOffset * iTeam] = iColorByte2; - temppixels[iDstPixelCounter + iBlueOffset + iNextImageOffset * iTeam] = iColorByte3; - } - } else { - temppixels[iDstPixelCounter + iRedOffset] = iColorByte1; - temppixels[iDstPixelCounter + iGreenOffset] = iColorByte2; - temppixels[iDstPixelCounter + iBlueOffset] = iColorByte3; - } - } - - iSrcPixelCounter += 3; - iDstPixelCounter += 3; - } - - iSrcPixelCounter += sImage->pitch - sImage->w * 3; - iDstPixelCounter += sTempImage->pitch - sImage->w * 3; - } - - SDL_UnlockSurface(sImage); - SDL_UnlockSurface(sTempImage); - - if ( SDL_SETCOLORKEY(sTempImage, SDL_TRUE, SDL_MapRGB(sTempImage->format, key.r, key.g, key.b)) < 0 ) { - printf("\n ERROR: Couldn't set ColorKey + RLE for new team colored surface: %s\n", SDL_GetError()); - return NULL; - } - - if (alpha < 255) { - if (SDL_SETALPHABYTE(sTempImage, SDL_TRUE, alpha) < 0) { - cout << endl << " ERROR: Couldn't set per-surface alpha: " << SDL_GetError() << endl; - return NULL; - } - } - -#ifdef USE_SDL2 - SDL_Surface * sFinalImage = SDL_ConvertSurface(sTempImage, screen->format, 0); -#else - SDL_Surface * sFinalImage = SDL_DisplayFormat(sTempImage); -#endif - if (!sFinalImage) { - printf("\n ERROR: Couldn't create new surface using SDL_DisplayFormat(): %s\n", SDL_GetError()); - return NULL; - } - SDL_FreeSurface(sTempImage); - - return sFinalImage; -} - -bool gfx_loadteamcoloredimage(gfxSprite ** gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fWrap) -{ - //Load the image into a surface - SDL_Surface * sImage = IMG_Load(filename.c_str()); - - if (sImage == NULL) { - cout << endl << " ERROR: Couldn't load " << filename << ": " << SDL_GetError() << endl; - return false; - } - - for (short k = 0; k < 4; k++) { - SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, k, rgb, a); - - if (sTeamColoredSurface == NULL) { - cout << endl << " ERROR: Couldn't create menu skin from " << filename << ": " << SDL_GetError() << endl; - SDL_FreeSurface(sTeamColoredSurface); - return false; - } - - gSprites[k]->setSurface(sTeamColoredSurface); - gSprites[k]->SetWrap(fWrap); - } - - SDL_FreeSurface(sImage); - - - return true; -} - -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fVertical, bool fWrap) -{ - //Load the image into a surface - SDL_Surface * sImage = IMG_Load(filename.c_str()); - - if (sImage == NULL) { - cout << endl << " ERROR: Couldn't load " << filename << ": " << SDL_GetError() << endl; - return false; - } - - SDL_Surface * sTeamColoredSurface = gfx_createteamcoloredsurface(sImage, fVertical ? -1 : -2, rgb, a); - - if (sTeamColoredSurface == NULL) { - cout << endl << " ERROR: Couldn't create menu skin from " << filename << ": " << SDL_GetError() << endl; - SDL_FreeSurface(sTeamColoredSurface); - return false; - } - - gSprites->setSurface(sTeamColoredSurface); - gSprites->SetWrap(fWrap); - - SDL_FreeSurface(sImage); - - return true; -} - void gfx_cliprect(SDL_Rect * srcRect, SDL_Rect * dstRect, short x, short y, short w, short h) { if (dstRect->x >= x + w || dstRect->x + dstRect->w < x || dstRect->y >= y + h || dstRect->y + dstRect->h < y) { @@ -578,16 +411,6 @@ void gfx_drawpreview( } } -bool gfx_loadteamcoloredimage(gfxSprite* sprites, const std::string& path, bool fVertical, bool fWrap) -{ - return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA, 255, fVertical, fWrap); -} - -bool gfx_loadteamcoloredimage(gfxSprite* sprites, const std::string& path, Uint8 a, bool fVertical, bool fWrap) -{ - return gfx_loadteamcoloredimage(sprites, path, colors::MAGENTA, a, fVertical, fWrap); -} - bool gfx_loadimagenocolorkey(gfxSprite* sprite, const std::string& path) { return sprite->init(path); diff --git a/src/common/gfx.h b/src/common/gfx.h index 938ddfbc..01f8a4d2 100644 --- a/src/common/gfx.h +++ b/src/common/gfx.h @@ -58,14 +58,6 @@ void gfx_drawpreview(SDL_Surface * surface, short dstX, short dstY, short srcX, bool gfx_loadfullskin(gfxSprite ** gSprites, const std::string& filename, const RGB& colorkey, short colorScheme); bool gfx_loadmenuskin(gfxSprite ** gSprite, const std::string& filename, const RGB& colorkey, short colorScheme, bool fLoadBothDirections); -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fVertical, bool fWrap); -//Load image into an array of 4 gfxSprites, each with it's own team color -bool gfx_loadteamcoloredimage(gfxSprite ** gSprites, const std::string& filename, const RGB& rgb, Uint8 a, bool fWrap); - -//Load image into a single gfxSprite with 4 team colored sprites -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, bool fVertical, bool fWrap); -bool gfx_loadteamcoloredimage(gfxSprite * gSprites, const std::string& filename, Uint8 a, bool fVertical, bool fWrap); - bool gfx_loadimagenocolorkey(gfxSprite * gSprite, const std::string& f); bool gfx_loadimage(gfxSprite& sprite, const std::string& path, bool fWrap = true); bool gfx_loadimage(gfxSprite& sprite, const std::string& path, Uint8 alpha, bool fWrap = true); diff --git a/src/common/gfx/gfxPalette.cpp b/src/common/gfx/gfxPalette.cpp index ecf126e8..818ff7b7 100644 --- a/src/common/gfx/gfxPalette.cpp +++ b/src/common/gfx/gfxPalette.cpp @@ -10,6 +10,8 @@ namespace { Uint32 getRawPixel(SDL_Surface* surf, int x, int y) { assert(surf); + assert(0 <= x && x < surf->w); + assert(0 <= y && y < surf->h); const Uint8 bpp = surf->format->BytesPerPixel; const size_t idx = y * surf->pitch + x * bpp; @@ -17,13 +19,14 @@ Uint32 getRawPixel(SDL_Surface* surf, int x, int y) switch (bpp) { case 1: return *pixel8; - case 2: return *pixel8; + case 2: return *reinterpret_cast(pixel8); case 3: return (SDL_BYTEORDER == SDL_BIG_ENDIAN) ? pixel8[0] << 16 | pixel8[1] << 8 | pixel8[2] : pixel8[0] | pixel8[1] << 8 | pixel8[2] << 16; - case 4: return *pixel8; - default: return 0x0; + case 4: return *reinterpret_cast(pixel8); } + assert(false); + return 0x0; } @@ -31,7 +34,7 @@ RGB getRgb(SDL_Surface* surf, int x, int y) { assert(surf); const Uint32 rawPixel = getRawPixel(surf, x, y); - RGB color; + RGB color {}; SDL_GetRGB(rawPixel, surf->format, &color.r, &color.g, &color.b); return color; }