X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Fsurface.cpp;h=3c98b30747c3526a8fb52798f8cafbb06a7dfe11;hb=133d94d5b145f325c38c8c15c9ea561bfffb092d;hp=8385766a55980b5b3b0116b285e64f7d9aac2ff3;hpb=00fb759c2385ff08caf38e916c2d0ba8cafc8a41;p=supertux.git diff --git a/lib/video/surface.cpp b/lib/video/surface.cpp index 8385766a5..3c98b3074 100644 --- a/lib/video/surface.cpp +++ b/lib/video/surface.cpp @@ -27,17 +27,18 @@ #include "SDL.h" #include "SDL_image.h" -#include "../video/surface.h" -#include "../video/screen.h" -#include "../app/globals.h" -#include "../app/setup.h" +#include "video/surface.h" +#include "video/screen.h" +#include "app/globals.h" +#include "app/setup.h" using namespace SuperTux; Surface::Surfaces Surface::surfaces; SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_) - : type(SURFACE), surface(0), use_alpha(use_alpha_) + : type(SURFACE), surface(0), use_alpha(use_alpha_), + x(0), y(0), w(0), h(0) { // Copy the given surface and make sure that it is not stored in // video memory @@ -165,8 +166,8 @@ Surface::Surface(const std::string& file, bool use_alpha) surfaces.push_back(this); } -Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha) - : data(file, x, y, w, h, use_alpha), w(0), h(0) +Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use_alpha) + : data(file, x, y, w_, h_, use_alpha), w(0), h(0) { impl = data.create(); if (impl) @@ -254,58 +255,41 @@ Surface::debug_check() } void -Surface::resize(int w_, int h_) -{ - if (impl) - { - w = w_; - h = h_; - if (impl->resize(w_,h_) == -2) - reload(); - } -} - -void apply_filter_to_surface(SDL_Surface* surface, int filter, Color color) { -if(filter == HORIZONTAL_FLIP_FILTER) - { - SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); - SDL_BlitSurface(surface, NULL, sur_copy, NULL); - SDL_SetAlpha(sur_copy,0,0); - - SDL_Rect src, dst; - src.y = dst.y = 0; - src.w = dst.w = 1; - src.h = dst.h = sur_copy->h; - for(int x = 0; x < sur_copy->w; x++) + if(filter == HORIZONTAL_FLIP_FILTER) { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); + SDL_BlitSurface(surface, NULL, sur_copy, NULL); + SDL_SetAlpha(sur_copy,0,0); + + SDL_Rect src, dst; + src.y = dst.y = 0; + src.w = dst.w = 1; + src.h = dst.h = sur_copy->h; + for(int x = 0; x < sur_copy->w; x++) { - src.x = x; dst.x = sur_copy->w-1 - x; - SDL_BlitSurface(sur_copy, &src, surface, &dst); + src.x = x; dst.x = sur_copy->w-1 - x; + SDL_BlitSurface(sur_copy, &src, surface, &dst); } - SDL_FreeSurface(sur_copy); - } -else if(filter == MASK_FILTER) - { - SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); + SDL_FreeSurface(sur_copy); + } else if(filter == MASK_FILTER) { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); - Uint8 r,g,b,a; + Uint8 r,g,b,a; - SDL_LockSurface(sur_copy); - for(int x = 0; x < sur_copy->w; x++) - for(int y = 0; y < sur_copy->h; y++) - { - SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a); - if(a != 0) - { - putpixel(sur_copy, x,y, color.map_rgba(sur_copy)); + SDL_LockSurface(sur_copy); + for(int x = 0; x < sur_copy->w; x++) + for(int y = 0; y < sur_copy->h; y++) { + SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a); + if(a != 0) { + putpixel(sur_copy, x,y, color.map_rgba(sur_copy)); } } - SDL_UnlockSurface(sur_copy); + SDL_UnlockSurface(sur_copy); - SDL_BlitSurface(sur_copy, NULL, surface, NULL); - SDL_FreeSurface(sur_copy); + SDL_BlitSurface(sur_copy, NULL, surface, NULL); + SDL_FreeSurface(sur_copy); } } @@ -329,19 +313,12 @@ sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, src.w = w; src.h = h; - conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel, + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, temp->format->BitsPerPixel, temp->format->Rmask, temp->format->Gmask, temp->format->Bmask, temp->format->Amask); - /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); - #else - - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - #endif*/ - SDL_SetAlpha(temp,0,0); SDL_BlitSurface(temp, &src, conv, NULL); @@ -480,20 +457,6 @@ SDL_Surface* SurfaceImpl::get_sdl_surface() const return sdl_surface; } -int SurfaceImpl::resize(int w_, int h_) -{ - w = w_; - h = h_; - SDL_Rect dest; - dest.x = 0; - dest.y = 0; - dest.w = w; - dest.h = h; - int ret = SDL_SoftStretch(sdl_surface, NULL, - sdl_surface, &dest); - return ret; -} - #ifndef NOOPENGL SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha) { @@ -1089,4 +1052,3 @@ SurfaceSDL::apply_filter(int filter, Color color) SurfaceSDL::~SurfaceSDL() {} -/* EOF */