# HG changeset patch # User robcast # Date 1294606267 -3600 # Node ID 2b58d2783ef01455171da5620474989941a07f35 # Parent e8668edcb880eb12467b54df260230429ed70ecf small cleanup diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/DocuImage.java --- a/servlet/src/digilib/image/DocuImage.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/DocuImage.java Sun Jan 09 21:51:07 2011 +0100 @@ -29,6 +29,7 @@ import digilib.io.FileOpException; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** The basic class for the representation of a digilib image. * diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/DocuImageImpl.java --- a/servlet/src/digilib/image/DocuImageImpl.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/DocuImageImpl.java Sun Jan 09 21:51:07 2011 +0100 @@ -34,6 +34,7 @@ import digilib.io.FileOpException; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** Simple abstract implementation of the DocuImage interface. * diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/ImageInfoDocuImage.java --- a/servlet/src/digilib/image/ImageInfoDocuImage.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/ImageInfoDocuImage.java Sun Jan 09 21:51:07 2011 +0100 @@ -9,6 +9,7 @@ import org.marcoschmidt.image.ImageInfo; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** Simple abstract implementation of the DocuImage interface. * Implements only the identify method using the ImageInfo class. diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/ImageJobDescription.java --- a/servlet/src/digilib/image/ImageJobDescription.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/ImageJobDescription.java Sun Jan 09 21:51:07 2011 +0100 @@ -14,6 +14,7 @@ import digilib.io.ImageInput; import digilib.io.ImageSet; import digilib.servlet.DigilibConfiguration; +import digilib.util.ImageSize; import digilib.util.OptionsSet; import digilib.util.Parameter; import digilib.util.ParameterMap; diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/ImageLoaderDocuImage.java --- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Sun Jan 09 21:51:07 2011 +0100 @@ -49,6 +49,7 @@ import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. */ public class ImageLoaderDocuImage extends ImageInfoDocuImage { diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/ImageSize.java --- a/servlet/src/digilib/image/ImageSize.java Sun Jan 09 21:11:03 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,230 +0,0 @@ -/* - * ImageSize.java -- digilib image size class. - * Digital Image Library servlet components - * Copyright (C) 2003 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 26.08.2003 - */ - -package digilib.image; - -/** Class for image size (width, height). - * - * A width or height of 0 is treated as a 'wildcard' that matches any size. - * - * @author casties - * - */ -public class ImageSize { - public int width; - public int height; - - public ImageSize() { - super(); - } - - public ImageSize(int width, int height) { - this.width = width; - this.height = height; - } - - public ImageSize(ImageSize i) { - this.width = i.width; - this.height = i.height; - } - - public void setSize(int width, int height) { - this.width = width; - this.height = height; - } - - /** - * Returns if the size of this image is smaller in every dimension than the - * other image. - * - * - * - * @param is - * @return - */ - public boolean isTotallySmallerThan(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height <= is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width <= is.width); - } - return ((this.width <= is.width)&&(this.height <= is.height)); - } - - /** - * Returns if the size of this image is smaller in at least one dimension - * than the other image. - * - * @param is - * @return - */ - public boolean isSmallerThan(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height <= is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width <= is.width); - } - return ((this.width <= is.width) || (this.height <= is.height)); - } - - /** - * Returns if the size of this image is bigger in every dimension than the - * other image. - * - * - * - * @param is - * @return - */ - public boolean isTotallyBiggerThan(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height >= is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width >= is.width); - } - return ((this.width >= is.width) && (this.height >= is.height)); - } - - /** - * Returns if the size of this image is bigger in at least one dimension - * than the other image. - * - * - * - * @param is - * @return - */ - public boolean isBiggerThan(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height >= is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width >= is.width); - } - return ((this.width >= is.width) || (this.height >= is.height)); - } - - /** - * Returns if this image has the same size or height as the other image. - * - * - * - * @param is - * @return - */ - public boolean fitsIn(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height == is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width == is.width); - } - return ( - (this.width == is.width) - && (this.height <= is.height) - || (this.width <= is.width) - && (this.height == is.height)); - } - - /** - * Returns if the size of this image is the same as the other image. - * - * - * - * @param is - * @return - */ - public boolean equals(ImageSize is) { - if ((this.width == 0)||(is.width == 0)) { - // width wildcard - return (this.height == is.height); - } - if ((this.height == 0)||(is.height == 0)) { - // height wildcard - return (this.width == is.width); - } - return ((this.width == is.width) && (this.height == is.height)); - } - - /** - * @return - */ - public int getHeight() { - return height; - } - - /** - * @param height - */ - public void setHeight(int height) { - this.height = height; - } - - /** - * @return - */ - public int getWidth() { - return width; - } - - /** - * @param width - */ - public void setWidth(int width) { - this.width = width; - } - - /** - * Returns the aspect ratio. - * - * Aspect ratio is (width/height). So it's <1 for portrait and >1 for - * landscape. - * - * @return - */ - public float getAspect() { - return (height > 0) ? ((float) width / (float) height) : 0; - } - - /** - * Returns a scaled copy of this image size. - * - * @param scale - * @return - */ - public ImageSize getScaled(float scale) { - return new ImageSize((int) (width * scale), (int) (height * scale)); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - String s = "[" + width + "x" + height + "]"; - return s; - } -} diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/JAIDocuImage.java --- a/servlet/src/digilib/image/JAIDocuImage.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/JAIDocuImage.java Sun Jan 09 21:51:07 2011 +0100 @@ -46,6 +46,7 @@ import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** A DocuImage implementation using Java Advanced Imaging Library. */ /** diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/image/JAIImageLoaderDocuImage.java --- a/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Sun Jan 09 21:51:07 2011 +0100 @@ -39,6 +39,7 @@ import digilib.io.FileOpException; import digilib.io.ImageInput; +import digilib.util.ImageSize; /** DocuImage implementation using the Java Advanced Imaging API and the ImageLoader * API of Java 1.4. diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/io/ImageFile.java --- a/servlet/src/digilib/io/ImageFile.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/io/ImageFile.java Sun Jan 09 21:51:07 2011 +0100 @@ -22,15 +22,14 @@ package digilib.io; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import javax.imageio.stream.FileImageInputStream; import javax.imageio.stream.ImageInputStream; -import digilib.image.ImageSize; import digilib.servlet.DigilibConfiguration; +import digilib.util.ImageSize; /** * @author casties diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/io/ImageInput.java --- a/servlet/src/digilib/io/ImageInput.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/io/ImageInput.java Sun Jan 09 21:51:07 2011 +0100 @@ -26,7 +26,7 @@ import javax.imageio.stream.ImageInputStream; -import digilib.image.ImageSize; +import digilib.util.ImageSize; public abstract class ImageInput { diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/io/ImageSet.java --- a/servlet/src/digilib/io/ImageSet.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/io/ImageSet.java Sun Jan 09 21:51:07 2011 +0100 @@ -21,7 +21,7 @@ import java.util.List; import java.util.ListIterator; -import digilib.image.ImageSize; +import digilib.util.ImageSize; /** * @author casties diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/servlet/DocumentBean.java --- a/servlet/src/digilib/servlet/DocumentBean.java Sun Jan 09 21:11:03 2011 +0100 +++ b/servlet/src/digilib/servlet/DocumentBean.java Sun Jan 09 21:51:07 2011 +0100 @@ -33,13 +33,13 @@ import digilib.auth.AuthOpException; import digilib.auth.AuthOps; -import digilib.image.ImageSize; import digilib.io.DocuDirCache; import digilib.io.DocuDirectory; +import digilib.io.ImageFile; import digilib.io.FileOps.FileClass; -import digilib.io.ImageFile; import digilib.io.ImageInput; import digilib.io.ImageSet; +import digilib.util.ImageSize; public class DocumentBean { diff -r e8668edcb880 -r 2b58d2783ef0 servlet/src/digilib/util/ImageSize.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/util/ImageSize.java Sun Jan 09 21:51:07 2011 +0100 @@ -0,0 +1,230 @@ +/* + * ImageSize.java -- digilib image size class. + * Digital Image Library servlet components + * Copyright (C) 2003 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 26.08.2003 + */ + +package digilib.util; + +/** Class for image size (width, height). + * + * A width or height of 0 is treated as a 'wildcard' that matches any size. + * + * @author casties + * + */ +public class ImageSize { + public int width; + public int height; + + public ImageSize() { + super(); + } + + public ImageSize(int width, int height) { + this.width = width; + this.height = height; + } + + public ImageSize(ImageSize i) { + this.width = i.width; + this.height = i.height; + } + + public void setSize(int width, int height) { + this.width = width; + this.height = height; + } + + /** + * Returns if the size of this image is smaller in every dimension than the + * other image. + * + * + * + * @param is + * @return + */ + public boolean isTotallySmallerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height <= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width <= is.width); + } + return ((this.width <= is.width)&&(this.height <= is.height)); + } + + /** + * Returns if the size of this image is smaller in at least one dimension + * than the other image. + * + * @param is + * @return + */ + public boolean isSmallerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height <= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width <= is.width); + } + return ((this.width <= is.width) || (this.height <= is.height)); + } + + /** + * Returns if the size of this image is bigger in every dimension than the + * other image. + * + * + * + * @param is + * @return + */ + public boolean isTotallyBiggerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height >= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width >= is.width); + } + return ((this.width >= is.width) && (this.height >= is.height)); + } + + /** + * Returns if the size of this image is bigger in at least one dimension + * than the other image. + * + * + * + * @param is + * @return + */ + public boolean isBiggerThan(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height >= is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width >= is.width); + } + return ((this.width >= is.width) || (this.height >= is.height)); + } + + /** + * Returns if this image has the same size or height as the other image. + * + * + * + * @param is + * @return + */ + public boolean fitsIn(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height == is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width == is.width); + } + return ( + (this.width == is.width) + && (this.height <= is.height) + || (this.width <= is.width) + && (this.height == is.height)); + } + + /** + * Returns if the size of this image is the same as the other image. + * + * + * + * @param is + * @return + */ + public boolean equals(ImageSize is) { + if ((this.width == 0)||(is.width == 0)) { + // width wildcard + return (this.height == is.height); + } + if ((this.height == 0)||(is.height == 0)) { + // height wildcard + return (this.width == is.width); + } + return ((this.width == is.width) && (this.height == is.height)); + } + + /** + * @return + */ + public int getHeight() { + return height; + } + + /** + * @param height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * @return + */ + public int getWidth() { + return width; + } + + /** + * @param width + */ + public void setWidth(int width) { + this.width = width; + } + + /** + * Returns the aspect ratio. + * + * Aspect ratio is (width/height). So it's <1 for portrait and >1 for + * landscape. + * + * @return + */ + public float getAspect() { + return (height > 0) ? ((float) width / (float) height) : 0; + } + + /** + * Returns a scaled copy of this image size. + * + * @param scale + * @return + */ + public ImageSize getScaled(float scale) { + return new ImageSize((int) (width * scale), (int) (height * scale)); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + String s = "[" + width + "x" + height + "]"; + return s; + } +}