001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.img.coder; 020 021import java.awt.image.BufferedImage; 022import java.io.IOException; 023 024import lucee.commons.io.res.Resource; 025import lucee.commons.lang.ExceptionUtil; 026import lucee.commons.lang.SystemOut; 027public abstract class Coder { 028 029 private static Coder instance; 030 031 protected Coder(){} 032 033 public static Coder getInstance(){ 034 035 if(instance==null){ 036 instance = new JRECoder(); 037 038 // try to load Sanselan, does not load when lib not exist 039 try{ 040 SanselanCoder sanselan = new SanselanCoder(); 041 instance=new DoubleCoder(sanselan, instance); 042 SystemOut.printDate("use Sanselan and JRE Image Coder "); 043 } 044 catch(Throwable t){ 045 ExceptionUtil.rethrowIfNecessary(t); 046 SystemOut.printDate("use JRE Image Coder "); 047 } 048 } 049 return instance; 050 } 051 052 053 /** 054 * translate a file resource to a buffered image 055 * @param res 056 * @return 057 * @throws IOException 058 */ 059 public abstract BufferedImage toBufferedImage(Resource res,String format) throws IOException; 060 061 /** 062 * translate a binary array to a buffered image 063 * @param binary 064 * @return 065 * @throws IOException 066 */ 067 public abstract BufferedImage toBufferedImage(byte[] bytes,String format) throws IOException; 068 069 public abstract String[] getWriterFormatNames(); 070 071 public abstract String[] getReaderFormatNames(); 072 073}