Platforms to show: All Mac Windows Linux Cross-Platform

/Images/JPEG/JPEG 2000 Test


Required plugins for this example: MBS Images Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/JPEG/JPEG 2000 Test

This example is the version from Tue, 26th Oct 2015.

Project "JPEG 2000 Test.xojo_binary_project"
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
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
EventHandler Sub Open() dim p as Picture = LogoMBS(200) dim j80 as MemoryBlock = JPEG2000MBS.Encode(p, 80) dim j50 as MemoryBlock = JPEG2000MBS.Encode(p, 50) dim j20 as MemoryBlock = JPEG2000MBS.Encode(p, 20) dim j05 as MemoryBlock = JPEG2000MBS.Encode(p, 05) WriteFile "Normal", j80 dim p80 as Picture = JPEG2000MBS.Decode(j80) dim p50 as Picture = JPEG2000MBS.Decode(j50) dim p20 as Picture = JPEG2000MBS.Decode(j20) dim p05 as Picture = JPEG2000MBS.Decode(j05) canvas1.Backdrop = p80 canvas2.Backdrop = p50 canvas3.Backdrop = p20 canvas4.Backdrop = p05 dim m as Picture = p.Mask dim g as Graphics = m.Graphics g.ForeColor = &c000000 g.FillRect 0, 0, g.Width, g.Height g.ForeColor = &cFFFFFF g.FillOval 0, 0, g.Width, g.Height j80 = JPEG2000MBS.Encode(p, 80) j50 = JPEG2000MBS.Encode(p, 50) j20 = JPEG2000MBS.Encode(p, 20) j05 = JPEG2000MBS.Encode(p, 05) WriteFile "With Mask", j80 p80 = JPEG2000MBS.Decode(j80) p50 = JPEG2000MBS.Decode(j50) p20 = JPEG2000MBS.Decode(j20) p05 = JPEG2000MBS.Decode(j05) canvas5.Backdrop = p80 canvas6.Backdrop = p50 canvas7.Backdrop = p20 canvas8.Backdrop = p05 // now with PictureMBS dim pp as new PictureMBS(p) dim mm as new PictureMBS(p.Mask) // make a gray copy dim pg as new PictureMBS(p.Width, p.Height, pp.ImageFormatG) call pg.CopyPixels(pp, 0, 0, p.width, p.height, 0, 0) // make a RGB copy with alpha channel dim pa as new PictureMBS(p.Width, p.Height, pp.ImageFormatRGBA) call pa.CopyPixels(pp, 0, 0, p.width, p.height, 0, 0) // make RGB dim je as new JPEG2000MBS 'je.Options = "mode=real rate=100" if je.InitCompress(pp.Width, pp.Height, 3, pp.RowSize) then dim h as integer = pp.Height-1 for i as integer = 0 to h dim rowData as MemoryBlock = pp.RowInFormat(i, pp.ImageFormatRGB) if not je.SetRow(i, rowData) then Break exit end if next if je.Compress then dim ImageData as MemoryBlock = je.ImageData if ImageData <> nil then dim pic as Picture = JPEG2000MBS.Decode(ImageData) canvas9.Backdrop = pic end if end if end if // make RGBA if je.InitCompress(pa.Width, pa.Height, 4, pa.RowSize) then dim h as integer = pp.Height-1 dim gg as PictureMBS = mm.GreenChannel // copy rows from mask to picture, so we have something for alpha channel for i as integer = 0 to h dim maskRowData as MemoryBlock = gg.RowInFormat(i, pp.ImageFormatG) pa.AlphaChannel.RowInFormat(i, pp.ImageFormatG) = maskRowData next // encode rows for i as integer = 0 to h dim rowData as MemoryBlock = pa.RowInFormat(i, pp.ImageFormatRGBA) if not je.SetRow(i, rowData) then Break exit end if next // and compress if je.Compress then dim ImageData as MemoryBlock = je.ImageData if ImageData <> nil then WriteFile "ImageData", ImageData dim pic as Picture = JPEG2000MBS.Decode(ImageData) canvas10.Backdrop = pic end if end if end if // make Gray if je.InitCompress(pg.Width, pg.Height, 1, pp.RowSize) then dim h as integer = pg.Height-1 for i as integer = 0 to h dim rowData as MemoryBlock = pg.RowInFormat(i, pp.ImageFormatG) // green only if not je.SetRow(i, rowData) then Break exit end if next if je.Compress then dim ImageData as MemoryBlock = je.ImageData if ImageData <> nil then canvas11.Backdrop = JPEG2000MBS.Decode(ImageData) end if end if end if // decompress to PictureMBS dim jd as new JPEG2000MBS if jd.InitDecompress(j80) then dim pi as new PictureMBS(jd.Width, jd.Height, PictureMBS.ImageFormatRGBA) dim h as integer = pi.Height-1 dim r as MemoryBlock for i as integer = 0 to h // get row. Recycle MemoryBlock, so we don't create new one each row. r = jd.getRow(i, r) pi.RowInFormat(i, pi.ImageFormatRGBA) = r next // invert alpha pi.AlphaChannel.Invert // get picture canvas12.Backdrop = pi.CopyPictureWithMask end if 'dim f as FolderItem = SpecialFolder.Desktop.Child("test.jp2") 'dim b as BinaryStream = BinaryStream.Open(f) 'dim s as string = b.Read(b.Length) 'canvas8.Backdrop = JPEG2000ToPictureMBS(s) End EventHandler
Sub WriteFile(name as string, data as string) name = "Image "+name+".jp2" dim f as FolderItem = SpecialFolder.Desktop.Child(name) dim b as BinaryStream = BinaryStream.Create(f, true) b.Write data 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

See also:

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


The biggest plugin in space...