DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36326>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36326





------- Additional Comments From [EMAIL PROTECTED]  2005-09-01 23:41 -------
(From update of attachment 16165)
>Index: ImageReader.java
>===================================================================
>--- ImageReader.java   (revision 239426)
>+++ ImageReader.java   (working copy)
>@@ -31,12 +31,14 @@
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.cocoon.ProcessingException;
> import org.apache.cocoon.environment.SourceResolver;
>+import org.apache.cocoon.reading.ResourceReader;
> import org.apache.commons.lang.SystemUtils;
> import org.xml.sax.SAXException;
> 
> import com.sun.image.codec.jpeg.ImageFormatException;
> import com.sun.image.codec.jpeg.JPEGCodec;
> import com.sun.image.codec.jpeg.JPEGDecodeParam;
>+import com.sun.image.codec.jpeg.JPEGEncodeParam;
> import com.sun.image.codec.jpeg.JPEGImageDecoder;
> import com.sun.image.codec.jpeg.JPEGImageEncoder;
> 
>@@ -52,13 +54,13 @@
>  *     <dd> This parameter is optional. When specified, it determines the
>  *          width of the binary image.
>  *          If no height parameter is specified, the aspect ratio
>- *          of the image is kept.
>+ *          of the image is kept. The parameter may be expressed as an int or 
>a percentage.
>  *     </dd>
>  *     <dt>&lt;height&gt;</dt>
>  *     <dd> This parameter is optional. When specified, it determines the
>  *          height of the binary image.
>  *          If no width parameter is specified, the aspect ratio
>- *          of the image is kept.
>+ *          of the image is kept. The parameter may be expressed as an int or 
>a percentage.
>  *     </dd>
>  *     <dt>&lt;scale(Red|Green|Blue)&gt;</dt>
>  *     <dd>This parameter is optional. When specified it will cause the
>@@ -82,11 +84,17 @@
>  *         images will be reduced in size, but not enlarged. The default is
>  *         "<code>true</code>".
>  *     </dd>
>+ *     <dt>&lt;quality&gt;</dt>
>+ *     <dd>This parameter is optional. By default, the quality uses the
>+ *         default for the JVM. If it is specified, the proper JPEG quality
>+ *         compression is used. The range is 0.0 to 1.0, if specified.
>+ *     </dd>
>  *   </dl>
>  *
>  * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
>  * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
>  * @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a>
>+ * @author <a href="mailto:[EMAIL PROTECTED]">Eric Caron</a>
>  * @version CVS $Id$
>  */
> final public class ImageReader extends ResourceReader {
>@@ -101,9 +109,11 @@
>     private int height;
>     private float[] scaleColor = new float[3];
>     private float[] offsetColor = new float[3];
>+    private float[] quality = new float[1];
> 
>     private boolean enlarge;
>     private boolean fitUniform;
>+    private boolean usePercent;
>     private RescaleOp colorFilter;
>     private ColorConvertOp grayscaleFilter;
> 
>@@ -111,8 +121,9 @@
>     public void setup(SourceResolver resolver, Map objectModel, String src, 
> Parameters par)
>     throws ProcessingException, SAXException, IOException {
> 
>-        width = par.getParameterAsInteger("width", 0);
>-        height = par.getParameterAsInteger("height", 0);
>+        char lastChar;
>+        String tmpWidth = par.getParameter("width", "0");
>+        String tmpHeight = par.getParameter("height", "0");
> 
>         scaleColor[0] = par.getParameterAsFloat("scaleRed", -1.0f);
>         scaleColor[1] = par.getParameterAsFloat("scaleGreen", -1.0f);
>@@ -120,6 +131,7 @@
>         offsetColor[0] = par.getParameterAsFloat("offsetRed", 0.0f);
>         offsetColor[1] = par.getParameterAsFloat("offsetGreen", 0.0f);
>         offsetColor[2] = par.getParameterAsFloat("offsetBlue", 0.0f);
>+        quality[0] = par.getParameterAsFloat("quality", 0.9f);
> 
>         boolean filterColor = false;
>         for (int i = 0; i < 3; ++i) {
>@@ -137,6 +149,23 @@
>             this.colorFilter = new RescaleOp(scaleColor, offsetColor, null);
>         }
> 
>+        usePercent = false;
>+        lastChar = tmpWidth.charAt(tmpWidth.length() - 1);
>+        if (lastChar == '%') {
>+            usePercent = true;
>+            width = Integer.parseInt(tmpWidth.substring(0, tmpWidth.length() 
>- 1));
>+        } else {
>+            width = Integer.parseInt(tmpWidth);
>+        }
>+
>+        lastChar = tmpHeight.charAt(tmpHeight.length() - 1);
>+        if(lastChar == '%') {
>+            usePercent = true;
>+            height = Integer.parseInt(tmpHeight.substring(0, 
>tmpHeight.length() - 1));
>+        } else {
>+            height = Integer.parseInt(tmpHeight);
>+        }
>+              
>         if (par.getParameterAsBoolean("grayscale", GRAYSCALE_DEFAULT)) {
>             this.grayscaleFilter = new 
> ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
>         }
>@@ -160,7 +189,7 @@
>      * @return True if image transform is specified
>      */
>     private boolean hasTransform() {
>-        return width > 0 || height > 0 || null != colorFilter || null != 
>grayscaleFilter;
>+        return width > 0 || height > 0 || null != colorFilter || null != 
>grayscaleFilter || (quality[0] != 0.9f);
>     }
> 
>     /**
>@@ -258,6 +287,15 @@
>                     double ow = decodeParam.getWidth();
>                     double oh = decodeParam.getHeight();
> 
>+                    if (usePercent == true) {
>+                        if (width > 0) {
>+                            width = Math.round((int)(ow * width) / 100);
>+                        }
>+                        if (height > 0) {
>+                            height = Math.round((int)(oh * height) / 100);
>+                        }
>+                    }
>+
>                     AffineTransformOp filter = new 
> AffineTransformOp(getTransform(ow, oh, width, height), 
> AffineTransformOp.TYPE_BILINEAR);
>                     WritableRaster scaledRaster = 
> filter.createCompatibleDestRaster(currentImage.getRaster());
> 
>@@ -277,10 +315,16 @@
>                 // JVM Bug handling
>                 if (JVMBugFixed) {
>                     JPEGImageEncoder encoder = 
> JPEGCodec.createJPEGEncoder(out);
>+                    JPEGEncodeParam p = 
>encoder.getDefaultJPEGEncodeParam(currentImage);
>+                    p.setQuality(quality[0], true);
>+                    encoder.setJPEGEncodeParam(p);
>                     encoder.encode(currentImage);
>                 } else { 
>                     ByteArrayOutputStream bstream = new 
> ByteArrayOutputStream();
>                     JPEGImageEncoder encoder = 
> JPEGCodec.createJPEGEncoder(bstream);
>+                    JPEGEncodeParam p = 
>encoder.getDefaultJPEGEncodeParam(currentImage);
>+                    p.setQuality(quality[0], true);
>+                    encoder.setJPEGEncodeParam(p);
>                     encoder.encode(currentImage);
>                     out.write(bstream.toByteArray());
>                 }
>@@ -321,6 +365,7 @@
>                 + ":" + this.offsetColor[0]
>                 + ":" + this.offsetColor[1]
>                 + ":" + this.offsetColor[2]
>+                + ":" + this.quality[0]
>                 + ":" + ((null == this.grayscaleFilter) ? "color" : 
> "grayscale")
>                 + ":" + super.getKey();
>     }


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

Reply via email to