Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSImage/NSImageMBS multithreading
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS Images Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSImage/NSImageMBS multithreading
This example is the version from Wed, 12th Feb 2013.
Project "NSImageMBS multithreading.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action()
useMBS = me.Value
End EventHandler
End Control
Control CheckBox2 Inherits CheckBox
ControlInstance CheckBox2 Inherits CheckBox
EventHandler Sub Action()
Use4Threads = me.Value
End EventHandler
End Control
Control DoneTimer Inherits Timer
ControlInstance DoneTimer Inherits Timer
EventHandler Sub Action()
checkbox1.Enabled = true
checkbox2.Enabled = true
PushButton1.Enabled = true
ProgressWheel1.Visible = false
dim mode as string = "pure RB"
if UseMBS then mode = "MBS"
dim threads as string = "one thread"
if Use4Threads then threads = "4 threads"
List.addrow str((EndTime-startTime)/1000000.0)+" seconds for "+mode+" with "+threads
End EventHandler
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run()
if Use4Threads then
work
else
// just one thread, so we do it here 4 times
Work
work
work
work
end if
CheckEnd
End EventHandler
End Control
Control Thread2 Inherits Thread
ControlInstance Thread2 Inherits Thread
EventHandler Sub Run()
work
CheckEnd
End EventHandler
End Control
Control Thread3 Inherits Thread
ControlInstance Thread3 Inherits Thread
EventHandler Sub Run()
work
CheckEnd
End EventHandler
End Control
Control Thread4 Inherits Thread
ControlInstance Thread4 Inherits Thread
EventHandler Sub Run()
work
CheckEnd
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
me.Enabled = false
CheckBox1.Enabled = False
CheckBox2.Enabled = False
startTime = Microseconds
ProgressWheel1.Visible = True
if Use4Threads then
Thread1.run
Thread2.run
Thread3.run
Thread4.run
else
Thread1.run
end if
End EventHandler
End Control
Control ProgressWheel1 Inherits ProgressWheel
ControlInstance ProgressWheel1 Inherits ProgressWheel
End Control
EventHandler Sub Open()
// create huge image
dim logo as Picture = LogoMBS(5000)
logodata = PictureToJPEGStringMBS(logo, 80)
End EventHandler
Sub CheckEnd()
dim Running as integer
if Thread1.State = Thread.Running then
Running = Running + 1
end if
if Thread2.State = Thread.Running then
Running = Running + 1
end if
if Thread3.State = Thread.Running then
Running = Running + 1
end if
if Thread4.State = Thread.Running then
Running = Running + 1
end if
if Running = 1 then
// we are the last
endTime = Microseconds
DoneTimer.Mode = 1
end if
End Sub
Sub work()
for i as integer = 1 to 3
if UseMBS then
// decompress
dim n as NSImageMBS = NSImageMBS.imageWithDataMT(logodata)
// recompress
dim data as MemoryBlock = n.JPEGRepresentationWithCompressionFactorMT(0.8)
else
// decompress
dim p as Picture = Picture.FromData(logodata)
// recompress
dim d as MemoryBlock = p.GetData(p.FormatJPEG, 80)
end if
next
End Sub
Property EndTime As double
Property Use4Threads As Boolean
Property UseMBS As Boolean
Property logodata As MemoryBlock
Property startTime As Double
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.