Platforms to show: All Mac Windows Linux Cross-Platform
/Picture/Graphics Transform Benchmark
Required plugins for this example: MBS Main Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/Graphics Transform Benchmark
This example is the version from Sun, 8th Dec 2012.
Project "Graphics Transform Benchmark.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class TestWindow Inherits Window
Control fldResult Inherits TextArea
ControlInstance fldResult Inherits TextArea
End Control
Control cvsPic Inherits Canvas
ControlInstance cvsPic(0) Inherits Canvas
ControlInstance cvsPic(1) Inherits Canvas
ControlInstance cvsPic(2) Inherits Canvas
ControlInstance cvsPic(3) Inherits Canvas
EventHandler Sub Paint(index as Integer, g As Graphics)
if Pics.Ubound < index then return
dim pic as Picture = Pics( index )
if pic <> nil then
g.DrawPicture( pic, 0, 0, g.Width, g.Height, 0, 0, pic.Width, pic.Height )
end
End EventHandler
End Control
Control btnOriginal Inherits PushButton
ControlInstance btnOriginal Inherits PushButton
EventHandler Sub Action()
dim pic as Picture = LogoMBS(5000)
if pic <> nil then
if Pics.Ubound = -1 then
redim Pics( 0 )
end if
Pics( 0 ) = pic
AddToResult "Image loaded: " + str( pic.Width ) + " X " + str( pic.Height )
btnPixels.Enabled = true
btnTransform.Enabled = true
btnPlugin.Enabled = true
me.Enabled = false
end if
self.Refresh(False)
End EventHandler
End Control
Control btnPixels Inherits PushButton
ControlInstance btnPixels Inherits PushButton
EventHandler Sub Action()
#pragma BackgroundTasks False
#pragma BoundsChecking False
const kPicIndex = 1
dim pic as Picture = GetPicture( kPicIndex )
if pic <> nil then
dim startTime, diffTime as double
dim msg as string
dim invertedPic as Picture = CopyOfPicture( pic )
// Invert with RGBSurface.Pixel
dim map() as integer = GetInvertMap
startTime = microseconds
dim srcRGB as RGBSurface = invertedPic.RGBSurface
dim lastX as integer = pic.Width - 1
dim lastY as integer = pic.Height - 1
dim thisColor as color
dim newRed, newGreen, newBlue as integer
for y as integer = 0 to lastY
for x as integer = 0 to lastX
thisColor = srcRGB.Pixel( x, y )
newRed = map(thisColor.Red)
newGreen = map(thisColor.Green)
newBlue = map(thisColor.Blue)
srcRGB.Pixel( x, y ) = RGB( newRed, newGreen, newBlue )
next x
next y
diffTime = microseconds - startTime
msg = "Pixel: " + format( diffTime / 10000., "#,0.000" ) + " ms"
AddToResult msg
StorePicture( kPicIndex ) = invertedPic
end if
self.Refresh
End EventHandler
End Control
Control btnTransform Inherits PushButton
ControlInstance btnTransform Inherits PushButton
EventHandler Sub Action()
#pragma BackgroundTasks False
#pragma BoundsChecking False
const kPicIndex = 2
dim pic as Picture = GetPicture( kPicIndex )
if pic <> nil then
dim startTime, diffTime as double
dim msg as string
dim map() as integer = GetInvertMap
dim invertedPic as Picture = CopyOfPicture( pic )
// Invert with RGBSurface
startTime = microseconds
for i as integer = 1 to 10
invertedPic.RGBSurface.Transform( map )
next
diffTime = microseconds - startTime
msg = "RGBSurface: " + format( diffTime / 10000.0, "#,0.000" ) + " ms"
AddToResult msg
StorePicture( kPicIndex ) = invertedPic
end if
self.Refresh
End EventHandler
End Control
Control btnPlugin Inherits PushButton
ControlInstance btnPlugin Inherits PushButton
EventHandler Sub Action()
#pragma BackgroundTasks False
#pragma BoundsChecking False
const kPicIndex = 3
dim pic as Picture = GetPicture( kPicIndex )
if pic <> nil then
dim startTime, diffTime as double
dim msg as string
dim invertedPic as Picture = CopyOfPicture( pic )
if checkThreaded.Value then
dim map() as integer = GetInvertMap
// Invert with Plugin
startTime = microseconds
for i as integer = 1 to 10
invertedPic = pic.ThreadedTransformMBS( 0, map, map, map, invertedPic )
next
else
dim map as MemoryBlock = GetInvertMapMB
// Invert with Plugin
startTime = microseconds
for i as integer = 1 to 10
invertedPic = pic.TransformColorsMBS( map, map, map, invertedPic )
next
end if
diffTime = microseconds - startTime
msg = "Plugin: " + format( diffTime / 10000.0, "#,0.000" ) + " ms "
AddToResult msg
StorePicture( kPicIndex ) = invertedPic
end if
self.Refresh
End EventHandler
End Control
Control checkThreaded Inherits CheckBox
ControlInstance checkThreaded Inherits CheckBox
End Control
EventHandler Sub Open()
redim Pics( 2 )
End EventHandler
Sub AddToResult(msg As String)
fldResult.AppendText msg
fldResult.AppendText EndOfLine
End Sub
Function CopyOfPicture(pic As Picture) As Picture
if pic is nil then return nil
dim r as new Picture( pic.Width, pic.Height, pic.Depth )
r.Graphics.DrawPicture( pic, 0, 0 )
return r
End Function
Function GetInvertMap() As Integer()
const kLastIndex = 255
static map() as integer
if map.Ubound <> kLastIndex then
redim map( kLastIndex )
for i as integer = 0 to kLastIndex
map( i ) = kLastIndex - i
next
end if
return map
End Function
Function GetInvertMapMB() As MemoryBlock
static mb as MemoryBlock
if mb is nil then
mb = new MemoryBlock( 256 )
dim p as Ptr = mb
dim map() as integer = GetInvertMap
for i as integer = 0 to 255
p.Byte( i ) = map( i )
next
end if
return mb
End Function
Function GetPicture(index As Integer) As Picture
if Pics.Ubound = -1 then
return nil
elseif index <= Pics.Ubound and Pics( index ) <> nil then
return Pics( index )
else
return Pics( 0 )
end if
End Function
Sub StorePicture(index As Integer, Assigns pic As Picture)
if pic = nil then return
if Pics.Ubound < index then
redim Pics( index )
end if
Pics( index ) = pic
End Sub
Property Pics() As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS Picture Plugin.