summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp78
1 files changed, 0 insertions, 78 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 7f14a73e..31e6a913 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -326,84 +326,6 @@ void Image::setAlpha(float alpha)
}
}
-Image* Image::SDLmerge(Image *image, int x, int y)
-{
- if (!mSDLSurface)
- return NULL;
-
- SDL_Surface* surface = new SDL_Surface(*(image->mSDLSurface));
-
- Uint32 surface_pix, cur_pix;
- Uint8 r, g, b, a, p_r, p_g, p_b, p_a;
- double f_a, f_ca, f_pa;
- SDL_PixelFormat *current_fmt = mSDLSurface->format;
- SDL_PixelFormat *surface_fmt = surface->format;
- int current_offset, surface_offset;
- int offset_x, offset_y;
-
- SDL_LockSurface(surface);
- SDL_LockSurface(mSDLSurface);
- // for each pixel lines of a source image
- for (offset_x = (x > 0 ? 0 : -x); offset_x < image->getWidth() &&
- x + offset_x < getWidth(); offset_x++)
- {
- for (offset_y = (y > 0 ? 0 : -y); offset_y < image->getHeight()
- && y + offset_y < getHeight(); offset_y++)
- {
- // Computing offset on both images
- current_offset = (y + offset_y) * getWidth() + x + offset_x;
- surface_offset = offset_y * surface->w + offset_x;
-
- // Retrieving a pixel to merge
- surface_pix = ((Uint32*) surface->pixels)[surface_offset];
- cur_pix = ((Uint32*) mSDLSurface->pixels)[current_offset];
-
- // Retreiving each channel of the pixel using pixel format
- r = (Uint8)(((surface_pix & surface_fmt->Rmask) >>
- surface_fmt->Rshift) << surface_fmt->Rloss);
- g = (Uint8)(((surface_pix & surface_fmt->Gmask) >>
- surface_fmt->Gshift) << surface_fmt->Gloss);
- b = (Uint8)(((surface_pix & surface_fmt->Bmask) >>
- surface_fmt->Bshift) << surface_fmt->Bloss);
- a = (Uint8)(((surface_pix & surface_fmt->Amask) >>
- surface_fmt->Ashift) << surface_fmt->Aloss);
-
- // Retreiving previous alpha value
- p_a = (Uint8)(((cur_pix & current_fmt->Amask) >>
- current_fmt->Ashift) << current_fmt->Aloss);
-
- // new pixel with no alpha or nothing on previous pixel
- if (a == SDL_ALPHA_OPAQUE || (p_a == 0 && a > 0))
- ((Uint32 *)(surface->pixels))[current_offset] =
- SDL_MapRGBA(current_fmt, r, g, b, a);
- else if (a > 0)
- { // alpha is lower => merge color with previous value
- f_a = (double) a / 255.0;
- f_ca = 1.0 - f_a;
- f_pa = (double) p_a / 255.0;
- p_r = (Uint8)(((cur_pix & current_fmt->Rmask) >>
- current_fmt->Rshift) << current_fmt->Rloss);
- p_g = (Uint8)(((cur_pix & current_fmt->Gmask) >>
- current_fmt->Gshift) << current_fmt->Gloss);
- p_b = (Uint8)(((cur_pix & current_fmt->Bmask) >>
- current_fmt->Bshift) << current_fmt->Bloss);
- r = (Uint8)((double) p_r * f_ca * f_pa + (double)r * f_a);
- g = (Uint8)((double) p_g * f_ca * f_pa + (double)g * f_a);
- b = (Uint8)((double) p_b * f_ca * f_pa + (double)b * f_a);
- a = (a > p_a ? a : p_a);
- ((Uint32 *)(surface->pixels))[current_offset] =
- SDL_MapRGBA(current_fmt, r, g, b, a);
- }
- }
- }
- SDL_UnlockSurface(surface);
- SDL_UnlockSurface(mSDLSurface);
-
- Image *newImage = new Image(surface);
-
- return newImage;
-}
-
Image* Image::SDLgetScaledImage(int width, int height)
{
// No scaling on incorrect new values.