Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImageImpl.java @ 86:997ba69afb81
New version 1.8b1.
With directory and file information cache.
With enhanceRGB method for color correction.
author | robcast |
---|---|
date | Sun, 09 Mar 2003 21:37:27 +0100 |
parents | 4e6757e8ccd4 |
children | a32e8c80e2f2 |
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 | |
86 | 23 import java.awt.Dimension; |
85 | 24 import java.awt.Rectangle; |
25 import java.io.File; | |
86 | 26 import java.io.IOException; |
85 | 27 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
28 import digilib.Utils; |
86 | 29 import digilib.io.DocuFile; |
85 | 30 import digilib.io.FileOpException; |
86 | 31 import digilib.io.FileOps; |
1 | 32 |
73 | 33 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
34 * | |
35 * This implementation provides basic functionality for the utility methods like | |
36 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like | |
37 * <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
|
38 * <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
|
39 * implemented by derived classes. |
73 | 40 */ |
1 | 41 public abstract class DocuImageImpl implements DocuImage { |
42 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
43 /** Internal utils object. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
44 protected Utils util = null; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
45 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
46 /** Interpolation quality. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
47 protected int quality = 0; |
85 | 48 |
86 | 49 /** epsilon for float comparisons. */ |
85 | 50 public final double epsilon = 1e-5; |
86 | 51 |
52 /** image mime-type */ | |
53 protected String mimeType = null; | |
1 | 54 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
55 /** Default constructor. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
56 public DocuImageImpl() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
57 util = new Utils(); |
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 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
60 /** Contructor taking an utils object. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
61 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
62 * @param u Utils object. |
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 public DocuImageImpl(Utils u) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
65 util = u; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
66 } |
1 | 67 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
68 /** Set local Utils object. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
69 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
70 * @param u Utils object. |
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 public void setUtils(Utils u) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 util = u; |
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 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
76 /** Internal knownFileTypes. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 protected String[] knownFileTypes = { "jpg", "png", "gif", "tiff" }; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
78 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
79 /** 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
|
80 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
81 * @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
|
82 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
83 public String[] getKnownFileTypes() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
84 return knownFileTypes; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
85 } |
1 | 86 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
87 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
88 * Returns the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 * @return int |
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 getQuality() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
92 return quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
93 } |
1 | 94 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
95 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
96 * Sets the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
97 * @param quality The quality to set |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
98 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
99 public void setQuality(int quality) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
100 this.quality = quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
101 } |
1 | 102 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
103 /** Crop and scale the current image. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
104 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
105 * 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
|
106 * 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
|
107 * interpolation quality qual (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
108 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
109 * @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
|
110 * @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
|
111 * @param width Width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
112 * @param height Height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
113 * @param scale Scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
114 * @param qual Interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
115 * @throws ImageOpException Exception thrown on any error. |
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 cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
118 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
|
119 throws ImageOpException { |
1 | 120 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
121 setQuality(qual); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
122 crop(x_off, y_off, width, height); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
123 scale(scale); |
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 |
86 | 126 /* this is a rather stupid implementation, eventually loading the whole file. */ |
127 public boolean checkFile(DocuFile f) throws IOException { | |
128 loadImage(f.getFile()); | |
129 int w = getWidth(); | |
130 int h = getHeight(); | |
131 Dimension s = new Dimension(w, h); | |
132 f.setSize(s); | |
133 String m = FileOps.mimeForFile(f.getFile()); | |
134 mimeType = m; | |
135 f.setMimetype(m); | |
136 return true; | |
137 } | |
138 | |
139 public String getMimetype() { | |
140 return mimeType; | |
141 } | |
142 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
143 public void rotate(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
144 // just a do-nothing implementation |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
145 } |
1 | 146 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
147 public void mirror(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
148 // just a do-nothing implementation |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
149 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
150 |
86 | 151 public void enhance(float mult, float add) throws ImageOpException { |
85 | 152 // just a do-nothing implementation |
153 } | |
154 | |
155 public boolean isSubimageSupported() { | |
86 | 156 // partial loading not supported per default |
85 | 157 return false; |
158 } | |
159 | |
160 public void loadSubimage(File f, Rectangle region, int subsample) | |
161 throws FileOpException { | |
162 // empty implementation | |
163 } | |
164 | |
86 | 165 public void enhanceRGB(float[] rgbm, float[] rgba) |
166 throws ImageOpException { | |
167 // emtpy implementation | |
168 } | |
169 | |
1 | 170 } |