Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/DocuImageImpl.java @ 566:50f291d808b1 digilibPDF
starting stream support
author | robcast |
---|---|
date | Mon, 20 Dec 2010 11:57:55 +0100 |
parents | 4c51d71aef13 |
children | beeedf90cb81 |
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.IOException; |
533 | 26 import java.io.OutputStream; |
464 | 27 import java.util.Iterator; |
28 import java.util.LinkedList; | |
29 import java.util.List; | |
85 | 30 |
181 | 31 import org.apache.log4j.Logger; |
32 | |
33 import digilib.io.FileOpException; | |
159 | 34 import digilib.io.ImageFile; |
566 | 35 import digilib.io.ImageInput; |
1 | 36 |
73 | 37 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
38 * | |
39 * This implementation provides basic functionality for the utility methods like | |
562 | 40 * <code>getKnownFileTypes</code>. Image methods like |
73 | 41 * <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
|
42 * <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
|
43 * implemented by derived classes. |
73 | 44 */ |
1 | 45 public abstract class DocuImageImpl implements DocuImage { |
46 | |
181 | 47 /** logger */ |
469
11e11fe4d680
Improved performance of JAIDocuImage for large images
robcast
parents:
464
diff
changeset
|
48 protected static final Logger logger = Logger.getLogger(DocuImage.class); |
181 | 49 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
50 /** Interpolation quality. */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
51 protected int quality = 0; |
85 | 52 |
86 | 53 /** epsilon for float comparisons. */ |
85 | 54 public final double epsilon = 1e-5; |
86 | 55 |
56 /** image mime-type */ | |
57 protected String mimeType = null; | |
1 | 58 |
79
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 * Returns the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
61 * @return int |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
62 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
63 public int getQuality() { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
64 return quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
65 } |
1 | 66 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
67 /** |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
68 * Sets the quality. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
69 * @param quality The quality to set |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
70 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
71 public void setQuality(int quality) { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
72 this.quality = quality; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
73 } |
1 | 74 |
564 | 75 /** Crop and scale the current image. |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
76 * |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
77 * 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
|
78 * 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
|
79 * interpolation quality qual (0=worst). |
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 * @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
|
82 * @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
|
83 * @param width Width of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
84 * @param height Height of the crop rectangle in pixel. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
85 * @param scale Scaling factor. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
86 * @param qual Interpolation quality (0=worst). |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
87 * @throws ImageOpException Exception thrown on any error. |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
88 */ |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
89 public void cropAndScale( |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
90 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
|
91 throws ImageOpException { |
562 | 92 // default implementation: first crop, then scale |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
93 setQuality(qual); |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
94 crop(x_off, y_off, width, height); |
149 | 95 scale(scale, scale); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
96 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
97 |
86 | 98 public String getMimetype() { |
99 return mimeType; | |
100 } | |
101 | |
564 | 102 /* (non-Javadoc) |
103 * @see digilib.image.DocuImage#identify(digilib.io.ImageFile) | |
104 */ | |
566 | 105 public ImageInput identify(ImageFile imgf) throws IOException { |
564 | 106 // just a do-nothing implementation |
107 return null; | |
108 } | |
109 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
110 public void rotate(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 } |
1 | 113 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
114 public void mirror(double angle) throws ImageOpException { |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
115 // just a do-nothing implementation |
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 |
86 | 118 public void enhance(float mult, float add) throws ImageOpException { |
85 | 119 // just a do-nothing implementation |
120 } | |
121 | |
122 public boolean isSubimageSupported() { | |
86 | 123 // partial loading not supported per default |
85 | 124 return false; |
125 } | |
126 | |
159 | 127 public void loadSubimage(ImageFile f, Rectangle region, int subsample) |
85 | 128 throws FileOpException { |
129 // empty implementation | |
130 } | |
131 | |
86 | 132 public void enhanceRGB(float[] rgbm, float[] rgba) |
133 throws ImageOpException { | |
134 // emtpy implementation | |
135 } | |
136 | |
207 | 137 public void dispose() { |
464 | 138 // emtpy implementation |
139 } | |
140 | |
531 | 141 public Iterator<String> getSupportedFormats() { |
142 List<String> empty = new LinkedList<String>(); | |
464 | 143 return empty.iterator(); |
207 | 144 } |
533 | 145 |
146 public void crop(int xoff, int yoff, int width, int height) | |
147 throws ImageOpException { | |
148 // TODO Auto-generated method stub | |
149 } | |
150 | |
151 public Image getAwtImage() { | |
152 // TODO Auto-generated method stub | |
153 return null; | |
154 } | |
155 | |
156 public int getHeight() { | |
157 // TODO Auto-generated method stub | |
158 return 0; | |
159 } | |
207 | 160 |
533 | 161 public int getWidth() { |
162 // TODO Auto-generated method stub | |
163 return 0; | |
164 } | |
165 | |
166 public void loadImage(ImageFile f) throws FileOpException { | |
167 // TODO Auto-generated method stub | |
168 | |
169 } | |
170 | |
171 public void scale(double scaleX, double scaleY) throws ImageOpException { | |
172 // TODO Auto-generated method stub | |
173 | |
174 } | |
175 | |
176 public void writeImage(String mt, OutputStream ostream) | |
177 throws FileOpException { | |
178 // TODO Auto-generated method stub | |
179 } | |
180 | |
1 | 181 } |