FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Compare pixels


DIM rgbRED.6
DIM myRGB.6
WINDOW #1,,(0,0)-(320,200)
rgbRED.red% = 65535
rgbRED.green% = 0
rgbRED.blue% = 0
CALL RGBFORECOLOR(#@rgbRED)
BOX FILL 0,0 to 320,200
CALL GETCPIXEL(128,96,#@myRGB)
color _zWhite
color _zBlack
redhue& = myRGB.red%
greenhue& = myRGB.green%
bluehue& = myRGB.blue%
print "red:";redhue&
print "green:";greenhue&
print "blue:";bluehue&

If one of the functions above complains about the wrong variable type, take out the "#@". It's required for GETCPIXEL I think. Also keep in mind that redhue& is a long int and not just an int. red%, green%, and blue% are just offsets into the record, not the expected return type.

My old progress bar re-write uses alot of RGB math and techniques(except for getcpixel), you can get that from: ftp://foxchange.com/pub/inspired/FBIIrsrc/32ProgBarSrcB1.sit.hqx

Just reading the source could give you alot of info on how to deal with RGBrecs in general.

TJ Grant


The above code works pretty good. Using SETCPIXEL, and then getting the same one back will yield slightly different values.

For instance, placing 300000 into myRGB.green, will yield something like 29596 on the way back out.
Anyway, your above code does help. The printing gives a negative number, with "-1" for a 65535 value. Wonder why things come out negative.

I forgot to mention that this will need to work in thousands of colors too, unfortunately. So that means no "DIM palette(255,2):' for holding RGB vals " in that case ,I reckon, or am I wrong about that?

Robert Covington


The reason the numbers aren't coming out exact is because the system is matching your number to the closest color value it can display.

As for the negative numbers, RGB values are stored as unsigned integers. So when you get above 32767 in FB it will flip to negative. The solution if you need to view these is either redhue& = VAL(UNS$(myRGB.red%)) or to do it yourself using peek to move the data into the redhue& variable

If you want to do it that way, try

redhue& = {myRGB.red%} AND &FFFF

*Chris


Thanks Chris; here's a re-write that works properly; note I use the val(uns$( thing and DEFSTR WORD...

COMPILE 0,_macsbuglabels
DIM rgbRED.6
DIM myRGB.6
DIM redhue&
DIM greenhue&
DIM bluehue&

END GLOBALS
DEFSTR WORD
WINDOW #1,,(0,0)-(320,200)
rgbRED.red% = 65535
rgbRED.green% = 0
rgbRED.blue% = 0
CALL RGBFORECOLOR(rgbRED)
BOX FILL 0,0 TO 320,200
CALL GETCPIXEL(128,96,myRGB)
COLOR _zWhite
CLS
COLOR _zBlack
redhue& = VAL(UNS$(myRGB.red%))
greenhue& = VAL(UNS$(myRGB.green%))
bluehue& = VAL(UNS$(myRGB.blue%))
PRINT "red:";redhue&
PRINT "green:";greenhue&
PRINT "blue:";bluehue&
DO
UNTIL FN BUTTON

TJ Grant