From 0492637aa051052435aff8198b8e995d060da870 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 4 May 2002 19:34:14 +0000 Subject: [PATCH] Moved hitTest() into ImageUtil where its accessible to all that need it. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1334 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/media/image/ImageUtil.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/media/image/ImageUtil.java b/src/java/com/threerings/media/image/ImageUtil.java index 2f5576d06..8f86eb6a5 100644 --- a/src/java/com/threerings/media/image/ImageUtil.java +++ b/src/java/com/threerings/media/image/ImageUtil.java @@ -1,5 +1,5 @@ // -// $Id: ImageUtil.java,v 1.10 2002/04/30 02:14:13 mdb Exp $ +// $Id: ImageUtil.java,v 1.11 2002/05/04 19:34:14 mdb Exp $ package com.threerings.media.util; @@ -273,6 +273,28 @@ public class ImageUtil return new BufferedImage(mask.getColorModel(), target, true, null); } + /** + * Returns true if the supplied image contains a non-transparent pixel + * at the specified coordinates, false otherwise. + */ + public static boolean hitTest (Image image, int x, int y) + { + if (image instanceof BufferedImage) { + BufferedImage bimage = (BufferedImage)image; + int argb = bimage.getRGB(x, y); + int alpha = argb >> 24; + // Log.info("Checking [x=" + x + ", y=" + y + ", " + alpha); + + // it's only a hit if the pixel is non-transparent + return (argb >> 24) != 0; + + } else { + Log.warning("Can't check for transparent pixel " + + "[image=" + image + "]."); + return true; + } + } + /** * Converts floating point HSV values to a fixed point integer * representation.