Code archives/Graphics/Read and Write pixel functions

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

Download source code

Read and Write pixel functions by Rob Farley2003
OK, 2 functions here...

GetRGB and WriteRGB, these have to be used on locked image buffers.

Set up the globals so when you've read the RGB of an XY of an image you only need to do one readpixelfast.

Usage:
GetRGB(gfx,50,20)

This reads the RGB from X=50, Y=20 on image GFX and places the RGB vlaues into GotR, GotG and GotB globals.

WriteRGB(gfx,50,20,100,160,200)

This writes the RGB value of 100,160,200 to x=50, y=20 on image GFX.

I hope this helps!
;ARGB Functions by Rob Farley 2003
;rob@mentalillusion.co.uk
;http://www.mentalillusion.co.uk

; RGB Functions
Global GotR=0
Global GotG=0
Global GotB=0


Function GetRGB(image_name,x,y)
; Gets the RGB components from an image.
; The imagebuffer needs to be locked as it does a read pixel fast.
; The components are put into the global varibles gotr, gotg and gotb
	argb=ReadPixelFast(x,y,ImageBuffer(image_name))
	gotr=(ARGB Shr 16) And $ff 
	gotg=(ARGB Shr 8) And $ff 
	gotb=ARGB And $ff
End Function

Function WriteRGB(image_name,x,y,red,green,blue)
; Writes a pixel to an image.
; The imagebuffer needs to be locked as it does a write pixel fast.
argb=(blue Or (green Shl 8) Or (red Shl 16) Or ($ff000000))
WritePixelFast x,y,argb,ImageBuffer(image_name)
End Function

Comments

Rob Farley2004
Updated due the the old ones being... um... old.


aab2004
Uses slightly less code than my ol method: thanks

This is something that all Mid-Newbies should read.

i spent hours figuring this out on my own when i was a Mid-Newbie, and i didnt even know i was using Hex at the time (!)


DheDarkhCustard2008
that's cool

;)


Code Archives Forum