Mercurial > hg > digilib-old
annotate common/src/main/java/digilib/image/DocuImageImpl.java @ 912:cbfc94584d3b
reset imgSize in operations that change size.
author | robcast |
---|---|
date | Wed, 08 Jun 2011 17:49:01 +0200 |
parents | 28d007673346 |
children | 4e368c85cce4 |
rev | line source |
---|---|
1 | 1 /* DocuImage -- General image interface class implementation |
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 | |
73 | 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1 | 18 |
19 */ | |
20 | |
21 package digilib.image; | |
22 | |
533 | 23 import java.awt.Image; |
85 | 24 import java.awt.Rectangle; |
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
25 import java.io.IOException; |
533 | 26 import java.io.OutputStream; |
464 | 27 import java.util.Iterator; |
28 import java.util.LinkedList; | |
29 import java.util.List; | |
85 | 30 |
570 | 31 |
181 | 32 import org.apache.log4j.Logger; |
33 | |
34 import digilib.io.FileOpException; | |
566 | 35 import digilib.io.ImageInput; |
596 | 36 import digilib.util.ImageSize; |
1 | 37 |
73 | 38 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
39 * | |
40 * This implementation provides basic functionality for the utility methods like | |
562 | 41 * <code>getKnownFileTypes</code>. Image methods like |
73 | 42 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>, |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
43 * <code>getHeight</code>, <code>crop</code> and <code>scale</code> must be |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
44 * implemented by derived classes. |
73 | 45 */ |
1 | 46 public abstract class DocuImageImpl implements DocuImage { |
47 | |
181 | 48 /** logger */ |
469
11e11fe4d680
Improved performance of JAIDocuImage for large images
robcast
parents:
464
diff
changeset
|
49 protected static final Logger logger = Logger.getLogger(DocuImage.class); |
181 | 50 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
51 /** Interpolation quality. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
52 protected int quality = 0; |
85 | 53 |
86 | 54 /** epsilon for float comparisons. */ |
864 | 55 public static final double epsilon = 1e-5; |
1 | 56 |
570 | 57 /** image size */ |
58 protected ImageSize imgSize = null; | |
59 | |
588 | 60 /** ImageInput that was read */ |
61 protected ImageInput input; | |
62 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
63 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
64 * Returns the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
65 * @return int |
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 public int getQuality() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
68 return quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
69 } |
1 | 70 |
79
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 * Sets the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 * @param quality The quality to set |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
74 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
75 public void setQuality(int quality) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
76 this.quality = quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 } |
1 | 78 |
564 | 79 /** Crop and scale the current image. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
80 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
81 * The current image is cropped to a rectangle of width, height at position |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
82 * x_off, y_off. The resulting image is scaled by the factor scale using the |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
83 * interpolation quality qual (0=worst). |
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 * @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
|
86 * @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
|
87 * @param width Width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
88 * @param height Height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 * @param scale Scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
90 * @param qual Interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
91 * @throws ImageOpException Exception thrown on any error. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
92 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
93 public void cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
94 int x_off, int y_off, int width, int height, double scale, int qual) |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
95 throws ImageOpException { |
562 | 96 // default implementation: first crop, then scale |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
97 setQuality(qual); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
98 crop(x_off, y_off, width, height); |
149 | 99 scale(scale, scale); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
100 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
101 |
588 | 102 /* (non-Javadoc) |
103 * @see digilib.image.DocuImage#getMimetype() | |
104 */ | |
86 | 105 public String getMimetype() { |
588 | 106 if (input != null) { |
107 return input.getMimetype(); | |
108 } | |
109 return null; | |
86 | 110 } |
111 | |
564 | 112 /* (non-Javadoc) |
113 * @see digilib.image.DocuImage#identify(digilib.io.ImageFile) | |
114 */ | |
588 | 115 public ImageInput identify(ImageInput ii) throws IOException { |
564 | 116 // just a do-nothing implementation |
117 return null; | |
118 } | |
119 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
120 public void rotate(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
121 // just a do-nothing implementation |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
122 } |
1 | 123 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
124 public void mirror(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
125 // just a do-nothing implementation |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
126 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
127 |
86 | 128 public void enhance(float mult, float add) throws ImageOpException { |
85 | 129 // just a do-nothing implementation |
130 } | |
131 | |
132 public boolean isSubimageSupported() { | |
86 | 133 // partial loading not supported per default |
85 | 134 return false; |
135 } | |
136 | |
588 | 137 public void loadSubimage(ImageInput ii, Rectangle region, int subsample) |
85 | 138 throws FileOpException { |
139 // empty implementation | |
140 } | |
141 | |
86 | 142 public void enhanceRGB(float[] rgbm, float[] rgba) |
143 throws ImageOpException { | |
144 // emtpy implementation | |
145 } | |
146 | |
829 | 147 public void colorOp(ColorOp op) throws ImageOpException { |
148 // emtpy implementation | |
149 } | |
150 | |
207 | 151 public void dispose() { |
464 | 152 // emtpy implementation |
153 } | |
154 | |
531 | 155 public Iterator<String> getSupportedFormats() { |
156 List<String> empty = new LinkedList<String>(); | |
464 | 157 return empty.iterator(); |
207 | 158 } |
533 | 159 |
160 public void crop(int xoff, int yoff, int width, int height) | |
161 throws ImageOpException { | |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
162 // emtpy implementation |
533 | 163 } |
164 | |
165 public Image getAwtImage() { | |
819
a23c4c15a6a8
clean up possible resource leaks. better behaviour with unknown image types.
robcast
parents:
596
diff
changeset
|
166 // emtpy implementation |
533 | 167 return null; |
168 } | |
169 | |
170 public int getHeight() { | |
570 | 171 ImageSize is = getSize(); |
172 if (is != null) { | |
173 return is.getHeight(); | |
174 } | |
533 | 175 return 0; |
176 } | |
207 | 177 |
533 | 178 public int getWidth() { |
570 | 179 ImageSize is = getSize(); |
180 if (is != null) { | |
181 return is.getWidth(); | |
182 } | |
533 | 183 return 0; |
184 } | |
185 | |
570 | 186 public ImageSize getSize() { |
187 return imgSize; | |
188 } | |
189 | |
588 | 190 public abstract void loadImage(ImageInput ii) throws FileOpException; |
533 | 191 |
588 | 192 public abstract void scale(double scaleX, double scaleY) throws ImageOpException; |
533 | 193 |
588 | 194 public abstract void writeImage(String mt, OutputStream ostream) |
906 | 195 throws ImageOpException, FileOpException; |
829 | 196 |
533 | 197 |
1 | 198 } |