Platforms to show: All Mac Windows Linux Cross-Platform
/MacCG/CoreImage/Simple Filter Chain
Required plugins for this example: MBS MacCI Plugin, MBS MacBase Plugin, MBS Main 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 Chain
This example is the version from Mon, 6th Oct 2013.
Project "Simple Filter Chain.xojo_binary_project"
Class Window1 Inherits Window
Control BrightnessSlider Inherits Slider
ControlInstance BrightnessSlider Inherits Slider
EventHandler Sub ValueChanged()
update
End EventHandler
End Control
Control out Inherits Canvas
ControlInstance out Inherits Canvas
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control ContrastSlider Inherits Slider
ControlInstance ContrastSlider Inherits Slider
EventHandler Sub ValueChanged()
update
End EventHandler
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control SaturationSlider Inherits Slider
ControlInstance SaturationSlider Inherits Slider
EventHandler Sub ValueChanged()
update
End EventHandler
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control AngleSlider Inherits Slider
ControlInstance AngleSlider Inherits Slider
EventHandler Sub ValueChanged()
update
End EventHandler
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action()
BrightnessSlider.Value = 0
ContrastSlider.Value = 100
SaturationSlider.Value = 100
AngleSlider.Value = 0
End EventHandler
End Control
Control BevelButton2 Inherits BevelButton
ControlInstance BevelButton2 Inherits BevelButton
EventHandler Sub Action()
dim f as FolderItem = GetOpenFolderItem(FileTypes1.Any)
if f = nil then Return // cancel
load f
End EventHandler
End Control
Control BevelButton3 Inherits BevelButton
ControlInstance BevelButton3 Inherits BevelButton
EventHandler Sub Action()
// Like update, but without scaling down
dim f as FolderItem = GetSaveFolderItem(FileTypes1.Png, "output.png")
if f = nil then Return // cancel
dim ColorFilter as new CIFilterColorControlsMBS
ColorFilter.inputImage = inputImage
ColorFilter.inputBrightness = BrightnessSlider.Value / 100.0
ColorFilter.inputContrast = ContrastSlider.Value / 100.0
ColorFilter.inputSaturation = SaturationSlider.Value / 100.0
dim HueFilter as new CIFilterHueAdjustMBS
HueFilter.inputImage = ColorFilter.outputImage
HueFilter.inputAngle = AngleSlider.Value / 100.0
dim OutputImage as CIImageMBS = HueFilter.outputImage
dim image as NSImageMBS = OutputImage.RenderNSImage(false)
dim pngData as MemoryBlock = image.PNGRepresentation
dim b as BinaryStream = BinaryStream.Create(f, true)
b.Write pngData
End EventHandler
End Control
EventHandler Sub Open()
Load LogoMBS(500)
End EventHandler
Protected Sub Load(f as FolderItem)
dim i as new CIImageMBS(f)
if i.Handle = 0 then
MsgBox "Failed to read image."
Return
end if
InputImage = i
update
End Sub
Protected Sub Load(p as Picture)
dim c as CGImageMBS = CGCreateImageMBS(p)
if c = nil then
MsgBox "Failed to allocate image"
Return
end if
InputImage = new CIImageMBS(c)
update
End Sub
Protected Sub Update()
dim ScaleFilter as new CIFilterLanczosScaleTransformMBS
ScaleFilter.inputImage = InputImage
ScaleFilter.inputScale = 1.0 // min( canvas1.Width / InputImage.Width, canvas1.Height / InputImage.Height)
dim ColorFilter as new CIFilterColorControlsMBS
ColorFilter.inputImage = ScaleFilter.outputImage
ColorFilter.inputBrightness = BrightnessSlider.Value / 100.0
ColorFilter.inputContrast = ContrastSlider.Value / 100.0
ColorFilter.inputSaturation = SaturationSlider.Value / 100.0
dim HueFilter as new CIFilterHueAdjustMBS
HueFilter.inputImage = ColorFilter.outputImage
HueFilter.inputAngle = AngleSlider.Value / 100.0
OutputImage = HueFilter.outputImage
out.Backdrop = outputImage.RenderPicture
End Sub
Property Protected InputImage As CIImageMBS
Property Protected OutputImage As CIImageMBS
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
FileTypes1
Filetype special/any
Filetype image/png
End FileTypes1
End Project
See also:
The items on this page are in the following plugins: MBS MacCG Plugin.