Java JPEG2000 Writer
The JDeli Java image library includes a JPEG2000 Writer to write JPEG2000 files in Java. The JPEG2000 Encoder is written in 100% Java and provides JPEG2000 support with no dependencies.
Key information:
- 100% Java solution. No dlls or dependencies on native code
- Fast and easy to use
- Lossless and lossy supported
- JP2 or JPX output format
- Supports image compression settings
Quick start or to replace in existing code using ImageIO:
JDeli.write(myBufferedImage, "jpx", outputStreamOrFile);
or
byte[] outputData = JDeli.write(myBufferedImage, "jpx");
New method for quick and simple usage
JDeli.write(myBufferedImage, OutputFormat.JPEG2000, outputStreamOrFile)
OutputFormat allows setting of any supported Image Format
For complete control of output:
final Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions();
//set any options in options instance - examples below
options.setOutputSubtype(Jpeg2000OutputSubtype.JP2);
// or options.setOutputSubtype(Jpeg2000OutputSubtype.JPX);
options.setQuality(100);//0-100
//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);
Jpeg2000EncoderOptions allows setting of specific options.
Various image processing operations can be conducted on the image, detailed documentation can be found here.
Performance comparisons:
These figures were generated using jmh (as documented on our blog) with a standard set of images (also documented). They should be easy to replicate if you wish to validate, the code is on GitHub.
The higher the number, the better.
Mode: Throughput Count: 25 Units: ops/s
| Benchmark | Score | Error |
|---|---|---|
| ImageIOWithJAI | 2.306 | ± 0.007 |
| JDeli_JP2 | 6.226 | ± 0.023 |
| JDeli_JPX | 6.228 | ± 0.020 |
Number of files: 166
| Benchmark | Size | unreadable output | AVG SSIM score | AVG Similarity |
|---|---|---|---|---|
| ImageIOWithJAI | 1,419.60KB | 0 | 0.9659635878077559 | Very similar (high quality) |
| JDeli JP2 | 288.66KB | 0 | 0.8817187006016771 | Similar (noticeable but minor differences) |
| JDeli JPX | 277.31KB | 0 | 0.8817187006016771 | Similar (noticeable but minor differences) |
Tested on 2020 13inch M1 MacBook Pro using JDK 18.0.1.1