Skidracer

Blitz3D Forums/Blitz3D Programming/Skidracer

Chroma(Posted 2006) [#1]
I'm having some problems with your code from the archives. I'm loading a texture that will be masked. I'm then plugging in the texture handle and a zero to your function but it either ends my program or gives me a readpixelfast error.

I'm thinking there's something wrong with the code. Can you or someone else look it over plz. I'm wanting to just use regular masking in order to avoid the z-order problem and if I can get your function working and it will take away the black outline then that'd be just perfect.

; ID: 1131
; Author: skidracer
; Date: 2004-08-11 20:09:34
; Title: KeyImage
; Description: Produces clean edges for masked textures

Function KeyImage(texture,keycolor)
	oldbuffer=GraphicsBuffer() 
	buffer=TextureBuffer(texture)
	SetBuffer buffer
	LockBuffer buffer	
	w=GraphicsWidth()
	h=GraphicsHeight()
	keycolor=keycolor And $fcfcfc
; first pass set key
	For y=0 To h-1
		For x=0 To w-1
			c=ReadPixelFast(x,y)
			If (c And $fcfcfc)<>keycolor
				c=c Or $ff000000
			Else
				c=0
			EndIf
			WritePixelFast x,y,c
		Next
	Next
; second pass fix edges
	For y=1 To h-2
		For x=1 To w-2
			c=ReadPixelFast(x,y)
			If c=0
				t=0
				For yy=-1 To 1
					For xx=-1 To 1
						c=ReadPixelFast(x+xx,y+yy)
						If c and $ffffff
							t=((t And $fefefe) Shr 1)+((c And $fefefe) Shr 1)
						EndIf
					Next
				Next			
				WritePixelFast x+xx,y+yy,t
			EndIf
		Next
	Next
	UnlockBuffer buffer
	SetBuffer oldbuffer
End Function



Yan(Posted 2006) [#2]
w = TextureWidth(texture)
h = textureHeight(texture)

??


Panno(Posted 2006) [#3]
-1


Stevie G(Posted 2006) [#4]
What Yan said.


Chroma(Posted 2006) [#5]
Tried that...still doesn't work right. :(


skidracer(Posted 2006) [#6]
Can you email me a test image and the flags you are using with the LoadTexture command.

As for GraphicsWidth, I thought that was equivalent to current buffer width. The docs seem to disagree...


fredborg(Posted 2006) [#7]
This is what I'm using (or used to use): http://www.blitzbasic.com/codearcs/codearcs.php?code=1739

It will use the alpha channel of an image to generate the mask, and it works without hiccups.


Stevie G(Posted 2006) [#8]
Nice function Fred. A long lost code archive entry ;) There's so much crap in there it's sometimes difficult to weed out the good stuff".


Ross C(Posted 2006) [#9]
It would be nice if the code archives had a rating system, and you could sort code by the highest rated, so good entries never get lost so easy.


kfprimm(Posted 2006) [#10]
he posted that entry a day ago...


Stevie G(Posted 2006) [#11]
LOL .. yeah ... I didn't realise that at the time :)