Class Jpeg2000
A pure-Java JPEG 2000 decoder, for platforms whose image APIs cannot read the format (most of them) and for the backend, which has no image support of its own for it.
It reads either a JP2 file (the jp2h header boxes and the jp2c codestream) or a raw
J2K codestream, and decodes every tile into one integer plane per component. The
decoder covers what PDF producers emit: all five progression orders, multiple tiles and
tile-parts, subsampled components, default and custom precincts, every code-block style
switch, the 5/3 and 9/7 wavelets, scalar quantization, the RCT and ICT component
transforms and bit depths from 1 to 16. Region of interest shifts and progression order
changes (POC) are ignored, and High Throughput code-blocks are refused.
Malformed or truncated data never escapes as an exception: decode answers null, or
the image as far as it could be decoded. Images above 25 megapixels are refused.
byte[] data = new byte[0]; // the contents of a .jp2 or .j2k file
Jpeg2000 j = Jpeg2000.decode(data);
if (j != null) {
int[] argb = j.toArgb();
// on the client: Image.createImage(argb, j.getWidth(), j.getHeight())
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConverts colour components the file does not describe itself, as when a PDF gives the image's colour space in its own dictionary. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Jpeg2000decode(byte[] data) Parses a JP2 file or a raw J2K codestream; null when it cannot be decoded.intThe image height in pixels.intgetWidth()The image width in pixels.int[]toArgb()ARGB pixels, row by row,getWidth() * getHeight()of them; null when the image's components cannot be turned into a colour.int[]toArgb(Jpeg2000.Colors colors, boolean alpha) ARGB pixels astoArgb(), with the colours ofcolorsinstead of the file's own.
-
Constructor Details
-
Jpeg2000
public Jpeg2000()
-
-
Method Details
-
getWidth
public int getWidth()The image width in pixels. -
getHeight
public int getHeight()The image height in pixels. -
toArgb
public int[] toArgb()ARGB pixels, row by row,getWidth() * getHeight()of them; null when the image's components cannot be turned into a colour. A JP2 palette is applied, YCC and CMYK are converted, and an alpha channel named by acdefbox, or a component past the colour ones, becomes the alpha. -
toArgb
ARGB pixels astoArgb(), with the colours ofcolorsinstead of the file's own. Withalphafalse any alpha channel is ignored and the image is opaque. -
decode
Parses a JP2 file or a raw J2K codestream; null when it cannot be decoded.
-