Platforms to show: All Mac Windows Linux Cross-Platform
/MacCG/CoreImage/Simple Filter
Required plugins for this example: MBS Main Plugin, MBS MacCI Plugin, MBS MacCG Plugin, MBS MacCF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreImage/Simple Filter
This example is the version from Thu, 31th Jul 2019.
Project "Simple Filter.xojo_binary_project"
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
dim time as integer =ticks
dim CGContextHandle as integer =g.Handle(g.HandleTypeCGContextRef)
dim cgContext as CGContextMBS = CGContextMBS.contextWithCGContext(CGContextHandle)
dim cicontext as new CIContextMBS(cgContext)
cifilter.inputBrightness=SliderB.Value/100.0
CIFilter.inputContrast=SliderC.Value/100.0
CIFilter.inputSaturation=SliderS.Value/100.0
dim result as CIImageMBS = cifilter.outputImage
if result<>nil then
cicontext.drawImageRect result, result.Extent,result.Extent
end if
System.DebugLog "Paint needed "+str((ticks-time)/60.0)+" seconds."
End EventHandler
End Control
Control SliderB Inherits Slider
ControlInstance SliderB Inherits Slider
EventHandler Sub ValueChanged()
if me.Enabled then
Canvas1.Invalidate
end if
End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control SliderC Inherits Slider
ControlInstance SliderC Inherits Slider
EventHandler Sub ValueChanged()
if me.Enabled then
Canvas1.Invalidate
end if
End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control SliderS Inherits Slider
ControlInstance SliderS Inherits Slider
EventHandler Sub ValueChanged()
if me.Enabled then
Canvas1.Invalidate
end if
End EventHandler
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
EventHandler Sub Open()
dim n as CIAttributeMBS
dim file as FolderItem
dim ciimage as CIImageMBS
cifilter=new CIFilterColorControlsMBS
n=CIFilter.AttributeinputBrightness
if n<>Nil then
SliderB.Minimum=n.SliderMinNumber*100.0
SliderB.Maximum=n.SliderMaxNumber*100.0
sliderB.Value=n.DefaultNumber*100.0
SliderB.enabled=true
end if
n=CIFilter.AttributeinputContrast
if n<>Nil then
SliderC.Minimum=n.SliderMinNumber*100.0
SliderC.Maximum=n.SliderMaxNumber*100.0
sliderC.Value=n.DefaultNumber*100.0
SliderC.enabled=true
end if
n=CIFilter.AttributeinputSaturation
if n<>Nil then
SliderS.Minimum=n.SliderMinNumber*100.0
SliderS.Maximum=n.SliderMaxNumber*100.0
sliderS.Value=n.DefaultNumber*100.0
SliderS.enabled=true
end if
file=FindFile("juz.jpg")
ciimage=NewCIImagewithFileMBS(file)
if ciimage=nil then // Fails always on Mac OS X 10.3...
MsgBox "Failed to load image file "+file.NativePath
quit
end if
CIFilter.inputImage=CIImage
Width=juz.Width+169
Height=juz.Height
End EventHandler
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
Property Protected CIFilter As CIFilterColorControlsMBS
Property Protected count As integer
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
if TargetMachO then
else
MsgBox "This project needs a MachO target."
end if
End EventHandler
End Class
ExternalFile juz
End ExternalFile
End Project
See also:
The items on this page are in the following plugins: MBS MacCG Plugin.