PROC computecolorhash(redbuf:PTR TO CHAR,grnbuf:PTR TO CHAR,blubuf:PTR TO CHAR,cols,rows,maxcolors,colorsP:PTR TO LONG)
DEF cht=0:PTR TO LONG
DEF pP=0
DEF chl=0:PTR TO colorhist_list_item
DEF col,row,hash,ccoolloorr
cht:=alloccolorhash()
IF cht
IF colorsP
colorsP[0]:=0
row:=0
REPEAT
IF checkcancel(statwindow)
freecolorhash(cht)
Raise("canc")
ENDIF
IF ((row/4)=((row+3)/4))
IF gaugeobj THEN fuelgauge(statwindow.rport,gaugeobj,row,rows-1,stat.histogram_string,drawinfo)
ENDIF
col:=0
REPEAT
ccoolloorr:=(PPM_PUTR(redbuf[pP]) OR PPM_PUTG(grnbuf[pP]) OR PPM_PUTB(blubuf[pP]) AND $FCFEF8) -> Give RED 6 BITS, GRN 7 BITS, and BLU 5 BITS...this helps improve clustering, and to keep the number of unique colors below 32768 !
hash:=HASHPIXEL(ccoolloorr)
chl:=cht[hash]
WHILE (chl<>0)
IF (chl.ch.color=ccoolloorr)
JUMP break
ENDIF
chl:=chl.next
ENDWHILE
break:
IF (chl<>0)
chl.ch.value:=(chl.ch.value+1)
ELSE
colorsP[0]:=colorsP[0]+1
IF colorsP[0]>maxcolors
freecolorhash(cht)
RETURN 0
ENDIF
-> chl:=New(SIZEOF colorhist_list_item)
chl:=alloc(histopool,SIZEOF colorhist_list_item)
IF chl
chl.ch.color:=ccoolloorr
chl.ch.value:=1
chl.next:=cht[hash]
cht[hash]:=chl
ENDIF
ENDIF
col:=col+1;pP:=pP+1;UNTIL col=cols
row:=row+1;UNTIL row=rows
ENDIF
ENDIF
ENDPROC cht
PROC alloccolorhash()
DEF cht=0
cht:=New((HASH_SIZE*4)+20)
ENDPROC cht
PROC colorhashtocolorhist(cht:PTR TO LONG,maxcolors)