void gr_palette_load (ubyte *pal) { int i, j; ggi_color colors[256]; for (i = 0, j = 0; j < 256; j++) { gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; colors[j].r = (min(gr_current_pal[i] + gr_palette_gamma, 63)) * 0x3ff; i++; gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; colors[j].g = (min(gr_current_pal[i] + gr_palette_gamma, 63)) * 0x3ff; i++; gr_current_pal[i] = pal[i]; if (gr_current_pal[i] > 63) gr_current_pal[i] = 63; colors[j].b = (min(gr_current_pal[i] + gr_palette_gamma, 63)) * 0x3ff; i++; } ggiSetPalette(screenvis, 0, 256, colors); gr_palette_faded_out = 0; init_computed_colors(); }
void gr_palette_step_up (int r, int g, int b) { int i; ubyte *p = gr_palette; int temp; ggi_color colors[256]; if (gr_palette_faded_out) return; if ((r==last_r) && (g==last_g) && (b==last_b)) return; last_r = r; last_g = g; last_b = b; for (i = 0; i < 256; i++) { temp = (int)(*p++) + r + gr_palette_gamma; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].r = temp * 0x3ff; temp = (int)(*p++) + g + gr_palette_gamma; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].g = temp * 0x3ff; temp = (int)(*p++) + b + gr_palette_gamma; if (temp<0) temp=0; else if (temp>63) temp=63; colors[i].b = temp * 0x3ff; } ggiSetPalette (screenvis, 0, 256, colors); }
void gr_palette_clear() { ggi_color *colors = calloc (256, sizeof(ggi_color)); ggiSetPalette (screenvis, 0, 256, colors); gr_palette_faded_out = 1; }
static void testcase1(const char *desc) { ggi_visual_t vis; ggi_color green, back; int err; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_8BIT); if(err < 0) { printassert(0, "Palettized mode not available.\n"); printsuccess(); ggiClose(vis); ggiExit(); return; } green.r = 100; green.g = 40000; green.b = 4000; err = ggiSetPalette(vis, GGI_PALETTE_DONTCARE, 1, &green); if (err < 0) { printfailure("Unable to install colormap with one entry.\n"); ggiClose(vis); ggiExit(); return; } printassert(err == (int)ggiMapColor(vis, &green), "ggiMapColor inconsistent with retval of ggiSetPalette.\n"); ggiUnmapPixel(vis, err, &back); if(green.r != back.r || green.g != back.g || green.b != back.b) { printfailure("Unexpected color from ggiUnmapPixel.\n"); ggiClose(vis); ggiExit(); return; } ggiSetGCForeground(vis, err); ggiDrawBox(vis, 0, 0, 3000, 3000); ggiFlush(vis); /* You should see a green square, how to test this? */ ggUSleep(5000000); printsuccess(); ggiClose(vis); ggiExit(); }
int gr_palette_fade_out (ubyte *pal, int nsteps, int allow_keys) { int i, j, k; ubyte c; fix fade_palette[768]; fix fade_palette_delta[768]; ggi_color fade_colors[256]; if (gr_palette_faded_out) return 0; if (pal==NULL) pal=gr_current_pal; for (i=0; i<768; i++) { gr_current_pal[i] = pal[i]; fade_palette[i] = i2f(pal[i]); fade_palette_delta[i] = fade_palette[i] / nsteps; } for (j=0; j<nsteps; j++) { for (i = 0; i < 768; i++) { fade_palette[i] -= fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma)) fade_palette[i] = i2f(pal[i] + gr_palette_gamma); } for (i = 0, k = 0; k < 256; k++) { c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].r = c * 0x3ff; c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].g = c * 0x3ff; c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].b = c * 0x3ff; } ggiSetPalette (screenvis, 0, 256, fade_colors); gr_update(); } gr_palette_faded_out = 1; return 0; }
int GGI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { int i; ggi_color pal[256]; /* Set up the colormap */ for (i = 0; i < ncolors; i++) { pal[i].r = (colors[i].r << 8) | colors[i].r; pal[i].g = (colors[i].g << 8) | colors[i].g; pal[i].b = (colors[i].b << 8) | colors[i].b; } ggiSetPalette(VIS, firstcolor, ncolors, pal); return 1; }
static void perf_SETPALETTE(TeleUser *u, TeleCmdSetPaletteData *d) { int i; /* !!! validate */ for (i=0; i < d->len; i++, d->start++) { ggi_color col; col.r = (d->colors[i] & 0xff0000) >> 8; col.g = (d->colors[i] & 0x00ff00) ; col.b = (d->colors[i] & 0x0000ff) << 8; /* horribly inefficient */ ggiSetPalette(vis, d->start, 1, &col); } }