Mercurial > hg > digilib-old
changeset 829:a630d0303cce stream
new servlet operation colop=grayscale.
author | robcast |
---|---|
date | Fri, 25 Feb 2011 11:34:49 +0100 |
parents | ba708c57e57c |
children | f4d3543b6a62 |
files | servlet/src/digilib/image/DocuImage.java servlet/src/digilib/image/DocuImageImpl.java servlet/src/digilib/image/ImageJobDescription.java servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/image/ImageWorker.java servlet/src/digilib/io/ImageInput.java servlet/src/digilib/io/ImageInputImpl.java servlet/src/digilib/servlet/AsyncServletWorker.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/Scaler.java |
diffstat | 10 files changed, 223 insertions(+), 164 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImage.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/image/DocuImage.java Fri Feb 25 11:34:49 2011 +0100 @@ -202,6 +202,22 @@ public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException; + + /** Operations for colorOps. + * + * + */ + public enum ColorOp {GRAYSCALE}; + + /** Changes the colors of the current image. + * + * Changes the colors of the current image. Operations are e.g. + * reduction to grayscale or false-color palettes. + * + * @throws ImageOpException + */ + public void colorOp(ColorOp op) throws ImageOpException; + /** * Returns the interpolation quality. * @return int
--- a/servlet/src/digilib/image/DocuImageImpl.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/image/DocuImageImpl.java Fri Feb 25 11:34:49 2011 +0100 @@ -145,6 +145,10 @@ // emtpy implementation } + public void colorOp(ColorOp op) throws ImageOpException { + // emtpy implementation + } + public void dispose() { // emtpy implementation } @@ -190,5 +194,6 @@ public abstract void writeImage(String mt, OutputStream ostream) throws ServletException, ImageOpException; + }
--- a/servlet/src/digilib/image/ImageJobDescription.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/image/ImageJobDescription.java Fri Feb 25 11:34:49 2011 +0100 @@ -6,6 +6,7 @@ import org.apache.log4j.Logger; +import digilib.image.DocuImage.ColorOp; import digilib.io.DocuDirCache; import digilib.io.DocuDirectory; import digilib.io.FileOpException; @@ -100,6 +101,8 @@ newParameter("ddpiy", new Float(0), null, 's'); // scale factor for mo=ascale newParameter("scale", new Float(1), null, 's'); + // color conversion operation + newParameter("colop", "", null, 's'); } @@ -427,6 +430,15 @@ return qual; } + public ColorOp getColOp() { + String op = getAsString("colop"); + try { + return ColorOp.valueOf(op.toUpperCase()); + } catch (Exception e) { + logger.error("Invalid color op: " + op); + } + return null; + } /** * Returns the area of the source image that will be transformed into the
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Fri Feb 25 11:34:49 2011 +0100 @@ -22,10 +22,12 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.RenderingHints; +import java.awt.color.ColorSpace; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; +import java.awt.image.ColorConvertOp; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import java.awt.image.RescaleOp; @@ -46,6 +48,7 @@ import javax.imageio.stream.ImageOutputStream; import javax.servlet.ServletException; +import digilib.image.DocuImage.ColorOp; import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageInput; @@ -420,8 +423,7 @@ */ int ncol = img.getColorModel().getNumColorComponents(); if ((ncol != 3) || (rgbm.length != 3) || (rgba.length != 3)) { - logger - .debug("ERROR(enhance): unknown number of color bands or coefficients (" + logger.debug("ERROR(enhance): unknown number of color bands or coefficients (" + ncol + ")"); return; } @@ -472,6 +474,21 @@ return fb; } + /* + * (non-Javadoc) + * + * @see + * digilib.image.DocuImageImpl#colorOp(digilib.image.DocuImage.ColorOps) + */ + public void colorOp(ColorOp op) throws ImageOpException { + if (op == ColorOp.GRAYSCALE) { + // convert image to grayscale + ColorConvertOp colop = new ColorConvertOp( + ColorSpace.getInstance(ColorSpace.CS_GRAY), null); + img = colop.filter(img, null); + } + } + public void rotate(double angle) throws ImageOpException { // setup rotation double rangle = Math.toRadians(angle);
--- a/servlet/src/digilib/image/ImageWorker.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/image/ImageWorker.java Fri Feb 25 11:34:49 2011 +0100 @@ -19,7 +19,6 @@ */ public class ImageWorker implements Callable<DocuImage> { - protected static Logger logger = Logger.getLogger(ImageWorker.class); private DigilibConfiguration dlConfig; private ImageJobDescription jobinfo; @@ -139,6 +138,12 @@ docuImage.enhance(mult, paramBRGT); } + // color operation + DocuImage.ColorOp colop = jobinfo.getColOp(); + if (colop != null) { + docuImage.colorOp(colop); + } + logger.debug("rendered in " + (System.currentTimeMillis() - startTime) + "ms"); return docuImage;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/io/ImageInput.java Fri Feb 25 11:34:49 2011 +0100 @@ -0,0 +1,159 @@ +/* ImageInput-- digilib image input interface. + + Digital Image Library servlet components + + Copyright (C) 2010 Robert Casties (robcast@mail.berlios.de) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + Please read license.txt for the full details. A copy of the GPL + may be found at http://www.gnu.org/copyleft/lgpl.html + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + * Created on 20.12.2010 + */ + +package digilib.io; + +import java.io.File; +import java.io.InputStream; + +import javax.imageio.stream.ImageInputStream; + +import digilib.util.ImageSize; + +public abstract class ImageInput { + + // mime file type + protected String mimetype = null; + // image size in pixels + protected ImageSize pixelSize = null; + protected ImageSet parent = null; + + /** + * @return ImageSize + */ + public ImageSize getSize() { + return pixelSize; + } + + /** + * Sets the imageSize. + * @param imageSize The imageSize to set + */ + public void setSize(ImageSize imageSize) { + this.pixelSize = imageSize; + } + + /** returns if mimetype has been set. + * + * @return String + */ + public boolean hasMimetype() { + return (mimetype != null); + } + + /** + * @return String + */ + public String getMimetype() { + return mimetype; + } + + /** + * Sets the mimetype. + * @param mimetype The mimetype to set + */ + public void setMimetype(String filetype) { + this.mimetype = filetype; + } + + /** returns if this image has been checked + * (i.e. has size and mimetype) + * TODO: deprecated + * @return boolean + */ + public boolean isChecked() { + return (pixelSize != null); + } + + /** Returns the aspect ratio of the image (width/height). + * + * @return + */ + public float getAspect() { + return (pixelSize != null) ? pixelSize.getAspect() : 0f; + } + + /** + * @return ImageSet + */ + public ImageSet getParent() { + return parent; + } + + /** + * Sets the parent. + * @param parent The parent to set + */ + public void setParent(ImageSet parent) { + this.parent = parent; + } + + /** Returns if the input can be returned as ImageInputStream. + * + * @return + */ + public boolean hasImageInputStream() { + return false; + } + + /** Returns the input as ImageInputStream (if available) + * + * @return + */ + public ImageInputStream getImageInputStream() { + return null; + } + + /** Returns if the input can be returned as InputStream. + * + * @return + */ + public boolean hasInputStream() { + return false; + } + + /** Returns the input as InputStream (if available) + * + * @return + */ + public InputStream getInputStream() { + return null; + } + + /** Returns if the input can be returned as File. + * + * @return + */ + public boolean hasFile() { + return false; + } + + /** Returns the input as File (if available) + * + * @return + */ + public File getFile() { + return null; + } + + + +} \ No newline at end of file
--- a/servlet/src/digilib/io/ImageInputImpl.java Wed Feb 23 18:09:31 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -/* ImageInput-- digilib image input interface. - - Digital Image Library servlet components - - Copyright (C) 2010 Robert Casties (robcast@mail.berlios.de) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - Please read license.txt for the full details. A copy of the GPL - may be found at http://www.gnu.org/copyleft/lgpl.html - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - * Created on 20.12.2010 - */ - -package digilib.io; - -import java.io.File; -import java.io.InputStream; - -import javax.imageio.stream.ImageInputStream; - -import digilib.util.ImageSize; - -public abstract class ImageInput { - - // mime file type - protected String mimetype = null; - // image size in pixels - protected ImageSize pixelSize = null; - protected ImageSet parent = null; - - /** - * @return ImageSize - */ - public ImageSize getSize() { - return pixelSize; - } - - /** - * Sets the imageSize. - * @param imageSize The imageSize to set - */ - public void setSize(ImageSize imageSize) { - this.pixelSize = imageSize; - } - - /** returns if mimetype has been set. - * - * @return String - */ - public boolean hasMimetype() { - return (mimetype != null); - } - - /** - * @return String - */ - public String getMimetype() { - return mimetype; - } - - /** - * Sets the mimetype. - * @param mimetype The mimetype to set - */ - public void setMimetype(String filetype) { - this.mimetype = filetype; - } - - /** returns if this image has been checked - * (i.e. has size and mimetype) - * TODO: deprecated - * @return boolean - */ - public boolean isChecked() { - return (pixelSize != null); - } - - /** Returns the aspect ratio of the image (width/height). - * - * @return - */ - public float getAspect() { - return (pixelSize != null) ? pixelSize.getAspect() : 0f; - } - - /** - * @return ImageSet - */ - public ImageSet getParent() { - return parent; - } - - /** - * Sets the parent. - * @param parent The parent to set - */ - public void setParent(ImageSet parent) { - this.parent = parent; - } - - /** Returns if the input can be returned as ImageInputStream. - * - * @return - */ - public boolean hasImageInputStream() { - return false; - } - - /** Returns the input as ImageInputStream (if available) - * - * @return - */ - public ImageInputStream getImageInputStream() { - return null; - } - - /** Returns if the input can be returned as InputStream. - * - * @return - */ - public boolean hasInputStream() { - return false; - } - - /** Returns the input as InputStream (if available) - * - * @return - */ - public InputStream getInputStream() { - return null; - } - - /** Returns if the input can be returned as File. - * - * @return - */ - public boolean hasFile() { - return false; - } - - /** Returns the input as File (if available) - * - * @return - */ - public File getFile() { - return null; - } - - - -} \ No newline at end of file
--- a/servlet/src/digilib/servlet/AsyncServletWorker.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/servlet/AsyncServletWorker.java Fri Feb 25 11:34:49 2011 +0100 @@ -32,7 +32,8 @@ protected static Logger logger = Logger.getLogger(AsyncServletWorker.class); private long startTime; - ErrMsg errMsgType = ErrMsg.IMAGE; + private ErrMsg errMsgType = ErrMsg.IMAGE; + private ImageJobDescription jobinfo; /** * @param dlConfig @@ -47,6 +48,7 @@ this.asyncContext = asyncContext; this.startTime = startTime; this.errMsgType = errMsgType; + this.jobinfo = jobinfo; } /**
--- a/servlet/src/digilib/servlet/DigilibRequest.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/servlet/DigilibRequest.java Fri Feb 25 11:34:49 2011 +0100 @@ -131,6 +131,8 @@ newParameter("ddpiy", new Float(0), null, 's'); // scale factor for mo=ascale newParameter("scale", new Float(1), null, 's'); + // color conversion operation + newParameter("colop", "", null, 's'); /* * Parameters of type 'i' are not exchanged between client and server,
--- a/servlet/src/digilib/servlet/Scaler.java Wed Feb 23 18:09:31 2011 +0100 +++ b/servlet/src/digilib/servlet/Scaler.java Fri Feb 25 11:34:49 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.1a10"; + public static final String version = "1.9.1a11"; /** servlet error codes */ public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};