Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/Mac ColorSpace tests
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/Mac ColorSpace tests
This example is the version from Sun, 20th Jan 2018.
Project "Mac ColorSpace tests.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithName(CGColorSpaceMBS.kCGColorSpaceGenericRGB) dim Red as CGColorMBS = CGColorMBS.Create(ColorSpace, array(1.0, 0.0, 0.0, 1.0)) context.SetFillColorSpace(ColorSpace) context.SetFillColor(Red) context.FillRect CGMakeRectMBS(0, 0, g.Width, g.Height) context.Flush End EventHandler
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithName(CGColorSpaceMBS.kCGColorSpaceSRGB) dim Red as CGColorMBS = CGColorMBS.Create(ColorSpace, array(1.0, 0.0, 0.0, 1.0)) context.SetFillColorSpace(ColorSpace) context.SetFillColor(Red) context.FillRect CGMakeRectMBS(0, 0, g.Width, g.Height) context.Flush End EventHandler
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim screen as NSScreenMBS = NSScreenMBS.mainScreen dim ScreenColorSpace as NSColorSpaceMBS = screen.colorSpace dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithHandle(ScreenColorSpace.CGColorSpaceHandle) dim Red as CGColorMBS = CGColorMBS.Create(ColorSpace, array(1.0, 0.0, 0.0, 1.0)) context.SetFillColorSpace(ColorSpace) context.SetFillColor(Red) context.FillRect CGMakeRectMBS(0, 0, g.Width, g.Height) context.Flush End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithName(CGColorSpaceMBS.kCGColorSpaceGenericRGB) dim w as integer = g.Width * 2 dim h as integer = g.Height * 2 const kCGImageAlphaNone = 0 const kCGImageAlphaPremultipliedLast = 1 // For example, premultiplied RGBA const kCGImageAlphaPremultipliedFirst = 2 // For example, premultiplied ARGB const kCGImageAlphaLast = 3 // For example, non-premultiplied RGBA const kCGImageAlphaFirst = 4 // For example, non-premultiplied ARGB const kCGImageAlphaNoneSkipLast = 5 // Equivalent to kCGImageAlphaNone. const kCGImageAlphaNoneSkipFirst = 6 dim rowBytes as integer = w * 4 dim data as new MemoryBlock(rowBytes * h) for y as integer = 0 to 199 for x as integer = 0 to 199 data.UInt32Value( y * rowBytes + x * 4) = &h0000FF00 // red next next dim bitmap as CGBitmapContextMBS = CGBitmapContextMBS.Create(data, w, h, 8, rowBytes, ColorSpace, kCGImageAlphaNoneSkipFirst) dim image as CGImageMBS = bitmap.CreateImage context.DrawPicture(image, CGMakeRectMBS(0, 0, g.Width, g.Height)) context.Flush End EventHandler
End Control
Control Canvas5 Inherits Canvas
ControlInstance Canvas5 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithName(CGColorSpaceMBS.kCGColorSpaceSRGB) dim w as integer = g.Width * 2 dim h as integer = g.Height * 2 const kCGImageAlphaNone = 0 const kCGImageAlphaPremultipliedLast = 1 // For example, premultiplied RGBA const kCGImageAlphaPremultipliedFirst = 2 // For example, premultiplied ARGB const kCGImageAlphaLast = 3 // For example, non-premultiplied RGBA const kCGImageAlphaFirst = 4 // For example, non-premultiplied ARGB const kCGImageAlphaNoneSkipLast = 5 // Equivalent to kCGImageAlphaNone. const kCGImageAlphaNoneSkipFirst = 6 dim rowBytes as integer = w * 4 dim data as new MemoryBlock(rowBytes * h) for y as integer = 0 to 199 for x as integer = 0 to 199 data.UInt32Value( y * rowBytes + x * 4) = &h0000FF00 // red next next dim bitmap as CGBitmapContextMBS = CGBitmapContextMBS.Create(data, w, h, 8, rowBytes, ColorSpace, kCGImageAlphaNoneSkipFirst) dim image as CGImageMBS = bitmap.CreateImage context.DrawPicture(image, CGMakeRectMBS(0, 0, g.Width, g.Height)) context.Flush End EventHandler
End Control
Control Canvas6 Inherits Canvas
ControlInstance Canvas6 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim context as CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef)) dim screen as NSScreenMBS = NSScreenMBS.mainScreen dim ScreenColorSpace as NSColorSpaceMBS = screen.colorSpace dim ColorSpace as CGColorSpaceMBS = CGColorSpaceMBS.CreateWithHandle(ScreenColorSpace.CGColorSpaceHandle) dim w as integer = g.Width * 2 dim h as integer = g.Height * 2 const kCGImageAlphaNone = 0 const kCGImageAlphaPremultipliedLast = 1 // For example, premultiplied RGBA const kCGImageAlphaPremultipliedFirst = 2 // For example, premultiplied ARGB const kCGImageAlphaLast = 3 // For example, non-premultiplied RGBA const kCGImageAlphaFirst = 4 // For example, non-premultiplied ARGB const kCGImageAlphaNoneSkipLast = 5 // Equivalent to kCGImageAlphaNone. const kCGImageAlphaNoneSkipFirst = 6 dim rowBytes as integer = w * 4 dim data as new MemoryBlock(rowBytes * h) for y as integer = 0 to 199 for x as integer = 0 to 199 data.UInt32Value( y * rowBytes + x * 4) = &h0000FF00 // red next next dim bitmap as CGBitmapContextMBS = CGBitmapContextMBS.Create(data, w, h, 8, rowBytes, ColorSpace, kCGImageAlphaNoneSkipFirst) dim image as CGImageMBS = bitmap.CreateImage context.DrawPicture(image, CGMakeRectMBS(0, 0, g.Width, g.Height)) context.Flush End EventHandler
End Control
EventHandler Sub Open() 'CheckScreen 'CheckPicture 'CheckWindows End EventHandler
Sub CheckPicture() // show colorspace of picture dim p as new Picture(100, 100) dim colorspace as CGColorSpaceMBS = p.CGColorSpaceMBS MsgBox colorspace.Name // generic RGB End Sub
Sub CheckScreen() // shows Display profile dim screen as NSScreenMBS = NSScreenMBS.mainScreen dim ScreenColorSpace as NSColorSpaceMBS = screen.colorSpace MsgBox ScreenColorSpace.localizedName // open same profile in LCMS for conversion dim screenICCProfile as Memoryblock = ScreenColorSpace.ICCProfileData dim LCMS2Profile as LCMS2ProfileMBS = LCMS2ProfileMBS.OpenProfileFromMemory(screenICCProfile) MsgBox LCMS2Profile.Name End Sub
Sub CheckWindows() // show colorspace of window, usually the screen one dim n as new NSWindowMBS(self) MsgBox n.colorSpace.localizedName End Sub
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

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins