Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImageImpl.java @ 562:baaa5bab5e16 digilibPDF
trying to reduce use of ImageOps
| author | robcast |
|---|---|
| date | Fri, 17 Dec 2010 16:24:03 +0100 |
| parents | a5168978555f |
| children | 4c51d71aef13 |
| 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 | |
| 533 | 23 import java.awt.Image; |
| 85 | 24 import java.awt.Rectangle; |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
25 import java.io.File; |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
26 import java.io.IOException; |
| 533 | 27 import java.io.OutputStream; |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
28 import java.io.RandomAccessFile; |
| 464 | 29 import java.util.Iterator; |
| 30 import java.util.LinkedList; | |
| 31 import java.util.List; | |
| 85 | 32 |
| 181 | 33 import org.apache.log4j.Logger; |
| 464 | 34 import org.marcoschmidt.image.ImageInfo; |
| 181 | 35 |
| 36 import digilib.io.FileOpException; | |
| 159 | 37 import digilib.io.ImageFile; |
| 1 | 38 |
| 73 | 39 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
| 40 * | |
| 41 * This implementation provides basic functionality for the utility methods like | |
| 562 | 42 * <code>getKnownFileTypes</code>. Image methods like |
| 73 | 43 * <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
|
44 * <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
|
45 * implemented by derived classes. |
| 73 | 46 */ |
| 1 | 47 public abstract class DocuImageImpl implements DocuImage { |
| 48 | |
| 181 | 49 /** logger */ |
|
469
11e11fe4d680
Improved performance of JAIDocuImage for large images
robcast
parents:
464
diff
changeset
|
50 protected static final Logger logger = Logger.getLogger(DocuImage.class); |
| 181 | 51 |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
52 /** Interpolation quality. */ |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
53 protected int quality = 0; |
| 85 | 54 |
| 86 | 55 /** epsilon for float comparisons. */ |
| 85 | 56 public final double epsilon = 1e-5; |
| 86 | 57 |
| 58 /** image mime-type */ | |
| 59 protected String mimeType = null; | |
| 1 | 60 |
|
79
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 * Returns the quality. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
63 * @return int |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
64 */ |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
65 public int getQuality() { |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
66 return quality; |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
67 } |
| 1 | 68 |
|
79
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 * Sets the quality. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
71 * @param quality The quality to set |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
72 */ |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 public void setQuality(int quality) { |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
74 this.quality = quality; |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
75 } |
| 1 | 76 |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
77 /** Check image size and type and store in ImageFile f */ |
| 562 | 78 public ImageFile identify(ImageFile imgf) throws IOException { |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
79 // fileset to store the information |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
80 File f = imgf.getFile(); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
81 if (f == null) { |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
82 throw new IOException("File not found!"); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
83 } |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
84 RandomAccessFile raf = new RandomAccessFile(f, "r"); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
85 // set up ImageInfo object |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
86 ImageInfo iif = new ImageInfo(); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
87 iif.setInput(raf); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
88 iif.setCollectComments(false); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
89 iif.setDetermineImageNumber(false); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
90 logger.debug("identifying (ImageInfo) " + f); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
91 // try with ImageInfo first |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
92 if (iif.check()) { |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
93 ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight()); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
94 imgf.setSize(d); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
95 imgf.setMimetype(iif.getMimeType()); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
96 //logger.debug(" format:"+iif.getFormatName()); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
97 raf.close(); |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
98 logger.debug("image size: " + imgf.getSize()); |
| 562 | 99 return imgf; |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
100 } |
| 562 | 101 return null; |
|
462
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
102 } |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
103 |
|
03ff7238c9d4
second try for flashpix support (doesn't work currently...)
robcast
parents:
278
diff
changeset
|
104 /** Crop and scale the current image. |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
105 * |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
106 * 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
|
107 * 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
|
108 * interpolation quality qual (0=worst). |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
109 * |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
110 * @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
|
111 * @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
|
112 * @param width Width of the crop rectangle in pixel. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
113 * @param height Height of the crop rectangle in pixel. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
114 * @param scale Scaling factor. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
115 * @param qual Interpolation quality (0=worst). |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
116 * @throws ImageOpException Exception thrown on any error. |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
117 */ |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
118 public void cropAndScale( |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
119 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
|
120 throws ImageOpException { |
| 562 | 121 // default implementation: first crop, then scale |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
122 setQuality(qual); |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
123 crop(x_off, y_off, width, height); |
| 149 | 124 scale(scale, scale); |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
125 } |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
126 |
| 86 | 127 public String getMimetype() { |
| 128 return mimeType; | |
| 129 } | |
| 130 | |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
131 public void rotate(double angle) throws ImageOpException { |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
132 // just a do-nothing implementation |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
133 } |
| 1 | 134 |
|
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
135 public void mirror(double angle) throws ImageOpException { |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
136 // just a do-nothing implementation |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
137 } |
|
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
138 |
| 86 | 139 public void enhance(float mult, float add) throws ImageOpException { |
| 85 | 140 // just a do-nothing implementation |
| 141 } | |
| 142 | |
| 143 public boolean isSubimageSupported() { | |
| 86 | 144 // partial loading not supported per default |
| 85 | 145 return false; |
| 146 } | |
| 147 | |
| 159 | 148 public void loadSubimage(ImageFile f, Rectangle region, int subsample) |
| 85 | 149 throws FileOpException { |
| 150 // empty implementation | |
| 151 } | |
| 152 | |
| 86 | 153 public void enhanceRGB(float[] rgbm, float[] rgba) |
| 154 throws ImageOpException { | |
| 155 // emtpy implementation | |
| 156 } | |
| 157 | |
| 207 | 158 public void dispose() { |
| 464 | 159 // emtpy implementation |
| 160 } | |
| 161 | |
| 531 | 162 public Iterator<String> getSupportedFormats() { |
| 163 List<String> empty = new LinkedList<String>(); | |
| 464 | 164 return empty.iterator(); |
| 207 | 165 } |
| 533 | 166 |
| 167 public void crop(int xoff, int yoff, int width, int height) | |
| 168 throws ImageOpException { | |
| 169 // TODO Auto-generated method stub | |
| 170 } | |
| 171 | |
| 172 public Image getAwtImage() { | |
| 173 // TODO Auto-generated method stub | |
| 174 return null; | |
| 175 } | |
| 176 | |
| 177 public int getHeight() { | |
| 178 // TODO Auto-generated method stub | |
| 179 return 0; | |
| 180 } | |
| 207 | 181 |
| 533 | 182 public int getWidth() { |
| 183 // TODO Auto-generated method stub | |
| 184 return 0; | |
| 185 } | |
| 186 | |
| 187 public void loadImage(ImageFile f) throws FileOpException { | |
| 188 // TODO Auto-generated method stub | |
| 189 | |
| 190 } | |
| 191 | |
| 192 public void scale(double scaleX, double scaleY) throws ImageOpException { | |
| 193 // TODO Auto-generated method stub | |
| 194 | |
| 195 } | |
| 196 | |
| 197 public void writeImage(String mt, OutputStream ostream) | |
| 198 throws FileOpException { | |
| 199 // TODO Auto-generated method stub | |
| 200 } | |
| 201 | |
| 1 | 202 } |
