| 1 | 
– | 
/* Copyright (c) 1993 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * Simple median-cut color quantization based on colortab.c | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
< | 
#include "standard.h" | 
| 8 | 
> | 
#include "copyright.h" | 
| 9 | 
  | 
 | 
| 10 | 
+ | 
#include <string.h> | 
| 11 | 
+ | 
 | 
| 12 | 
+ | 
#include "standard.h" | 
| 13 | 
  | 
#include "color.h" | 
| 14 | 
+ | 
 | 
| 15 | 
  | 
                                /* histogram resolution */ | 
| 16 | 
  | 
#define NRED            36 | 
| 17 | 
  | 
#define NGRN            48 | 
| 41 | 
  | 
#endif | 
| 42 | 
  | 
#endif | 
| 43 | 
  | 
 | 
| 44 | 
+ | 
static  cut(), mktabent(), closest(), addneigh(), setclosest(); | 
| 45 | 
+ | 
static int      split(); | 
| 46 | 
+ | 
static unsigned dist(); | 
| 47 | 
  | 
 | 
| 48 | 
+ | 
 | 
| 49 | 
  | 
new_histo(n)            /* clear our histogram */ | 
| 50 | 
  | 
int     n; | 
| 51 | 
  | 
{ | 
| 52 | 
< | 
        bzero((char *)histo, sizeof(histo)); | 
| 52 | 
> | 
        memset((void *)histo, '\0', sizeof(histo)); | 
| 53 | 
  | 
        return(0); | 
| 54 | 
  | 
} | 
| 55 | 
  | 
 | 
| 123 | 
  | 
 | 
| 124 | 
  | 
        if (n != N) {           /* get error propogation array */ | 
| 125 | 
  | 
                if (N) { | 
| 126 | 
< | 
                        free((char *)cerr); | 
| 126 | 
> | 
                        free((void *)cerr); | 
| 127 | 
  | 
                        cerr = NULL; | 
| 128 | 
  | 
                } | 
| 129 | 
  | 
                if (n) | 
| 134 | 
  | 
                        return; | 
| 135 | 
  | 
                } | 
| 136 | 
  | 
                N = n; | 
| 137 | 
< | 
                bzero((char *)cerr, 3*N*sizeof(short)); | 
| 137 | 
> | 
                memset((void *)cerr, '\0', 3*N*sizeof(short)); | 
| 138 | 
  | 
        } | 
| 139 | 
  | 
        err[0] = err[1] = err[2] = 0; | 
| 140 | 
  | 
        for (x = 0; x < n; x++) { | 
| 173 | 
  | 
        } | 
| 174 | 
  | 
                                        /* split box */ | 
| 175 | 
  | 
        branch = split(box); | 
| 176 | 
< | 
        bcopy((char *)box, (char *)kb, sizeof(kb)); | 
| 176 | 
> | 
        memcpy((void *)kb, (void *)box, sizeof(kb)); | 
| 177 | 
  | 
                                                /* do left (lesser) branch */ | 
| 178 | 
  | 
        kb[prim(branch)][1] = part(branch); | 
| 179 | 
  | 
        cut(kb, c0, (c0+c1)>>1); | 
| 341 | 
  | 
                if (nl[i][t] == i) {            /* add to list */ | 
| 342 | 
  | 
                        nl[i][t++] = j; | 
| 343 | 
  | 
                        if (t % NBSIZ == 0) {   /* enlarge list */ | 
| 344 | 
< | 
                                if ((nnl = realloc(nl[i], t+NBSIZ)) == NULL) | 
| 344 | 
> | 
                                if ((nnl = realloc((void *)nl[i], | 
| 345 | 
> | 
                                                t+NBSIZ)) == NULL) | 
| 346 | 
  | 
                                        t--; | 
| 347 | 
  | 
                                else | 
| 348 | 
  | 
                                        nl[i] = (BYTE *)nnl; |