001 /* 002 * 003 004 Licensed under the Apache License, Version 2.0 (the "License"); 005 you may not use this file except in compliance with the License. 006 You may obtain a copy of the License at 007 008 http://www.apache.org/licenses/LICENSE-2.0 009 010 Unless required by applicable law or agreed to in writing, software 011 distributed under the License is distributed on an "AS IS" BASIS, 012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 See the License for the specific language governing permissions and 014 limitations under the License. 015 */ 016 017 package railo.runtime.img.filter;import java.awt.Rectangle; 018 import java.awt.image.BufferedImage; 019 020 import railo.runtime.engine.ThreadLocalPageContext; 021 import railo.runtime.exp.FunctionException; 022 import railo.runtime.exp.PageException; 023 import railo.runtime.img.ImageUtil; 024 import railo.runtime.type.Struct; 025 import railo.runtime.type.util.CollectionUtil; 026 027 /** 028 * This filter tries to apply the Swing "flush 3D" effect to the black lines in an image. 029 */ 030 public class Flush3DFilter extends WholeImageFilter implements DynFiltering { 031 032 public Flush3DFilter() { 033 } 034 035 protected int[] filterPixels( int width, int height, int[] inPixels, Rectangle transformedSpace ) { 036 int index = 0; 037 int[] outPixels = new int[width * height]; 038 039 for (int y = 0; y < height; y++) { 040 for (int x = 0; x < width; x++) { 041 int pixel = inPixels[y*width+x]; 042 043 if (pixel != 0xff000000 && y > 0 && x > 0) { 044 int count = 0; 045 if (inPixels[y*width+x-1] == 0xff000000) 046 count++; 047 if (inPixels[(y-1)*width+x] == 0xff000000) 048 count++; 049 if (inPixels[(y-1)*width+x-1] == 0xff000000) 050 count++; 051 if (count >= 2) 052 pixel = 0xffffffff; 053 } 054 outPixels[index++] = pixel; 055 } 056 057 } 058 return outPixels; 059 } 060 061 public String toString() { 062 return "Stylize/Flush 3D..."; 063 } 064 065 public BufferedImage filter(BufferedImage src, Struct parameters) throws PageException {BufferedImage dst=ImageUtil.createBufferedImage(src); 066 //Object o; 067 068 // check for arguments not supported 069 if(parameters.size()>0) { 070 throw new FunctionException(ThreadLocalPageContext.get(), "ImageFilter", 3, "parameters", "the parameter"+(parameters.size()>1?"s":"")+" ["+CollectionUtil.getKeyList(parameters,", ")+"] "+(parameters.size()>1?"are":"is")+" not allowed, only the following parameters are supported []"); 071 } 072 073 return filter(src, dst); 074 } 075 } 076