comparison common/src/main/java/digilib/image/DocuImageImpl.java @ 1032:4e368c85cce4

CLOSED - # 22: wrong contrast setting. dito #23 (at least on OSX 10.7) mostly juggling color channels. also separate version number for DocuImage class.
author robcast
date Sat, 10 Mar 2012 23:09:38 +0100
parents 28d007673346
children
comparison
equal deleted inserted replaced
1031:e077f52205a7 1032:4e368c85cce4
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19 */ 19 */
20 20
21 package digilib.image; 21 package digilib.image;
22 22
23 import java.awt.Image; 23 import java.awt.Image;
24 import java.awt.Rectangle; 24 import java.awt.Rectangle;
26 import java.io.OutputStream; 26 import java.io.OutputStream;
27 import java.util.Iterator; 27 import java.util.Iterator;
28 import java.util.LinkedList; 28 import java.util.LinkedList;
29 import java.util.List; 29 import java.util.List;
30 30
31
32 import org.apache.log4j.Logger; 31 import org.apache.log4j.Logger;
33 32
34 import digilib.io.FileOpException; 33 import digilib.io.FileOpException;
35 import digilib.io.ImageInput; 34 import digilib.io.ImageInput;
36 import digilib.util.ImageSize; 35 import digilib.util.ImageSize;
37 36
38 /** Simple abstract implementation of the <code>DocuImage</code> interface. 37 /**
39 * 38 * Simple abstract implementation of the <code>DocuImage</code> interface.
39 *
40 * This implementation provides basic functionality for the utility methods like 40 * This implementation provides basic functionality for the utility methods like
41 * <code>getKnownFileTypes</code>. Image methods like 41 * <code>getKnownFileTypes</code>. Image methods like <code>loadImage</code>,
42 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>, 42 * <code>writeImage</code>, <code>getWidth</code>, <code>getHeight</code>,
43 * <code>getHeight</code>, <code>crop</code> and <code>scale</code> must be 43 * <code>crop</code> and <code>scale</code> must be implemented by derived
44 * implemented by derived classes. 44 * classes.
45 */ 45 */
46 public abstract class DocuImageImpl implements DocuImage { 46 public abstract class DocuImageImpl implements DocuImage {
47 47
48 /** logger */ 48 /** DocuImage version */
49 protected static final Logger logger = Logger.getLogger(DocuImage.class); 49 public static final String version = "DocuImageImpl 2.1";
50 50
51 /** Interpolation quality. */ 51 /** logger */
52 protected int quality = 0; 52 protected static final Logger logger = Logger.getLogger(DocuImage.class);
53 53
54 /** epsilon for float comparisons. */ 54 /** Interpolation quality. */
55 public static final double epsilon = 1e-5; 55 protected int quality = 0;
56 56
57 /** image size */ 57 /** epsilon for float comparisons. */
58 public static final double epsilon = 1e-5;
59
60 /** image size */
58 protected ImageSize imgSize = null; 61 protected ImageSize imgSize = null;
59 62
60 /** ImageInput that was read */ 63 /** ImageInput that was read */
61 protected ImageInput input; 64 protected ImageInput input;
62 65
63 /** 66 /**
64 * Returns the quality. 67 * Returns the version.
65 * @return int 68 * @return the version
66 */ 69 */
67 public int getQuality() { 70 public String getVersion() {
68 return quality; 71 return version;
69 } 72 }
70 73
71 /** 74 /**
72 * Sets the quality. 75 * Returns the quality.
73 * @param quality The quality to set 76 *
74 */ 77 * @return int
75 public void setQuality(int quality) { 78 */
76 this.quality = quality; 79 public int getQuality() {
77 } 80 return quality;
78 81 }
79 /** Crop and scale the current image. 82
80 * 83 /**
81 * The current image is cropped to a rectangle of width, height at position 84 * Sets the quality.
82 * x_off, y_off. The resulting image is scaled by the factor scale using the 85 *
83 * interpolation quality qual (0=worst). 86 * @param quality
84 * 87 * The quality to set
85 * @param x_off X offset of the crop rectangle in pixel. 88 */
86 * @param y_off Y offset of the crop rectangle in pixel. 89 public void setQuality(int quality) {
87 * @param width Width of the crop rectangle in pixel. 90 this.quality = quality;
88 * @param height Height of the crop rectangle in pixel. 91 }
89 * @param scale Scaling factor. 92
90 * @param qual Interpolation quality (0=worst). 93 /**
91 * @throws ImageOpException Exception thrown on any error. 94 * Crop and scale the current image.
92 */ 95 *
93 public void cropAndScale( 96 * The current image is cropped to a rectangle of width, height at position
94 int x_off, int y_off, int width, int height, double scale, int qual) 97 * x_off, y_off. The resulting image is scaled by the factor scale using the
95 throws ImageOpException { 98 * interpolation quality qual (0=worst).
96 // default implementation: first crop, then scale 99 *
97 setQuality(qual); 100 * @param x_off
98 crop(x_off, y_off, width, height); 101 * X offset of the crop rectangle in pixel.
99 scale(scale, scale); 102 * @param y_off
100 } 103 * Y offset of the crop rectangle in pixel.
101 104 * @param width
102 /* (non-Javadoc) 105 * Width of the crop rectangle in pixel.
103 * @see digilib.image.DocuImage#getMimetype() 106 * @param height
104 */ 107 * Height of the crop rectangle in pixel.
105 public String getMimetype() { 108 * @param scale
106 if (input != null) { 109 * Scaling factor.
107 return input.getMimetype(); 110 * @param qual
108 } 111 * Interpolation quality (0=worst).
109 return null; 112 * @throws ImageOpException
110 } 113 * Exception thrown on any error.
111 114 */
112 /* (non-Javadoc) 115 public void cropAndScale(int x_off, int y_off, int width, int height, double scale, int qual) throws ImageOpException {
116 // default implementation: first crop, then scale
117 setQuality(qual);
118 crop(x_off, y_off, width, height);
119 scale(scale, scale);
120 }
121
122 /*
123 * (non-Javadoc)
124 *
125 * @see digilib.image.DocuImage#getMimetype()
126 */
127 public String getMimetype() {
128 if (input != null) {
129 return input.getMimetype();
130 }
131 return null;
132 }
133
134 /*
135 * (non-Javadoc)
136 *
113 * @see digilib.image.DocuImage#identify(digilib.io.ImageFile) 137 * @see digilib.image.DocuImage#identify(digilib.io.ImageFile)
114 */ 138 */
115 public ImageInput identify(ImageInput ii) throws IOException { 139 public ImageInput identify(ImageInput ii) throws IOException {
116 // just a do-nothing implementation 140 // just a do-nothing implementation
117 return null; 141 return null;
118 } 142 }
119 143
120 public void rotate(double angle) throws ImageOpException { 144 public void rotate(double angle) throws ImageOpException {
121 // just a do-nothing implementation 145 // just a do-nothing implementation
122 } 146 }
123 147
124 public void mirror(double angle) throws ImageOpException { 148 public void mirror(double angle) throws ImageOpException {
125 // just a do-nothing implementation 149 // just a do-nothing implementation
126 } 150 }
127 151
128 public void enhance(float mult, float add) throws ImageOpException { 152 public void enhance(float mult, float add) throws ImageOpException {
129 // just a do-nothing implementation 153 // just a do-nothing implementation
130 } 154 }
131 155
132 public boolean isSubimageSupported() { 156 public boolean isSubimageSupported() {
133 // partial loading not supported per default 157 // partial loading not supported per default
134 return false; 158 return false;
135 } 159 }
136 160
137 public void loadSubimage(ImageInput ii, Rectangle region, int subsample) 161 public void loadSubimage(ImageInput ii, Rectangle region, int subsample) throws FileOpException {
138 throws FileOpException { 162 // empty implementation
139 // empty implementation 163 }
140 } 164
141 165 public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException {
142 public void enhanceRGB(float[] rgbm, float[] rgba) 166 // emtpy implementation
143 throws ImageOpException { 167 }
144 // emtpy implementation 168
145 } 169 public void colorOp(ColorOp op) throws ImageOpException {
146 170 // emtpy implementation
147 public void colorOp(ColorOp op) throws ImageOpException { 171 }
148 // emtpy implementation 172
149 } 173 public void dispose() {
150 174 // emtpy implementation
151 public void dispose() { 175 }
152 // emtpy implementation 176
153 } 177 public Iterator<String> getSupportedFormats() {
154 178 List<String> empty = new LinkedList<String>();
155 public Iterator<String> getSupportedFormats() { 179 return empty.iterator();
156 List<String> empty = new LinkedList<String>(); 180 }
157 return empty.iterator(); 181
158 } 182 public void crop(int xoff, int yoff, int width, int height) throws ImageOpException {
159
160 public void crop(int xoff, int yoff, int width, int height)
161 throws ImageOpException {
162 // emtpy implementation 183 // emtpy implementation
163 } 184 }
164 185
165 public Image getAwtImage() { 186 public Image getAwtImage() {
166 // emtpy implementation 187 // emtpy implementation
189 210
190 public abstract void loadImage(ImageInput ii) throws FileOpException; 211 public abstract void loadImage(ImageInput ii) throws FileOpException;
191 212
192 public abstract void scale(double scaleX, double scaleY) throws ImageOpException; 213 public abstract void scale(double scaleX, double scaleY) throws ImageOpException;
193 214
194 public abstract void writeImage(String mt, OutputStream ostream) 215 public abstract void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException;
195 throws ImageOpException, FileOpException; 216
196
197
198 } 217 }