Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImageImpl.java @ 355:4a45cd965133
Servlet version 1.5.9e
- fixed a bug reading directories that don't exist anymore
author | robcast |
---|---|
date | Tue, 25 Oct 2005 20:39:44 +0200 |
parents | d5fe845db95f |
children | 03ff7238c9d4 |
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 | |
85 | 23 import java.awt.Rectangle; |
24 | |
181 | 25 import org.apache.log4j.Logger; |
26 | |
27 import digilib.io.FileOpException; | |
159 | 28 import digilib.io.ImageFile; |
1 | 29 |
73 | 30 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
31 * | |
32 * This implementation provides basic functionality for the utility methods like | |
33 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like | |
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 | 37 */ |
1 | 38 public abstract class DocuImageImpl implements DocuImage { |
39 | |
181 | 40 /** logger */ |
278 | 41 protected static Logger logger = Logger.getLogger(DocuImage.class); |
181 | 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 | 45 |
86 | 46 /** epsilon for float comparisons. */ |
85 | 47 public final double epsilon = 1e-5; |
86 | 48 |
49 /** image mime-type */ | |
50 protected String mimeType = null; | |
1 | 51 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
52 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
53 * Returns the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
54 * @return int |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
55 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
56 public int getQuality() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
57 return quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
58 } |
1 | 59 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
60 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
61 * Sets the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
62 * @param quality The quality to set |
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 void setQuality(int quality) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
65 this.quality = quality; |
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 /** Crop and scale the current image. |
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 * 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
|
71 * 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
|
72 * interpolation quality qual (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
74 * @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
|
75 * @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
|
76 * @param width Width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 * @param height Height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
78 * @param scale Scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
79 * @param qual Interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
80 * @throws ImageOpException Exception thrown on any error. |
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 public void cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
83 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
|
84 throws ImageOpException { |
1 | 85 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
86 setQuality(qual); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
87 crop(x_off, y_off, width, height); |
149 | 88 scale(scale, scale); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
90 |
86 | 91 public String getMimetype() { |
92 return mimeType; | |
93 } | |
94 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
95 public void rotate(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
96 // just a do-nothing implementation |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
97 } |
1 | 98 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
99 public void mirror(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
100 // just a do-nothing implementation |
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 |
86 | 103 public void enhance(float mult, float add) throws ImageOpException { |
85 | 104 // just a do-nothing implementation |
105 } | |
106 | |
107 public boolean isSubimageSupported() { | |
86 | 108 // partial loading not supported per default |
85 | 109 return false; |
110 } | |
111 | |
159 | 112 public void loadSubimage(ImageFile f, Rectangle region, int subsample) |
85 | 113 throws FileOpException { |
114 // empty implementation | |
115 } | |
116 | |
86 | 117 public void enhanceRGB(float[] rgbm, float[] rgba) |
118 throws ImageOpException { | |
119 // emtpy implementation | |
120 } | |
121 | |
207 | 122 public void dispose() { |
123 } | |
124 | |
1 | 125 } |