From 9a32158ae895b2be5736ecb942dcf1c1046d5033 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Thu, 6 Dec 2001 01:33:14 +0000 Subject: Screenshots in software mode (menus) implemented. --- src/main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index b2a6d7c..87a895e 100644 --- a/src/main.c +++ b/src/main.c @@ -99,7 +99,36 @@ unsigned char *GetScreenShot24(int *width, int *height) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glReadPixels(0, 0, surface->w, surface->h, GL_RGB, GL_BYTE, buf); } else { - fprintf(stderr, "GetScreenShot24: add software mode 16->24!\n"); + unsigned char *ptrd; + unsigned short int *ptrs; + int x, y; + + if (SDL_MUSTLOCK(surface)) { + if (SDL_LockSurface(surface) < 0) { + free(buf); + return NULL; /* ... */ + } + } + + ptrd = buf; + for (y = 0; y < surface->h; y++) { + ptrs = (unsigned short *)(((unsigned char *)surface->pixels) + (surface->h-y-1)*surface->pitch); + for (x = 0; x < surface->w; x++) { + unsigned int c; + + c = *ptrs; + ptrd[0] = (c & 0xF800)>>8; + ptrd[1] = (c & 0x07E0)>>3; + ptrd[2] = (c & 0x001F)<<3; + + ptrs++; + ptrd += 3; + } + } + + if (SDL_MUSTLOCK(surface)) { + SDL_UnlockSurface(surface); + } } *width = surface->w; -- cgit v1.3