organizing imports
[mir.git] / source / mir / misc / WebdbImage.java
index ff035b9..136acb1 100755 (executable)
-/*
- * Copyright (C) 2001, 2002  The Mir-coders group
- *
- * This file is part of Mir.
- *
- * Mir is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Mir is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mir; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with the com.oreilly.servlet library, any library
- * licensed under the Apache Software License, The Sun (tm) Java Advanced
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of
- * the above that use the same license as the above), and distribute linked
- * combinations including the two.  You must obey the GNU General Public
- * License in all respects for all of the code used other than the above
- * mentioned libraries.  If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so.  If you do
- * not wish to do so, delete this exception statement from your version.
- */
-
-package mir.misc;
-
-/**
- * Title:
- * Description:
- * Copyright:    Copyright (c) 2002 Mir-coders
- * @author $Author: idfx $
- * @version $Id: WebdbImage.java,v 1.9 2003/01/25 17:45:18 idfx Exp $
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Random;
-
-import javax.media.jai.InterpolationBilinear;
-import javax.media.jai.JAI;
-import javax.media.jai.ParameterBlockJAI;
-import javax.media.jai.PlanarImage;
-
-import com.sun.media.jai.codec.FileSeekableStream;
-
-public class WebdbImage
-{
-
-       // default values for scaling
-       private int               maxIconSize=120;
-       private int               maxImageSize=640;
-
-       private int               iconWidth;
-       private int               iconHeight;
-
-  Random r = new Random();
-
-       // internal representation of the image
-       private PlanarImage       planarImage;
-
-  // type of the image
-  private String _type;
-
-
-       // constructor
-  // takes a temporary file as a parameter
-       public WebdbImage(File f, String type)
-               throws IOException
-       {
-    // It has to be a FileSeekableStream cause the image conversion
-    // needs to seek backwards.
-               planarImage = JAI.create("stream",new FileSeekableStream(f));
-    _type = type;
-               scaleImage();
-       }
-
-       // acc3ssor-methods
-  // must be run after scaleIcon()
-       public int getIconWidth() throws IOException {
-               return iconWidth;
-       }
-
-  // must be run after scaleIcon()
-       public int getIconHeight() throws IOException {
-               return iconHeight;
-       }
-
-       public int getImageWidth() {
-               return (int)planarImage.getWidth();
-       }
-
-       public int getImageHeight() {
-               return (int)planarImage.getHeight();
-       }
-
-       public void setImage(OutputStream outStream) {
-    JAI.create("encode", planarImage, outStream, _type, null);
-       }
-
-       public void setIcon(OutputStream outStream)
-               throws IOException
-       {
-               scaleIcon(outStream);
-       }
-
-       private void scaleImage()
-               throws java.io.IOException
-       {
-               if (maxImageSize>0 && ( getImageHeight()> maxImageSize|| getImageWidth() >maxImageSize))
-               {
-                       float scale;
-      ParameterBlockJAI params = new ParameterBlockJAI("scale");
-      params.addSource(planarImage);
-                       if (getImageHeight() > getImageWidth())
-        scale = (float)maxImageSize / (float)getImageHeight();
-      else
-        scale = (float)maxImageSize / (float)getImageWidth();
-
-      params.setParameter("xScale", scale);
-      params.setParameter("yScale", scale);
-                       params.setParameter("xTrans",0.0F);
-                       params.setParameter("yTrans",0.0F);
-                       params.setParameter("interpolation",new InterpolationBilinear());
-                       planarImage = JAI.create("scale", params);
-               }
-       }
-
-       private void scaleIcon(OutputStream outStream)
-               throws java.io.IOException
-       {
-    float scale;
-    ParameterBlockJAI params = new ParameterBlockJAI("scale");
-    params.addSource(planarImage);
-    if (getImageHeight() > getImageWidth())
-      scale = (float)maxIconSize / (float)getImageHeight();
-    else
-      scale = (float)maxIconSize / (float)getImageWidth();
-
-    params.setParameter("xScale", scale);
-    params.setParameter("yScale", scale);
-    params.setParameter("xTrans",0.0F);
-    params.setParameter("yTrans",0.0F);
-    params.setParameter("interpolation",new InterpolationBilinear());
-    PlanarImage temp = JAI.create("scale", params);
-    JAI.create("encode", temp, outStream, _type, null);
-    iconWidth=temp.getWidth();
-    iconHeight=temp.getHeight();
-       }
-
-}
+/*\r
+ * Copyright (C) 2001, 2002  The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with the com.oreilly.servlet library, any library\r
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
+ * the above that use the same license as the above), and distribute linked\r
+ * combinations including the two.  You must obey the GNU General Public\r
+ * License in all respects for all of the code used other than the above\r
+ * mentioned libraries.  If you modify this file, you may extend this exception\r
+ * to your version of the file, but you are not obligated to do so.  If you do\r
+ * not wish to do so, delete this exception statement from your version.\r
+ */\r
+\r
+package mir.misc;\r
+\r
+/**\r
+ * Title:\r
+ * Description:\r
+ * Copyright:    Copyright (c) 2002 Mir-coders\r
+ * @author $Author: idfx $\r
+ * @version $Id: WebdbImage.java,v 1.12 2003/03/05 19:23:14 idfx Exp $\r
+ */\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.Random;\r
+\r
+import javax.media.jai.InterpolationBilinear;\r
+import javax.media.jai.JAI;\r
+import javax.media.jai.ParameterBlockJAI;\r
+import javax.media.jai.PlanarImage;\r
+\r
+import mir.config.MirPropertiesConfiguration;\r
+\r
+import com.sun.media.jai.codec.FileSeekableStream;\r
+\r
+public class WebdbImage\r
+{\r
+\r
+  // default values for scaling\r
+  private int maxIconSize;\r
+  private int maxImageSize;\r
+\r
+  private int iconWidth;\r
+  private int iconHeight;\r
+\r
+  Random r = new Random();\r
+\r
+  // internal representation of the image\r
+  private PlanarImage planarImage;\r
+\r
+  // type of the image\r
+  private String _type;\r
+\r
+  private WebdbImage() {\r
+  }\r
+\r
+  // constructor\r
+  // takes a temporary file as a parameter\r
+  public WebdbImage(File f, String type) throws Exception {\r
+    // It has to be a FileSeekableStream cause the image conversion\r
+    // needs to seek backwards.\r
+    maxImageSize = MirPropertiesConfiguration.instance().getInt("Producer.Image.MaxSize");\r
+    maxIconSize = MirPropertiesConfiguration.instance().getInt("Producer.Image.MaxIconSize");\r
+\r
+    planarImage = JAI.create("stream", new FileSeekableStream(f));\r
+    _type = type;\r
+    scaleImage();\r
+  }\r
+\r
+  // acc3ssor-methods\r
+  // must be run after scaleIcon()\r
+  public int getIconWidth() throws IOException {\r
+    return iconWidth;\r
+  }\r
+\r
+  // must be run after scaleIcon()\r
+  public int getIconHeight() throws IOException {\r
+    return iconHeight;\r
+  }\r
+\r
+  public int getImageWidth() {\r
+    return (int) planarImage.getWidth();\r
+  }\r
+\r
+  public int getImageHeight() {\r
+    return (int) planarImage.getHeight();\r
+  }\r
+\r
+  public void setImage(OutputStream outStream) {\r
+    JAI.create("encode", planarImage, outStream, _type, null);\r
+  }\r
+\r
+  public void setIcon(OutputStream outStream) throws IOException {\r
+    scaleIcon(outStream);\r
+  }\r
+\r
+  private void scaleImage() throws java.io.IOException {\r
+    if (maxImageSize > 0 &&\r
+        (getImageHeight() > maxImageSize || getImageWidth() > maxImageSize)) {\r
+      float scale;\r
+      ParameterBlockJAI params = new ParameterBlockJAI("scale");\r
+      params.addSource(planarImage);\r
+      if (getImageHeight() > getImageWidth())\r
+        scale = (float) maxImageSize / (float) getImageHeight();\r
+      else\r
+        scale = (float) maxImageSize / (float) getImageWidth();\r
+\r
+      params.setParameter("xScale", scale);\r
+      params.setParameter("yScale", scale);\r
+      params.setParameter("xTrans", 0.0F);\r
+      params.setParameter("yTrans", 0.0F);\r
+      params.setParameter("interpolation", new InterpolationBilinear());\r
+      planarImage = JAI.create("scale", params);\r
+    }\r
+  }\r
+\r
+  private void scaleIcon(OutputStream outStream) throws java.io.IOException {\r
+    float scale;\r
+    ParameterBlockJAI params = new ParameterBlockJAI("scale");\r
+    params.addSource(planarImage);\r
+    if (getImageHeight() > getImageWidth())\r
+      scale = (float) maxIconSize / (float) getImageHeight();\r
+    else\r
+      scale = (float) maxIconSize / (float) getImageWidth();\r
+\r
+    params.setParameter("xScale", scale);\r
+    params.setParameter("yScale", scale);\r
+    params.setParameter("xTrans", 0.0F);\r
+    params.setParameter("yTrans", 0.0F);\r
+    params.setParameter("interpolation", new InterpolationBilinear());\r
+    PlanarImage temp = JAI.create("scale", params);\r
+    JAI.create("encode", temp, outStream, _type, null);\r
+    iconWidth = temp.getWidth();\r
+    iconHeight = temp.getHeight();\r
+  }\r
+\r
+}
\ No newline at end of file