annotate servlet/src/digilib/image/DocuImageImpl.java @ 260:46fc3f0bd7c2

Servlet version 1.21b1 - directory indexing got faster but less safe (configurable by "safe-dir-index") - mo=rawfile supplies filename - DigilibConfig takes File parameters - some SerialVersionUIDs (suggested by Eclipse)
author robcast
date Mon, 11 Oct 2004 21:23:00 +0200
parents 1a65d8e43620
children d5fe845db95f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
1 /* DocuImage -- General image interface class implementation
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
2
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
3 Digital Image Library servlet components
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
4
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
5 Copyright (C) 2001, 2002, 2003 Robert Casties (robcast@mail.berlios.de)
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
6
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify it
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
9 Free Software Foundation; either version 2 of the License, or (at your
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
10 option) any later version.
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
11
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
12 Please read license.txt for the full details. A copy of the GPL
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
13 may be found at http://www.gnu.org/copyleft/lgpl.html
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
14
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
16 along with this program; if not, write to the Free Software
73
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
18
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
19 */
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
20
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
21 package digilib.image;
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
22
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
23 import java.awt.Rectangle;
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
24
181
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
25 import org.apache.log4j.Logger;
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
26
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
27 import digilib.io.FileOpException;
159
e743b853efca servlet version 1.16a4
robcast
parents: 149
diff changeset
28 import digilib.io.ImageFile;
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
29
73
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
30 /** Simple abstract implementation of the <code>DocuImage</code> interface.
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
31 *
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
32 * This implementation provides basic functionality for the utility methods like
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
33 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
34 * <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
35 * <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
36 * implemented by derived classes.
73
3b8797fc3e90 New servlet version 1.5b.
robcast
parents: 1
diff changeset
37 */
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
38 public abstract class DocuImageImpl implements DocuImage {
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
39
181
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
40 /** logger */
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
41 protected Logger logger = Logger.getLogger(this.getClass());
afe7ff98bb71 Servlet version 1.18b1
robcast
parents: 159
diff changeset
42
79
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
43 /** Interpolation quality. */
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
44 protected int quality = 0;
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
45
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
46 /** epsilon for float comparisons. */
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
47 public final double epsilon = 1e-5;
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
48
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
49 /** image mime-type */
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
50 protected String mimeType = null;
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
51
79
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
52 /** Internal knownFileTypes. */
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
53 protected String[] knownFileTypes = { "jpg", "png", "gif", "tiff" };
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
54
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
55 /** Returns the list of image file types known to the DocuImage implementation.
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
56 *
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
57 * @return List of image file types. Strings are standard file extensions.
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
58 */
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
59 public String[] getKnownFileTypes() {
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
60 return knownFileTypes;
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
61 }
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
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
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
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
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
78
79
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
79 /** Crop and scale the current image.
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 {
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
96
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
04ad64b2137a Servlet version 1.14b1
robcast
parents: 122
diff changeset
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
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
102 public String getMimetype() {
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
103 return mimeType;
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
104 }
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
105
79
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
106 public void rotate(double angle) throws ImageOpException {
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
107 // just a do-nothing implementation
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
108 }
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
109
79
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
110 public void mirror(double angle) throws ImageOpException {
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
111 // just a do-nothing implementation
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
112 }
63c8186455c1 Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents: 73
diff changeset
113
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
114 public void enhance(float mult, float add) throws ImageOpException {
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
115 // just a do-nothing implementation
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
116 }
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
117
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
118 public boolean isSubimageSupported() {
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
119 // partial loading not supported per default
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
120 return false;
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
121 }
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
122
159
e743b853efca servlet version 1.16a4
robcast
parents: 149
diff changeset
123 public void loadSubimage(ImageFile f, Rectangle region, int subsample)
85
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
124 throws FileOpException {
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
125 // empty implementation
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
126 }
4e6757e8ccd4 New enhanced ImageLoader stuff.
robcast
parents: 79
diff changeset
127
86
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
128 public void enhanceRGB(float[] rgbm, float[] rgba)
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
129 throws ImageOpException {
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
130 // emtpy implementation
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
131 }
997ba69afb81 New version 1.8b1.
robcast
parents: 85
diff changeset
132
207
1a65d8e43620 Servlet version 1.18b9 -- cleanup and bugfixes
robcast
parents: 185
diff changeset
133 public void dispose() {
1a65d8e43620 Servlet version 1.18b9 -- cleanup and bugfixes
robcast
parents: 185
diff changeset
134 }
1a65d8e43620 Servlet version 1.18b9 -- cleanup and bugfixes
robcast
parents: 185
diff changeset
135
1
0ff3ede32060 Initial revision
robcast
parents:
diff changeset
136 }