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