From a3208576a5cc8c571a0633c34a46aaa83e8028d1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 1 Feb 2011 21:51:09 -0800 Subject: [PATCH] SDL doesn't actually support the physical/logical palette split anymore. --- test/Makefile.in | 5 +- test/sail.bmp | Bin 15858 -> 0 bytes test/testpalette.c | 347 --------------------------------------------- 3 files changed, 1 insertion(+), 351 deletions(-) delete mode 100644 test/sail.bmp delete mode 100644 test/testpalette.c diff --git a/test/Makefile.in b/test/Makefile.in index c3268f614..f1969286a 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -7,7 +7,7 @@ EXE = @EXE@ CFLAGS = @CFLAGS@ LIBS = @LIBS@ -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testshape$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testgesture$(EXE) +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testshape$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testgesture$(EXE) all: Makefile $(TARGETS) @@ -101,9 +101,6 @@ testoverlay2$(EXE): $(srcdir)/testoverlay2.c testoverlay$(EXE): $(srcdir)/testoverlay.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testpalette$(EXE): $(srcdir)/testpalette.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@ - testplatform$(EXE): $(srcdir)/testplatform.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) diff --git a/test/sail.bmp b/test/sail.bmp deleted file mode 100644 index 12850c300f82a028d1ab2bb4b37ecb99c9ce5bd7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15858 zcmd5@Ux*|}8L#f%nccm;oAs`@H?yR@ZKiuCvpM%VlilgwbEa?7QBJ|X2);xKL0=Nk zmpoh`!GQO0!iA7vd{AQW$%m69Xb=qsBq~aRQGAGkc}T!NpaBC0j1VOH`@X8`uAZIU z+spP4YiGKvyQ}K^)$jZ2tFNkOZ~w%bnc#HZ5~7FPWBA^KuO$}v{trh&oLZ9K+i{1! zU$AZQ_FHd>fBfaI;?s;%t6V zoWF3dxZ~n?#g8su79aWWm&A{+ToKP)x+MPd_S@o_XI~WmeEoIt+@p_*PYpjOc0d0O z@#~lWBp$l&in#i~gW{cc-Vqlsd`8^$#mnN^pZ!6+_~g^#I}cnE4}be7;$LsPA^!gA zYv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ASrKr0=C1rPRI7)Ev>-z?2VYQNk)> z`5FX~g_8PGmZ*6-ZbGVH%6r&@Qkypf#6ZTFG%9*FyHQu=DIf6f78wiC#qLT0DS2Y2 zHG>sYNtLNP`o)-Zp*6BnL0U|t{WX6DmyEB`98Px

wcioaEz@4EZ0IEq$xkKKdI=v8G<{jUvbN5my%sB1Al$T)=VL{Tw$tyah zGYT*juDzJB0#(xWSzi{LX0uh@Ufls}R<5f|Jr=(sn#qFvK;7XXMM{K=vB@xixMDv+ zXQTcsvQu;iG5pe#R0mY$8cXYP7C6i{r(?nfH38zUiawE7iTvkG(>|CGpGyQVA__2> zA{Eum6c07NA0}A3oMtTi_#T!8_pZaw_Yf1jr{srz)_~=c_L?(?bO2AZNv-A;kc6E) zW#aEGCj6QdZ=qmUK%*5`?)}UT+y3^%GJ}YzB24NR*t3IDw0sRrpb9}ctlbUqk0LOz zqT&oQ*TRGiSo}K&z@#>QGxPs~DNjPYIK*!_Y1eRu?37Jko2NV<#Qg6uc#&Avn`Q1W xnDPKdb=z&}wf{@49;AoDgvG;cNVARP%KjV@Q%;!5TC>d^785|t7KqWh_#c$H%mM%a diff --git a/test/testpalette.c b/test/testpalette.c deleted file mode 100644 index f9a2a7ebd..000000000 --- a/test/testpalette.c +++ /dev/null @@ -1,347 +0,0 @@ -/* - * testpalette.c - * - * A simple test of runtime palette modification for animation - * (using the SDL_SetPalette() API). - */ - -#include -#include -#include -#include - -#include "SDL.h" - -/* screen size */ -#define SCRW 640 -#define SCRH 480 - -#define NBOATS 5 -#define SPEED 2 - -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - -/* - * wave colours: Made by taking a narrow cross-section of a wave picture - * in Gimp, saving in PPM ascii format and formatting with Emacs macros. - */ -static SDL_Color wavemap[] = { - {0, 2, 103}, {0, 7, 110}, {0, 13, 117}, {0, 19, 125}, - {0, 25, 133}, {0, 31, 141}, {0, 37, 150}, {0, 43, 158}, - {0, 49, 166}, {0, 55, 174}, {0, 61, 182}, {0, 67, 190}, - {0, 73, 198}, {0, 79, 206}, {0, 86, 214}, {0, 96, 220}, - {5, 105, 224}, {12, 112, 226}, {19, 120, 227}, {26, 128, 229}, - {33, 135, 230}, {40, 143, 232}, {47, 150, 234}, {54, 158, 236}, - {61, 165, 238}, {68, 173, 239}, {75, 180, 241}, {82, 188, 242}, - {89, 195, 244}, {96, 203, 246}, {103, 210, 248}, {112, 218, 250}, - {124, 224, 250}, {135, 226, 251}, {146, 229, 251}, {156, 231, 252}, - {167, 233, 252}, {178, 236, 252}, {189, 238, 252}, {200, 240, 252}, - {211, 242, 252}, {222, 244, 252}, {233, 247, 252}, {242, 249, 252}, - {237, 250, 252}, {209, 251, 252}, {174, 251, 252}, {138, 252, 252}, - {102, 251, 252}, {63, 250, 252}, {24, 243, 252}, {7, 225, 252}, - {4, 203, 252}, {3, 181, 252}, {2, 158, 252}, {1, 136, 251}, - {0, 111, 248}, {0, 82, 234}, {0, 63, 213}, {0, 50, 192}, - {0, 39, 172}, {0, 28, 152}, {0, 17, 132}, {0, 7, 114} -}; - -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ -static void -quit(int rc) -{ - SDL_Quit(); - exit(rc); -} - -static void -sdlerr(char *when) -{ - fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError()); - quit(1); -} - -/* create a background surface */ -static SDL_Surface * -make_bg(SDL_Surface * screen, int startcol) -{ - int i; - SDL_Surface *bg = - SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, - 8, 0, 0, 0, 0); - if (!bg) - sdlerr("creating background surface"); - - /* set the palette to the logical screen palette so that blits - won't be translated */ - SDL_SetSurfacePalette(bg, screen->format->palette); - - /* Make a wavy background pattern using colours 0-63 */ - if (SDL_LockSurface(bg) < 0) - sdlerr("locking background"); - for (i = 0; i < SCRH; i++) { - Uint8 *p = (Uint8 *) bg->pixels + i * bg->pitch; - int j, d; - d = 0; - for (j = 0; j < SCRW; j++) { - int v = MAX(d, -2); - v = MIN(v, 2); - if (i > 0) - v += p[-bg->pitch] + 65 - startcol; - p[j] = startcol + (v & 63); - d += ((rand() >> 3) % 3) - 1; - } - } - SDL_UnlockSurface(bg); - return (bg); -} - -/* - * Return a surface flipped horisontally. Only works for 8bpp; - * extension to arbitrary bitness is left as an exercise for the reader. - */ -static SDL_Surface * -hflip(SDL_Surface * s) -{ - int i; - SDL_Surface *z = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 8, - 0, 0, 0, 0); - /* copy palette */ - SDL_SetColors(z, s->format->palette->colors, - 0, s->format->palette->ncolors); - if (SDL_LockSurface(s) < 0 || SDL_LockSurface(z) < 0) - sdlerr("locking flip images"); - - for (i = 0; i < s->h; i++) { - int j; - Uint8 *from = (Uint8 *) s->pixels + i * s->pitch; - Uint8 *to = (Uint8 *) z->pixels + i * z->pitch + s->w - 1; - for (j = 0; j < s->w; j++) - to[-j] = from[j]; - } - - SDL_UnlockSurface(z); - SDL_UnlockSurface(s); - return z; -} - -int -main(int argc, char **argv) -{ - SDL_Color cmap[256]; - SDL_Surface *screen; - SDL_Surface *bg; - SDL_Surface *boat[2]; - unsigned vidflags = 0; - unsigned start; - int fade_max = 400; - int fade_level, fade_dir; - int boatcols, frames, i, red; - int boatx[NBOATS], boaty[NBOATS], boatdir[NBOATS]; - int gamma_fade = 0; - int gamma_ramp = 0; - - if (SDL_Init(SDL_INIT_VIDEO) < 0) - sdlerr("initialising SDL"); - - while (--argc) { - ++argv; - if (strcmp(*argv, "-hw") == 0) - vidflags |= SDL_HWSURFACE; - else if (strcmp(*argv, "-fullscreen") == 0) - vidflags |= SDL_FULLSCREEN; - else if (strcmp(*argv, "-nofade") == 0) - fade_max = 1; - else if (strcmp(*argv, "-gamma") == 0) - gamma_fade = 1; - else if (strcmp(*argv, "-gammaramp") == 0) - gamma_ramp = 1; - else { - fprintf(stderr, - "usage: testpalette " - " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n"); - quit(1); - } - } - - /* Ask explicitly for 8bpp and a hardware palette */ - if ((screen = - SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) { - fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n", - SCRW, SCRH, SDL_GetError()); - quit(1); - } - - if (vidflags & SDL_FULLSCREEN) - SDL_ShowCursor(SDL_FALSE); - - if ((boat[0] = SDL_LoadBMP("sail.bmp")) == NULL) - sdlerr("loading sail.bmp"); - /* We've chosen magenta (#ff00ff) as colour key for the boat */ - SDL_SetColorKey(boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL, - SDL_MapRGB(boat[0]->format, 0xff, 0x00, 0xff)); - boatcols = boat[0]->format->palette->ncolors; - if (boatcols >= 256) - sdlerr("too many colors in sail.bmp"); - boat[1] = hflip(boat[0]); - SDL_SetColorKey(boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL, - SDL_MapRGB(boat[1]->format, 0xff, 0x00, 0xff)); - - /* - * First set the physical screen palette to black, so the user won't - * see our initial drawing on the screen. - */ - memset(cmap, 0, sizeof(cmap)); - SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256); - - /* - * Proper palette management is important when playing games with the - * colormap. We have divided the palette as follows: - * - * index 0..(boatcols-1): used for the boat - * index boatcols..(boatcols+63): used for the waves - */ - SDL_SetPalette(screen, SDL_LOGPAL, - boat[0]->format->palette->colors, 0, boatcols); - SDL_SetPalette(screen, SDL_LOGPAL, wavemap, boatcols, 64); - - /* - * Now the logical screen palette is set, and will remain unchanged. - * The boats already have the same palette so fast blits can be used. - */ - memcpy(cmap, screen->format->palette->colors, 256 * sizeof(SDL_Color)); - - /* save the index of the red colour for later */ - red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); - - bg = make_bg(screen, boatcols); /* make a nice wavy background surface */ - - /* initial screen contents */ - if (SDL_BlitSurface(bg, NULL, screen, NULL) < 0) - sdlerr("blitting background to screen"); - SDL_Flip(screen); /* actually put the background on screen */ - - /* determine initial boat placements */ - for (i = 0; i < NBOATS; i++) { - boatx[i] = (rand() % (SCRW + boat[0]->w)) - boat[0]->w; - boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1); - boatdir[i] = ((rand() >> 5) & 1) * 2 - 1; - } - - start = SDL_GetTicks(); - frames = 0; - fade_dir = 1; - fade_level = 0; - do { - SDL_Event e; - SDL_Rect updates[NBOATS]; - SDL_Rect r; - int redphase; - - /* A small event loop: just exit on any key or mouse button event */ - while (SDL_PollEvent(&e)) { - if (e.type == SDL_KEYDOWN || e.type == SDL_QUIT - || e.type == SDL_MOUSEBUTTONDOWN) { - if (fade_dir < 0) - fade_level = 0; - fade_dir = -1; - } - } - - /* move boats */ - for (i = 0; i < NBOATS; i++) { - int old_x = boatx[i]; - /* update boat position */ - boatx[i] += boatdir[i] * SPEED; - if (boatx[i] <= -boat[0]->w || boatx[i] >= SCRW) - boatdir[i] = -boatdir[i]; - - /* paint over the old boat position */ - r.x = old_x; - r.y = boaty[i]; - r.w = boat[0]->w; - r.h = boat[0]->h; - if (SDL_BlitSurface(bg, &r, screen, &r) < 0) - sdlerr("blitting background"); - - /* construct update rectangle (bounding box of old and new pos) */ - updates[i].x = MIN(old_x, boatx[i]); - updates[i].y = boaty[i]; - updates[i].w = boat[0]->w + SPEED; - updates[i].h = boat[0]->h; - /* clip update rectangle to screen */ - if (updates[i].x < 0) { - updates[i].w += updates[i].x; - updates[i].x = 0; - } - if (updates[i].x + updates[i].w > SCRW) - updates[i].w = SCRW - updates[i].x; - } - - for (i = 0; i < NBOATS; i++) { - /* paint boat on new position */ - r.x = boatx[i]; - r.y = boaty[i]; - if (SDL_BlitSurface(boat[(boatdir[i] + 1) / 2], NULL, - screen, &r) < 0) - sdlerr("blitting boat"); - } - - /* cycle wave palette */ - for (i = 0; i < 64; i++) - cmap[boatcols + ((i + frames) & 63)] = wavemap[i]; - - if (fade_dir) { - /* Fade the entire palette in/out */ - fade_level += fade_dir; - - if (gamma_fade) { - /* Fade linearly in gamma level (lousy) */ - float level = (float) fade_level / fade_max; - if (SDL_SetGamma(level, level, level) < 0) - sdlerr("setting gamma"); - - } else if (gamma_ramp) { - /* Fade using gamma ramp (better) */ - Uint16 ramp[256]; - for (i = 0; i < 256; i++) - ramp[i] = (i * fade_level / fade_max) << 8; - if (SDL_SetGammaRamp(ramp, ramp, ramp) < 0) - sdlerr("setting gamma ramp"); - - } else { - /* Fade using direct palette manipulation (best) */ - memcpy(cmap, screen->format->palette->colors, - boatcols * sizeof(SDL_Color)); - for (i = 0; i < boatcols + 64; i++) { - cmap[i].r = cmap[i].r * fade_level / fade_max; - cmap[i].g = cmap[i].g * fade_level / fade_max; - cmap[i].b = cmap[i].b * fade_level / fade_max; - } - } - if (fade_level == fade_max) - fade_dir = 0; - } - - /* pulse the red colour (done after the fade, for a night effect) */ - redphase = frames % 64; - cmap[red].r = (int) (255 * sin(redphase * M_PI / 63)); - - SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, boatcols + 64); - - /* update changed areas of the screen */ - SDL_UpdateRects(screen, NBOATS, updates); - frames++; - } while (fade_level > 0); - - printf("%d frames, %.2f fps\n", - frames, 1000.0 * frames / (SDL_GetTicks() - start)); - - if (vidflags & SDL_FULLSCREEN) - SDL_ShowCursor(SDL_TRUE); - SDL_Quit(); - return 0; -}