Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImage.java @ 574:790cbfb58b52 stream
ripping apart ImageFileSet
author | robcast |
---|---|
date | Wed, 22 Dec 2010 18:32:06 +0100 |
parents | beeedf90cb81 |
children | aee436f0549d |
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 import javax.servlet.ServletException; |
29 | |
159 | 30 import digilib.io.ImageFile; |
73 | 31 import digilib.io.FileOpException; |
566 | 32 import digilib.io.ImageInput; |
73 | 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 */ | |
1 | 41 public interface DocuImage { |
42 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
43 /** Loads an image file into the Object. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
44 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
45 * @param f Image File. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
46 * @throws FileOpException Exception thrown if any error occurs. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
47 */ |
159 | 48 public void loadImage(ImageFile f) throws FileOpException; |
1 | 49 |
566 | 50 /** This DocuImage supports the loadSubImage operation. |
85 | 51 * |
52 * @return boolean | |
53 */ | |
54 public boolean isSubimageSupported(); | |
55 | |
56 /** Load only a subsampled region of the image file. | |
57 * | |
58 * @param f | |
59 * @param region | |
60 * @param subsample | |
61 * @throws FileOpException | |
62 */ | |
159 | 63 public void loadSubimage(ImageFile f, Rectangle region, int subsample) |
85 | 64 throws FileOpException; |
65 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
66 /** Writes the current image to a ServletResponse. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
67 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
68 * The image is encoded to the mime-type <code>mt</code> and sent to the output |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
69 * stream of the <code>ServletResponse</code> <code>res</code>. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
70 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
71 * 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
|
72 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 * @param mt mime-type of the image to be sent. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
74 * @param res ServletResponse where the image is sent. |
570 | 75 * @throws ServletException Exception thrown on sending data. |
76 * @throws ImageOpException Exception in other cases. | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
78 public void writeImage(String mt, OutputStream ostream) |
570 | 79 throws ServletException, ImageOpException; |
1 | 80 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
81 /** The width of the current image in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
82 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
83 * @return Image width in pixels. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
84 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
85 public int getWidth(); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
86 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
87 /** The height of the current image in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
88 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 * @return Image height in pixels. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
90 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
91 public int getHeight(); |
570 | 92 |
93 /** The size of the current image in pixel. | |
94 * | |
95 * @return | |
96 */ | |
97 public ImageSize getSize(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
98 |
86 | 99 /** The mime-type of the current image. |
100 * | |
101 * @return String the mime-type of this image. | |
102 */ | |
103 public String getMimetype(); | |
104 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
105 /** Crops the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
106 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
107 * 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
|
108 * 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
|
109 * and replaces the current image with the result. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
110 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
111 * @param xoff X offset of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
112 * @param yoff Y offset of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
113 * @param width width of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
114 * @param height height of crop region |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
115 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
116 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
117 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
|
118 throws ImageOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
119 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
120 /** Scales the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
121 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
122 * 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
|
123 * <code>scale</code>. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
124 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
125 * @param scale scaling factor |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
126 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
127 */ |
149 | 128 public void scale(double scaleX, double scaleY) throws ImageOpException; |
1 | 129 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
130 /** Crops and scales the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
131 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
132 * 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
|
133 * <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
|
134 * 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
|
135 * interpolation quality <code>qual</code> (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
136 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
137 * @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
|
138 * @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
|
139 * @param width width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
140 * @param height height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
141 * @param scale scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
142 * @param qual interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
143 * @throws ImageOpException exception thrown on any error. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
144 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
145 public void cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
146 int x_off, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
147 int y_off, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
148 int width, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
149 int height, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
150 double scale, |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
151 int qual) |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
152 throws ImageOpException; |
85 | 153 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
154 /** Rotates the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
155 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
156 * Replaces the current image with a rotated image. The image is rotated |
101 | 157 * around the center by the <code>angle</code> |
85 | 158 * given in degrees [0, 360] clockwise. |
159 * 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
|
160 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
161 * @param angle rotation angle in degree |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
162 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
163 public void rotate(double angle) throws ImageOpException; |
85 | 164 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
165 /** Mirrors the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
166 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
167 * 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
|
168 * 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
|
169 * degrees. Currently only horizontal and vertical mirroring (0 and 90 |
101 | 170 * degree) are supported. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
171 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
172 * @param angle angle of mirror axis |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
173 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
174 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
175 public void mirror(double angle) throws ImageOpException; |
85 | 176 |
86 | 177 /** Enhances brightness and contrast of the current image. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
178 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
179 * 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
|
180 * 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
|
181 * <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
|
182 * <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
|
183 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
184 * @param mult multiplicative constant for contrast enhancement |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
185 * @param add additive constant for brightness enhancement |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
186 * @throws ImageOpException |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
187 */ |
86 | 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; | |
1 | 204 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
205 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
206 * Returns the interpolation quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
207 * @return int |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
208 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
209 public int getQuality(); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
210 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
211 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
212 * Sets the interpolation quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
213 * @param quality The quality to set |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
214 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
215 public void setQuality(int quality); |
207 | 216 |
217 /** Frees all resources bound to the DocuImage. | |
218 * | |
219 * Things that should be freed are image objects and open files. | |
220 * | |
221 */ | |
222 public void dispose(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
223 |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
224 /** |
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
225 * Check image size and type and store in ImageFile f |
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
226 */ |
566 | 227 public ImageInput identify(ImageFile imgf) throws IOException; |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
228 |
463 | 229 /** |
230 * Returns a list of supported image formats | |
231 */ | |
531 | 232 public Iterator<String> getSupportedFormats(); |
533 | 233 |
234 /** | |
235 * returns the underlying image as java.awt.Image (if possible, or null) | |
236 * @return | |
237 */ | |
238 public java.awt.Image getAwtImage(); | |
463 | 239 |
1 | 240 } |