#include "video/sdl/sdl_renderer.hpp"
#include "video/drawing_request.hpp"
#include "video/sdl/sdl_surface_data.hpp"
#include "video/sdl/sdl_texture.hpp"
#include <iomanip>
#include <iostream>
#include <physfs.h>
#include <sstream>
#include <stdexcept>
Go to the source code of this file.
Functions | |
SDL_Surface * | apply_alpha (SDL_Surface *src, float alpha_factor) |
SDL_Surface* @522::apply_alpha | ( | SDL_Surface * | src, | |
float | alpha_factor | |||
) | [static] |
Definition at line 31 of file sdl_renderer.cpp.
00032 { 00033 // FIXME: This is really slow 00034 assert(src->format->Amask); 00035 int alpha = (int) (alpha_factor * 256); 00036 SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w, src->h, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask); 00037 int bpp = dst->format->BytesPerPixel; 00038 if(SDL_MUSTLOCK(src)) 00039 { 00040 SDL_LockSurface(src); 00041 } 00042 if(SDL_MUSTLOCK(dst)) 00043 { 00044 SDL_LockSurface(dst); 00045 } 00046 for(int y = 0;y < dst->h;y++) { 00047 for(int x = 0;x < dst->w;x++) { 00048 Uint8 *srcpixel = (Uint8 *) src->pixels + y * src->pitch + x * bpp; 00049 Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp; 00050 Uint32 mapped = 0; 00051 switch(bpp) { 00052 case 1: 00053 mapped = *srcpixel; 00054 break; 00055 case 2: 00056 mapped = *(Uint16 *)srcpixel; 00057 break; 00058 case 3: 00059 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 00060 mapped |= srcpixel[0] << 16; 00061 mapped |= srcpixel[1] << 8; 00062 mapped |= srcpixel[2] << 0; 00063 #else 00064 mapped |= srcpixel[0] << 0; 00065 mapped |= srcpixel[1] << 8; 00066 mapped |= srcpixel[2] << 16; 00067 #endif 00068 break; 00069 case 4: 00070 mapped = *(Uint32 *)srcpixel; 00071 break; 00072 } 00073 Uint8 r, g, b, a; 00074 SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a); 00075 mapped = SDL_MapRGBA(dst->format, r, g, b, (a * alpha) >> 8); 00076 switch(bpp) { 00077 case 1: 00078 *dstpixel = mapped; 00079 break; 00080 case 2: 00081 *(Uint16 *)dstpixel = mapped; 00082 break; 00083 case 3: 00084 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 00085 dstpixel[0] = (mapped >> 16) & 0xff; 00086 dstpixel[1] = (mapped >> 8) & 0xff; 00087 dstpixel[2] = (mapped >> 0) & 0xff; 00088 #else 00089 dstpixel[0] = (mapped >> 0) & 0xff; 00090 dstpixel[1] = (mapped >> 8) & 0xff; 00091 dstpixel[2] = (mapped >> 16) & 0xff; 00092 #endif 00093 break; 00094 case 4: 00095 *(Uint32 *)dstpixel = mapped; 00096 break; 00097 } 00098 } 00099 } 00100 if(SDL_MUSTLOCK(dst)) 00101 { 00102 SDL_UnlockSurface(dst); 00103 } 00104 if(SDL_MUSTLOCK(src)) 00105 { 00106 SDL_UnlockSurface(src); 00107 } 00108 return dst; 00109 }