A pure Java 8 implementation of Quite OK Image Format.
This library has no runtime dependencies, including Java AWT. ImageIO/BufferedImage support is provided using separate module qoi-java-awt.
On average, when using qoi-java-awt as an ImageIO plugin, QOI can encode 7 times faster than PNG with default settings and decode 2 times faster, while having 15% less size than PNG.
To get maximum performance, you can skip ImageIO and use pixel data arrays directly.
See full results in BENCHMARK.md.
Before choosing or rejecting QOI for your project, it is recommended to run benchmarks yourself with appropriate sample files. Here is benchmark code used to produce above results.
This library is available in Maven Central.
<dependency>
<groupId>me.saharnooby</groupId>
<artifactId>qoi-java</artifactId>
<version>1.2.1</version>
</dependency>
<!-- Also add this, if you want to use QOI with ImageIO -->
<dependency>
<groupId>me.saharnooby</groupId>
<artifactId>qoi-java-awt</artifactId>
<version>1.2.1</version>
</dependency>dependencies {
implementation 'me.saharnooby:qoi-java:1.2.1'// Also add this, if you want to use QOI with ImageIO
implementation 'me.saharnooby:qoi-java-awt:1.2.1'
}You can download prebuilt JARs from GitHub releases or build them yourself.
Use methods in class me.saharnooby.qoi.QOIUtil:
// Read image from a fileQOIImageimage = QOIUtil.readFile(newFile("image.qoi"));
System.out.println("Image size: " + image.getWidth() + " x " + image.getHeight());
// Access pixel dataSystem.out.println("Red channel is " + image.getPixelData()[0]);
// Create new 1x1 RGBA image from raw pixel databyte[] pixelData = {(byte) 255, 127, 0, (byte) 255};
QOIImageorangeImage = QOIUtil.createFromPixelData(pixelData, 1, 1, 4);
// Write image to a fileQOIUtil.writeImage(orangeImage, newFile("orange.qoi"));To use QOI with ImageIO, you need to also add qoi-java-awt dependency. It provides an ImageIO plugin, which installs automatically using service provider mechanism.
To read and write QOI images, use standard ImageIO methods:
// Read QOI image from a fileBufferedImageimage = ImageIO.read(newFile("image.qoi"));
Objects.requireNonNull(image, "Invalid QOI image");
// Write QOI image into a fileif (!ImageIO.write(image, "QOI", newFile("copy.qoi"))) {
thrownewIllegalStateException("Image type is not supported");
}To convert QOI images into BufferedImages and back, use methods in class me.saharnooby.qoi.QOIUtilAWT:
// Convert PNG to QOIBufferedImageimage = ImageIO.read(newFile("image.png"));
QOIImageqoi = QOIUtilAWT.createFromBufferedImage(image);
QOIUtil.writeImage(qoi, newFile("image.qoi"));
// Convert QOI to PNGQOIImagesecondImage = QOIUtil.readFile(newFile("second-image.qoi"));
BufferedImageconvertedImage = QOIUtilAWT.convertToBufferedImage(secondImage);
ImageIO.write(convertedImage, "PNG", newFile("second-image.png"));You will need Git, Maven and JDK 8 or higher.
git clone https://github.com/saharNooby/qoi-java.git
cd qoi-java
mvn clean installNo AWT classes are used, so it should be compatible with Android. Please report compatibility issues, if they arise.
This project uses semantic versioning.