home *** CD-ROM | disk | FTP | other *** search
- /* nearest.c
- * AUTHOR: Cy Booker, cy@cheepnis.demon.co.uk
- * LICENSE: FreeWare, Copyright (c) 1995 Cy Booker
- */
-
- #include "internal.h"
-
- #include <assert.h>
-
- #include "OS:macros.h"
-
-
-
- /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
-
- static void calc_pixtrans(
- const process_gif *p,
- bits *pixtrans);
-
-
-
- /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
-
- extern bool process_gif_16bpp_nearest_66bit(
- const process_gif *p) {
- byte *rove;
- bits dest;
- int width;
- int x, y;
- const os_colour *palette;
- int line_length;
- bits pixtrans[256];
-
- assert(p);
- assert(p->pixel_width > 0);
- assert(p->pixel_height > 0);
- assert(p->in_palette.colours);
-
- calc_pixtrans(p, pixtrans);
-
- /*
- * not we pre-load values from the process_gif array
- * because it considerably helps the compiler produce better code
- */
- rove = p->buffer;
- width = (p->pixel_width + 1) & ~1;
- palette = p->in_palette.colours;
- line_length = p->line_length;
-
- for (y= p->pixel_height - 1; (y >= 0); y--) {
- for (x= width - 1; (x >= 0); x--) {
- /*
- * writing one 32-bit word is much faster than two 16-bit shorts
- */
- dest = pixtrans[rove[x]];
- x--;
- dest <<= 16;
- dest |= pixtrans[rove[x]];
- *(((int *)rove) + (((unsigned int)x) >> 1)) = dest;
- }
- rove += line_length;
- }
- return FALSE;
- }
-
-
-
- /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
-
- static void calc_pixtrans(
- const process_gif *p,
- bits *pixtrans) {
- int red, grn, blu;
- os_colour colour;
- int i;
- const os_colour *palette;
-
- assert(p);
- assert(p->in_palette.colours);
- assert(p->in_palette.ncolours > 0);
- assert(p->in_palette.ncolours <= 256);
- assert(pixtrans);
-
- palette = p->in_palette.colours;
- for (i= p->in_palette.ncolours - 1; (i >= 0); i--) {
- colour = palette[i];
- red = Gscale_8bit_to_22bit[(colour >> 8) & 0xff];
- grn = Gscale_8bit_to_22bit[(colour >> 16) & 0xff];
- blu = Gscale_8bit_to_22bit[(colour >> 24) & 0xff];
- red = ((bits)(red * 0x1f) + (SCALE / 2)) / (bits)SCALE; /* scale to output */
- grn = ((bits)(grn * 0x1f) + (SCALE / 2)) / (bits)SCALE;
- blu = ((bits)(blu * 0x1f) + (SCALE / 2)) / (bits)SCALE;
- pixtrans[i] = red | (grn << 5) | (blu << 10);
- }
- }
-
-
-
-