JPEG 2000 for Pascal

JPEG 2000 for Pascal is a free library for Object Pascal (Delphi and Free Pascal) developers that want to use JPEG 2000 images in their applications. It is based on OpenJpeg library written in C language (BSD license). C library is precompiled (using C++ Builder for Delphi and GCC for FPC) for several platforms and Pascal header is provided. Some higher level classes for easier manipulation with JPEG 2000 images are part of the JPEG 2000 for Pascal as well.

Library Contents

  • Cross-platform Pascal interface to OpenJpeg – low level access to precompiled library. Currently supported platforms: Windows 32bit, Linux 32/64bit, and Mac OS X.
  • VCL wrapper for Delphi (TBitmap descendant) enabling easy loading and saving of JPEG 2000 images.
  • Samples that demonstrate usage of all library interfaces and few test images in various data formats.


Delphi: Just add some of JPEG 2000 for Pascal units you want to use to your uses clause (must be in you search path) and precompiled library will be linked automatically.

Free Pascal: OpenJpeg is compiled into static libraries so you have to set library search path when compiling your project. Libraries are located in J2KObjects directory.


Current version of JPEG 2000 for Pascal library is: 1.00 (7th July 2009) .

  PasJpeg2000 v1.00
» 2.0 MiB - 4,343 hits - July 7, 2009
JPEG 2000 for Pascal library. Crossplatform JPEG 2000 image file format support for Delphi and FPC.

Source Repository

Hosted at BitBucket

Future Plans

  • Free Pascal fpimage and Lazarus LCL support
  • loading of CMYK and indexed images
  • saving images in YCC colorspace, irreversible DWT in lossy mode

Notes and Tips

If you want to recompile OpenJpeg yourself (custom modification, other compiler settings, etc.) you'll need source code from SVN repository at OpenJpeg's Google Code page. Note that Pascal header is based on SVN revision 507 with my CDEF patch applied (needed to store alpha channels correctly and for better compatibility of saved files with other software) but latest revision 543 works too. You can get the patch and some more info here: OpenJpeg group on Google (updated patch is in Files section of the group).

In this thread there’s also a mention about channel values being saved as 128. When library is compiled with GCC (depends on optimization settings) fourth and subsequent image channel is saved wrongly and all pixels have the value of 128 for this channel. So when recompiling make sure you test if this problem appears.

This "alpha saved as 128" error was finally fixed in recent OpenJpeg revision (it was caused by accessing C array[3] at index 3!).

Compiling in GCC: Just apply CDEF patch and use makefiles shipped with OpenJpeg.

Compiling in C++ Builder: Another patch is needed, you can find it here. Additionally, this define must be included in project options: WIN32 and optional OPJ_STATIC for using standard C calling convention (needed for object files usable by Delphi wrapper) and OPJ_EXPORTS if you want to build DLL.

14 thoughts on “JPEG 2000 for Pascal

  1. Pingback: JPEG2000 for pascal | Venus Debris' Blog

  2. Hi, guys, thank you for your work. I’m using JPEG 2000 for Pascal
    in my DICOM component, the first test shows that it works great.
    Thanks. Did you meet a Jpeg Lossless software for delphi translated?

  3. Pingback: JPEG 2000 for Object Pascal-Delphi and FreePascal « PDF Hacks

  4. A great effort, thank you very much.

    A question: I am using Delphi 7 and reading Jpeg 2000 files as OpenGL textures. I see right now the way to extract raw pixel data would be assign() to a tbitmap and then extract data from there using ScanLines. Unluckily since Alpha isn’t supported in D7 Tbitmaps this pretty much nullifies the whole idea of using Jpeg 2000 as the format of choice.

    So I wonder… is there some other way, perhaps, of extracting pixel data from TJpeg2000Bitmap in the form or R,G,B,A,R,G,B,A,R,G,B,A …. ? Thanks in advance,


    • I don’t have D7 to test it right now but you can create 32bit TBitmaps with it and alpha data should be accessible using ScanLine property (D7 just doesn’t support alpha blending when drawing the bitmap).

      I’ll be adding crossplatform JPEG 2000 reader/writer to PasJpeg2000 package witch easier access to decoded pixels than in TBitmap descendant.

      Meanwhile you could use Imaging library, PasJpeg2000 was originally part of it, and it also support creation of OpenGL textures (var Tex: GLuint := LoadGLTextureFromFile(‘tex.jp2’)).

Leave a Reply

Your email address will not be published. Required fields are marked *