Platforms to show: All Mac Windows Linux Cross-Platform

/Images/LCMS2/Transform Threaded


Required plugins for this example: MBS Main Plugin, MBS Images Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/LCMS2/Transform Threaded

This example is the version from Sun, 28th Aug 2021.

Project "Transform Threaded.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control TestButton1 Inherits PushButton
ControlInstance TestButton1 Inherits PushButton
EventHandler Sub Action() ConvertOnMainThread End EventHandler
End Control
Control Output Inherits Canvas
ControlInstance Output Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic <> Nil Then Dim faktor As Double = Min( g.Height / Pic.Height, g.Width / Pic.Width) // Calculate new size Dim w As Integer = Pic.Width * faktor Dim h As Integer = Pic.Height * faktor // create new picture Dim NewPic As New Picture(w,h,32) // draw picture in the new size g.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height End If End EventHandler
End Control
Control TestButton Inherits PushButton
ControlInstance TestButton Inherits PushButton
EventHandler Sub Action() RunThread 0 End EventHandler
End Control
Control TestButton2 Inherits PushButton
ControlInstance TestButton2 Inherits PushButton
EventHandler Sub Action() RunThread 1 End EventHandler
End Control
Control TestButton3 Inherits PushButton
ControlInstance TestButton3 Inherits PushButton
EventHandler Sub Action() RunThread 2 End EventHandler
End Control
Control TestButton4 Inherits PushButton
ControlInstance TestButton4 Inherits PushButton
EventHandler Sub Action() RunThread 4 End EventHandler
End Control
EventHandler Sub Open() Input = LogoMBS(5000) pic = Nil End EventHandler
Sub ConvertOnMainThread() // we just convert from generic RGB to SRGB // not useful, but we measure how long this takes Dim fi As FolderItem = FindFile("Generic RGB Profile.icc") Dim pi As LCMS2ProfileMBS = LCMS2ProfileMBS.OpenProfileFromFile(fi) Dim po As LCMS2ProfileMBS = LCMS2ProfileMBS.CreateSRGBProfile Dim b1 As New LCMS2BitmapMBS(Input) Dim out As New Picture(Input.Width, Input.Height, 32) Dim b2 As New LCMS2BitmapMBS(out) Dim pif As Integer = pi.FormatterForColorspace(1, False) Dim pof As Integer = po.FormatterForColorspace(1, False) Dim intent As Integer = 1 // relative colormetric Dim t As LCMS2TransformMBS = LCMS2TransformMBS.CreateTransform(po, pof, pi, pif, intent) Dim m1 as Double = Microseconds Dim b As Boolean = t.Transform(b1, b2) Dim m2 As Double = Microseconds Log "Transform on main thread: "+Str( (m2-m1) / 1000.0, "0")+"ms" If b Then // show in canvas pic = b2.Picture output.invalidate End If End Sub
Shared 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
Sub RunThread(ThreadCount as integer) Dim t As New WorkThread t.Input = Input t.ThreadCount = ThreadCount t.win = Self t.run End Sub
Sub log(message as string) List.AddRow message End Sub
Property Input As Picture
Property pic As Picture
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class WorkThread Inherits Thread
EventHandler Sub Run() // we just convert from generic RGB to SRGB // not useful, but we measure how long this takes Dim fi As FolderItem = MainWindow.FindFile("Generic RGB Profile.icc") Dim pi As LCMS2ProfileMBS = LCMS2ProfileMBS.OpenProfileFromFile(fi) Dim po As LCMS2ProfileMBS = LCMS2ProfileMBS.CreateSRGBProfile Dim b1 As New LCMS2BitmapMBS(Input) Dim out As New Picture(Input.Width, Input.Height, 32) Dim b2 As New LCMS2BitmapMBS(out) Dim pif As Integer = pi.FormatterForColorspace(1, False) Dim pof As Integer = po.FormatterForColorspace(1, False) Dim intent As Integer = 1 // relative colormetric Dim t As LCMS2TransformMBS = LCMS2TransformMBS.CreateTransform(po, pof, pi, pif, intent) Dim m1 As Double = Microseconds Dim b As Boolean = t.TransformMT(b1, b2, ThreadCount) Dim m2 As Double = Microseconds TimeMessage = "Transform on helper threads: "+Str( (m2-m1) / 1000.0, "0")+"ms" If b Then // show in canvas Self.pic = b2.Picture Else TimeMessage = "Transform failed" End If xojo.core.Timer.CallLater 0, Addressof Finished End EventHandler
Sub Finished() win.pic = pic win.output.invalidate win.Log TimeMessage win = Nil End Sub
Property Input As Picture
Property ThreadCount As Integer
Property TimeMessage As string
Property pic As Picture
Property win As MainWindow
End Class
End Project

The items on this page are in the following plugins: MBS Images Plugin.


The biggest plugin in space...