bloritsch 00/12/04 16:23:11
Modified: src/org/apache/cocoon/components/image Tag: xml-cocoon2
JAIJPEGEncoder.java
Log:
Slight formatting, and log messages. Still trying to locate 500 ok error for
WebSphere.
Revision Changes Path
No revision
No revision
1.1.2.7 +35 -8
xml-cocoon/src/org/apache/cocoon/components/image/Attic/JAIJPEGEncoder.java
Index: JAIJPEGEncoder.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/image/Attic/JAIJPEGEncoder.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- JAIJPEGEncoder.java 2000/11/26 21:48:02 1.1.2.6
+++ JAIJPEGEncoder.java 2000/12/05 00:23:11 1.1.2.7
@@ -32,27 +32,54 @@
private Logger log = LogKit.getLoggerFor("cocoon");
/** The quality level. The default is 0.75 (high quality) */
- private float quality;
+ private float quality = -1.0f;
+ /**
+ * Configure the JAIJPEGEncoder. The implementation enforces proper
+ * semantics on Configurable (write once), and as such enforces no
+ * race conditions on <code>quality</code>.
+ */
public void configure(Configuration conf) throws ConfigurationException {
- // Using the passed Configuration, generate a far more friendly
Parameters object.
- Parameters p = Parameters.fromConfiguration(conf);
- quality = p.getParameterAsFloat("quality", 0.75f);
- log.debug("Quality set to " + quality);
+ if (quality == -1.0f) {
+ // Using the passed Configuration, generate a far more friendly
Parameters object.
+ Parameters p = Parameters.fromConfiguration(conf);
+ quality = p.getParameterAsFloat("quality", 0.75f);
+ log.debug("Quality set to " + quality);
+ }
}
public String getMimeType() {
return "image/jpeg";
}
+ /**
+ * This method starts the whole shebang. The JPEG encoder requires
+ * 3 band byte-based images, so this encoder checks to see if the
+ * type is correct. If the image type is not correct, it creates
+ * a new image with the proper type.
+ *
+ * @param image The <code>BufferedImage</code> we are getting ready
+ * to serialize.
+ * @param out The <code>OutputStream</code> we are serializing.
+ */
public void encode(BufferedImage image, OutputStream out) throws
IOException {
// The JPEG encoder requires 3 band byte-based images, so create a
new image
// TODO: find a faster way of doing this
int w = image.getWidth();
int h = image.getHeight();
- BufferedImage noalpha = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR);
- Raster raster = image.getRaster().createChild(0, 0, w, h, 0, 0, new
int[] {0, 1, 2});
- noalpha.setData(raster);
+ BufferedImage noalpha;
+
+ if (image.getType() == BufferedImage.TYPE_3BYTE_BGR) {
+ noalpha = image;
+ } else {
+ noalpha = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
+ Raster raster = image.getRaster().createChild(0, 0, w, h, 0, 0,
new int[] {0, 1, 2});
+ noalpha.setData(raster);
+ }
+
+ // Make sure quality is set properly: if configure() has not
+ // been called then too bad.
+ if (quality == -1.0f) quality = 0.75f;
JPEGEncodeParam param = new JPEGEncodeParam();
param.setQuality(quality);