/** * qdgdfv_build_light_table_ext - Builds a light table (extended). * @lut: the buffer where to store the light table * @levels: number of light levels * @mid: the level where color is 100% * @fr: red component of fade color * @fg: green component of fade color * @fb: blue component of fade color * * This function is an extended version of qdgdfv_build_light_table(). * Instead of fading to black, this function allows to specify what * color the dark light levels fade to. * [Video Functions] */ void qdgdfv_build_light_table_ext(unsigned char *lut, int levels, int mid, int fr, int fg, int fb) { int n, m; int r, g, b; mid--; mid = levels - mid; for (n = 0; n < levels; n++) { for (m = 0; m < 255; m++) { r = _qdgdfv_palette[m * 3]; g = _qdgdfv_palette[(m * 3) + 1]; b = _qdgdfv_palette[(m * 3) + 2]; /* old algorithm was r=(r*(n+mid))/levels; */ r += ((fr - r) / levels) * (levels - (n + mid)); g += ((fg - g) / levels) * (levels - (n + mid)); b += ((fb - b) / levels) * (levels - (n + mid)); lut[(n * 256) + m] = qdgdfv_seek_color(r, g, b); } lut[(n * 256) + 255] = 255; } }
/** * qdgdfv_blend_color - Blends two colors into one. * @c1: first color * @c2: second color * @percent: percentage of blending * * Blends two colors into the nearest matching one. If @percent is 100, * the returned color will be @c1, if it's 0, @c2, or a blending between * both otherwise. * [Video Functions] */ unsigned char qdgdfv_blend_color(unsigned char c1, unsigned char c2, int percent) { int r, g, b; int *p; if (percent == 100) return c1; if (percent == 0) return c2; p = (int *) &_qdgdfv_palette[(int) c1 * 3]; r = (*(p++) * percent) / 100; g = (*(p++) * percent) / 100; b = (*p * percent) / 100; percent = 100 - percent; p = (int *) &_qdgdfv_palette[(int) c2 * 3]; r += (*(p++) * percent) / 100; g += (*(p++) * percent) / 100; b += (*p * percent) / 100; return qdgdfv_seek_color(r, g, b); }
void show_info(void) { int c = qdgdfv_seek_color(255, 255, 255); int y; qdgdfv_clear_virtual_screen(); for (y = 0; info[y] != NULL; y++) qdgdfv_font_print(1, y * _qdgdfv_font_height, (unsigned char *)info[y], c); qdgdfv_font_print(1, y * _qdgdfv_font_height, (unsigned char *)qdgdfv_sprintf("%d %c", _qdgdfv_key_alnum, _qdgdfv_alnum), c); qdgdfv_font_print(-1, -1, (unsigned char *)"Press ESCAPE", c); qdgdfv_dump_virtual_screen(); }
static void load_pcx(unsigned char *pcx, char *pcxfile, int size, int usepal) { int n, m; unsigned char c; FILE *f; unsigned char _pcx_palette[256][3]; f = qdgdfv_fopen(pcxfile, "rb"); /* skips header */ fseek(f, 128, SEEK_SET); n = 0; while (n < size) { c = fgetc(f); if (c > 0xC0) { /* run-length */ m = c & 0x3F; c = fgetc(f); } else m = 1; while (m) { pcx[n++] = c; m--; } } /* reads palette */ fseek(f, -((long) sizeof(_pcx_palette)), SEEK_END); fread(_pcx_palette, 3, 256, f); fclose(f); /* if the palette is not to be used, it's over */ if (!usepal) return; if (usepal == 1) { /* fixes the pcx to use current palette */ for (n = 0; n < size; n++) { c = pcx[n]; pcx[n] = qdgdfv_seek_color(_pcx_palette[c][0], _pcx_palette[c][1], _pcx_palette[c][2] ); } } else if (usepal == 2) { /* transfers this pcx's palette to system one */ for (n = 0; n < 256; n++) { _qdgdfv_palette[n * 3] = _pcx_palette[n][0]; _qdgdfv_palette[(n * 3) + 1] = _pcx_palette[n][1]; _qdgdfv_palette[(n * 3) + 2] = _pcx_palette[n][2]; } /* and set it */ qdgdfv_set_palette(); } }