Colorizing a specific area on the screen.

BlitzMax Forums/BlitzMax Programming/Colorizing a specific area on the screen.

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.

i think this is what your after...
this is a very unoptimised replace olour technique.
usage
i:tpixmap = loadpixmap("image.png")

' replace all exact white occurances with bright purple
p:tpixmap = replacecolour(i:tpixamp,$ffffff,$ff00ff)

' replace all nearly white occurances with bright purple
p:tpixmap = replacecolour(i:tpixamp,$ffffff,$ff00ff,10)


functions
Function replacecolour:TPixmap(p:TPixmap,old_rgb:Int,new_rgb:Int,threshold:Int)
	Local w:Int = PixmapWidth(p)
	Local h:Int = PixmapHeight(p)
	Local x:Int,y:Int
	Local b1:Byte Ptr
	Local b2:Byte Ptr
	Local n:TPixmap = CreatePixmap(w,h,pf_BGRA8888)
	
	Local r:Int = (old_rgb Shr 16) & 255
	Local g:Int = (old_rgb Shr 8) & 255
	Local b:Int = (old_rgb Shr 0) & 255
	
	Local p1:TPixmap = ConvertPixmap(p,PF_BGRA8888)
	
	' scan through image
	x  =0
	While x < w
		y = 0
		While y < h
			b1 = PixmapPixelPtr(p1,x,y)
			b2 = PixmapPixelPtr(n,x,y)
			
			If threshold_check(r,b1[2],threshold) And threshold_check(g,b1[1],threshold) And threshold_check(b,b1[0],threshold)
				b2[0] = (new_rgb Shr 0) & 255
				b2[1] = (new_rgb Shr 8) & 255
				b2[2] = (new_rgb Shr 16) & 255
				b2[3] = $ff
			Else
				b2[0] = b1[0]
				b2[1] = b1[1]
				b2[2] = b1[2]
				b2[3] = b1[3]
			EndIf
			
			y:+1
		Wend
		x:+1
	Wend
	
	Return n
End Function

Function threshold_check:Int(v1:Int,v2:Int,t:Int)
	If (v1 > v2-t) And (v1 < v2+t+1) Then Return True
	
	Return False
End Function