[solved] CustomFilter for FillArea on CanvasGadget at MacOS doesn't work

Just starting out? Need help? Post your questions and find answers here.
hoerbie
Enthusiast
Enthusiast
Posts: 136
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

[solved] CustomFilter for FillArea on CanvasGadget at MacOS doesn't work

Post by hoerbie »

Hi,
it would be nice if anyone of the PB pros could have a look at the following code, that I extracted from a bigger project where I try to mimic good old GFA fill patterns.

On Windows this generally works with a lot tested PB versions of ASM and C compiler.
PB 6.02 on MacOS crashes with ASM.
MacOS C-Backend PB 6.02, PB 6.04, PB 6.10 and PB 6.11 Beta 2 all give same wrong results of grey boxes instead of blue patterns, as if there is no filter.
And in my bigger project on MacOS the 2ddrawing engine simply seems to crash in the background, because the DrawText after some CustomFilters doesn't do anything.

Code: Select all

Structure str_fillpattern
  Array fil.a(7,7)
EndStructure
DataSection
  lbl_fillpattern:
  
  Data.a 1,1,1,0,1,1,1,0
  Data.a 1,1,0,1,1,1,0,1
  Data.a 1,0,1,1,1,0,1,1
  Data.a 0,1,1,1,0,1,1,1
  Data.a 1,1,1,0,1,1,1,0
  Data.a 1,1,0,1,1,1,0,1
  Data.a 1,0,1,1,1,0,1,1
  Data.a 0,1,1,1,0,1,1,1
  
  Data.a 0,1,1,1,1,1,1,0
  Data.a 1,0,1,1,1,1,0,1
  Data.a 1,1,0,1,1,0,1,1
  Data.a 1,1,1,0,0,1,1,1
  Data.a 1,1,1,0,0,1,1,1
  Data.a 1,1,0,1,1,0,1,1
  Data.a 1,0,1,1,1,1,0,1
  Data.a 0,1,1,1,1,1,1,0
EndDataSection
Restore lbl_fillpattern

Global Dim fillpattern.str_fillpattern(2)
For fy = 0 To 7
  For fx = 0 To 7
    Read.a fillpattern(1)\fil(fy,fx)
  Next fx
Next fy
For fy = 0 To 7
  For fx = 0 To 7
    Read.a fillpattern(2)\fil(fy,fx)
  Next fx
Next fy
Global *fillpointer.str_fillpattern

Global backcol.l = RGB(255,255,255)
Global frontcol.l = RGB(0,0,255)

Procedure FilterCallback(x, y, source.l, target.l)
  mx = x % 8
  my = y % 8
  If *fillpointer\fil(my, mx) = 0
    target = backcol
  Else
    target = frontcol  ;Additional question: when commented out I would expect the blue color set at FillArea set as target.
  EndIf
  ProcedureReturn target
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "CustomFilter TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  cid = CanvasGadget(#PB_Any, 0, 0, 400, 200)
  If StartDrawing(CanvasOutput(cid))
    Box(50,50,100,100,$0000ff)
    Box(250,50,100,100,$000000)
      
    DrawingMode(#PB_2DDrawing_CustomFilter)      
    CustomFilterCallback(@FilterCallback())
    *fillpointer = @fillpattern(1)
    FillArea(100, 100, $ffffff, frontcol)   
    *fillpointer = @fillpattern(2)
    FillArea(300, 100, $ffffff, frontcol)
      
    DrawingMode(#PB_2DDrawing_Default)      
    DrawText(100,180,"Hallo")
      
    StopDrawing() 
  EndIf
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Maybe there is an doc/understanding/mistake from my side or is it a bug? If this is a bug, please move it to the bug section.

Additional question: Also I'm wondering why the blue color set at the FillArea seems to not be send to the filter callback as target color, and it is set as source color, from my point of view the naming of "source" and "target" in the example and docs is wrong.

Thanks, hoerbie
Last edited by hoerbie on Fri May 03, 2024 8:26 am, edited 2 times in total.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CustomFilter for FillArea on CanvasGadget at MacOS doesn't work

Post by infratec »

If you don't modify the target color it results in the original color of the area.
In your case red in one box and black in the other.

You may need RGBA() for frontcolor and backcolor, because it is written in the doc that the colors are always 32bits with alpha channel.
Maybe macOS is more 'exact'.
hoerbie
Enthusiast
Enthusiast
Posts: 136
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: CustomFilter for FillArea on CanvasGadget at MacOS doesn't work

Post by hoerbie »

@infratec thanks for your exact look in the docs
infratec wrote: Mon Apr 29, 2024 7:19 pm You may need RGBA() for frontcolor and backcolor, because it is written in the doc that the colors are always 32bits with alpha channel.
Maybe macOS is more 'exact'.
This is indeed the solution, macOS seems to be more exact as Windows, after defining my frontcolor and backcolor with RGBA() everything works in the FilterCallback.
Post Reply