51 |
|
|
52 |
|
#define setskip(sp,n) ((sp)[0]=(n)>>16,(sp)[1]=((n)>>8)&255,(sp)[2]=(n)&255) |
53 |
|
|
54 |
+ |
static cpyclrtab(); |
55 |
|
|
56 |
+ |
|
57 |
|
neu_init(npixels) /* initialize our sample array */ |
58 |
|
long npixels; |
59 |
|
{ |
65 |
|
nsamples = npixels/samplefac; |
66 |
|
if (nsamples < 600) |
67 |
|
return(-1); |
68 |
< |
thesamples = (BYTE *)malloc((nsamples+1)*3); |
68 |
> |
thesamples = (BYTE *)malloc(nsamples*3); |
69 |
|
if (thesamples == NULL) |
70 |
|
return(-1); |
71 |
|
cursamp = thesamples; |
77 |
|
cumprob = 0.; |
78 |
|
while ((cumprob += (1.-cumprob)*nsleft/(npleft-sv)) < rval) |
79 |
|
sv++; |
80 |
< |
setskip(cursamp, sv); |
81 |
< |
cursamp += 3; |
82 |
< |
npleft -= sv; |
80 |
> |
if (nsleft == nsamples) |
81 |
> |
skipcount = sv; |
82 |
> |
else { |
83 |
> |
setskip(cursamp, sv); |
84 |
> |
cursamp += 3; |
85 |
> |
} |
86 |
> |
npleft -= sv+1; |
87 |
|
nsleft--; |
88 |
|
} |
89 |
< |
setskip(cursamp, 0); /* dummy tagged onto end */ |
89 |
> |
setskip(cursamp, npleft); /* tag on end to skip the rest */ |
90 |
|
cursamp = thesamples; |
85 |
– |
skipcount = nskip(cursamp); |
91 |
|
return(0); |
92 |
|
} |
93 |
|
|
96 |
|
register BYTE col[]; |
97 |
|
{ |
98 |
|
if (!skipcount--) { |
99 |
+ |
skipcount = nskip(cursamp); |
100 |
|
cursamp[0] = col[BLU]; |
101 |
|
cursamp[1] = col[GRN]; |
102 |
|
cursamp[2] = col[RED]; |
103 |
|
cursamp += 3; |
98 |
– |
skipcount = nskip(cursamp); |
104 |
|
} |
105 |
|
} |
106 |
|
|
111 |
|
{ |
112 |
|
while (n > skipcount) { |
113 |
|
cs += skipcount; |
114 |
+ |
n -= skipcount+1; |
115 |
+ |
skipcount = nskip(cursamp); |
116 |
|
cursamp[0] = cs[0][BLU]; |
117 |
|
cursamp[1] = cs[0][GRN]; |
118 |
|
cursamp[2] = cs[0][RED]; |
119 |
|
cs++; |
113 |
– |
n -= skipcount+1; |
120 |
|
cursamp += 3; |
115 |
– |
skipcount = nskip(cursamp); |
121 |
|
} |
122 |
|
skipcount -= n; |
123 |
|
} |
210 |
|
} |
211 |
|
|
212 |
|
/* The following was adapted and modified from the original (GW) */ |
213 |
+ |
|
214 |
+ |
/* cheater definitions (GW) */ |
215 |
+ |
#define thepicture thesamples |
216 |
+ |
#define lengthcount (nsamples*3) |
217 |
+ |
#define samplefac 1 |
218 |
+ |
|
219 |
|
/*----------------------------------------------------------------------*/ |
220 |
|
/* */ |
221 |
|
/* NeuQuant */ |
222 |
|
/* -------- */ |
223 |
|
/* */ |
224 |
< |
/* Copyright: Anthony Dekker, June 1994 */ |
224 |
> |
/* Copyright: Anthony Dekker, November 1994 */ |
225 |
|
/* */ |
226 |
|
/* This program performs colour quantization of graphics images (SUN */ |
227 |
|
/* raster files). It uses a Kohonen Neural Network. It produces */ |
254 |
|
/* Email: [email protected] */ |
255 |
|
/*----------------------------------------------------------------------*/ |
256 |
|
|
257 |
< |
#define bool int |
258 |
< |
#define false 0 |
259 |
< |
#define true 1 |
257 |
> |
#define bool int |
258 |
> |
#define false 0 |
259 |
> |
#define true 1 |
260 |
|
|
261 |
< |
#define initrad 32 |
262 |
< |
#define radiusdec 30 |
263 |
< |
#define alphadec; 30 |
261 |
> |
/* network defs */ |
262 |
> |
#define netsize clrtabsiz /* number of colours - can change this */ |
263 |
> |
#define maxnetpos (netsize-1) |
264 |
> |
#define netbiasshift 4 /* bias for colour values */ |
265 |
> |
#define ncycles 100 /* no. of learning cycles */ |
266 |
|
|
267 |
|
/* defs for freq and bias */ |
268 |
< |
#define gammashift 10 |
269 |
< |
#define betashift gammashift |
270 |
< |
#define intbiasshift 16 |
271 |
< |
#define intbias (1<<intbiasshift) |
272 |
< |
#define gamma (1<<gammashift) |
273 |
< |
#define beta (intbias>>betashift) |
268 |
> |
#define intbiasshift 16 /* bias for fractions */ |
269 |
> |
#define intbias (((int) 1)<<intbiasshift) |
270 |
> |
#define gammashift 10 /* gamma = 1024 */ |
271 |
> |
#define gamma (((int) 1)<<gammashift) |
272 |
> |
#define betashift 10 |
273 |
> |
#define beta (intbias>>betashift) /* beta = 1/1024 */ |
274 |
|
#define betagamma (intbias<<(gammashift-betashift)) |
262 |
– |
#define gammaphi (intbias<<(gammashift-8)) |
275 |
|
|
276 |
< |
/* defs for rad and alpha */ |
277 |
< |
#define maxrad (initrad+1) |
278 |
< |
#define radiusbiasshift 6 |
279 |
< |
#define radiusbias (1<<radiusbiasshift) |
280 |
< |
#define initradius ((int) (initrad*radiusbias)) |
281 |
< |
#define alphabiasshift 10 |
282 |
< |
#define initalpha (1<<alphabiasshift) |
276 |
> |
/* defs for decreasing radius factor */ |
277 |
> |
#define initrad (256>>3) /* for 256 cols, radius starts */ |
278 |
> |
#define radiusbiasshift 6 /* at 32.0 biased by 6 bits */ |
279 |
> |
#define radiusbias (((int) 1)<<radiusbiasshift) |
280 |
> |
#define initradius (initrad*radiusbias) /* and decreases by a */ |
281 |
> |
#define radiusdec 30 /* factor of 1/30 each cycle */ |
282 |
> |
|
283 |
> |
/* defs for decreasing alpha factor */ |
284 |
> |
#define alphabiasshift 10 /* alpha starts at 1.0 */ |
285 |
> |
#define initalpha (((int) 1)<<alphabiasshift) |
286 |
> |
int alphadec; /* biased by 10 bits */ |
287 |
> |
|
288 |
> |
/* radbias and alpharadbias used for radpower calculation */ |
289 |
|
#define radbiasshift 8 |
290 |
< |
#define radbias (1<<radbiasshift) |
290 |
> |
#define radbias (((int) 1)<<radbiasshift) |
291 |
|
#define alpharadbshift (alphabiasshift+radbiasshift) |
292 |
< |
#define alpharadbias (1<<alpharadbshift) |
292 |
> |
#define alpharadbias (((int) 1)<<alpharadbshift) |
293 |
|
|
294 |
< |
/* other defs */ |
295 |
< |
#define netbiasshift 4 |
296 |
< |
#define funnyshift (intbiasshift-netbiasshift) |
297 |
< |
#define maxnetval ((256<<netbiasshift)-1) |
298 |
< |
#define ncycles 100 |
299 |
< |
#define jump1 499 /* prime */ |
282 |
< |
#define jump2 491 /* prime */ |
283 |
< |
#define jump3 487 /* any pic whose size was divisible by all */ |
284 |
< |
#define jump4 503 /* four primes would be simply enormous */ |
294 |
> |
/* four primes near 500 - assume no image has a length so large */ |
295 |
> |
/* that it is divisible by all four primes */ |
296 |
> |
#define prime1 499 |
297 |
> |
#define prime2 491 |
298 |
> |
#define prime3 487 |
299 |
> |
#define prime4 503 |
300 |
|
|
286 |
– |
/* cheater definitions (GW) */ |
287 |
– |
#define thepicture thesamples |
288 |
– |
#define lengthcount (nsamples*3) |
289 |
– |
#define samplefac 1 |
290 |
– |
|
301 |
|
typedef int pixel[4]; /* BGRc */ |
302 |
+ |
pixel network[256]; |
303 |
|
|
304 |
< |
static pixel network[256]; |
304 |
> |
int netindex[256]; /* for network lookup - really 256 */ |
305 |
|
|
306 |
< |
static int netindex[256]; |
306 |
> |
int bias [256]; /* bias and freq arrays for learning */ |
307 |
> |
int freq [256]; |
308 |
> |
int radpower[initrad]; /* radpower for precomputation */ |
309 |
|
|
297 |
– |
static int bias [256]; |
298 |
– |
static int freq [256]; |
299 |
– |
static int radpower[256]; /* actually need only go up to maxrad */ |
310 |
|
|
311 |
< |
/* fixed space overhead 256*4+256+256+256+256 words = 256*8 = 8kB */ |
311 |
> |
/* initialise network in range (0,0,0) to (255,255,255) */ |
312 |
|
|
313 |
< |
|
304 |
< |
static |
305 |
< |
initnet() |
313 |
> |
initnet() |
314 |
|
{ |
315 |
|
register int i; |
316 |
|
register int *p; |
317 |
|
|
318 |
< |
for (i=0; i<clrtabsiz; i++) { |
318 |
> |
for (i=0; i<netsize; i++) { |
319 |
|
p = network[i]; |
320 |
< |
p[0] = i << netbiasshift; |
321 |
< |
p[1] = i << netbiasshift; |
314 |
< |
p[2] = i << netbiasshift; |
315 |
< |
freq[i] = intbias >> 8; /* 1/256 */ |
320 |
> |
p[0] = p[1] = p[2] = (i << (netbiasshift+8))/netsize; |
321 |
> |
freq[i] = intbias/netsize; /* 1/netsize */ |
322 |
|
bias[i] = 0; |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
< |
static |
327 |
> |
/* do after unbias - insertion sort of network and build netindex[0..255] */ |
328 |
> |
|
329 |
|
inxbuild() |
330 |
|
{ |
331 |
|
register int i,j,smallpos,smallval; |
332 |
|
register int *p,*q; |
333 |
< |
int start,previous; |
333 |
> |
int previouscol,startpos; |
334 |
|
|
335 |
< |
previous = 0; |
336 |
< |
start = 0; |
337 |
< |
for (i=0; i<clrtabsiz; i++) { |
335 |
> |
previouscol = 0; |
336 |
> |
startpos = 0; |
337 |
> |
for (i=0; i<netsize; i++) { |
338 |
|
p = network[i]; |
339 |
|
smallpos = i; |
340 |
|
smallval = p[1]; /* index on g */ |
341 |
< |
/* find smallest in i+1..clrtabsiz-1 */ |
342 |
< |
for (j=i+1; j<clrtabsiz; j++) { |
341 |
> |
/* find smallest in i..netsize-1 */ |
342 |
> |
for (j=i+1; j<netsize; j++) { |
343 |
|
q = network[j]; |
344 |
|
if (q[1] < smallval) { /* index on g */ |
345 |
|
smallpos = j; |
347 |
|
} |
348 |
|
} |
349 |
|
q = network[smallpos]; |
350 |
+ |
/* swap p (i) and q (smallpos) entries */ |
351 |
|
if (i != smallpos) { |
352 |
|
j = q[0]; q[0] = p[0]; p[0] = j; |
353 |
|
j = q[1]; q[1] = p[1]; p[1] = j; |
355 |
|
j = q[3]; q[3] = p[3]; p[3] = j; |
356 |
|
} |
357 |
|
/* smallval entry is now in position i */ |
358 |
< |
if (smallval != previous) { |
359 |
< |
netindex[previous] = (start+i)>>1; |
360 |
< |
for (j=previous+1; j<smallval; j++) netindex[j] = i; |
361 |
< |
previous = smallval; |
362 |
< |
start = i; |
358 |
> |
if (smallval != previouscol) { |
359 |
> |
netindex[previouscol] = (startpos+i)>>1; |
360 |
> |
for (j=previouscol+1; j<smallval; j++) netindex[j] = i; |
361 |
> |
previouscol = smallval; |
362 |
> |
startpos = i; |
363 |
|
} |
364 |
|
} |
365 |
< |
netindex[previous] = (start+clrtabsiz-1)>>1; |
366 |
< |
for (j=previous+1; j<clrtabsiz; j++) netindex[j] = clrtabsiz-1; |
365 |
> |
netindex[previouscol] = (startpos+maxnetpos)>>1; |
366 |
> |
for (j=previouscol+1; j<256; j++) netindex[j] = maxnetpos; /* really 256 */ |
367 |
|
} |
368 |
|
|
369 |
|
|
370 |
< |
static int |
363 |
< |
inxsearch(b,g,r) /* accepts real BGR values after net is unbiased */ |
370 |
> |
int inxsearch(b,g,r) /* accepts real BGR values after net is unbiased */ |
371 |
|
register int b,g,r; |
372 |
|
{ |
373 |
< |
register int i,j,best,x,y,bestd; |
373 |
> |
register int i,j,dist,a,bestd; |
374 |
|
register int *p; |
375 |
+ |
int best; |
376 |
|
|
377 |
|
bestd = 1000; /* biggest possible dist is 256*3 */ |
378 |
|
best = -1; |
379 |
|
i = netindex[g]; /* index on g */ |
380 |
< |
j = i-1; |
380 |
> |
j = i-1; /* start at netindex[g] and work outwards */ |
381 |
|
|
382 |
< |
while ((i<clrtabsiz) || (j>=0)) { |
383 |
< |
if (i<clrtabsiz) { |
382 |
> |
while ((i<netsize) || (j>=0)) { |
383 |
> |
if (i<netsize) { |
384 |
|
p = network[i]; |
385 |
< |
x = p[1] - g; /* inx key */ |
386 |
< |
if (x >= bestd) i = clrtabsiz; /* stop iter */ |
385 |
> |
dist = p[1] - g; /* inx key */ |
386 |
> |
if (dist >= bestd) i = netsize; /* stop iter */ |
387 |
|
else { |
388 |
|
i++; |
389 |
< |
if (x<0) x = -x; |
390 |
< |
y = p[0] - b; |
391 |
< |
if (y<0) y = -y; |
392 |
< |
x += y; |
393 |
< |
if (x<bestd) { |
394 |
< |
y = p[2] - r; |
395 |
< |
if (y<0) y = -y; |
388 |
< |
x += y; /* x holds distance */ |
389 |
< |
if (x<bestd) {bestd=x; best=p[3];} |
389 |
> |
if (dist<0) dist = -dist; |
390 |
> |
a = p[0] - b; if (a<0) a = -a; |
391 |
> |
dist += a; |
392 |
> |
if (dist<bestd) { |
393 |
> |
a = p[2] - r; if (a<0) a = -a; |
394 |
> |
dist += a; |
395 |
> |
if (dist<bestd) {bestd=dist; best=p[3];} |
396 |
|
} |
397 |
|
} |
398 |
|
} |
399 |
|
if (j>=0) { |
400 |
|
p = network[j]; |
401 |
< |
x = g - p[1]; /* inx key - reverse dif */ |
402 |
< |
if (x >= bestd) j = -1; /* stop iter */ |
401 |
> |
dist = g - p[1]; /* inx key - reverse dif */ |
402 |
> |
if (dist >= bestd) j = -1; /* stop iter */ |
403 |
|
else { |
404 |
|
j--; |
405 |
< |
if (x<0) x = -x; |
406 |
< |
y = p[0] - b; |
407 |
< |
if (y<0) y = -y; |
408 |
< |
x += y; |
409 |
< |
if (x<bestd) { |
410 |
< |
y = p[2] - r; |
411 |
< |
if (y<0) y = -y; |
406 |
< |
x += y; /* x holds distance */ |
407 |
< |
if (x<bestd) {bestd=x; best=p[3];} |
405 |
> |
if (dist<0) dist = -dist; |
406 |
> |
a = p[0] - b; if (a<0) a = -a; |
407 |
> |
dist += a; |
408 |
> |
if (dist<bestd) { |
409 |
> |
a = p[2] - r; if (a<0) a = -a; |
410 |
> |
dist += a; |
411 |
> |
if (dist<bestd) {bestd=dist; best=p[3];} |
412 |
|
} |
413 |
|
} |
414 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
< |
static int |
421 |
< |
contest(b,g,r) /* accepts biased BGR values */ |
420 |
> |
/* finds closest neuron (min dist) and updates freq */ |
421 |
> |
/* finds best neuron (min dist-bias) and returns position */ |
422 |
> |
/* for frequently chosen neurons, freq[i] is high and bias[i] is negative */ |
423 |
> |
/* bias[i] = gamma*((1/netsize)-freq[i]) */ |
424 |
> |
|
425 |
> |
int contest(b,g,r) /* accepts biased BGR values */ |
426 |
|
register int b,g,r; |
427 |
|
{ |
428 |
< |
register int i,best,bestbias,x,y,bestd,bestbiasd; |
429 |
< |
register int *p,*q, *pp; |
428 |
> |
register int i,dist,a,biasdist,betafreq; |
429 |
> |
int bestpos,bestbiaspos,bestd,bestbiasd; |
430 |
> |
register int *p,*f, *n; |
431 |
|
|
432 |
< |
bestd = ~(1<<31); |
432 |
> |
bestd = ~(((int) 1)<<31); |
433 |
|
bestbiasd = bestd; |
434 |
< |
best = -1; |
435 |
< |
bestbias = best; |
436 |
< |
q = bias; |
437 |
< |
p = freq; |
438 |
< |
for (i=0; i<clrtabsiz; i++) { |
439 |
< |
pp = network[i]; |
440 |
< |
x = pp[0] - b; |
441 |
< |
if (x<0) x = -x; |
442 |
< |
y = pp[1] - g; |
443 |
< |
if (y<0) y = -y; |
444 |
< |
x += y; |
445 |
< |
y = pp[2] - r; |
446 |
< |
if (y<0) y = -y; |
447 |
< |
x += y; /* x holds distance */ |
448 |
< |
/* >> netbiasshift not needed if funnyshift used */ |
449 |
< |
if (x<bestd) {bestd=x; best=i;} |
450 |
< |
y = x - ((*q)>>funnyshift); /* y holds biasd */ |
451 |
< |
if (y<bestbiasd) {bestbiasd=y; bestbias=i;} |
443 |
< |
y = (*p >> betashift); /* y holds beta*freq */ |
444 |
< |
*p -= y; |
445 |
< |
*q += (y<<gammashift); |
446 |
< |
p++; |
447 |
< |
q++; |
434 |
> |
bestpos = -1; |
435 |
> |
bestbiaspos = bestpos; |
436 |
> |
p = bias; |
437 |
> |
f = freq; |
438 |
> |
|
439 |
> |
for (i=0; i<netsize; i++) { |
440 |
> |
n = network[i]; |
441 |
> |
dist = n[0] - b; if (dist<0) dist = -dist; |
442 |
> |
a = n[1] - g; if (a<0) a = -a; |
443 |
> |
dist += a; |
444 |
> |
a = n[2] - r; if (a<0) a = -a; |
445 |
> |
dist += a; |
446 |
> |
if (dist<bestd) {bestd=dist; bestpos=i;} |
447 |
> |
biasdist = dist - ((*p)>>(intbiasshift-netbiasshift)); |
448 |
> |
if (biasdist<bestbiasd) {bestbiasd=biasdist; bestbiaspos=i;} |
449 |
> |
betafreq = (*f >> betashift); |
450 |
> |
*f++ -= betafreq; |
451 |
> |
*p++ += (betafreq<<gammashift); |
452 |
|
} |
453 |
< |
freq[best] += beta; |
454 |
< |
bias[best] -= betagamma; |
455 |
< |
return(bestbias); |
453 |
> |
freq[bestpos] += beta; |
454 |
> |
bias[bestpos] -= betagamma; |
455 |
> |
return(bestbiaspos); |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
< |
static |
460 |
< |
alterneigh(rad,i,b,g,r) /* accepts biased BGR values */ |
459 |
> |
/* move neuron i towards (b,g,r) by factor alpha */ |
460 |
> |
|
461 |
> |
altersingle(alpha,i,b,g,r) /* accepts biased BGR values */ |
462 |
> |
register int alpha,i,b,g,r; |
463 |
> |
{ |
464 |
> |
register int *n; |
465 |
> |
|
466 |
> |
n = network[i]; /* alter hit neuron */ |
467 |
> |
*n -= (alpha*(*n - b)) / initalpha; |
468 |
> |
n++; |
469 |
> |
*n -= (alpha*(*n - g)) / initalpha; |
470 |
> |
n++; |
471 |
> |
*n -= (alpha*(*n - r)) / initalpha; |
472 |
> |
} |
473 |
> |
|
474 |
> |
|
475 |
> |
/* move neurons adjacent to i towards (b,g,r) by factor */ |
476 |
> |
/* alpha*(1-((i-j)^2/[r]^2)) precomputed as radpower[|i-j|]*/ |
477 |
> |
|
478 |
> |
alterneigh(rad,i,b,g,r) /* accents biased BGR values */ |
479 |
|
int rad,i; |
480 |
|
register int b,g,r; |
481 |
|
{ |
482 |
|
register int j,k,lo,hi,a; |
483 |
|
register int *p, *q; |
484 |
|
|
485 |
< |
lo = i-rad; |
486 |
< |
if (lo<-1) lo= -1; |
465 |
< |
hi = i+rad; |
466 |
< |
if (hi>clrtabsiz) hi=clrtabsiz; |
485 |
> |
lo = i-rad; if (lo<-1) lo= -1; |
486 |
> |
hi = i+rad; if (hi>netsize) hi=netsize; |
487 |
|
|
488 |
|
j = i+1; |
489 |
|
k = i-1; |
512 |
|
} |
513 |
|
|
514 |
|
|
495 |
– |
static |
496 |
– |
altersingle(alpha,j,b,g,r) /* accepts biased BGR values */ |
497 |
– |
register int alpha,j,b,g,r; |
498 |
– |
{ |
499 |
– |
register int *q; |
500 |
– |
|
501 |
– |
q = network[j]; /* alter hit neuron */ |
502 |
– |
*q -= (alpha*(*q - b)) / initalpha; |
503 |
– |
q++; |
504 |
– |
*q -= (alpha*(*q - g)) / initalpha; |
505 |
– |
q++; |
506 |
– |
*q -= (alpha*(*q - r)) / initalpha; |
507 |
– |
} |
508 |
– |
|
509 |
– |
|
510 |
– |
static |
515 |
|
learn() |
516 |
|
{ |
517 |
|
register int i,j,b,g,r; |
518 |
< |
int radius,rad,alpha,step,delta,upto; |
518 |
> |
int radius,rad,alpha,step,delta,samplepixels; |
519 |
|
register unsigned char *p; |
520 |
|
unsigned char *lim; |
521 |
|
|
522 |
< |
upto = lengthcount/(3*samplefac); |
519 |
< |
delta = upto/ncycles; |
520 |
< |
lim = thepicture + lengthcount; |
522 |
> |
alphadec = 30 + ((samplefac-1)/3); |
523 |
|
p = thepicture; |
524 |
+ |
lim = thepicture + lengthcount; |
525 |
+ |
samplepixels = lengthcount/(3*samplefac); |
526 |
+ |
delta = samplepixels/ncycles; |
527 |
|
alpha = initalpha; |
528 |
|
radius = initradius; |
529 |
+ |
|
530 |
|
rad = radius >> radiusbiasshift; |
531 |
|
if (rad <= 1) rad = 0; |
532 |
|
for (i=0; i<rad; i++) |
533 |
|
radpower[i] = alpha*(((rad*rad - i*i)*radbias)/(rad*rad)); |
534 |
< |
|
535 |
< |
if ((lengthcount%jump1) != 0) step = 3*jump1; |
534 |
> |
|
535 |
> |
if ((lengthcount%prime1) != 0) step = 3*prime1; |
536 |
|
else { |
537 |
< |
if ((lengthcount%jump2) !=0) step = 3*jump2; |
537 |
> |
if ((lengthcount%prime2) !=0) step = 3*prime2; |
538 |
|
else { |
539 |
< |
if ((lengthcount%jump3) !=0) step = 3*jump3; |
540 |
< |
else step = 3*jump4; |
539 |
> |
if ((lengthcount%prime3) !=0) step = 3*prime3; |
540 |
> |
else step = 3*prime4; |
541 |
|
} |
542 |
|
} |
543 |
+ |
|
544 |
|
i = 0; |
545 |
< |
while (i < upto) { |
545 |
> |
while (i < samplepixels) { |
546 |
|
b = p[0] << netbiasshift; |
547 |
|
g = p[1] << netbiasshift; |
548 |
|
r = p[2] << netbiasshift; |
549 |
|
j = contest(b,g,r); |
550 |
|
|
551 |
|
altersingle(alpha,j,b,g,r); |
552 |
< |
if (rad) alterneigh(rad,j,b,g,r); |
546 |
< |
/* alter neighbours */ |
552 |
> |
if (rad) alterneigh(rad,j,b,g,r); /* alter neighbours */ |
553 |
|
|
554 |
|
p += step; |
555 |
|
if (p >= lim) p -= lengthcount; |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
< |
static |
569 |
> |
/* unbias network to give 0..255 entries */ |
570 |
> |
/* which can then be used for colour map */ |
571 |
> |
/* and record position i to prepare for sort */ |
572 |
> |
|
573 |
|
unbiasnet() |
574 |
|
{ |
575 |
|
int i,j; |
576 |
|
|
577 |
< |
for (i=0; i<clrtabsiz; i++) { |
577 |
> |
for (i=0; i<netsize; i++) { |
578 |
|
for (j=0; j<3; j++) |
579 |
|
network[i][j] >>= netbiasshift; |
580 |
|
network[i][3] = i; /* record colour no */ |
581 |
|
} |
582 |
|
} |
583 |
|
|
584 |
< |
/* Don't do this until the network has been unbiased */ |
584 |
> |
|
585 |
> |
/* Don't do this until the network has been unbiased (GW) */ |
586 |
|
|
587 |
|
static |
588 |
|
cpyclrtab() |
589 |
|
{ |
590 |
|
register int i,j,k; |
591 |
|
|
592 |
< |
for (j=0; j<clrtabsiz; j++) { |
592 |
> |
for (j=0; j<netsize; j++) { |
593 |
|
k = network[j][3]; |
594 |
|
for (i = 0; i < 3; i++) |
595 |
|
clrtab[k][i] = network[j][2-i]; |