Mercurial > hg > digilib-old
changeset 834:c07c21ac78f9 stream
color invert operation. doesn't work with all image types yet...
author | robcast |
---|---|
date | Tue, 01 Mar 2011 15:17:51 +0100 |
parents | 8ee72433bb8f |
children | abd5513ef7b2 |
files | servlet/src/digilib/image/DocuImage.java servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 3 files changed, 31 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImage.java Tue Mar 01 10:14:29 2011 +0100 +++ b/servlet/src/digilib/image/DocuImage.java Tue Mar 01 15:17:51 2011 +0100 @@ -207,7 +207,7 @@ * * */ - public enum ColorOp {GRAYSCALE}; + public enum ColorOp {GRAYSCALE, INVERT}; /** Changes the colors of the current image. *
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Tue Mar 01 10:14:29 2011 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Tue Mar 01 15:17:51 2011 +0100 @@ -27,9 +27,12 @@ import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; +import java.awt.image.ByteLookupTable; import java.awt.image.ColorConvertOp; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; +import java.awt.image.LookupOp; +import java.awt.image.LookupTable; import java.awt.image.RescaleOp; import java.io.IOException; import java.io.OutputStream; @@ -62,6 +65,7 @@ /** interpolation type */ protected RenderingHints renderHint; + /** convolution kernels for blur() */ protected static Kernel[] convolutionKernels = { null, new Kernel(1, 1, new float[] {1f}), @@ -69,6 +73,23 @@ new Kernel(3, 3, new float[] {1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f}) }; + /** lookup table for inverting images (byte) */ + protected static LookupTable invertByteTable; + + static { + byte[] invertByte = new byte[256]; + byte[] orderedByte = new byte[256]; + for (int i = 0; i < 256; ++i) { + invertByte[i] = (byte) (256 - i); + orderedByte[i] = (byte) i; + } + // works for JPEG in q2 + invertByteTable = new ByteLookupTable(0, new byte[][] { + invertByte, invertByte, orderedByte, invertByte}); + // should work... + /* invertByteTable = new ByteLookupTable(0, invertByte); */ + } + /** the size of the current image */ protected ImageSize imageSize; @@ -482,10 +503,18 @@ public void colorOp(ColorOp op) throws ImageOpException { if (op == ColorOp.GRAYSCALE) { // convert image to grayscale + logger.debug("Color op: grayscaling"); ColorConvertOp colop = new ColorConvertOp( ColorSpace.getInstance(ColorSpace.CS_GRAY), null); img = colop.filter(img, null); + } else if (op == ColorOp.INVERT) { + // invert colors i.e. invert every channel + logger.debug("Color op: inverting"); + // TODO: is this enough for all image types? + LookupOp colop = new LookupOp(invertByteTable, renderHint); + img = colop.filter(img, null); } + } public void rotate(double angle) throws ImageOpException {
--- a/servlet/src/digilib/servlet/Scaler.java Tue Mar 01 10:14:29 2011 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Tue Mar 01 15:17:51 2011 +0100 @@ -31,7 +31,7 @@ private static final long serialVersionUID = 5289386646192471549L; /** digilib servlet version (for all components) */ - public static final String version = "1.9.1a13"; + public static final String version = "1.9.1a14"; /** servlet error codes */ public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};