From: Holger Schemel Date: Sat, 25 Jan 2003 23:15:42 +0000 (+0100) Subject: rnd-20030126-1-src X-Git-Tag: 3.0.0^2~160 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=8d93b043cc23f5a580363763ad459913127a8664 rnd-20030126-1-src --- diff --git a/Makefile b/Makefile index ba491935..03809fd4 100644 --- a/Makefile +++ b/Makefile @@ -49,8 +49,8 @@ CROSS_PATH_WIN32=/usr/local/cross-tools/i386-mingw32msvc SRC_DIR = src MAKE_CMD = $(MAKE) -C $(SRC_DIR) -DEFAULT_TARGET = x11 -# DEFAULT_TARGET = sdl +# DEFAULT_TARGET = x11 +DEFAULT_TARGET = sdl all: @$(MAKE_CMD) TARGET=$(DEFAULT_TARGET) diff --git a/src/conftime.h b/src/conftime.h index a0ec7636..ec7ca768 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-01-25 14:33]" +#define COMPILE_DATE_STRING "[2003-01-26 00:14]" diff --git a/src/events.c b/src/events.c index bb28e127..332dcca2 100644 --- a/src/events.c +++ b/src/events.c @@ -546,14 +546,14 @@ void HandleKey(Key key, int key_status) TapeTogglePause(TAPE_TOGGLE_MANUAL); } - +#if 0 #ifndef DEBUG if (game_status == PLAYING && (tape.playing || tape.pausing)) return; #endif - +#endif HandleGadgetsKeyInput(key); diff --git a/src/init.c b/src/init.c index 2f0998ae..448a2876 100644 --- a/src/init.c +++ b/src/init.c @@ -259,6 +259,33 @@ static void ReinitializeGraphics() InitGadgets(); InitToons(); + + + + /* !!! TEST ONLY !!! */ + +#ifdef TARGET_SDL + + { + Bitmap tmp_bitmap; + SDL_Surface *dst = SDLZoomSurface(graphic_info[IMG_SAND].bitmap->surface, + 0.5, 0.5); + tmp_bitmap.surface = dst; + + BlitBitmap(&tmp_bitmap, graphic_info[IMG_SAND].bitmap, + 0, 0, 256, 224, 0, 448); + + SDL_FreeSurface(dst); + } + +#elif defined(PLATFORM_MSDOS) + + stretch_blit((BITMAP *)(graphic_info[IMG_SAND].bitmap->drawable), + (BITMAP *)(graphic_info[IMG_SAND].bitmap->drawable), + 0, 0, 512, 448, + 0, 448, 256, 224); + +#endif } static void ReinitializeSounds() diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 212ce1b8..c6f4da02 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -377,7 +377,7 @@ inline Pixel SDLGetPixel(Bitmap *dst_bitmap, int x, int y) /* ========================================================================= */ -/* The following functions have been taken from the SGE library */ +/* The following functions were taken from the SGE library */ /* (SDL Graphics Extension Library) by Anders Lindström */ /* http://www.etek.chalmers.se/~e8cal1/sge/index.html */ /* ========================================================================= */ @@ -822,6 +822,325 @@ void sge_LineRGB(SDL_Surface *Surface, Sint16 x1, Sint16 y1, Sint16 x2, sge_Line(Surface, x1, y1, x2, y2, SDL_MapRGB(Surface->format, R, G, B)); } + +/* ========================================================================= */ +/* The following functions were taken from the SDL_gfx library version 2.0.3 */ +/* (Rotozoomer) by Andreas Schiffler */ +/* http://www.ferzkopp.net/Software/SDL_gfx-2.0/index.html */ +/* ========================================================================= */ + +typedef struct +{ + Uint8 r; + Uint8 g; + Uint8 b; + Uint8 a; +} tColorRGBA; + +/* + ----------------------------------------------------------------------------- + 32 bit zoomer + + zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. + ----------------------------------------------------------------------------- +*/ + +int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) +{ + int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; + tColorRGBA *sp, *csp, *dp; + int sgap, dgap; + + /* variable setup */ + sx = (int) (65536.0 * (float) src->w / (float) dst->w); + sy = (int) (65536.0 * (float) src->h / (float) dst->h); + + /* allocate memory for row increments */ + sax = (int *)checked_malloc((dst->w + 1) * sizeof(Uint32)); + say = (int *)checked_malloc((dst->h + 1) * sizeof(Uint32)); + + /* precalculate row increments */ + csx = 0; + csax = sax; + for (x = 0; x <= dst->w; x++) + { + *csax = csx; + csax++; + csx &= 0xffff; + csx += sx; + } + + csy = 0; + csay = say; + for (y = 0; y <= dst->h; y++) + { + *csay = csy; + csay++; + csy &= 0xffff; + csy += sy; + } + + /* pointer setup */ + sp = csp = (tColorRGBA *) src->pixels; + dp = (tColorRGBA *) dst->pixels; + sgap = src->pitch - src->w * 4; + dgap = dst->pitch - dst->w * 4; + + csay = say; + for (y = 0; y < dst->h; y++) + { + sp = csp; + csax = sax; + + for (x = 0; x < dst->w; x++) + { + /* draw */ + *dp = *sp; + + /* advance source pointers */ + csax++; + sp += (*csax >> 16); + + /* advance destination pointer */ + dp++; + } + + /* advance source pointer */ + csay++; + csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); + + /* advance destination pointers */ + dp = (tColorRGBA *) ((Uint8 *) dp + dgap); + } + + free(sax); + free(say); + + return 0; +} + +/* + ----------------------------------------------------------------------------- + 8 bit zoomer + + zoomes 8 bit palette/Y 'src' surface to 'dst' surface + ----------------------------------------------------------------------------- +*/ + +int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst) +{ + Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; + Uint8 *sp, *dp, *csp; + int dgap; + + /* variable setup */ + sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w); + sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h); + + /* allocate memory for row increments */ + sax = (Uint32 *)checked_malloc(dst->w * sizeof(Uint32)); + say = (Uint32 *)checked_malloc(dst->h * sizeof(Uint32)); + + /* precalculate row increments */ + csx = 0; + csax = sax; + for (x = 0; x < dst->w; x++) + { + csx += sx; + *csax = (csx >> 16); + csx &= 0xffff; + csax++; + } + + csy = 0; + csay = say; + for (y = 0; y < dst->h; y++) + { + csy += sy; + *csay = (csy >> 16); + csy &= 0xffff; + csay++; + } + + csx = 0; + csax = sax; + for (x = 0; x < dst->w; x++) + { + csx += (*csax); + csax++; + } + + csy = 0; + csay = say; + for (y = 0; y < dst->h; y++) + { + csy += (*csay); + csay++; + } + + /* pointer setup */ + sp = csp = (Uint8 *) src->pixels; + dp = (Uint8 *) dst->pixels; + dgap = dst->pitch - dst->w; + + /* draw */ + csay = say; + for (y = 0; y < dst->h; y++) + { + csax = sax; + sp = csp; + for (x = 0; x < dst->w; x++) + { + /* draw */ + *dp = *sp; + + /* advance source pointers */ + sp += (*csax); + csax++; + + /* advance destination pointer */ + dp++; + } + + /* advance source pointer (for row) */ + csp += ((*csay) * src->pitch); + csay++; + + /* advance destination pointers */ + dp += dgap; + } + + free(sax); + free(say); + + return 0; +} + +/* + ----------------------------------------------------------------------------- + zoomSurface() + + Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + 'zoomx' and 'zoomy' are scaling factors for width and height. + If 'smooth' is 1 then the destination 32bit surface is anti-aliased. + If the surface is not 8bit or 32bit RGBA/ABGR it will be converted + into a 32bit RGBA format on the fly. + ----------------------------------------------------------------------------- +*/ + +void zoomSurfaceSize(int width, int height, float zoom_x, float zoom_y, + int *dst_width, int *dst_height) +{ + const float value_limit = 0.001; + + /* sanity check zoom factors */ + if (zoom_x < value_limit) + zoom_x = value_limit; + if (zoom_y < value_limit) + zoom_y = value_limit; + + /* calculate target size */ + *dst_width = (int) ((float) width * zoom_x); + *dst_height = (int) ((float) height * zoom_y); + + if (*dst_width < 1) + *dst_width = 1; + if (*dst_height < 1) + *dst_height = 1; +} + +SDL_Surface *zoomSurface(SDL_Surface *src, float zoom_x, float zoom_y) +{ + SDL_Surface *zoom_src = NULL; + SDL_Surface *zoom_dst = NULL; + int dst_width, dst_height; + boolean is_converted = FALSE; + boolean is_32bit; + int i; + + if (src == NULL) + return NULL; + + /* determine if source surface is 32 bit or 8 bit */ + is_32bit = (src->format->BitsPerPixel == 32); + + if (is_32bit || src->format->BitsPerPixel == 8) + { + /* use source surface 'as is' */ + zoom_src = src; + } + else + { + /* new source surface is 32 bit with a defined RGB ordering */ + zoom_src = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, + 0x000000ff, 0x0000ff00, 0x00ff0000, 0); + SDL_BlitSurface(src, NULL, zoom_src, NULL); + is_32bit = TRUE; + is_converted = TRUE; + } + + /* get size of destination surface */ + zoomSurfaceSize(zoom_src->w, zoom_src->h, zoom_x, zoom_y, + &dst_width, &dst_height); + + /* allocate surface to completely contain the zoomed surface */ + if (is_32bit) + { + /* target surface is 32 bit with source RGBA/ABGR ordering */ + zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 32, + zoom_src->format->Rmask, + zoom_src->format->Gmask, + zoom_src->format->Bmask, 0); + } + else + { + /* target surface is 8 bit */ + zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 8, + 0, 0, 0, 0); + } + + /* lock source surface */ + SDL_LockSurface(zoom_src); + + /* check which kind of surface we have */ + if (is_32bit) + { + /* call the 32 bit transformation routine to do the zooming */ + zoomSurfaceRGBA(zoom_src, zoom_dst); + } + else + { + /* copy palette */ + for (i=0; i < zoom_src->format->palette->ncolors; i++) + zoom_dst->format->palette->colors[i] = + zoom_src->format->palette->colors[i]; + zoom_dst->format->palette->ncolors = zoom_src->format->palette->ncolors; + + /* call the 8 bit transformation routine to do the zooming */ + zoomSurfaceY(zoom_src, zoom_dst); + } + + /* unlock source surface */ + SDL_UnlockSurface(zoom_src); + + /* free temporary surface */ + if (is_converted) + SDL_FreeSurface(zoom_src); + + /* return destination surface */ + return zoom_dst; +} + +SDL_Surface *SDLZoomSurface(SDL_Surface *src, float zoom_x, float zoom_y) +{ + return zoomSurface(src, zoom_x, zoom_y); +} + + +/* ========================================================================= */ +/* load image to bitmap */ +/* ========================================================================= */ + Bitmap *SDLLoadImage(char *filename) { Bitmap *new_bitmap = CreateBitmapStruct(); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 64db7795..8d9f0941 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -330,6 +330,8 @@ inline void SDLDrawSimpleLine(Bitmap *, int, int, int, int, unsigned int); inline void SDLDrawLine(Bitmap *, int, int, int, int, Uint32); inline Pixel SDLGetPixel(Bitmap *, int, int); +SDL_Surface *SDLZoomSurface(SDL_Surface *, float, float); + Bitmap *SDLLoadImage(char *); inline void SDLOpenAudio(void); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 561c51ed..dcf94aaa 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -425,11 +425,11 @@ static char *getCorrectedImageBasename(char *basename) { static char *msdos_filename = NULL; - if (filename != NULL) - free(filename); + if (msdos_filename != NULL) + free(msdos_filename); - filename = getStringCopy(basename_corrected); - strncpy(&filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1); + msdos_filename = getStringCopy(basename_corrected); + strncpy(&msdos_filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1); } } #endif