Mercurial > hg > digilib-old
annotate common/src/main/java/digilib/image/DocuImage.java @ 964:0b5fa035af30
fixed old versions in poms.
author | casties |
---|---|
date | Wed, 25 Jan 2012 16:41:43 +0100 |
parents | 28d007673346 |
children | 4e368c85cce4 |
rev | line source |
---|---|
1 | 1 /* DocuImage -- General image interface class |
2 | |
3 Digital Image Library servlet components | |
4 | |
85 | 5 Copyright (C) 2001, 2002, 2003 Robert Casties (robcast@mail.berlios.de) |
1 | 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 | |
149 | 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1 | 18 |
19 */ | |
20 | |
21 package digilib.image; | |
22 | |
85 | 23 import java.awt.Rectangle; |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
24 import java.io.IOException; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
25 import java.io.OutputStream; |
463 | 26 import java.util.Iterator; |
73 | 27 |
570 | 28 |
73 | 29 import digilib.io.FileOpException; |
566 | 30 import digilib.io.ImageInput; |
596 | 31 import digilib.util.ImageSize; |
73 | 32 |
33 /** The basic class for the representation of a digilib image. | |
34 * | |
35 * The actual image object is hidden in the class, only methods for loading, | |
36 * manipulation, and saving are exported. This strategy enables implementations | |
37 * using different toolkits that rely on different image base classes (like | |
38 * JIMI, Java2D and JAI). | |
39 */ | |
1 | 40 public interface DocuImage { |
41 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
42 /** Loads an image file into the Object. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
43 * |
588 | 44 * @param ii Image File. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
45 * @throws FileOpException Exception thrown if any error occurs. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
46 */ |
588 | 47 public void loadImage(ImageInput ii) throws FileOpException; |
1 | 48 |
566 | 49 /** This DocuImage supports the loadSubImage operation. |
85 | 50 * |
51 * @return boolean | |
52 */ | |
53 public boolean isSubimageSupported(); | |
54 | |
55 /** Load only a subsampled region of the image file. | |
56 * | |
588 | 57 * @param ii |
85 | 58 * @param region |
59 * @param subsample | |
60 * @throws FileOpException | |
61 */ | |
588 | 62 public void loadSubimage(ImageInput ii, Rectangle region, int subsample) |
85 | 63 throws FileOpException; |
64 | |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
65 /** Writes the current image to an OutputStream. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
66 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
67 * The image is encoded to the mime-type <code>mt</code> and sent to the output |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
68 * stream <code>ostream</code>. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
69 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
70 * Currently only mime-types "image/jpeg" and "image/png" are supported. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
71 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
72 * @param mt mime-type of the image to be sent. |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
73 * @param ostream OutputStream where the image is sent. |
570 | 74 * @throws ImageOpException Exception in other cases. |
906 | 75 * @throws FileOpException Exception on sending data |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
76 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 public void writeImage(String mt, OutputStream ostream) |
906 | 78 throws ImageOpException, FileOpException; |
1 | 79 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
80 /** The width of the current image in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
81 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
82 * @return Image width in pixels. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
83 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
84 public int getWidth(); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
85 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
86 /** The height of the current image in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
87 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
88 * @return Image height in pixels. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
90 public int getHeight(); |
570 | 91 |
92 /** The size of the current image in pixel. | |
93 * | |
94 * @return | |
95 */ | |
96 public ImageSize getSize(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
97 |
588 | 98 /** The mime-type of the image, i.e. the mime-type of the input that was read. |
86 | 99 * |
100 * @return String the mime-type of this image. | |
101 */ | |
102 public String getMimetype(); | |
103 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
104 /** Crops the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
105 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
106 * Cuts out a region of the size <code>width</code> x <code>height</code> at |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
107 * the offset <code>xoff</code>, <code>yoff</code> from the current image |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
108 * and replaces the current image with the result. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
109 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
110 * @param xoff X offset of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
111 * @param yoff Y offset of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
112 * @param width width of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
113 * @param height height of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
114 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
115 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
116 public void crop(int xoff, int yoff, int width, int height) |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
117 throws ImageOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
118 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
119 /** Scales the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
120 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
121 * Replaces the current image with an image scaled by the factor |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
122 * <code>scale</code>. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
123 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
124 * @param scale scaling factor |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
125 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
126 */ |
149 | 127 public void scale(double scaleX, double scaleY) throws ImageOpException; |
1 | 128 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
129 /** Crops and scales the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
130 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
131 * The current image is cropped to a rectangle of <code>width</code>, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
132 * <code>height</code> at position <code>x_off</code>, <code>y_off</code>. The |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
133 * resulting image is scaled by the factor <code>scale</code> using the |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
134 * interpolation quality <code>qual</code> (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
135 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
136 * @param x_off x offset of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
137 * @param y_off y offset of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
138 * @param width width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
139 * @param height height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
140 * @param scale scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
141 * @param qual interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
142 * @throws ImageOpException exception thrown on any error. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
143 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
144 public void cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
145 int x_off, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
146 int y_off, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
147 int width, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
148 int height, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
149 double scale, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
150 int qual) |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
151 throws ImageOpException; |
85 | 152 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
153 /** Rotates the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
154 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
155 * Replaces the current image with a rotated image. The image is rotated |
101 | 156 * around the center by the <code>angle</code> |
85 | 157 * given in degrees [0, 360] clockwise. |
158 * Image size and aspect ratio are likely to change. | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
159 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
160 * @param angle rotation angle in degree |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
161 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
162 public void rotate(double angle) throws ImageOpException; |
85 | 163 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
164 /** Mirrors the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
165 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
166 * Replaces the current image with a mirrored image. The mirror axis goes |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
167 * through the center of the image and is rotated by <code>angle</code> |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
168 * degrees. Currently only horizontal and vertical mirroring (0 and 90 |
101 | 169 * degree) are supported. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
170 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
171 * @param angle angle of mirror axis |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
172 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
173 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
174 public void mirror(double angle) throws ImageOpException; |
85 | 175 |
86 | 176 /** Enhances brightness and contrast of the current image. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
177 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
178 * Replaces the current image with a brightness and contrast enhanced image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
179 * Contrast is enhanced by multiplying the pixel value with the constant |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
180 * <code>mult</code>. Brightness is enhanced by adding the constant |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
181 * <code>add</code> to the pixel value. Operation: p1 = (p0*mult)+add. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
182 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
183 * @param mult multiplicative constant for contrast enhancement |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
184 * @param add additive constant for brightness enhancement |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
185 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
186 */ |
86 | 187 public void enhance(float mult, float add) throws ImageOpException; |
188 | |
189 /** Manipulates the colors of the current image. | |
190 * | |
191 * Replaces the current image with a color modified image. | |
192 * For the red, green and blue color channels all pixel values are multiplied | |
193 * by the constant | |
194 * <code>m</code> and added to the constant | |
195 * <code>a</code>. Operation: p1 = (p0*m)+a. | |
196 * | |
197 * @param rgbm multiplicative constants for red, green, blue | |
198 * @param rgba additive constant for red, green, blue | |
199 * @throws ImageOpException | |
200 */ | |
201 public void enhanceRGB(float[] rgbm, float[] rgba) | |
202 throws ImageOpException; | |
1 | 203 |
829 | 204 |
205 /** Operations for colorOps. | |
206 * | |
860 | 207 * GRAYSCALE: cast color image to grayscale |
208 * NTSC_GRAY: convert color image to grayscale using NTSC formula | |
209 * INVERT: invert colors (every channel separately) | |
210 * MAP_GRAY_BGR: false color image from grayscale (0: blue, 128: green, 255: red) | |
829 | 211 * |
212 */ | |
860 | 213 public enum ColorOp {GRAYSCALE, NTSC_GRAY, INVERT, MAP_GRAY_BGR}; |
829 | 214 |
215 /** Changes the colors of the current image. | |
216 * | |
860 | 217 * Changes the colors of the current image. Operations are instances of ColorOp: |
218 * | |
219 * GRAYSCALE: cast color image to grayscale | |
220 * NTSC_GRAY: convert color image to grayscale using NTSC formula | |
221 * INVERT: invert colors (every channel separately) | |
222 * MAP_GRAY_BGR: false color image from grayscale (0: blue, 128: green, 255: red) | |
829 | 223 * |
224 * @throws ImageOpException | |
225 */ | |
226 public void colorOp(ColorOp op) throws ImageOpException; | |
227 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
228 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
229 * Returns the interpolation quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
230 * @return int |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
231 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
232 public int getQuality(); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
233 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
234 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
235 * Sets the interpolation quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
236 * @param quality The quality to set |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
237 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
238 public void setQuality(int quality); |
207 | 239 |
240 /** Frees all resources bound to the DocuImage. | |
241 * | |
242 * Things that should be freed are image objects and open files. | |
243 * | |
244 */ | |
245 public void dispose(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
246 |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
247 /** |
588 | 248 * Check image size and type and store in ImageInput ii |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
249 */ |
588 | 250 public ImageInput identify(ImageInput ii) throws IOException; |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
251 |
463 | 252 /** |
253 * Returns a list of supported image formats | |
254 */ | |
531 | 255 public Iterator<String> getSupportedFormats(); |
533 | 256 |
257 /** | |
258 * returns the underlying image as java.awt.Image (if possible, or null) | |
259 * @return | |
260 */ | |
261 public java.awt.Image getAwtImage(); | |
463 | 262 |
1 | 263 } |