Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 480

Previous Page 479   Index   Next Page 481

Function Reference
Page 480 of 750
JPEG2000 Encode (Experimental)
JPEG2000 is a compression method that supports loss-less and lossy compression. It produces very
good compression rates for color and gray scale images, and it can be used with all color depths and
supported color spaces.
The loss-less variant is used if the JPEG quality is set to 0 or 1000 (see below). However, the
compression ratio of loss-less JPEG2000 compression is not very high and Flate compression
produces mostly much better compression ratios and it is up to 30 times faster.
The lossy variant of JPEG2000 compression supports two different compression methods: Real-Mode
and Integer-Mode, which produces slightly different output at high compression rates. The resulting
image looks slightly smoother if Real-Mode is used. The compression method can be adjusted with
SetCompressionLevel(). The Real-Mode is used if the compression level is set to clMax, otherwise the
Integer-Mode is used. However, the compression level does not change the compression ratio in this
The compression ratio can be adjusted with SetJPEGQuality(). The name "JPEG Quality" refers
normally to the JPEG compression filter, however, the value has a completely different meaning
when using JPEG 2000 compression.
The property JPEG quality can be in the range from 0 to 1000, but it does not adjust the loss of
quality; it is used as a divisor of the raw uncompressed image data size to the whished compressed
image data size. This makes the usage very complicated and it is practically impossible to find a
suitable mathematically function that produces good results in most cases.
The value 1000 means that loss-less compression should be used. Lower values are used as follows:
compressed_image_size = uncompressed_raw_size * JPEGQuality / 1000
Lower values produces higher compression rates but worse image quality.
Another disadvantage of the filter is the bad compression speed. This is maybe a result of the bad
design of the used Jasper library, but it seems that JPEG 2000 compression is generally slow. Other
commercial JPEG 2000 libraries are about 2 times faster, but this is still incredible slow in comparison
to JPEG compression. In addition, the resulting image quality is practically identically with JPEG
compression if the same compression ratio was achieved.
JPEG 2000 images can contain an embedded ICC profile that can be used to create an ICC based
color space for the image (ICC based color spaces are device independent). To enable the usage of
embedded ICC profiles set the flag gfUseImageColorSpace with SetGStateFlags(). See also Color
Spaces and Images.
Why does DynaPDF not support LZW compression?
LZW is a very fast lossless compression filter that can be used for sampled images and arbitrary
binary data. Flate encoded output is usually more compact than LZW encoded output for the same
input, but Flate encoding is considerably slower than LZW. However, LZW encoding is marked as

Previous topic: Optimized Huffmann encoding

Next topic: 1 Bit TIFF images