March 05, 2021, 07:02:51 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Read and Write pixel functions by Rob Farley [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Read and Write pixel functions by Rob Farley [ 1+ years ago ] (Read 411 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bb] Read and Write pixel functions by Rob Farley [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:41 AM »
Title :
Read and Write pixel functions
Author :
Rob Farley
Posted :
1+ years ago
Description :
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!
Code :
Code: BlitzBasic
;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 Farley(Posted 1+ years ago)
Updated due the the old ones being... um... old.
aab(Posted 1+ years ago)
Uses slightly less code than my ol method: thanksThis 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 (!)
DheDarkhCustard(Posted 1+ years ago)
that's cool
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Read and Write pixel functions by Rob Farley [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal