Looking for Grayscaling Effect?

Blitz3D Forums/Blitz3D Programming/Looking for Grayscaling Effect?

Baystep Productions(Posted 2008) [#1]
Well this is what I came up with. For some reason I couldn't just use Read/Write PixelFast cause of a MAV. But whatever.

Function GrayScaleFX()
	LockBuffer(BackBuffer())
	For x%=0 To gfx_width%
		For y%=0 To gfx_height%
			pxl = ReadPixel(x%,y%)
			bl = pxl And 255
 			gr = (pxl Shr 8) And 255
 			rd = (pxl Shr 16) And 255
  			clr = .3 * rd + .59 * gr + .11 * bl
  			WritePixel x,y,clr + clr Shl 8 + clr Shl 16 - 16777216
		Next
	Next
	UnlockBuffer()
End Function


And why I'm posting it here is so that if you guys have any speed ideas in mind you can throw them in!

But basicly its the classic Grayscale algorithm. But what I believe makes this faster then others is that it is Reading and over-Writing in the same pass. I've seen other grayscale effects try and save screenshots or save the screen data to dim/array. But I figured that wasn't neccessary. And so running on the locked backbuffer I'm hoping my hunch of DirectDraw operating on a harware surface with the BackBuffer is true cause then that should speed this up more!

And I call this last before the FLIP.


Matty(Posted 2008) [#2]
The reason you get the MAV on read/writepixefast is because your loops go 1 pixel to many in each direction.

lockbuffer
[code]
for x=0 to gfx_width-1
for y=0 to gfx_height-1
writepixelfast x,y,16777215
next
next
unlockbuffer


Baystep Productions(Posted 2008) [#3]
Ok I tested it out on a 3D Application. And framerate was about 1. Not .1 at least!

It was actually really cool to see. It didn't matter what was happening in the game or how crowded the screen was it took the same ammount of time either way.

I could see using this as a pause menu or something. I'll try and get it to fade.

MATTY: Thanks! It actually sped it up a micro ammount but I could tell it was something!


Ross C(Posted 2008) [#4]
Try placing a quad over the screen when fading and copy from the screen onto the texture. It should be faster as accessing the backbuffer/front buffer is slower than accessing a texture. Just make sure the texture has the VRAM flag on it.