Counting colors used in an image.

BlitzMax Forums/BlitzMax Beginners Area/Counting colors used in an image.

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

In either case, here is the smart data / dumb algorithm version. It does pretty much everything you could want. It processes the test image in about 170ms.
SuperStrict

Local myPix:TPixmap = LoadPixmap("fucklars.jpg")
Local key:String
Local colours:TMap = New TMap
Local count:Int = 0

Local time:Int = MilliSecs()

For Local y:Int = 0 Until myPix.height
	For Local x:Int = 0 Until myPix.width
		key = Hex( myPix.readPixel( x,y ) )
		key = key [2..]
		If Not colours.contains(key)
			colours.insert(key , "1")
			count:+1
		Else
			Local inc:String = colours.valueForKey( key ).toString()
			inc = String( Int(inc) + 1 )
		EndIf
	Next
Next

Print "Pixels   : " + (myPix.width * myPix.height)
Print "Colors   : " + count
Print "Time     : " + (MilliSecs() - time) +" ms."
Print "Memory   : " + GCMemAlloced()/1024/1024.0 + " MB."