Specifies a callback that will be called for every pixel that is part of a drawing operation in #PB_2DDrawing_CustomFilter drawing mode.
@FilterCallback() The address of a callback function to call. It must have the following form:Procedure CustomCallback(x, y, SourceColor, TargetColor) ; ; Calculate ResultColor from the given input ; ProcedureReturn ResultColor EndProcedureThe callback will be called for every pixel that is drawn as a result of a call to drawing functions like Line(), Box() or DrawText(). The SourceColor parameter specifies the color given in the drawing operation and the TargetColor parameter specifies the color of the target pixel in the drawing area. Both colors are always 32-bit with alpha channel independent of the color depth of the output. The callback has to calculate the color that the target pixel should have after the drawing and return that.
The x and y coordinate received in the callback are always relative to the upper left corner of the drawing output. The coordinates are not affected by any calls to SetOrigin() or ClipOutput().
This callback will be called many times (for every pixel to draw) so it should be very small and fast to not have a too big impact on the drawing performance.
Note: The #PB_2DDrawing_CustomFilter drawing mode only works on ImageOutput() and CanvasOutput().
Procedure FilterCallback(x, y, SourceColor, TargetColor) ; Take only the Red component from the Source, do not modify the others ProcedureReturn RGBA(Red(SourceColor), Green(TargetColor), Blue(TargetColor), Alpha(TargetColor)) EndProcedure UseJPEGImageDecoder() If OpenWindow(0, 0, 0, 400, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) LoadImage(1, #PB_Compiler_Home + "examples/3d/Data/Textures/clouds.jpg") If CreateImage(0, 400, 200) And StartDrawing(ImageOutput(0)) DrawImage(ImageID(1), 0, 0, 400, 200) DrawingMode(#PB_2DDrawing_CustomFilter) CustomFilterCallback(@FilterCallback()) Circle(100, 100, 100, $0000FF) Circle(300, 100, 100, $000000) StopDrawing() ImageGadget(0, 0, 0, 400, 200, ImageID(0)) EndIf Repeat Event = WaitWindowEvent() Until Event = #PB_Event_CloseWindow EndIf