1 bit brush palette

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

1 bit brush palette

Post by amyren »

I wonder what I do wrong here, I tried some variations but if I set the Depth to 1 it aways say the pixel is black.
If I skip the Depth argument and create a full color brush it will be white.

Code: Select all

CreatePalette(1, {#PALETTE_MONOCHROME}, {Depth = 1})
visited = CreateBrush(Nil, 1280, 720, #WHITE, {Depth = 1, Palette = 1})
If ReadBrushPixel(visited, 1, 1) = #BLACK Then DebugPrint("Pixel is black")
If ReadBrushPixel(visited, 1, 1) = #WHITE Then DebugPrint("Pixel is white")
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: 1 bit brush palette

Post by airsoftsoftwair »

I'm sorry but it looks like every line in that code is wrong. Did you use ChatGPT for that? ;) It's all in the documentation though. Here's a corrected version:

Code: Select all

CreatePalette(1, #PALETTE_MONOCHROME)
visited = CreateBrush(Nil, 1280, 720, #WHITE, {Depth = 1, Palette = 1, FillPen = 1})
If ReadBrushPixel(visited, 1, 1) = 0 Then DebugPrint("Pixel is black")
If ReadBrushPixel(visited, 1, 1) = 1 Then DebugPrint("Pixel is white")
Explanation: In CreatePalette() you were passing #PALETTE_MONOCHROME as a color instead of a special inbuilt palette ID. In CreateBrush() the documentation says that the "color" argument is ignored if you're creating a palette brush and you have to use the "FillPen" tag instead. In the ReadBrushPixel() lines the documentation says that it will return pen indices for palette brushes so you need to compare against 0 (black) or 1 (white) to find out the pixel color.
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

Re: 1 bit brush palette

Post by amyren »

Thanks for explaining.
I must admit I was capable of creating these errors all by myself. As I said I tried several variations, so at one point I did have most of these lines right. But since I could not put the finger on what was missing I tried every variation I could think of :)
Like these two lines should provide the same result

Code: Select all

CreatePalette(1, {#BLACK, #WHITE}, {Depth = 1})
CreatePalette(1, #PALETTE_MONOCHROME)
I see now its the FillPen argument I missed, and hopefully I learned a bit about how palette works.
Post Reply