That did it, I had a 1.5 JRE and a 1.6 JDK installed, but not a 1.5 JDK,
after installing it I was able to write this patch fairly quickly, it
uses the javax.imageio libraries to read and write the images, which
means it doesn't need special cases for each image format, I was able to
remove the code for the possibly-deprecated sun jpeg image codec, and it
supports PNG's and BMP's in addition to JPEGs and GIFs,

I did some basic tests with getting image info and resizing pngs and
bmps and they worked fine, Can some people test this out and make sure
it's fairly robust? While bmp's aren't very common, png's are becoming
more and more common so support for them in this tag will be quite
useful imo.

- Josh

PS. Happy Holidays everyone, And yes I'm going to spend time with the
family after I click send. :-)

Matthew Woodward wrote:
> You have to compile under 1.5.
>
> Sent from my Verizon Wireless BlackBerry
>
> -----Original Message-----
> From: Josh Hayes-Sheen <[email protected]>
>
> Date: Wed, 24 Dec 2008 13:26:17 
> To: <[email protected]>
> Subject: [OpenBD] Compiling OpenBD from source, and changes to the cfimage tag
>
>
>
> I checked out Open BlueDragon from source recently, and it won't build
> due to the following files not completely implementing their interfaces,
> or being abstract,
>
> src\com\nary\sql\nConnection.java:
> src\com\nary\sql\poolFactory.java
> src\com\naryx\tagfusion\cfm\engine\cfQueryResultData.java
> src\com\naryx\tagfusion\cfm\engine\cfQueryResultSetMetaData.java
>
> specifically they all seem to use the interface DataSource but not
> implement:
>
> public boolean isWrapperFor(Class<?> arg0) throws SQLException
> and
> public <T> T unwrap(Class<T> arg0) throws SQLException
>
> I don't think the classes are supposed to be abstract, but I'm not sure
> what the details of those stubs are, Anyone know what the rational is or
> when this will be fixed in cvs? I'm compiling with JDK 1.6 under Eclipse,
>
> The reason I came across this, is that I was intending to add
> functionality to the cfImage tags to handle PNG's properly so maybe I'll
> ask about that here too, It seems like using javax.imageio.* is the best
> solution for this, as the ImageIO static interface will allow reading
> and writing to any image format supported by Java, which on my system is
> GIF, JPEG, PNG and WBMP. I'm not sure about the portability of this
> however, Any comments?
>
> Finally, Is there a CVS commit mailing list that I could subscribe to,
> to keep current on the CVS trunk and rational behind changes?
>
> Thanks,
>
> - Josh
>
>
>
> >
>   

--~--~---------~--~----~------------~-------~--~----~
Open BlueDragon Public Mailing List
 http://groups.google.com/group/openbd?hl=en
 official blog @ http://blog.openbluedragon.org/
!! save a network - trim replies before posting !!
-~----------~----~----~----~------~----~------~--~---

Index: src/com/nary/awt/image/imageOps.java
===================================================================
RCS file: /cvs/openbd/openbd/src/com/nary/awt/image/imageOps.java,v
retrieving revision 1.2
diff -u -r1.2 imageOps.java
--- src/com/nary/awt/image/imageOps.java        9 Jul 2008 18:13:22 -0000       
1.2
+++ src/com/nary/awt/image/imageOps.java        24 Dec 2008 21:34:05 -0000
@@ -38,50 +38,69 @@
 import java.awt.image.*;
 import java.awt.geom.*;
 import java.io.*;
-import com.sun.image.codec.jpeg.*;
-import com.naryx.tagfusion.cfm.graph.GifEncoder;
+
+import javax.imageio.ImageIO;
 
 public class imageOps{ 
 
-       public static final byte GIF=0, JPG=1;
-       private static final float jpegQuality = 0.75f; 
+       public static final byte GIF=0, JPG=1, PNG=2, BMP=3;
        
        /**
         * loads the image found at the given source (e.g. "picture.gif" )
-        * with the given image type.
         */
         
-       public static BufferedImage loadImage( String _source, byte _imageType 
){
-               switch ( _imageType ){
-               case GIF:
-                       return loadGif( _source );
-               case JPG:
-                       return loadJpeg( _source );
-               default:
-                       return null;
-                       //throw new Exception( "Invalid image type" );
-               }
-               
-       }// loadImage()
+         public static BufferedImage loadImage( String _source, byte 
_imageType ){
+                   FileInputStream fin = null;
+                   try {
+                     fin = new FileInputStream( _source );
+                     return ImageIO.read(fin);
+                   }
+                   catch ( Exception e ) {
+                           return null;
+                   }
+                   finally {
+                     try{ if ( fin != null ) fin.close(); }catch( Exception 
ignored ){}
+                   }
+         }// loadImage()
+
 
        /**
         * saves the image to the given destination (e.g. "picture.gif" )
-        * in the given image format.
+        * in image format specified by the filename
         */
         
-       public static void saveImage( BufferedImage _img, File _dest, byte 
_imageType ) throws IOException{
-               switch ( _imageType ){
-               case GIF:
-                       saveGif( _img, _dest );
-                       break;
-               case JPG:
-                       saveJpeg( _img, _dest );
-                       break;
-               default:
-                       //throw new Exception( "Invalid image type" );
-               }
-               
-       }// saveImage()
+         public static void saveImage( BufferedImage _img, File _dest, byte 
_imageType ) throws IOException{
+                   FileOutputStream output = null;
+                   try{
+                     output = new FileOutputStream( _dest );
+                     // Get the output file extension, it SHOULD be usable as 
our 'informal name' argument to write(...)
+                     /*
+                      * Commented out for now to maintain previous behaviour
+                     String ext = 
_dest.getName().substring(_dest.getName().lastIndexOf('.')+1, 
_dest.getName().length());
+                     ImageIO.write(_img, ext, output);
+                     */
+                     switch (_imageType )
+                     {
+                     case imageOps.JPG:
+                         ImageIO.write(_img, "jpeg", output);
+                         break;
+                     case imageOps.GIF:
+                         ImageIO.write(_img, "gif", output);
+                         break;
+                     case imageOps.PNG:
+                         ImageIO.write(_img, "png", output);
+                         break;
+                     case imageOps.BMP:
+                         ImageIO.write(_img, "bmp", output);
+                         break;
+                     }
+                     output.flush();
+                     output.close();
+                   }finally{
+                     if ( output != null )try{ output.close(); }catch( 
IOException e ){}
+                   }
+                 }// saveImage()
+
        
        
        /**
@@ -194,75 +213,6 @@
 
        //==> PRIVATE METHODS >>        
        
-       private static BufferedImage loadGif( String _source ){
-               try{
-                       Panel p = new Panel();
-                       Image img = Toolkit.getDefaultToolkit().getImage( 
_source );
-                       try {
-               MediaTracker tracker = new MediaTracker( p );
-                               tracker.addImage( img, 0 );
-       tracker.waitForID(0);
-                               //tracker = null;
-                       } catch (Exception ignored) {}
-                       //com.nary.Debug.println("image == null" + (img == 
null));
-                       int width = img.getWidth( p );
-                       int height = img.getHeight( p );
-                       BufferedImage bi = new BufferedImage(width, height, 
BufferedImage.TYPE_INT_RGB);
-                       Graphics2D biContext = bi.createGraphics();
-                       biContext.drawImage(img, 0, 0, null);
-                       return bi;
-               }catch( Exception e ){
-                       return null;
-               }
-       }// loadGif()
-
-       
-       private static BufferedImage loadJpeg( String _source ){
-    FileInputStream fin = null;
-    try{
-      fin = new FileInputStream( _source );
-                       JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( 
fin );
-                       return decoder.decodeAsBufferedImage();
-               }catch( Exception e ){
-                       return null;
-               }finally{
-      try{ if ( fin != null ) fin.close(); }catch( Exception ignored ){}
-               }
-
-       }// loadJpeg()
-       
-
-       private static void saveGif( BufferedImage _img, File _dest ) throws 
IOException{
-    FileOutputStream output = null;
-    try{
-                       output = new FileOutputStream( _dest );
-                       GifEncoder encoder = new GifEncoder( _img, output );
-      encoder.encode();
-      output.flush();
-      output.close();
-    }finally{
-      if ( output != null )try{ output.close(); }catch( IOException e ){}
-    }
-       }// saveGif()
-       
-       
-       private static void saveJpeg( BufferedImage _img, File _dest ) throws 
IOException{
-               FileOutputStream destFout = null;
-               try{
-                       destFout = new FileOutputStream( _dest );
-                       JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( 
destFout );             
-                       JPEGEncodeParam param = 
encoder.getDefaultJPEGEncodeParam( _img );
-                       param.setQuality( jpegQuality, false );
-
-                       encoder.setJPEGEncodeParam( param );
-                       encoder.encode( _img );
-                       destFout.close();
-               }finally{
-      try{ destFout.close(); }catch( Exception ignored ){}
-    }
-       }// saveGif()
-       
-       
        private static BufferedImage scaleToSize(int _nMaxWidth, int 
_nMaxHeight, BufferedImage _imgSrc){
                int nHeight = _imgSrc.getHeight();
                int nWidth = _imgSrc.getWidth();
Index: src/com/naryx/tagfusion/cfm/tag/cfIMAGE.java
===================================================================
RCS file: /cvs/openbd/openbd/src/com/naryx/tagfusion/cfm/tag/cfIMAGE.java,v
retrieving revision 1.2
diff -u -r1.2 cfIMAGE.java
--- src/com/naryx/tagfusion/cfm/tag/cfIMAGE.java        9 Jul 2008 18:13:22 
-0000       1.2
+++ src/com/naryx/tagfusion/cfm/tag/cfIMAGE.java        24 Dec 2008 21:34:05 
-0000
@@ -467,6 +467,10 @@
                                return imageOps.GIF;
                        }else if ( type.equalsIgnoreCase( "jpeg" ) ){
                                return imageOps.JPG;
+                       }else if ( type.equalsIgnoreCase( "png" ) ){
+                               return imageOps.PNG;
+                       }else if ( type.equalsIgnoreCase( "bmp" ) ){
+                               return imageOps.BMP;
                        }else{
                                throw newRunTimeException( "Invalid " + 
_typeAttr + " attribute. Valid values are \"GIF\" or \"JPEG\"." );
                        }
@@ -476,6 +480,10 @@
                                return imageOps.GIF;
                        }else if ( lowerCaseFile.endsWith( ".jpg" ) || 
lowerCaseFile.endsWith( ".jpeg" ) ){
                                return imageOps.JPG;
+                       }else if ( lowerCaseFile.endsWith( ".png" ) ){
+                               return imageOps.PNG;
+                       }else if ( lowerCaseFile.endsWith( ".bmp" ) ){
+                               return imageOps.BMP;
                        }else{
         throw newRunTimeException( "Couldn't determine image type. Please 
specify a value for the " + _typeAttr + " attribute. Valid values are \"GIF\" 
or \"JPEG\"." );
                        }

Reply via email to