001/*
002Copyright 2006 Jerry Huxtable
003
004Licensed under the Apache License, Version 2.0 (the "License");
005you may not use this file except in compliance with the License.
006You may obtain a copy of the License at
007
008   http://www.apache.org/licenses/LICENSE-2.0
009
010Unless required by applicable law or agreed to in writing, software
011distributed under the License is distributed on an "AS IS" BASIS,
012WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013See the License for the specific language governing permissions and
014limitations under the License.
015*/
016
017package com.jhlabs.image;
018
019import java.awt.*;
020import java.awt.image.*;
021
022/**
023 * This filter tries to apply the Swing "flush 3D" effect to the black lines in an image.
024 */
025public class Flush3DFilter extends WholeImageFilter {
026
027        public Flush3DFilter() {
028        }
029
030        protected int[] filterPixels( int width, int height, int[] inPixels, Rectangle transformedSpace ) {
031                int index = 0;
032                int[] outPixels = new int[width * height];
033
034                for (int y = 0; y < height; y++) {
035                        for (int x = 0; x < width; x++) {
036                                int pixel = inPixels[y*width+x];
037
038                                if (pixel != 0xff000000 && y > 0 && x > 0) {
039                                        int count = 0;
040                                        if (inPixels[y*width+x-1] == 0xff000000)
041                                                count++;
042                                        if (inPixels[(y-1)*width+x] == 0xff000000)
043                                                count++;
044                                        if (inPixels[(y-1)*width+x-1] == 0xff000000)
045                                                count++;
046                                        if (count >= 2)
047                                                pixel = 0xffffffff;
048                                }
049                                outPixels[index++] = pixel;
050                        }
051
052                }
053                return outPixels;
054        }
055
056        public String toString() {
057                return "Stylize/Flush 3D...";
058        }
059
060}
061