Page 1 of 1
1 bit brush palette
Posted: Wed Mar 26, 2025 7:46 pm
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")
Re: 1 bit brush palette
Posted: Sun Apr 06, 2025 12:05 am
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.
Re: 1 bit brush palette
Posted: Tue Apr 08, 2025 9:26 am
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.