From e714eea84b03a7af75cb02ca6132664185d9123a Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Thu, 28 Apr 2011 14:21:08 +0000
Subject: [PATCH] pixels fix
---
src/sdl-instead/graphics.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/sdl-instead/graphics.c b/src/sdl-instead/graphics.c
index a3fdeb9..21586c7 100644
--- a/src/sdl-instead/graphics.c
+++ b/src/sdl-instead/graphics.c
@@ -604,7 +604,9 @@ int gfx_get_pixel(img_t src, int x, int y, color_t *color)
bpp = 1; /* hack? */
ptr = (Uint8*)img->pixels;
- ptr += (y * img->w + x) * bpp;
+ ptr += img->pitch * y;
+ ptr += x * bpp;
+
memcpy(&col, ptr, bpp);
SDL_UnlockSurface(img);
@@ -641,7 +643,8 @@ int gfx_set_pixel(img_t src, int x, int y, color_t color)
bpp = 1; /* hack? */
ptr = (Uint8*)img->pixels;
- ptr += (y * img->w + x) * bpp;
+ ptr += img->pitch * y;
+ ptr += x * bpp;
col = SDL_MapRGBA(img->format, color.r, color.g, color.b, color.a);
memcpy(ptr, &col, bpp);
@@ -672,8 +675,9 @@ img_t gfx_alpha_img(img_t src, int alpha)
SDL_SetAlpha(img, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
if (SDL_LockSurface(img) == 0) {
+ int w = img->w;
ptr = (Uint8*)img->pixels;
- size = img->w * img->h;
+ size = img->w * img->h;
while (size --) {
Uint8 r, g, b, a;
memcpy(&col, ptr, bpp);
@@ -681,6 +685,12 @@ img_t gfx_alpha_img(img_t src, int alpha)
col = SDL_MapRGBA(img->format, r, g, b, a * alpha / 255);
memcpy(ptr, &col, bpp);
ptr += bpp;
+ w --;
+ if (!w) {
+ w = img->w;
+ ptr += img->pitch;
+ ptr -= w * bpp;
+ }
}
SDL_UnlockSurface(img);
}