Speedup for black/white image rendering

git-svn-id: https://zxing.googlecode.com/svn/trunk@2365 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-08-01 23:48:37 +00:00
parent 6ce63cc1a2
commit ba5dd02852
2 changed files with 8 additions and 1 deletions

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.j2se;
import java.awt.image.BufferedImage;
/**
* Encapsulates custom configuration used in methods of {@link MatrixToImageWriter}.
*/
@ -52,4 +54,9 @@ public final class MatrixToImageConfig {
return offColor;
}
int getBufferedImageColorModel() {
// Use faster BINARY if colors match default
return onColor == BLACK && offColor == WHITE ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_INT_RGB;
}
}

View file

@ -51,7 +51,7 @@ public final class MatrixToImageWriter {
public static BufferedImage toBufferedImage(BitMatrix matrix, MatrixToImageConfig config) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
BufferedImage image = new BufferedImage(width, height, config.getBufferedImageColorModel());
int onColor = config.getPixelOnColor();
int offColor = config.getPixelOffColor();
for (int x = 0; x < width; x++) {