Platforms to show: All Mac Windows Linux Cross-Platform

/Images/LCMS2/CMYK/RGB to CMYK and back


Required plugins for this example: MBS Images Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/LCMS2/CMYK/RGB to CMYK and back

This example is the version from Sun, 10th Dec 2016.

Project "RGB to CMYK and back.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
End Control
Control Canvas5 Inherits Canvas
ControlInstance Canvas5 Inherits Canvas
End Control
Control Canvas6 Inherits Canvas
ControlInstance Canvas6 Inherits Canvas
End Control
Control Canvas7 Inherits Canvas
ControlInstance Canvas7 Inherits Canvas
End Control
Control Canvas8 Inherits Canvas
ControlInstance Canvas8 Inherits Canvas
End Control
Control Canvas9 Inherits Canvas
ControlInstance Canvas9 Inherits Canvas
End Control
Control Canvas10 Inherits Canvas
ControlInstance Canvas10 Inherits Canvas
End Control
Control Canvas11 Inherits Canvas
ControlInstance Canvas11 Inherits Canvas
End Control
Control Canvas12 Inherits Canvas
ControlInstance Canvas12 Inherits Canvas
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
EventHandler Sub Change() run me.ListIndex End EventHandler
End Control
EventHandler Sub Open() run PopupMenu1.ListIndex End EventHandler
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
Function NewColorPicture(c as Color) As Picture dim p as Picture = new Picture(100,100,32) p.Graphics.ForeColor=c p.Graphics.FillRect 0,0,100,100 Return p End Function
Sub run(intent as integer) test canvas1, canvas2, &cFF0000, StaticText1, intent test canvas3, canvas4, &c00FF00, StaticText2, intent test canvas5, canvas6, &c0000FF, StaticText3, intent test canvas7, canvas8, &cFFFFFF, StaticText4, intent test canvas9, canvas10, &c000000, StaticText6, intent test canvas11, canvas12, &c777777, StaticText5, intent End Sub
Sub test(canvas1 as canvas, canvas2 as canvas, c as color, info as Label, intent as integer) dim ct as LCMS2TransformMBS dim mi,mo as MemoryBlock dim pi as LCMS2ProfileMBS dim po as LCMS2ProfileMBS dim f as FolderItem // you find this profiles on Mac OS X in /System/Library/ColorSync/Profiles f = FindFile("Generic RGB Profile.icc") pi = LCMS2ProfileMBS.OpenProfileFromFile(F) if pi = nil then MsgBox "Failed to find the profile."+EndOfLine+EndOfLine+f.Name end if f = FindFile("Generic CMYK Profile.icc") po = LCMS2ProfileMBS.OpenProfileFromFile(F) if po = nil then MsgBox "Failed to find the profile."+EndOfLine+EndOfLine+f.Name end if // get data format for 8 bit integers dim pif as integer = pi.FormatterForColorspace(1, false) dim pof as integer = po.FormatterForColorspace(1, false) dim flags as integer = LCMS2MBS.kcmsFLAGS_BLACKPOINTCOMPENSATION ct = LCMS2TransformMBS.CreateTransform(pi, pif, po, pof, intent, flags) canvas1.Backdrop = NewColorPicture(c) ' ... fill c mi=NewMemoryBlock(3) // RGB mo=NewMemoryBlock(4) // CMYK mi.UInt8Value(0)=c.red mi.UInt8Value(1)=c.green mi.UInt8Value(2)=c.blue if ct.Transform(mi,mo,1) then 'ok dim cc as integer = mo.UInt8Value(0) // C dim mm as integer = mo.UInt8Value(1) // M dim yy as integer = mo.UInt8Value(2) // Y dim kk as integer = mo.UInt8Value(3) // K // convert back ct = LCMS2TransformMBS.CreateTransform(po, pof, pi, pif, intent) if ct.Transform(mo,mi,1) then dim rr as integer = mi.UInt8Value(0) // R dim gg as integer = mi.UInt8Value(1) // G dim bb as integer = mi.UInt8Value(2) // B info.text = str(c.red)+" "+str(c.Green)+" "+str(c.Blue)+EndOfLine+_ str(cc)+" "+str(mm)+" "+str(yy)+" "+str(kk)+EndOfLine+_ str(rr)+" "+str(gg)+" "+str(bb)+EndOfLine canvas2.Backdrop = NewColorPicture(rgb(rr,gg,bb)) end if end if End Sub
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 Images Plugin.


The biggest plugin in space...