comparison common/src/main/java/digilib/image/DocuImage.java @ 903:7779b37d1d05

refactored into maven modules per servlet type. can build servlet-api 2.3 and 3.0 via profile now!
author robcast
date Tue, 26 Apr 2011 20:24:31 +0200
parents servlet/src/main/java/digilib/image/DocuImage.java@ba1eb2d821a2
children 28d007673346
comparison
equal deleted inserted replaced
902:89ba3ffcf552 903:7779b37d1d05
1 /* DocuImage -- General image interface class
2
3 Digital Image Library servlet components
4
5 Copyright (C) 2001, 2002, 2003 Robert Casties (robcast@mail.berlios.de)
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
11
12 Please read license.txt for the full details. A copy of the GPL
13 may be found at http://www.gnu.org/copyleft/lgpl.html
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 */
20
21 package digilib.image;
22
23 import java.awt.Rectangle;
24 import java.io.IOException;
25 import java.io.OutputStream;
26 import java.util.Iterator;
27
28 import javax.servlet.ServletException;
29
30 import digilib.io.FileOpException;
31 import digilib.io.ImageInput;
32 import digilib.util.ImageSize;
33
34 /** The basic class for the representation of a digilib image.
35 *
36 * The actual image object is hidden in the class, only methods for loading,
37 * manipulation, and saving are exported. This strategy enables implementations
38 * using different toolkits that rely on different image base classes (like
39 * JIMI, Java2D and JAI).
40 */
41 public interface DocuImage {
42
43 /** Loads an image file into the Object.
44 *
45 * @param ii Image File.
46 * @throws FileOpException Exception thrown if any error occurs.
47 */
48 public void loadImage(ImageInput ii) throws FileOpException;
49
50 /** This DocuImage supports the loadSubImage operation.
51 *
52 * @return boolean
53 */
54 public boolean isSubimageSupported();
55
56 /** Load only a subsampled region of the image file.
57 *
58 * @param ii
59 * @param region
60 * @param subsample
61 * @throws FileOpException
62 */
63 public void loadSubimage(ImageInput ii, Rectangle region, int subsample)
64 throws FileOpException;
65
66 /** Writes the current image to an OutputStream.
67 *
68 * The image is encoded to the mime-type <code>mt</code> and sent to the output
69 * stream <code>ostream</code>.
70 *
71 * Currently only mime-types "image/jpeg" and "image/png" are supported.
72 *
73 * @param mt mime-type of the image to be sent.
74 * @param ostream OutputStream where the image is sent.
75 * @throws ServletException Exception thrown on sending data.
76 * @throws ImageOpException Exception in other cases.
77 */
78 public void writeImage(String mt, OutputStream ostream)
79 throws ServletException, ImageOpException;
80
81 /** The width of the current image in pixel.
82 *
83 * @return Image width in pixels.
84 */
85 public int getWidth();
86
87 /** The height of the current image in pixel.
88 *
89 * @return Image height in pixels.
90 */
91 public int getHeight();
92
93 /** The size of the current image in pixel.
94 *
95 * @return
96 */
97 public ImageSize getSize();
98
99 /** The mime-type of the image, i.e. the mime-type of the input that was read.
100 *
101 * @return String the mime-type of this image.
102 */
103 public String getMimetype();
104
105 /** Crops the current image.
106 *
107 * Cuts out a region of the size <code>width</code> x <code>height</code> at
108 * the offset <code>xoff</code>, <code>yoff</code> from the current image
109 * and replaces the current image with the result.
110 *
111 * @param xoff X offset of crop region
112 * @param yoff Y offset of crop region
113 * @param width width of crop region
114 * @param height height of crop region
115 * @throws ImageOpException
116 */
117 public void crop(int xoff, int yoff, int width, int height)
118 throws ImageOpException;
119
120 /** Scales the current image.
121 *
122 * Replaces the current image with an image scaled by the factor
123 * <code>scale</code>.
124 *
125 * @param scale scaling factor
126 * @throws ImageOpException
127 */
128 public void scale(double scaleX, double scaleY) throws ImageOpException;
129
130 /** Crops and scales the current image.
131 *
132 * The current image is cropped to a rectangle of <code>width</code>,
133 * <code>height</code> at position <code>x_off</code>, <code>y_off</code>. The
134 * resulting image is scaled by the factor <code>scale</code> using the
135 * interpolation quality <code>qual</code> (0=worst).
136 *
137 * @param x_off x offset of the crop rectangle in pixel.
138 * @param y_off y offset of the crop rectangle in pixel.
139 * @param width width of the crop rectangle in pixel.
140 * @param height height of the crop rectangle in pixel.
141 * @param scale scaling factor.
142 * @param qual interpolation quality (0=worst).
143 * @throws ImageOpException exception thrown on any error.
144 */
145 public void cropAndScale(
146 int x_off,
147 int y_off,
148 int width,
149 int height,
150 double scale,
151 int qual)
152 throws ImageOpException;
153
154 /** Rotates the current image.
155 *
156 * Replaces the current image with a rotated image. The image is rotated
157 * around the center by the <code>angle</code>
158 * given in degrees [0, 360] clockwise.
159 * Image size and aspect ratio are likely to change.
160 *
161 * @param angle rotation angle in degree
162 */
163 public void rotate(double angle) throws ImageOpException;
164
165 /** Mirrors the current image.
166 *
167 * Replaces the current image with a mirrored image. The mirror axis goes
168 * through the center of the image and is rotated by <code>angle</code>
169 * degrees. Currently only horizontal and vertical mirroring (0 and 90
170 * degree) are supported.
171 *
172 * @param angle angle of mirror axis
173 * @throws ImageOpException
174 */
175 public void mirror(double angle) throws ImageOpException;
176
177 /** Enhances brightness and contrast of the current image.
178 *
179 * Replaces the current image with a brightness and contrast enhanced image.
180 * Contrast is enhanced by multiplying the pixel value with the constant
181 * <code>mult</code>. Brightness is enhanced by adding the constant
182 * <code>add</code> to the pixel value. Operation: p1 = (p0*mult)+add.
183 *
184 * @param mult multiplicative constant for contrast enhancement
185 * @param add additive constant for brightness enhancement
186 * @throws ImageOpException
187 */
188 public void enhance(float mult, float add) throws ImageOpException;
189
190 /** Manipulates the colors of the current image.
191 *
192 * Replaces the current image with a color modified image.
193 * For the red, green and blue color channels all pixel values are multiplied
194 * by the constant
195 * <code>m</code> and added to the constant
196 * <code>a</code>. Operation: p1 = (p0*m)+a.
197 *
198 * @param rgbm multiplicative constants for red, green, blue
199 * @param rgba additive constant for red, green, blue
200 * @throws ImageOpException
201 */
202 public void enhanceRGB(float[] rgbm, float[] rgba)
203 throws ImageOpException;
204
205
206 /** Operations for colorOps.
207 *
208 * GRAYSCALE: cast color image to grayscale
209 * NTSC_GRAY: convert color image to grayscale using NTSC formula
210 * INVERT: invert colors (every channel separately)
211 * MAP_GRAY_BGR: false color image from grayscale (0: blue, 128: green, 255: red)
212 *
213 */
214 public enum ColorOp {GRAYSCALE, NTSC_GRAY, INVERT, MAP_GRAY_BGR};
215
216 /** Changes the colors of the current image.
217 *
218 * Changes the colors of the current image. Operations are instances of ColorOp:
219 *
220 * GRAYSCALE: cast color image to grayscale
221 * NTSC_GRAY: convert color image to grayscale using NTSC formula
222 * INVERT: invert colors (every channel separately)
223 * MAP_GRAY_BGR: false color image from grayscale (0: blue, 128: green, 255: red)
224 *
225 * @throws ImageOpException
226 */
227 public void colorOp(ColorOp op) throws ImageOpException;
228
229 /**
230 * Returns the interpolation quality.
231 * @return int
232 */
233 public int getQuality();
234
235 /**
236 * Sets the interpolation quality.
237 * @param quality The quality to set
238 */
239 public void setQuality(int quality);
240
241 /** Frees all resources bound to the DocuImage.
242 *
243 * Things that should be freed are image objects and open files.
244 *
245 */
246 public void dispose();
247
248 /**
249 * Check image size and type and store in ImageInput ii
250 */
251 public ImageInput identify(ImageInput ii) throws IOException;
252
253 /**
254 * Returns a list of supported image formats
255 */
256 public Iterator<String> getSupportedFormats();
257
258 /**
259 * returns the underlying image as java.awt.Image (if possible, or null)
260 * @return
261 */
262 public java.awt.Image getAwtImage();
263
264 }