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 * A filter which uses the brightness of each pixel to lookup a color from a colormap. 024 */ 025public class LookupFilter extends PointFilter { 026 027 private Colormap colormap = new Gradient(); 028 029 /** 030 * Construct a LookupFilter. 031 */ 032 public LookupFilter() { 033 canFilterIndexColorModel = true; 034 } 035 036 /** 037 * Construct a LookupFilter. 038 * @param colormap the color map 039 */ 040 public LookupFilter(Colormap colormap) { 041 canFilterIndexColorModel = true; 042 this.colormap = colormap; 043 } 044 045 /** 046 * Set the colormap to be used for the filter. 047 * @param colormap the colormap 048 * @see #getColormap 049 */ 050 public void setColormap(Colormap colormap) { 051 this.colormap = colormap; 052 } 053 054 /** 055 * Get the colormap to be used for the filter. 056 * @return the colormap 057 * @see #setColormap 058 */ 059 public Colormap getColormap() { 060 return colormap; 061 } 062 063 public int filterRGB(int x, int y, int rgb) { 064// int a = rgb & 0xff000000; 065 int r = (rgb >> 16) & 0xff; 066 int g = (rgb >> 8) & 0xff; 067 int b = rgb & 0xff; 068 rgb = (r + g + b) / 3; 069 return colormap.getColor(rgb/255.0f); 070 } 071 072 public String toString() { 073 return "Colors/Lookup..."; 074 } 075 076} 077 078