Mercurial > hg > digilib
comparison common/src/main/java/digilib/image/DocuImageImpl.java @ 894:53dd7e189155
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/DocuImageImpl.java@7ffb45138f61 |
children | 7759f727a877 |
comparison
equal
deleted
inserted
replaced
893:1a16d79988c2 | 894:53dd7e189155 |
---|---|
1 /* DocuImage -- General image interface class implementation | |
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.Image; | |
24 import java.awt.Rectangle; | |
25 import java.io.IOException; | |
26 import java.io.OutputStream; | |
27 import java.util.Iterator; | |
28 import java.util.LinkedList; | |
29 import java.util.List; | |
30 | |
31 import javax.servlet.ServletException; | |
32 | |
33 import org.apache.log4j.Logger; | |
34 | |
35 import digilib.io.FileOpException; | |
36 import digilib.io.ImageInput; | |
37 import digilib.util.ImageSize; | |
38 | |
39 /** Simple abstract implementation of the <code>DocuImage</code> interface. | |
40 * | |
41 * This implementation provides basic functionality for the utility methods like | |
42 * <code>getKnownFileTypes</code>. Image methods like | |
43 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>, | |
44 * <code>getHeight</code>, <code>crop</code> and <code>scale</code> must be | |
45 * implemented by derived classes. | |
46 */ | |
47 public abstract class DocuImageImpl implements DocuImage { | |
48 | |
49 /** logger */ | |
50 protected static final Logger logger = Logger.getLogger(DocuImage.class); | |
51 | |
52 /** Interpolation quality. */ | |
53 protected int quality = 0; | |
54 | |
55 /** epsilon for float comparisons. */ | |
56 public static final double epsilon = 1e-5; | |
57 | |
58 /** image size */ | |
59 protected ImageSize imgSize = null; | |
60 | |
61 /** ImageInput that was read */ | |
62 protected ImageInput input; | |
63 | |
64 /** | |
65 * Returns the quality. | |
66 * @return int | |
67 */ | |
68 public int getQuality() { | |
69 return quality; | |
70 } | |
71 | |
72 /** | |
73 * Sets the quality. | |
74 * @param quality The quality to set | |
75 */ | |
76 public void setQuality(int quality) { | |
77 this.quality = quality; | |
78 } | |
79 | |
80 /** Crop and scale the current image. | |
81 * | |
82 * The current image is cropped to a rectangle of width, height at position | |
83 * x_off, y_off. The resulting image is scaled by the factor scale using the | |
84 * interpolation quality qual (0=worst). | |
85 * | |
86 * @param x_off X offset of the crop rectangle in pixel. | |
87 * @param y_off Y offset of the crop rectangle in pixel. | |
88 * @param width Width of the crop rectangle in pixel. | |
89 * @param height Height of the crop rectangle in pixel. | |
90 * @param scale Scaling factor. | |
91 * @param qual Interpolation quality (0=worst). | |
92 * @throws ImageOpException Exception thrown on any error. | |
93 */ | |
94 public void cropAndScale( | |
95 int x_off, int y_off, int width, int height, double scale, int qual) | |
96 throws ImageOpException { | |
97 // default implementation: first crop, then scale | |
98 setQuality(qual); | |
99 crop(x_off, y_off, width, height); | |
100 scale(scale, scale); | |
101 } | |
102 | |
103 /* (non-Javadoc) | |
104 * @see digilib.image.DocuImage#getMimetype() | |
105 */ | |
106 public String getMimetype() { | |
107 if (input != null) { | |
108 return input.getMimetype(); | |
109 } | |
110 return null; | |
111 } | |
112 | |
113 /* (non-Javadoc) | |
114 * @see digilib.image.DocuImage#identify(digilib.io.ImageFile) | |
115 */ | |
116 public ImageInput identify(ImageInput ii) throws IOException { | |
117 // just a do-nothing implementation | |
118 return null; | |
119 } | |
120 | |
121 public void rotate(double angle) throws ImageOpException { | |
122 // just a do-nothing implementation | |
123 } | |
124 | |
125 public void mirror(double angle) throws ImageOpException { | |
126 // just a do-nothing implementation | |
127 } | |
128 | |
129 public void enhance(float mult, float add) throws ImageOpException { | |
130 // just a do-nothing implementation | |
131 } | |
132 | |
133 public boolean isSubimageSupported() { | |
134 // partial loading not supported per default | |
135 return false; | |
136 } | |
137 | |
138 public void loadSubimage(ImageInput ii, Rectangle region, int subsample) | |
139 throws FileOpException { | |
140 // empty implementation | |
141 } | |
142 | |
143 public void enhanceRGB(float[] rgbm, float[] rgba) | |
144 throws ImageOpException { | |
145 // emtpy implementation | |
146 } | |
147 | |
148 public void colorOp(ColorOp op) throws ImageOpException { | |
149 // emtpy implementation | |
150 } | |
151 | |
152 public void dispose() { | |
153 // emtpy implementation | |
154 } | |
155 | |
156 public Iterator<String> getSupportedFormats() { | |
157 List<String> empty = new LinkedList<String>(); | |
158 return empty.iterator(); | |
159 } | |
160 | |
161 public void crop(int xoff, int yoff, int width, int height) | |
162 throws ImageOpException { | |
163 // emtpy implementation | |
164 } | |
165 | |
166 public Image getAwtImage() { | |
167 // emtpy implementation | |
168 return null; | |
169 } | |
170 | |
171 public int getHeight() { | |
172 ImageSize is = getSize(); | |
173 if (is != null) { | |
174 return is.getHeight(); | |
175 } | |
176 return 0; | |
177 } | |
178 | |
179 public int getWidth() { | |
180 ImageSize is = getSize(); | |
181 if (is != null) { | |
182 return is.getWidth(); | |
183 } | |
184 return 0; | |
185 } | |
186 | |
187 public ImageSize getSize() { | |
188 return imgSize; | |
189 } | |
190 | |
191 public abstract void loadImage(ImageInput ii) throws FileOpException; | |
192 | |
193 public abstract void scale(double scaleX, double scaleY) throws ImageOpException; | |
194 | |
195 public abstract void writeImage(String mt, OutputStream ostream) | |
196 throws ServletException, ImageOpException; | |
197 | |
198 | |
199 } |