cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r155098 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java
Date Wed, 23 Feb 2005 22:47:00 GMT
Author: vgritsenko
Date: Wed Feb 23 14:46:58 2005
New Revision: 155098

URL: http://svn.apache.org/viewcvs?view=rev&rev=155098
Log:
port 2.2 updates, and minor code cleanup.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java?view=diff&r1=155097&r2=155098
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java Wed Feb
23 14:46:58 2005
@@ -49,12 +49,16 @@
  * Parameters:
  *   <dl>
  *     <dt>&lt;width&gt;</dt>
- *     <dd>This parameter is optional. When specified it determines the width
- *         of the image that should be served.
+ *     <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.
  *     </dd>
  *     <dt>&lt;height&gt;</dt>
- *     <dd>This parameter is optional. When specified it determines the height
- *         of the image that should be served.
+ *     <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.
  *     </dd>
  *     <dt>&lt;scale(Red|Green|Blue)&gt;</dt>
  *     <dd>This parameter is optional. When specified it will cause the
@@ -74,9 +78,9 @@
  *     <dd>This parameter is optional. By default, if the image is smaller
  *         than the specified width and height, the image will be enlarged.
  *         In some circumstances this behaviour is undesirable, and can be
- *         switched off by setting this parameter to "no" so that images will
- *         be reduced in size, but not enlarged. The default is "yes".
-
+ *         switched off by setting this parameter to "<code>false</code>" so
that
+ *         images will be reduced in size, but not enlarged. The default is
+ *         "<code>true</code>".
  *     </dd>
  *   </dl>
  *
@@ -86,8 +90,9 @@
  * @version CVS $Id$
  */
 final public class ImageReader extends ResourceReader {
-    private static final String GRAYSCALE_DEFAULT = "false";
+    private static final boolean GRAYSCALE_DEFAULT = false;
     private static final boolean ENLARGE_DEFAULT = true;
+    private static final boolean FIT_DEFAULT = false;
 
     private int width;
     private int height;
@@ -95,6 +100,7 @@
     private float[] offsetColor = new float[3];
 
     private boolean enlarge;
+    private boolean fitUniform;
     private RescaleOp colorFilter;
     private ColorConvertOp grayscaleFilter;
 
@@ -128,12 +134,12 @@
             this.colorFilter = new RescaleOp(scaleColor, offsetColor, null);
         }
 
-        String grayscalePar = par.getParameter("grayscale", GRAYSCALE_DEFAULT);
-        if (BooleanUtils.toBoolean(grayscalePar)) {
+        if (par.getParameterAsBoolean("grayscale", GRAYSCALE_DEFAULT)) {
             this.grayscaleFilter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),
null);
         }
 
         this.enlarge = par.getParameterAsBoolean("allow-enlarging", ENLARGE_DEFAULT);
+        this.fitUniform = par.getParameterAsBoolean("fit-uniform", FIT_DEFAULT);
 
         super.setup(resolver, objectModel, src, par);
     }
@@ -158,7 +164,7 @@
      * Returns the affine transform that implements the scaling.
      * The behavior is the following: if both the new width and height values
      * are positive, the image is rescaled according to these new values and
-     * the original aspect ration is lost.
+     * the original aspect ratio is lost.
      * Otherwise, if one of the two parameters is zero or negative, the
      * aspect ratio is maintained and the positive parameter indicates the
      * scaling.
@@ -168,6 +174,19 @@
     private AffineTransform getTransform(double ow, double oh, double nw, double nh) {
         double wm = 1.0d;
         double hm = 1.0d;
+
+        if (fitUniform) {
+            //
+            // Compare aspect ratio of image vs. that of the "box"
+            // defined by nw and nh
+            //
+            if (ow/oh > nw/nh) {
+                nh = 0;    // Original image is proportionately wider than the box,
+                        // so scale to fit width
+            } else {
+                nw = 0;    // Scale to fit height
+            }
+        }
 
         if (nw > 0) {
             wm = nw / ow;



Mime
View raw message