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 022public class RGBAdjustFilter extends PointFilter { 023 024 public float rFactor, gFactor, bFactor; 025 026 public RGBAdjustFilter() { 027 this(0, 0, 0); 028 } 029 030 public RGBAdjustFilter(float r, float g, float b) { 031 rFactor = 1+r; 032 gFactor = 1+g; 033 bFactor = 1+b; 034 canFilterIndexColorModel = true; 035 } 036 037 public void setRFactor( float rFactor ) { 038 this.rFactor = 1+rFactor; 039 } 040 041 public float getRFactor() { 042 return rFactor-1; 043 } 044 045 public void setGFactor( float gFactor ) { 046 this.gFactor = 1+gFactor; 047 } 048 049 public float getGFactor() { 050 return gFactor-1; 051 } 052 053 public void setBFactor( float bFactor ) { 054 this.bFactor = 1+bFactor; 055 } 056 057 public float getBFactor() { 058 return bFactor-1; 059 } 060 061 public int[] getLUT() { 062 int[] lut = new int[256]; 063 for ( int i = 0; i < 256; i++ ) { 064 lut[i] = filterRGB( 0, 0, (i << 24) | (i << 16) | (i << 8) | i ); 065 } 066 return lut; 067 } 068 069 public int filterRGB(int x, int y, int rgb) { 070 int a = rgb & 0xff000000; 071 int r = (rgb >> 16) & 0xff; 072 int g = (rgb >> 8) & 0xff; 073 int b = rgb & 0xff; 074 r = PixelUtils.clamp((int)(r * rFactor)); 075 g = PixelUtils.clamp((int)(g * gFactor)); 076 b = PixelUtils.clamp((int)(b * bFactor)); 077 return a | (r << 16) | (g << 8) | b; 078 } 079 080 public String toString() { 081 return "Colors/Adjust RGB..."; 082 } 083} 084