001 package railo.runtime.functions.image; 002 003 import java.awt.RenderingHints; 004 005 import javax.media.jai.operator.ShearDescriptor; 006 import javax.media.jai.operator.ShearDir; 007 008 import railo.runtime.PageContext; 009 import railo.runtime.exp.FunctionException; 010 import railo.runtime.exp.PageException; 011 import railo.runtime.img.Image; 012 import railo.runtime.op.Caster; 013 014 public class ImageShear { 015 public static String call(PageContext pc, Object name, double shear) throws PageException { 016 return call(pc, name, shear, "horizontal", "nearest"); 017 } 018 019 public static String call(PageContext pc, Object name, double shear, String direction) throws PageException { 020 return call(pc, name, shear, direction,"nearest"); 021 } 022 023 public static String call(PageContext pc, Object name, double shear, String strDirection, String strInterpolation) throws PageException { 024 if(name instanceof String) name=pc.getVariable(Caster.toString(name)); 025 Image img = Image.toImage(name); 026 027 // direction 028 strDirection=strDirection.toLowerCase().trim(); 029 ShearDir direction; 030 if("horizontal".equals(strDirection)) direction = ShearDescriptor.SHEAR_HORIZONTAL; 031 else if("vertical".equals(strDirection)) direction = ShearDescriptor.SHEAR_VERTICAL; 032 else throw new FunctionException(pc,"ImageShear",3,"direction","invalid direction definition ["+strDirection+"], " + 033 "valid direction values are [horizontal,vertical]"); 034 035 // interpolation 036 strInterpolation=strInterpolation.toLowerCase().trim(); 037 Object interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; 038 if("nearest".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; 039 else if("bilinear".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_BILINEAR; 040 else if("bicubic".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_BICUBIC; 041 else throw new FunctionException(pc,"ImageTranslate",4,"interpolation","invalid interpolation definition ["+strInterpolation+"], " + 042 "valid interpolation values are [nearest,bilinear,bicubic]"); 043 044 img.shear((float)shear, direction, interpolation); 045 return null; 046 } 047 }