Performance Tools for Software Developers - Application Notes - Intel® IPP JPEG2000 and JasPer in Ksquirrel

Accelerating JasPer JPEG2000 Decoding in KSquirrel with Intel® Integrated Performance Primitives (Intel® IPP)

Overview

This application note shows how to improve performance of JPEG2000 decoding and viewing of images in KSquirrel with help of Intel IPP in comparison with a native JasPer-based plug-in.

Intel IPP

Intel IPP is a software library which provides a broad range of functionality including general signal, image, speech, graphics, data compression, cryptography, text strings and audio processing, vector manipulation and matrix math, as well as more sophisticated primitives for construction of audio, video and speech codecs such as MP3 (MPEG-1 Audio, Layer 3), MPEG-4, H.264, H.263, JPEG, JPEG2000, GSM-AMR* and G.723, plus computer vision.

Intel IPP JPEG 2000 Codec

A JPEG 2000 codec, which is based on Intel IPP, is available for download in source code from Intel IPP home page. It supports all Intel architectures and Intel-based platforms on Linux, MacOS X* and Windows*. The codec provides optimization for various features of Intel® architectures including SIMD and multi-core. Multi-threading model of codec is implemented with help of OpenMP support in Intel® Compiler.

JasPer

The JasPer project is an open-source initiative to provide a free software-based reference implementation of the codec specified in the JPEG-2000 Part-1 standard (i.e., ISO/IEC 15444-1).

This software has been incorporated into numerous other software projects (commercial and non-commercial).

For more information, please see http://www.ece.uvic.ca/~mdadams/jasper/

KSquirrel

KSquirrel is a convenient image viewer for KDE with disk navigator, file tree, multiple directory view, thumbnails, extended thumbnails, dynamic format support, DCOP interface and KIPI plug-ins support. KSquirrel supports about 51 file formats including JPEG 2000. The implementation of JPEG 2000 decoder is embedded into KSquirrel as a plug-in, which is based on open source JasPer JPEG 2000 codec.

KSquirrel was chosen for this case study because of the simple plug-in architecture and the easy way of plug-ins development and integration.

Version Information

This application note was created to help users of JasPer 1.900.1 to make use of the latest versions of Intel IPP JPEG2000 sample. In details, we used

  • Intel® Integrated Performance Primitives (Intel® IPP) 5.2 for Linux: l_ipp_ia32_b_5.2. 011
  • Intel® IPP 5.2 For LinuxJPEG sample code: l_ipp-sample-jpeg_b_5.2.xxx
  • JasPer: jasper-1.900.1.zip
  • Ksquirrel: ksquirrel-libs-0.7.0try2.tar.bz2 and ksquirrel-0.7.0.tar.tar
  • Intel® C++ Compiler 10.0 for 32 applications: l_cc_p_10.0.023.tar

Hardware: This note has been tested on Intel® Core® Duo T2400 1.83G Processors, 1G Memory.

Software: This note applies to the following environment:

  • RedHat Linux AS EL 4
  • GNU C 3.4.6

Prerequisites: KSquirrel requires the following libraries installed:

Downloading KSquirrel, JasPer, Intel®IPP JPEG Source Code

  • The latest version of Intel® IPP can be get from Intel® IPP Home Page /en-us/articles/intel-ipp/
  • The JPEG2000 images used in this application note are publicly available from the following URL http://premier.intel.com/ under "Intel® IPP Sample" product

Source Code Modification

Intel IPP software library's JPEG 2000 functions provide highly-optimized image processing functions that perform the key arithmetic encoding and decoding operations.

The Intel IPP JPEG 2000 sample demonstrates how to use Intel IPP functions in JPEG 2000 encoder/decoder development. Currently it provides a good coding performance and a lot of JPEG 2000 features support, especially in decoding.

In this application notes, we want to incorporate the IPP JPEG2000 codec implementation into KSquirrel as a substitution of JasPer JPEG2000. For such purpose, we need to do some source code modifications in the file “fmt_codec_jpeg2000.cpp” which is provided in KSquirrel package

There are mainly three functions which we need to rewrite. They are

#include "j2kit.h"
…….
s32 fmt_codec::read_init(const std::s tring &file)
{
char *ptr[3]; ……;
} s32 fmt_codec::read_next()
{
currentImage++; ……;
} s32 fmt_codec::read_scanline(RGBA *scan)
{
s32 *dptr[3]; ……;
};

For detailed code modification, please see the modified fmt_codec_jpeg2000.cpp

We also add a header file: fmt_codec_jpeg2000.ipp.h

#ifndef KSQUIRREL_LIBS_CLASS_DEFINITION_jpeg2000_IPP_H
#define KSQUIRREL_LIBS_CLASS_DEFINITION_jpeg2000_IPP_H #include "ksquirrel-libs/fmt_codec_base.h" class fmt_codec : public fmt_codec_base
{
public:
BASE_CODEC_DECLARATIONS private:
bool convert_colorspace();
};
#endif
Building KSquirrel Jasper & Intel IPP JPEG2000
  1. Build and Install the jasper-1.900.1

  1. Configuration jasper-1.900.1 sources

    # unzip jasper-1.900.1.zip
    # cd jasper-1.900.1/
    # ./configure CFLAGS=-fPIC
    # make
    # su –c “make install”
  2. Several executable programs are produced in../jasper-1.900.1/src/appl, including “jasper”, “imageinfo”, “imagcmp” etc.

    The “jasper” is a transcoder. It can convert image data from bmp to jp2. For example, you can convert our test images to jp2 format with the below command:
    #jasper –f image1_160.bmp –F image1_160.jp2 –T jp2

  • Build and Install the ksquirrel-libs

  • # tar jxfv ksquirrel-libs-0.7.0.tar.bz2
    # cd ksquirrel-libs-0.7.0/
    # Edit Configuration file: configure

    Change line 26601: LIBS=”-ljapser $LIBS” into

    IBS=”-ljasper –ljpeg –lm $ LIBS”
    # ./configure.gnu –-enable-devel
    # make
    # su -c 'make install'
  • Build and Install install KSquirrel:

  • # tar jxfv ksquirrel-0.7.0-try2.tar.tar
    # cd ksquirrel-0.7.0/
    # ./configure.gnu –-enable-devel
    # make
    # su -c “make install'

    By now, we can run # ksquirrel to show jp2 format image, which is based on JasPer jpeg2000 codec.
    For using IPP based JPEG2000 codec to replace JasPer codec, we need to do:
  1. Build IPP JPEG2000 sample code.
  1. Set up your building environment for Intel® IPP

    # source /opt/intel/ipp/5.2_beta /ia32/tools/env/ippvars32.sh
  2. Run building script (build32.bat for 32 bit application, buildem64.bat for Intel 64 bit application)

    # tar –zxvf l_ipp-sample-jpeg_b_5.2.006.tgz
    # cd ipp_sample/jpeg/jpeg2000
    # edit Makefile

    Change line 142 into CFLAGS=-c –Wall –O2 –fPIC

    #./buildxx.bat

    Or to use intel C++ compiler 10.0.0xx to enable the threading feature of IPP JPEG2000 sample the commands are

    #source /opt/intel/cc/10.0.038/bin/iccvars.sh
    #make ARCH=linux32 CC=icpc LINKAGE=dynamic MULTITHREADING=omp TIMING=1
  3. One executable program is produced in bin/linux32/j2kit. It can encoder and decoder image into jp2 and bmp format. You can try to run it with the command:

    #j2kit –i *.bmp –o *.jp2

  • Modify ksquirrel-libs to make use of IPP based JPEG2000 library .
  1. go to _obj/linux32 directory of jpeg2000 example, delete syswin.o file and prepare decoder library as ar cr libjpeg2000.a *.o, ranlib libjpeg2000.a

    # cd ipp_sample/jpeg/jpeg2000/_obj/linux32/
    # rm –f syswin.o
    # ar cr libjpeg2000.a *.o
    #ranlib libjpeg2000.a
  2. Create kls_jpeg2000_ipp directory in kernel directory of ksquirrel-libs directory. Copy contents of kls_jpeg2000 directory to it.

    # cd
    # cd ksquirrel-libs-0.7.0/kernel
    # mkdir kls_jpeg2000_ipp
    # cp –Rf kls_jpep2000/. kls_jpeg2000_ipp/.
  3. Create lib and src directories in kls_jpeg2000_ipp directory and copy the content of _obj/linux32 and src directories of jpeg2000 example to them respectively.

    # mkdir kls_jpeg2000_ipp/src
    # mkdir kls_jpeg2000_ipp/lib
    # cp -Rf ../../ipp_sample/jpeg/jpeg2000/src/. kls_jpeg2000_ipp/src/.
    # cp ../../ipp_sample/jpeg/jpeg2000/_obj/linux32/* kls_jpeg2000_ipp/lib/.
  4. Edit the Makefile in kls_jpeg2000_ipp directory.

    # cd kls_jpeg2000_ipp
    # vi Makefile

    Change line 41: subdir = kernel/kls_jpeg2000 into subdir = kernel/kls_jpeg2000_ip
    Change line 318 libkls_jpeg2000_la_LIBADD = ${SQ_LOCAL_RPATH} –ljasper into
    libkls_jpeg2000_la_LIBADD = -L./lib -ljpeg2000 $(IPPLIBPATH) $(IPPLIB) ${SQ_LOCAL_RPATH}

    Change line 122 –fno-exceptions into –f exceptions
    Replace the line 314 INCLUDES = -I../include with the following modifications:

    #
    #
    # Directory names for include files
    #
    IncDirs = ./src/application/system/core ./src/application/system/gui
    ./src/application ./src/common/container ./src/common/geometry
    ./src/common/image ./src/common/ippwrapper ./src/common/stream
    ./src/common/string ./src/common ./src/dib/common ./src/dib/file
    ./src/dib/imagedata ./src/dib/info ./src/dib/meta ./src/jp2/box
    ./src/jp2/codestream/common ./src/jp2/codestream/ebcot
    ./src/jp2/codestream/mainheader ./src/jp2/codestream/marker
    ./src/jp2/codestream/packetheader ./src/jp2/codestream/quant
    ./src/jp2/codestream/tile ./src/jp2/codestream/wavelet
    ./src/jp2/codestream ./src/jp2/file ./src/jp2/meta ./src/metaformat/rasterimage
    ./src/pnm/common ./src/pnm/file ./src/pnm/imagedata
    ./src/pnm/info ./src/pnm/meta

    # for em64 POSTFIX = em64t
    POSTFIX =
    INCLUDES = -DLINUX32 -DSYSLIN -I.. -I../include -I$(IPPROOT)/include
    INCLUDES += $(addprefix -I, $(IncDirs))
    IPPLIBPATH = -L$(IPPROOT)/lib
    IPPLIB = -lippjemerged$(POSTFIX) -lippjmerged$(POSTFIX) -lippiemerged$(POSTFIX) lippimerged$(POSTFIX) -lippsemerged$(POSTFIX) -lippsmerged$(POSTFIX) -lippcore$(POSTFIX)
  5. Copy modified fmt_codec_jpeg2000.cpp to. and fmt_codec_jpeg2000.ipp.h to../include and make:

    # cp yourtempfolder/fmt_codec_jpeg2000.cpp .
    # cp yourtempfolder/fmt_codec_jpeg2000.ipp.h ../include/.
    # make
  6. Copy .libs/libkls_jpeg2000.so.0.7.0 to ksquirrel libs directory – replace existing based on jasper:

    # cp .libs/libkls_jpeg2000.so.0.7.0 /usr/lib/ ksquirrel-libs/libkls_jpeg2000.so.0.7.0

  • Step 6 Start ksquirrel to see if the jpeg2000 library work correctly.

  • * We can also use intel C++ compiler 10.0.0xx to build the libkls_jpeg2000.so.0.7.0, thus enable the threading feature. But because of complexity of native plug-in Makefile, we provide a bash file build_plugin.sh for build the plug-in. If you are interesting in building it with Intel compiler, please contact us

Running KSquirrel with IPP-based JPEG2000 decoding

By default, Ksquirrel application is installed at /usr/bin/. Use “/usr/bin/Ksquirrel” command to run the application.

# source /opt/intel/ipp/5.2/ia32/tools/env/ippvars32.sh
# source /opt/intel/cc/10.0.023/bin/iccvar.sh (if icc build)
# /usr/bin/ksquirrel

It starts a ksqirrel GUI interface, explore your directory and click the .jp2 image.
When displaying JPEG image in KSquirrel, the bottom of image windows will shows the time to load the image.


Appendix A - Performance Comparison

Performance Enhancement
Intel IPP JPEG functions are highly optimized for new Intel® Core™ arichtechure. The table below shows that, for Intel Core Duo systems, Intel IPP based JPEG2000 library performs is about 10x faster than JasPer JPEG2000 library. For large size image, the gain is even up to 200x

Image

Size

Jasper decoding (ms)

IPP JPEG2000 Time(ms)

Jasper/ IPP-JPEG2000

Image1_160.jpg

160x120

620

64

9.7x

image1_320.jpg

320x240

1,993

92

21.7x

image1_640.jpg

640x480

5,465

222

24.6x

image1_800.jpg

800x600

7,683

583

13.2x

image1_1k.jpg

1024x768

11,377

523

21.8x

image1_4k.jpg

4096x4096

212,890

762

279.4x

(Tests run on Intel® Core Duo T2400 1.83G, 1G Memory, RedHat Enterprise Linux* AS Release 4 (Nahant Update 4), 2.6.9-42, Intel IPP 5.2 beta)

The test bmp &JPEG2000 files are sample images with Intel IPP JPEG samples, which can be downloaded from Intel® premier support website under "Intel® IPP Sample" product )

Multithreading Benefit

The high-level codec sources itself of Intel IPP JPEG200 sample are implemented as multi-threading by OpenMP directives, so we can also benefit from new Intel Multi-Core processors.

For enabling the multithreading, we need build the IPP JPEG2000 sample and the jpeg2000 plug-in libkls_jpeg2000.so.0.7.0 with Intel compiler. Then run the application with the commands,

# source /opt/intel/ipp/5.2/ia32/tools/env/ippvars32.sh
# source /opt/intel/cc/10.0.023/bin/iccvar.sh (if icc build)
# export OMP_NUM_THREADS= number of logical (default setting is 2)
# /usr/bin/ksquirrel

Here is our test result. To enable multithreads brings about 30%-100% speed-up.

Image

Size

IPP JPEG2000 Time(ms)

Multi-threading IPP JPEG2000 Time(ms)

S / M-IPP-JPEG2000

Image1_160.jpg

160x120

64

35

1.8x

image1_320.jpg

320x240

92

78

1.17x

image1_640.jpg

640x480

222

159

1.4x

image1_800.jpg

800x600

583

296

1.97x

image1_1k.jpg

1024x768

523

260

2.01x

image1_4k.jpg

4096x4096

762

598

1.27x

(Tests run on Intel Core Duo T2400 1.83G, 1G Memory, RedHat Enterprise Linux* AS Release 4 (Nahant Update 4), 2.6.9-42, Intel IPP 5.2 beta, Intel ICC 10)

Appendix B - Verifying Correctness

Both the JasPer codec plugin and Intel IPP JPEG2000 codec plugin will decode jp2 format image and show the image. To run Ksquirrel application and view some JPEG image files, the images should be displayed correctly.

* For ICC build version, please check if libkls_jpeg2000.so.0.7.0 depends on Intel Compiler threading library.

# ldd /usr/lib/ksquirrel-lib/ksquirrel-libs/libkls_jpeg2000.so.0.7.0
libksquirrel-libs.so.0 => /usr/lib/libksquirrel-libs.so.0 (0x0084a000)
libguide.so => /opt/intel/cc/10.0.023/lib/libguide.so (0x00bb3000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00727000)
libimf.so => /opt/intel/cc/10.0.023/lib/libimf.so (0x00d84000)
libm.so.6 => /lib/tls/libm.so.6 (0x00917000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0018b000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00823000)
libcxaguard.so.5 => /opt/intel/cc/10.0.023/lib/libcxaguard.so.5 (0x00111000)
libintlc.so.5 => /opt/intel/cc/10.0.023/lib/libintlc.so.5 (0x00113000)
libc.so.6 => /lib/tls/libc.so.6 (0x00256000)
libdl.so.2 => /lib/libdl.so.2 (0x00156000)
/lib/ld-linux.so.2 (0x00174000)

If it shows libguide.so => not found, please enter the command,

# export LD_LIBRARY_PATH=your_path_to_libguide.so_file:$LD_LIBRARY_PATH.
Or
# source /opt/intel/cc/10.0.023/bin/iccvar.sh

Then try again.

Appendix C - Known Issues and Limitations

There is no known issue reported at this release.

Appendix D - References

Intel® Integrated performance Primitives website

Intel Integrated Performance Primitives User Forum

Ksquirrel Application website



This link will take you off of the Intel Web site. Intel does not control the content of the destination Web Site.

Operating System:

Red Hat* Linux, Red Hat* Enterprise Linux 4.0, Red Hat* Enterprise Linux 3.0


Optimization Notice in English

Per informazioni più dettagliate sulle ottimizzazioni basate su compilatore, vedere il nostro Avviso sull'ottimizzazione.