|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: gfxpixelimage.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */
|
|
|
|
|
/* $Id: gfxpixelimage.c,v 1.2 2003/07/24 12:41:27 stpohle Exp $ */
|
|
|
|
|
/* gfx pixel manipulation and image manipulation */
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
@ -27,7 +27,7 @@ getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B)
|
|
|
|
|
*B = b;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* getpixel for every BPP version */
|
|
|
|
|
Uint32
|
|
|
|
|
getpixel (SDL_Surface * surface, int x, int y)
|
|
|
|
|
{
|
|
|
|
@ -54,6 +54,38 @@ getpixel (SDL_Surface * surface, int x, int y)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Uint32
|
|
|
|
|
getpixel32 (SDL_Surface * surface, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to retrieve */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
|
return *(Uint32 *) p;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Uint32
|
|
|
|
|
getpixel24 (SDL_Surface * surface, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to retrieve */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;;
|
|
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
|
return p[0] << 16 | p[1] << 8 | p[2];
|
|
|
|
|
#else
|
|
|
|
|
return p[0] | p[1] << 8 | p[2] << 16;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Uint32
|
|
|
|
|
getpixel16 (SDL_Surface * surface, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to retrieve */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
|
return *(Uint16 *) p;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* putpixel seperated for every BPP version */
|
|
|
|
|
void
|
|
|
|
|
putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|
|
|
|
{
|
|
|
|
@ -87,6 +119,41 @@ putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
putpixel32 (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to set */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
|
*(Uint32 *) p = pixel;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
putpixel24 (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to set */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
|
|
p[0] = (pixel >> 16) & 0xff;
|
|
|
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
|
|
|
p[2] = pixel & 0xff;
|
|
|
|
|
#else
|
|
|
|
|
p[0] = pixel & 0xff;
|
|
|
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
|
|
|
p[2] = (pixel >> 16) & 0xff;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
putpixel16 (SDL_Surface * surface, int x, int y, Uint32 pixel)
|
|
|
|
|
{
|
|
|
|
|
/* Here p is the address to the pixel we want to set */
|
|
|
|
|
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
|
|
|
|
|
*(Uint16 *) p = pixel;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
scale (short int *dpattern, short int x, short int y)
|
|
|
|
|
{
|
|
|
|
@ -141,6 +208,7 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
|
|
|
|
|
SDL_Surface *surface;
|
|
|
|
|
int y,
|
|
|
|
|
x;
|
|
|
|
|
int bpp = orginal->format->BytesPerPixel;
|
|
|
|
|
short int xpattern[SCALE_MAXRES];
|
|
|
|
|
short int ypattern[SCALE_MAXRES];
|
|
|
|
|
|
|
|
|
@ -155,7 +223,6 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
|
|
|
|
|
gmask = 0x0000ff00;
|
|
|
|
|
bmask = 0x000000ff;
|
|
|
|
|
amask = 0xff000000;
|
|
|
|
|
|
|
|
|
|
#endif /* */
|
|
|
|
|
|
|
|
|
|
surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask);
|
|
|
|
@ -182,9 +249,29 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
|
|
|
|
|
/* do the scaling work */
|
|
|
|
|
scale (xpattern, orginal->w - 1, newx);
|
|
|
|
|
scale (ypattern, orginal->h - 1, newy);
|
|
|
|
|
|
|
|
|
|
switch (bpp) {
|
|
|
|
|
case (2):
|
|
|
|
|
for (x = newx - 1; x >= 0; x--)
|
|
|
|
|
for (y = newy - 1; y >= 0; y--)
|
|
|
|
|
putpixel16 (surface, x, y, getpixel16 (orginal, xpattern[x], ypattern[y]));
|
|
|
|
|
break;
|
|
|
|
|
case (3):
|
|
|
|
|
for (x = newx - 1; x >= 0; x--)
|
|
|
|
|
for (y = newy - 1; y >= 0; y--)
|
|
|
|
|
putpixel24 (surface, x, y, getpixel24 (orginal, xpattern[x], ypattern[y]));
|
|
|
|
|
break;
|
|
|
|
|
case (4):
|
|
|
|
|
for (x = newx - 1; x >= 0; x--)
|
|
|
|
|
for (y = newy - 1; y >= 0; y--)
|
|
|
|
|
putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y]));
|
|
|
|
|
putpixel32 (surface, x, y, getpixel32 (orginal, xpattern[x], ypattern[y]));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf ("scale_image, wrong bpp value (%d).\n", bpp);
|
|
|
|
|
exit (1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SDL_MUSTLOCK (orginal)) {
|
|
|
|
|
SDL_UnlockSurface (orginal);
|
|
|
|
|
}
|
|
|
|
@ -204,7 +291,8 @@ makegray_image (SDL_Surface * org)
|
|
|
|
|
Uint32 pixel,
|
|
|
|
|
transpixel = 0;
|
|
|
|
|
SDL_Surface *dest;
|
|
|
|
|
int y,
|
|
|
|
|
int bpp = org->format->BytesPerPixel,
|
|
|
|
|
y,
|
|
|
|
|
x;
|
|
|
|
|
Uint8 r,
|
|
|
|
|
g,
|
|
|
|
@ -242,9 +330,12 @@ makegray_image (SDL_Surface * org)
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (bpp) {
|
|
|
|
|
case (2):
|
|
|
|
|
for (x = 0; x < org->w; x++)
|
|
|
|
|
for (y = 0; y < org->h; y++) {
|
|
|
|
|
pixel = getpixel (org, x, y);
|
|
|
|
|
pixel = getpixel16 (org, x, y);
|
|
|
|
|
if (x == 0 && y == 0)
|
|
|
|
|
transpixel = pixel;
|
|
|
|
|
if (pixel != transpixel) {
|
|
|
|
@ -252,8 +343,43 @@ makegray_image (SDL_Surface * org)
|
|
|
|
|
gray = (r / 3 + g / 3 + b / 3);
|
|
|
|
|
pixel = SDL_MapRGB (dest->format, gray, gray, gray);
|
|
|
|
|
}
|
|
|
|
|
putpixel (dest, x, y, pixel);
|
|
|
|
|
putpixel16 (dest, x, y, pixel);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case (3):
|
|
|
|
|
for (x = 0; x < org->w; x++)
|
|
|
|
|
for (y = 0; y < org->h; y++) {
|
|
|
|
|
pixel = getpixel24 (org, x, y);
|
|
|
|
|
if (x == 0 && y == 0)
|
|
|
|
|
transpixel = pixel;
|
|
|
|
|
if (pixel != transpixel) {
|
|
|
|
|
SDL_GetRGB (pixel, org->format, &r, &g, &b);
|
|
|
|
|
gray = (r / 3 + g / 3 + b / 3);
|
|
|
|
|
pixel = SDL_MapRGB (dest->format, gray, gray, gray);
|
|
|
|
|
}
|
|
|
|
|
putpixel24 (dest, x, y, pixel);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case (4):
|
|
|
|
|
for (x = 0; x < org->w; x++)
|
|
|
|
|
for (y = 0; y < org->h; y++) {
|
|
|
|
|
pixel = getpixel32 (org, x, y);
|
|
|
|
|
if (x == 0 && y == 0)
|
|
|
|
|
transpixel = pixel;
|
|
|
|
|
if (pixel != transpixel) {
|
|
|
|
|
SDL_GetRGB (pixel, org->format, &r, &g, &b);
|
|
|
|
|
gray = (r / 3 + g / 3 + b / 3);
|
|
|
|
|
pixel = SDL_MapRGB (dest->format, gray, gray, gray);
|
|
|
|
|
}
|
|
|
|
|
putpixel32 (dest, x, y, pixel);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf ("gray_image, wrong bpp value (%d).\n", bpp);
|
|
|
|
|
exit (1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SDL_MUSTLOCK (org)) {
|
|
|
|
|
SDL_UnlockSurface (org);
|
|
|
|
|
}
|
|
|
|
|