Java BufferedImage Operation testNeighbours(BufferedImage source, int x, int y, boolean alpha)

Here you can find the source of testNeighbours(BufferedImage source, int x, int y, boolean alpha)

Description

test Neighbours

License

Open Source License

Declaration

protected static boolean testNeighbours(BufferedImage source, int x,
            int y, boolean alpha) 

Method Source Code

//package com.java2s;
/*// ww w.j ava  2 s . c o m
 * Collab canvas - Java framework for graphics software enabling offline and shared
 * painting
 * Copyright (C) 2012 Martin Indra <aktive@seznam.cz>
 *
 * This file is part of Collab canvas.
 *
 * Collab canvas is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Collab canvas is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Collab canvas.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.image.BufferedImage;

public class Main {
    protected static boolean testNeighbours(BufferedImage source, int x,
            int y, boolean alpha) {
        boolean up = testNeighbour(source, x, y - 1, alpha);
        boolean down = testNeighbour(source, x, y + 1, alpha);
        boolean left = testNeighbour(source, x - 1, y, alpha);
        boolean right = testNeighbour(source, x + 1, y, alpha);
        return up || down || left || right;
    }

    protected static boolean testNeighbour(BufferedImage source, int x,
            int y, boolean alpha) {
        if (x >= 0 && y >= 0 && x < source.getWidth()
                && y < source.getHeight()) {
            int gray = source.getRGB(x, y) & 0x000000ff;
            int alphaI = (source.getRGB(x, y) & 0xff000000) >>> 24;
            return (alpha && alphaI == 0) || (!alpha && gray == 255);
        }
        return true;
    }
}

Related

  1. shrink(BufferedImage source, double factor)
  2. smaller(final BufferedImage src, final int radius, final int opaqueLimit)
  3. stitchImages(BufferedImage[] images, int[] relX)
  4. switchAxes(BufferedImage img)
  5. symmetrifyY(BufferedImage image, boolean useFirstHalfImage, boolean flipVertical)
  6. texture2D(BufferedImage normalMap, int x, int y)
  7. thresholdImage(BufferedImage image, int threshold)
  8. tile(BufferedImage source, Rectangle r, GraphicsConfiguration conf)
  9. tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets)