Mercurial > hg > digilib-old
comparison servlet/src/digilib/image/DocuImageImpl.java @ 79:63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
* mirroring
* contrast/brightness
* rotation (not finished)
author | robcast |
---|---|
date | Mon, 03 Feb 2003 16:04:53 +0100 |
parents | 3b8797fc3e90 |
children | 4e6757e8ccd4 |
comparison
equal
deleted
inserted
replaced
78:e0dcac9c66fa | 79:63c8186455c1 |
---|---|
18 | 18 |
19 */ | 19 */ |
20 | 20 |
21 package digilib.image; | 21 package digilib.image; |
22 | 22 |
23 import java.io.*; | 23 import digilib.Utils; |
24 import javax.servlet.ServletResponse; | |
25 | |
26 import digilib.*; | |
27 import digilib.io.*; | |
28 | 24 |
29 /** Simple abstract implementation of the <code>DocuImage</code> interface. | 25 /** Simple abstract implementation of the <code>DocuImage</code> interface. |
30 * | 26 * |
31 * This implementation provides basic functionality for the utility methods like | 27 * This implementation provides basic functionality for the utility methods like |
32 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like | 28 * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like |
33 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>, | 29 * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>, |
34 * <code>getHeight</code> and <code>cropAndScale</code> must be implemented by | 30 * <code>getHeight</code>, <code>crop</code> and <code>scale</code> must be |
35 * derived classes. | 31 * implemented by derived classes. |
36 */ | 32 */ |
37 public abstract class DocuImageImpl implements DocuImage { | 33 public abstract class DocuImageImpl implements DocuImage { |
38 | 34 |
39 /** Internal utils object. */ | 35 /** Internal utils object. */ |
40 protected Utils util = null; | 36 protected Utils util = null; |
41 | 37 |
42 /** Default constructor. */ | 38 /** Interpolation quality. */ |
43 public DocuImageImpl() { | 39 protected int quality = 0; |
44 util = new Utils(); | |
45 } | |
46 | 40 |
47 /** Contructor taking an utils object. | 41 /** Default constructor. */ |
48 * | 42 public DocuImageImpl() { |
49 * @param u Utils object. | 43 util = new Utils(); |
50 */ | 44 } |
51 public DocuImageImpl(Utils u) { | |
52 util = u; | |
53 } | |
54 | 45 |
55 /** Set local Utils object. | 46 /** Contructor taking an utils object. |
56 * | 47 * |
57 * @param u Utils object. | 48 * @param u Utils object. |
58 */ | 49 */ |
59 public void setUtils(Utils u) { | 50 public DocuImageImpl(Utils u) { |
60 util = u; | 51 util = u; |
61 } | 52 } |
62 | 53 |
63 /** Internal knownFileTypes. */ | 54 /** Set local Utils object. |
64 protected String[] knownFileTypes = {"jpg", "png", "gif", "tiff"}; | 55 * |
56 * @param u Utils object. | |
57 */ | |
58 public void setUtils(Utils u) { | |
59 util = u; | |
60 } | |
65 | 61 |
66 /** Returns the list of image file types known to the DocuImage implementation. | 62 /** Internal knownFileTypes. */ |
67 * | 63 protected String[] knownFileTypes = { "jpg", "png", "gif", "tiff" }; |
68 * @return List of image file types. Strings are standard file extensions. | |
69 */ | |
70 public String[] getKnownFileTypes() { | |
71 return knownFileTypes; | |
72 } | |
73 | 64 |
65 /** Returns the list of image file types known to the DocuImage implementation. | |
66 * | |
67 * @return List of image file types. Strings are standard file extensions. | |
68 */ | |
69 public String[] getKnownFileTypes() { | |
70 return knownFileTypes; | |
71 } | |
74 | 72 |
75 public abstract void loadImage(File f) throws FileOpException; | 73 /** |
76 public abstract void writeImage(String mt, ServletResponse res) throws FileOpException; | 74 * Returns the quality. |
77 public abstract int getWidth(); | 75 * @return int |
78 public abstract int getHeight(); | 76 */ |
79 public abstract void cropAndScale(int x_off, int y_off, int width, int height, float scale, int qual) throws ImageOpException; | 77 public int getQuality() { |
78 return quality; | |
79 } | |
80 | |
81 /** | |
82 * Sets the quality. | |
83 * @param quality The quality to set | |
84 */ | |
85 public void setQuality(int quality) { | |
86 this.quality = quality; | |
87 } | |
88 | |
89 /** Crop and scale the current image. | |
90 * | |
91 * The current image is cropped to a rectangle of width, height at position | |
92 * x_off, y_off. The resulting image is scaled by the factor scale using the | |
93 * interpolation quality qual (0=worst). | |
94 * | |
95 * @param x_off X offset of the crop rectangle in pixel. | |
96 * @param y_off Y offset of the crop rectangle in pixel. | |
97 * @param width Width of the crop rectangle in pixel. | |
98 * @param height Height of the crop rectangle in pixel. | |
99 * @param scale Scaling factor. | |
100 * @param qual Interpolation quality (0=worst). | |
101 * @throws ImageOpException Exception thrown on any error. | |
102 */ | |
103 public void cropAndScale( | |
104 int x_off, int y_off, int width, int height, double scale, int qual) | |
105 throws ImageOpException { | |
106 | |
107 setQuality(qual); | |
108 crop(x_off, y_off, width, height); | |
109 scale(scale); | |
110 } | |
111 | |
112 public void rotate(double angle) throws ImageOpException { | |
113 // just a do-nothing implementation | |
114 } | |
115 | |
116 public void mirror(double angle) throws ImageOpException { | |
117 // just a do-nothing implementation | |
118 } | |
119 | |
120 public void enhance(double mult, double add) throws ImageOpException { | |
121 // just a do-nothing implementation | |
122 } | |
123 | |
80 } | 124 } |