BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"RGB Color Value Conversion"
, by thechange
Just 4 functions to convert from RGB value to Red/Green/Blue values and vise versa. Especially useful with ReadPixel and WritePixel commands.
Code
; *---------------------------------* ; I I ; I RGB Color Value Conversion - VX I ; I I ; *---------------------------------* ;-[ Sub ]--------------------------------------------------------------------------------------------------------1-2-0-- Function GetRed% ( RGB% ) ; Returns the Red value from the given RGB value Return RGB Shr 16 And 255 End Function Function GetGreen% ( RGB% ) ; Returns the Green value from the given RGB value Return RGB Shr 8 And 255 End Function Function GetBlue% ( RGB% ) ; Returns the Blue value from the given RGB value Return RGB And 255 End Function Function GetRGB% ( Red% , Green% , Blue% ) ; Combines Red, Green and Blue values into one RGB value Return Red Shl 16 + Green Shl 8 + Blue End Function ;--> ; Example of GetRGB ; ---------------------------------------------------------------------------------------------------------------- ; SeedRnd MilliSecs() For CounterY = 0 To GraphicsHeight()/2-1 For CounterX = 0 To GraphicsWidth()/2-1 Red = 255 Blue = 0 Green = Rnd( 0 , 255 ) WritePixel CounterX , CounterY , GetRGB( Red , Green , Blue ) Next Next ; Example of GetRed, GetGreen and GetBlue ; ---------------------------------------------------------------------------------------------------------------- ; SeedRnd MilliSecs() For CounterY = 0 To GraphicsHeight()/2-1 For CounterX = 0 To GraphicsWidth()/2-1 RGB = ReadPixel( CounterX , CounterY ) InvertedRed = 255 - GetRed( RGB ) InvertedGreen = 255 - GetGreen( RGB ) InvertedBlue = 255 - GetBlue( RGB ) InvertedRGB = GetRGB( InvertedRed , InvertedGreen , InvertedBlue ) WritePixel CounterX + GraphicsWidth()/2 , CounterY + GraphicsHeight()/2 , InvertedRGB Next Next
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations