Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImageImpl.java @ 200:1cbd73aa5b48
latest servlet version 1.18b7 together with jai libs
| author | robcast |
|---|---|
| date | Mon, 26 Jan 2004 18:19:11 +0100 |
| parents | 91f28e4fee8f |
| children | 1a65d8e43620 |
| 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 */ |
| 41 protected Logger logger = Logger.getLogger(this.getClass()); | |
| 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 /** 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 | 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 |
|
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 | 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 | 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 | 102 public String getMimetype() { |
| 103 return mimeType; | |
| 104 } | |
| 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 | 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 | 114 public void enhance(float mult, float add) throws ImageOpException { |
| 85 | 115 // just a do-nothing implementation |
| 116 } | |
| 117 | |
| 118 public boolean isSubimageSupported() { | |
| 86 | 119 // partial loading not supported per default |
| 85 | 120 return false; |
| 121 } | |
| 122 | |
| 159 | 123 public void loadSubimage(ImageFile f, Rectangle region, int subsample) |
| 85 | 124 throws FileOpException { |
| 125 // empty implementation | |
| 126 } | |
| 127 | |
| 86 | 128 public void enhanceRGB(float[] rgbm, float[] rgba) |
| 129 throws ImageOpException { | |
| 130 // emtpy implementation | |
| 131 } | |
| 132 | |
| 1 | 133 } |
