CustomFilterCallback()
Syntax
CustomFilterCallback(@FilterCallback())Description
Specify a callback that will be called for every pixel that is part of a drawing operation in #PB_2DDrawing_CustomFilter drawing mode.
Parameters
The callback 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 32bit 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.
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().Example:
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/sources/data/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
Supported OS
All