--- ray/src/px/neuclrtab.c 1994/12/12 12:19:04 2.8 +++ ray/src/px/neuclrtab.c 2005/09/19 02:23:58 2.12 @@ -1,18 +1,18 @@ -/* 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.12 2005/09/19 02:23:58 greg 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" +#include "clrtab.h" #ifdef COMPAT_MODE #define neu_init new_histo @@ -28,12 +28,8 @@ extern BYTE clrtab[256][3]; static int clrtabsiz; #ifndef DEFSMPFAC -#ifdef SPEED -#define DEFSMPFAC (240/SPEED+3) -#else -#define DEFSMPFAC 30 +#define DEFSMPFAC 3 #endif -#endif int samplefac = DEFSMPFAC; /* sampling factor */ @@ -51,11 +47,21 @@ static long skipcount; #define setskip(sp,n) ((sp)[0]=(n)>>16,(sp)[1]=((n)>>8)&255,(sp)[2]=(n)&255) -static cpyclrtab(); +static void initnet(void); +static void inxbuild(void); +static int inxsearch(int b, int g, int r); +static int contest(int b, int g, int r); +static void altersingle(int alpha, int i, int b, int g, int r); +static void alterneigh(int rad, int i, int b, int g, int r); +static void learn(void); +static void unbiasnet(void); +static void cpyclrtab(void); -neu_init(npixels) /* initialize our sample array */ -long npixels; +extern int +neu_init( /* initialize our sample array */ + long npixels +) { register int nsleft; register long sv; @@ -92,8 +98,10 @@ long npixels; } -neu_pixel(col) /* add pixel to our samples */ -register BYTE col[]; +extern void +neu_pixel( /* add pixel to our samples */ + register BYTE col[] +) { if (!skipcount--) { skipcount = nskip(cursamp); @@ -105,9 +113,11 @@ register BYTE col[]; } -neu_colrs(cs, n) /* add a scanline to our samples */ -register COLR *cs; -register int n; +extern void +neu_colrs( /* add a scanline to our samples */ + register COLR *cs, + register int n +) { while (n > skipcount) { cs += skipcount; @@ -123,8 +133,10 @@ register int n; } -neu_clrtab(ncolors) /* make new color table using ncolors */ -int ncolors; +extern int +neu_clrtab( /* make new color table using ncolors */ + int ncolors +) { clrtabsiz = ncolors; if (clrtabsiz > 256) clrtabsiz = 256; @@ -134,7 +146,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 */ @@ -142,18 +154,21 @@ int ncolors; } -int -neu_map_pixel(col) /* get pixel for color */ -register BYTE col[]; +extern int +neu_map_pixel( /* get pixel for color */ + register BYTE col[] +) { return(inxsearch(col[BLU],col[GRN],col[RED])); } -neu_map_colrs(bs, cs, n) /* convert a scanline to color index values */ -register BYTE *bs; -register COLR *cs; -register int n; +extern void +neu_map_colrs( /* convert a scanline to color index values */ + register BYTE *bs, + register COLR *cs, + register int n +) { while (n-- > 0) { *bs++ = inxsearch(cs[0][BLU],cs[0][GRN],cs[0][RED]); @@ -162,10 +177,12 @@ register int n; } -neu_dith_colrs(bs, cs, n) /* convert scanline to dithered index values */ -register BYTE *bs; -register COLR *cs; -int n; +extern void +neu_dith_colrs( /* convert scanline to dithered index values */ + register BYTE *bs, + register COLR *cs, + int n +) { static short (*cerr)[3] = NULL; static int N = 0; @@ -174,7 +191,7 @@ int n; if (n != N) { /* get error propogation array */ if (N) { - free((char *)cerr); + free((void *)cerr); cerr = NULL; } if (n) @@ -185,7 +202,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++) { @@ -310,7 +327,8 @@ int radpower[initrad]; /* radpower for precomputation /* initialise network in range (0,0,0) to (255,255,255) */ -initnet() +static void +initnet(void) { register int i; register int *p; @@ -326,7 +344,8 @@ initnet() /* do after unbias - insertion sort of network and build netindex[0..255] */ -inxbuild() +static void +inxbuild(void) { register int i,j,smallpos,smallval; register int *p,*q; @@ -367,8 +386,12 @@ inxbuild() } -int inxsearch(b,g,r) /* accepts real BGR values after net is unbiased */ -register int b,g,r; +static int +inxsearch( /* accepts real BGR values after net is unbiased */ + register int b, + register int g, + register int r +) { register int i,j,dist,a,bestd; register int *p; @@ -422,8 +445,12 @@ register int b,g,r; /* for frequently chosen neurons, freq[i] is high and bias[i] is negative */ /* bias[i] = gamma*((1/netsize)-freq[i]) */ -int contest(b,g,r) /* accepts biased BGR values */ -register int b,g,r; +static int +contest( /* accepts biased BGR values */ + register int b, + register int g, + register int r +) { register int i,dist,a,biasdist,betafreq; int bestpos,bestbiaspos,bestd,bestbiasd; @@ -458,8 +485,14 @@ register int b,g,r; /* move neuron i towards (b,g,r) by factor alpha */ -altersingle(alpha,i,b,g,r) /* accepts biased BGR values */ -register int alpha,i,b,g,r; +static void +altersingle( /* accepts biased BGR values */ + register int alpha, + register int i, + register int b, + register int g, + register int r +) { register int *n; @@ -475,9 +508,14 @@ register int alpha,i,b,g,r; /* move neurons adjacent to i towards (b,g,r) by factor */ /* alpha*(1-((i-j)^2/[r]^2)) precomputed as radpower[|i-j|]*/ -alterneigh(rad,i,b,g,r) /* accents biased BGR values */ -int rad,i; -register int b,g,r; +static void +alterneigh( /* accents biased BGR values */ + int rad, + int i, + register int b, + register int g, + register int r +) { register int j,k,lo,hi,a; register int *p, *q; @@ -512,7 +550,8 @@ register int b,g,r; } -learn() +static void +learn(void) { register int i,j,b,g,r; int radius,rad,alpha,step,delta,samplepixels; @@ -570,7 +609,8 @@ learn() /* which can then be used for colour map */ /* and record position i to prepare for sort */ -unbiasnet() +static void +unbiasnet(void) { int i,j; @@ -584,8 +624,8 @@ unbiasnet() /* Don't do this until the network has been unbiased (GW) */ -static -cpyclrtab() +static void +cpyclrtab(void) { register int i,j,k;