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.image.*; 020 021/** 022 * A filter which replaces one color by another in an image. This is frankly, not often useful, but has its occasional 023 * uses when dealing with GIF transparency and the like. 024 */ 025public class MapColorsFilter extends PointFilter { 026 027 private int oldColor; 028 private int newColor; 029 030 /** 031 * Construct a MapColorsFilter. 032 */ 033 public MapColorsFilter() { 034 this( 0xffffffff, 0xff000000 ); 035 } 036 037 /** 038 * Construct a MapColorsFilter. 039 * @param oldColor the color to replace 040 * @param newColor the color to replace it with 041 */ 042 public MapColorsFilter(int oldColor, int newColor) { 043 canFilterIndexColorModel = true; 044 this.oldColor = oldColor; 045 this.newColor = newColor; 046 } 047 048 public int filterRGB(int x, int y, int rgb) { 049 if (rgb == oldColor) 050 return newColor; 051 return rgb; 052 } 053} 054