--- ray/src/px/neuclrtab.c 1994/11/21 15:56:20 2.6 +++ ray/src/px/neuclrtab.c 2003/06/30 14:59:12 2.10 @@ -1,17 +1,16 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: neuclrtab.c,v 2.10 2003/06/30 14:59:12 schorsch Exp $"; #endif - /* * Neural-Net quantization algorithm based on work of Anthony Dekker */ -#include "standard.h" +#include "copyright.h" -#include "color.h" +#include +#include "standard.h" +#include "color.h" #include "random.h" #ifdef COMPAT_MODE @@ -51,7 +50,9 @@ static long skipcount; #define setskip(sp,n) ((sp)[0]=(n)>>16,(sp)[1]=((n)>>8)&255,(sp)[2]=(n)&255) +static cpyclrtab(); + neu_init(npixels) /* initialize our sample array */ long npixels; { @@ -132,7 +133,7 @@ int ncolors; cpyclrtab(); inxbuild(); /* we're done with our samples */ - free((char *)thesamples); + free((void *)thesamples); /* reset dithering function */ neu_dith_colrs((BYTE *)NULL, (COLR *)NULL, 0); /* return new color table size */ @@ -172,7 +173,7 @@ int n; if (n != N) { /* get error propogation array */ if (N) { - free((char *)cerr); + free((void *)cerr); cerr = NULL; } if (n) @@ -183,7 +184,7 @@ int n; return; } N = n; - bzero((char *)cerr, 3*N*sizeof(short)); + memset((char *)cerr, '\0', 3*N*sizeof(short)); } err[0] = err[1] = err[2] = 0; for (x = 0; x < n; x++) { @@ -257,7 +258,7 @@ int n; #define true 1 /* network defs */ -#define netsize 256 /* number of colours - can change this */ +#define netsize clrtabsiz /* number of colours - can change this */ #define maxnetpos (netsize-1) #define netbiasshift 4 /* bias for colour values */ #define ncycles 100 /* no. of learning cycles */ @@ -272,7 +273,7 @@ int n; #define betagamma (intbias<<(gammashift-betashift)) /* defs for decreasing radius factor */ -#define initrad (netsize>>3) /* for 256 cols, radius starts */ +#define initrad (256>>3) /* for 256 cols, radius starts */ #define radiusbiasshift 6 /* at 32.0 biased by 6 bits */ #define radiusbias (((int) 1)<=0)) { - if (i=0)) { + if (i= bestd) i = clrtabsiz; /* stop iter */ + if (dist >= bestd) i = netsize; /* stop iter */ else { i++; if (dist<0) dist = -dist; @@ -418,7 +419,7 @@ register int b,g,r; /* finds closest neuron (min dist) and updates freq */ /* finds best neuron (min dist-bias) and returns position */ /* for frequently chosen neurons, freq[i] is high and bias[i] is negative */ -/* bias[i] = gamma*((1/clrtabsiz)-freq[i]) */ +/* bias[i] = gamma*((1/netsize)-freq[i]) */ int contest(b,g,r) /* accepts biased BGR values */ register int b,g,r; @@ -434,7 +435,7 @@ register int b,g,r; p = bias; f = freq; - for (i=0; iclrtabsiz) hi=clrtabsiz; + hi = i+rad; if (hi>netsize) hi=netsize; j = i+1; k = i-1; @@ -572,7 +573,7 @@ unbiasnet() { int i,j; - for (i=0; i>= netbiasshift; network[i][3] = i; /* record colour no */ @@ -587,7 +588,7 @@ cpyclrtab() { register int i,j,k; - for (j=0; j