cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: rev 54570 - in cocoon/trunk: . src/documentation/xdocs/userdocs/readers src/java/org/apache/cocoon/reading
Date Mon, 11 Oct 2004 12:12:25 GMT
Author: tcurdt
Date: Mon Oct 11 05:12:24 2004
New Revision: 54570

Modified:
   cocoon/trunk/src/documentation/xdocs/userdocs/readers/image-reader.xml
   cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java
   cocoon/trunk/status.xml
Log:
fixes bug 30417 due to ml@wrinkledog.com (Mark Lundquist)

Added best-fit-while-keeping-aspect-ratio option to the ImageReader



Modified: cocoon/trunk/src/documentation/xdocs/userdocs/readers/image-reader.xml
==============================================================================
--- cocoon/trunk/src/documentation/xdocs/userdocs/readers/image-reader.xml	(original)
+++ cocoon/trunk/src/documentation/xdocs/userdocs/readers/image-reader.xml	Mon Oct 11 05:12:24
2004
@@ -132,36 +132,55 @@
             <td>
               This parameter is optional. When specified it determines the
               width of the binary image.
-              If no height parameter is specified the aspect ratio
+              If no height parameter is specified, the aspect ratio
               of the image is kept.
             </td>
           </tr>
           <tr>
             <td>height</td>
             <td>Image height in pixels</td>
-            <td>
               This parameter is optional. When specified it determines the
               height of the binary image.
-              If no width parameter is specified the aspect ratio
+              If no width parameter is specified, the aspect ratio
               of the image is kept.
+            <td>
             </td>
           </tr>
           <tr>
             <td>allow-enlarging</td>
-            <td>Allow or prevent the enlarging of images</td>
+            <td>boolean</td>
             <td>
               This parameter is optional. The <code>width</code> and <code>height</code>
parameters allow an image 
               to be resized. 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 "<code>no</code>". With this parameter set to "<code>no</code>",
images will 
+              to "<code>false</code>". With this parameter set to "<code>false</code>",
images will 
               be reduced in size, but not enlarged. The default for this parameter is 
-              "<code>yes</code>".
+              "<code>true</code>".
+            </td>
+          </tr>
+          <tr>
+            <td>fit-uniform</td>
+            <td>boolean</td>
+            <td>
+              This parameter is optional.  When set to
+              "<code>true</code>", it constrains the image size to the
+              dimensions of the specified width and height, while
+              preserving the original aspect ratio.  The value of
+              <code>&lt;allow-enlarging&gt;</code> is honored.  If
+              <code>&lt;allow-enlarging&gt;</code> is
+              "<code>true</code>", then the image will be enlarged as
+              much as possible while still fitting in the "box"; if 
+              <code>&lt;allow-enlarging&gt;</code> is
+              "<code>false</code>," the image may be reduced to fit the
+              box, but never enlarged.  The default
+              setting of <code>&lt;fit-uniform&gt;</code> is
+              "<code>false</code>".
             </td>
           </tr>
           <tr>
             <td>grayscale</td>
-            <td>Render the colour as a scale of gray.</td>
+            <td>boolean</td>
             <td>
               This parameter is optional. When specified and set to true it
               will cause each image pixel to be normalized.
@@ -170,21 +189,13 @@
           </tr>
           <tr>
             <td>scale(Red|Green|Blue)</td>
-            <td>Scale the RGB colour components by a multiplication factor.</td>
-            <td>
-              These parameters are optional. When specified it will cause the
-              specified color component in the image to be multiplied by the
-              specified floating point value.
-            </td>
+            <td>float</td>
+            <td>(Optional) Scale the RGB colour components by a multiplication factor.</td>
           </tr>
           <tr>
             <td>offset(Red|Green|Blue)</td>
-            <td>Scale the RGB colour components by an increment.</td>
-            <td>
-              These parameters are optional. When specified it will cause the
-              specified color component in the image to be incremented by the
-              specified floating point value.
-            </td>
+            <td>float</td>
+            <td>(Optional) Offset the RGB colour components by an increment.</td>
           </tr>
         </table>
         <p>

Modified: cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java	Mon Oct 11 05:12:24 2004
@@ -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,16 +78,16 @@
  *     <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>
  *
  * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
  * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
- * @version CVS $Id: ImageReader.java,v 1.11 2004/06/24 06:28:00 cziegeler Exp $
+ * @version CVS $Id$
  */
 final public class ImageReader extends ResourceReader {
 
@@ -97,6 +101,9 @@
     private boolean enlarge;
     private final static String ENLARGE_DEFAULT = "true";
 
+    private boolean fitUniform;
+    private final static String FIT_DEFAULT = "false";
+
     private ColorConvertOp grayscaleFilter = null;
     private final static String GRAYSCALE_DEFAULT = "false";
 
@@ -140,15 +147,19 @@
         } else {
             grayscaleFilter = null;
         }   
+
         String enlargePar = par.getParameter("allow-enlarging", ENLARGE_DEFAULT);
         enlarge = BooleanUtils.toBoolean(enlargePar);
+
+        String fitUniformPar = par.getParameter("fit-uniform", FIT_DEFAULT);
+        fitUniform = BooleanUtils.toBoolean(fitUniformPar);
     }
 
     /** 
      * 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.
@@ -158,7 +169,20 @@
     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;
             if (nh > 0) {

Modified: cocoon/trunk/status.xml
==============================================================================
--- cocoon/trunk/status.xml	(original)
+++ cocoon/trunk/status.xml	Mon Oct 11 05:12:24 2004
@@ -205,6 +205,9 @@
 
   <changes>
  <release version="@version@" date="@date@">
+   <action dev="TC" type="add" fixes-bug="30417">
+    Added best-fit-while-keeping-aspect-ratio option to the ImageReader
+   </action>
    <action dev="RP" type="add" due-to="Adam Ratclif" fixes-bug="31359">
     Apply patch: Add support for calling webservices from within Flowscript.
    </action>   

Mime
View raw message