Code archives/Graphics/Grayscale

This code has been declared by its author to be Public Domain code.

Download source code

Grayscale by pexe
(Posted 22 years ago)
Turn your graphics to grayscale mode.

This is my first script using readpixel and writepixel. Because of this, its very slow.

If somebody have a tip to make it faster, tell me please.

Enjoy. =D
;Grayscale
;By pexe

;WARNING: This is my first script using readpixel and writepixel, and its VERY SLOW!

;Function grayscale(Buffer, X Starting Point, Y Starting Point, Width, Height)

Function grayscale(GS_buffer,GS_vx,GS_vy,GS_w,GS_h)
LockBuffer(GS_buffer)
For GS_y = GS_vy To GS_vy+GS_h-1
For GS_x = GS_vx To GS_vx+GS_w-1
GS_pix = ReadPixelFast(GS_x,GS_y,GS_buffer)

GS_r% = (GS_pix Shr 16) And $ff ;\
GS_g% = (GS_pix Shr 8) And $ff  ;  Transform values
GS_b% = GS_pix And $ff          ;/

GS_v% = GS_r+GS_g+GS_b
GS_v% = GS_v/3

GS_pix=(GS_v Or (GS_v Shl 8) Or (GS_v Shl 16) Or ($ff000000)) ;Put values back
WritePixelFast GS_x,GS_y,GS_pix,GS_buffer

Next
Next
UnlockBuffer(GS_buffer)
End Function