ReadBrushPixel usage

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

ReadBrushPixel usage

Post by amyren »

How does the result from ReadBrushPixel and ReadPixel work?
The docs say it will give the result in RGB format, but the output I get does not look like that.
Example black color returns simply 0. white 16777215, 16701184 - yellow, 14423100 - red,
3978097 - green etc.
How to get these into a format where I can read the value 0-255 for each of R, G and B?
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: ReadBrushPixel usage

Post by Flinx »

These numbers are the RGB values. For example, take a hexadecimal look at your white value:
DebugPrint(HexStr(16777215)) returns $FFFFFF.
Now you could extract the green value, for example, by dividing by 256, taking the integer part (that removes blue), dividing by 256 again, taking the remainder (that removes red) and multiplying by 256 again.
Another way would be to use the logical operators and the bitwise operators.
But Hollywood makes it easier for you and has the functions Red(), Green() and Blue().

Code: Select all

z=16777215
DebugPrint(HexStr(z))
DebugPrint(Frac(Int(z/256)/256)*256)
DebugPrint((z And $00FF00)>>8)
DebugPrint(Green(z))
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

Re: ReadBrushPixel usage

Post by amyren »

Thanks for explaining
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: ReadBrushPixel usage

Post by Flinx »

But I made a mistake: The fourth line must, of course, only use bitwise operators, no logical.

Code: Select all

DebugPrint((z & $00FF00)>>8)
Post Reply