Platforms to show: All Mac Windows Linux Cross-Platform

/AVFoundation/CVPixelBuffer test


Required plugins for this example: MBS Main Plugin, MBS AVFoundation Plugin, MBS MacCI Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS MacBase Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /AVFoundation/CVPixelBuffer test

This example is the version from Tue, 26th Aug 2019.

Project "CVPixelBuffer test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic1 <> Nil Then g.DrawPicture pic1, 0, 0, g.Width, g.Height, 0, 0, pic1.Width, pic1.Height End If End EventHandler
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic2 <> Nil Then g.DrawPicture pic2, 0, 0, g.Width, g.Height, 0, 0, pic2.Width, pic2.Height End If End EventHandler
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic3 <> Nil Then g.DrawPicture pic3, 0, 0, g.Width, g.Height, 0, 0, pic3.Width, pic3.Height End If End EventHandler
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic4 <> Nil Then g.DrawPicture pic4, 0, 0, g.Width, g.Height, 0, 0, pic4.Width, pic4.Height End If End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() MakePic1 MakePic2 MakePic3 MakePic4 End EventHandler
Sub MakePic1() // 8bit gray list.AddRow CurrentMethodName Const Width = 600 Const Height = 400 Dim BytesPerPixel As Integer = 1 Dim RowBytes As Integer = RoundUp32( BytesPerPixel * Width) Dim data As New MemoryBlock(RowBytes * Height) Dim w As Integer = Width -1 Dim h As Integer = Height-1 Dim o As Integer For y As Integer = 0 To h o = y * rowbytes For x As Integer = 0 To w data.UInt8Value(o) = x + y o = o + BytesPerPixel Next Next Dim dic As New Dictionary dic.Value(CVPixelBufferMBS.kCVPixelBufferCGImageCompatibilityKey) = True dic.Value(CVPixelBufferMBS.kCVPixelBufferCGBitmapContextCompatibilityKey) = True Dim c As New CVPixelBufferMBS(width, Height, CVPixelBufferMBS.kCVPixelFormatType_OneComponent8, data, RowBytes, dic) Dim image As CIImageMBS = c.CIImage If image <> Nil Then pic1 = image.RenderPicture Else List.AddRow "CIImage is nil" End If Exception u As UnsupportedOperationException list.AddRow u.message + " "+Str(u.errorNumber) End Sub
Sub MakePic2() // 24 bit RGB list.AddRow CurrentMethodName Const Width = 600 Const Height = 400 Dim BytesPerPixel As Integer = 3 Dim RowBytes As Integer = RoundUp32( BytesPerPixel * Width) Dim data As New MemoryBlock(RowBytes * Height) Dim w As Integer = Width -1 Dim h As Integer = Height-1 Dim o As Integer For y As Integer = 0 To h o = y * rowbytes For x As Integer = 0 To w data.UInt8Value(o+0) = x + y data.UInt8Value(o+1) = x data.UInt8Value(o+2) = y o = o + BytesPerPixel Next Next Dim dic As New Dictionary dic.Value(CVPixelBufferMBS.kCVPixelBufferCGImageCompatibilityKey) = True dic.Value(CVPixelBufferMBS.kCVPixelBufferCGBitmapContextCompatibilityKey) = True #Pragma BreakOnExceptions off Dim c As New CVPixelBufferMBS(width, Height, CVPixelBufferMBS.kCVPixelFormatType_24RGB, data, RowBytes, dic) Dim image As CIImageMBS = c.CIImage If image <> Nil Then pic2 = image.RenderPicture Else List.AddRow "CIImage is nil" End If Exception u As UnsupportedOperationException list.AddRow u.message + " "+Str(u.errorNumber) End Sub
Sub MakePic3() // 32bit RGB list.AddRow CurrentMethodName Const Width = 600 Const Height = 400 Dim BytesPerPixel As Integer = 4 Dim RowBytes As Integer = RoundUp32( BytesPerPixel * Width) Dim data As New MemoryBlock(RowBytes * Height) Dim w As Integer = Width -1 Dim h As Integer = Height-1 Dim o As Integer For y As Integer = 0 To h o = y * rowbytes For x As Integer = 0 To w data.UInt8Value(o+0) = 255 data.UInt8Value(o+1) = x + y data.UInt8Value(o+2) = x data.UInt8Value(o+3) = y o = o + BytesPerPixel Next Next Dim dic As New Dictionary dic.Value(CVPixelBufferMBS.kCVPixelBufferCGImageCompatibilityKey) = True dic.Value(CVPixelBufferMBS.kCVPixelBufferCGBitmapContextCompatibilityKey) = True #Pragma BreakOnExceptions off Dim c As New CVPixelBufferMBS(width, Height, CVPixelBufferMBS.kCVPixelFormatType_32ARGB, data, RowBytes, dic) Dim image As CIImageMBS = c.CIImage If image <> Nil Then pic3 = image.RenderPicture Else List.AddRow "CIImage is nil" End If Exception u As UnsupportedOperationException list.AddRow u.message + " "+Str(u.errorNumber) End Sub
Sub MakePic4() // VUY list.AddRow CurrentMethodName Const Width = 600 Const Height = 400 Dim BytesPerPixel As Integer = 1 Dim RowBytes As Integer = RoundUp32( BytesPerPixel * Width) Dim data As New MemoryBlock(RowBytes * Height) Dim w As Integer = Width -1 Dim h As Integer = Height-1 Dim o As Integer For y As Integer = 0 To h o = y * rowbytes For x As Integer = 0 To w data.UInt8Value(o+0) = x + y o = o + BytesPerPixel Next Next Dim dic As New Dictionary dic.Value(CVPixelBufferMBS.kCVPixelBufferCGImageCompatibilityKey) = True dic.Value(CVPixelBufferMBS.kCVPixelBufferCGBitmapContextCompatibilityKey) = True #Pragma BreakOnExceptions off Dim c As New CVPixelBufferMBS(width, Height, CVPixelBufferMBS.kCVPixelFormatType_422YpCbCr8, data, RowBytes, dic) Dim image As CIImageMBS = c.CIImage If image <> Nil Then pic4 = image.RenderPicture Else List.AddRow "CIImage is nil" End If Exception u As UnsupportedOperationException list.AddRow u.message + " "+Str(u.errorNumber) End Sub
Function RoundUp32(n as integer) As integer Dim r As Integer = (n+31) \ 32 Return r * 32 End Function
Property pic1 As picture
Property pic2 As picture
Property pic3 As picture
Property pic4 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
End Project

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


The biggest plugin in space...