From cffc83b19b5de0566daa7c228ec6c107de5f4779 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 7 Feb 2009 12:43:32 -0500 Subject: Fixed transparent image in ObjectLoader --- .../fourpuzzle/gamestate/mapview/ChipSet.java | 2 +- .../fourisland/fourpuzzle/util/ObjectLoader.java | 20 ++-------- .../fourpuzzle/util/TransparentImageFilter.java | 46 ---------------------- 3 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java index 4fac1c0..5ae3fbd 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java @@ -69,7 +69,7 @@ public class ChipSet { { ChipSet temp = new ChipSet(); temp.chipSetData = lower; - temp.chipSetImage = ObjectLoader.getImage("ChipSet", name); + temp.chipSetImage = ObjectLoader.getImage("ChipSet", name, trans); chipSets.put(name, temp); } diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index b149ddd..58cf5ee 100644 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java @@ -5,12 +5,9 @@ package com.fourisland.fourpuzzle.util; -//import com.alienfactory.javamappy.loader.MapLoader; import com.fourisland.fourpuzzle.PuzzleApplication; -import java.awt.Image; -import java.awt.Toolkit; +import java.awt.Color; import java.awt.image.BufferedImage; -import java.awt.image.FilteredImageSource; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -68,7 +65,7 @@ public class ObjectLoader { { throw new ResourceNotFoundException(type, name); } - + BufferedImage bImg = null; try { bImg = ImageIO.read(str); @@ -76,9 +73,7 @@ public class ObjectLoader { Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); } - bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB); - Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor))); - bImg.createGraphics().drawImage(image, 0, 0, null); + bImg.createGraphics().drawImage(bImg, 0, 0, new Color(transparencyColor, true), null); addToObjectCache(type,name,bImg); } @@ -86,15 +81,6 @@ public class ObjectLoader { return (BufferedImage) objectCache.get(type + "/" + name); } - /*public static com.alienfactory.javamappy.Map getMap(String name) throws Exception - { - ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); - String filename = rm.getResourcesDir() + "mapdata/" + name + ".fmp"; - - //com.alienfactory.javamappy.Map map = MapLoader.loadMap(rm.getClassLoader().getResourceAsStream(filename)); - return map; - }*/ - public static void addToObjectCache(String type, String name, Object object) { if (objectCache.size() >= 100) diff --git a/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java b/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java deleted file mode 100644 index bd830cc..0000000 --- a/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Tiled Map Editor, (c) 2004-2006 - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * Adam Turk - * Bjorn Lindeijer - */ - -package com.fourisland.fourpuzzle.util; - -import java.awt.image.RGBImageFilter; - -/** - * This filter is used for filtering out a given "transparent" color from an - * image. Sometimes known as magic pink. - */ -public class TransparentImageFilter extends RGBImageFilter -{ - int trans; - - /** - * @param col the color to make transparent - */ - public TransparentImageFilter(int col) { - trans = col; - - // The filter doesn't depend on pixel location - canFilterIndexColorModel = true; - } - - /** - * Filters the given pixel. It returns a transparent pixel for pixels that - * match the transparency color, or the existing pixel for anything else. - */ - public int filterRGB(int x, int y, int rgb) { - if (rgb == trans) { - return 0; - } else { - return rgb; - } - } -} \ No newline at end of file -- cgit 1.4.1