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 simulates chrome. 023 */ 024public class ChromeFilter extends LightFilter { 025 private float amount = 0.5f; 026 private float exposure = 1.0f; 027 028 /** 029 * Set the amount of effect. 030 * @param amount the amount 031 * @min-value 0 032 * @max-value 1 033 * @see #getAmount 034 */ 035 public void setAmount(float amount) { 036 this.amount = amount; 037 } 038 039 /** 040 * Get the amount of chrome. 041 * @return the amount 042 * @see #setAmount 043 */ 044 public float getAmount() { 045 return amount; 046 } 047 048 /** 049 * Set the exppsure of the effect. 050 * @param exposure the exposure 051 * @min-value 0 052 * @max-value 1 053 * @see #getExposure 054 */ 055 public void setExposure(float exposure) { 056 this.exposure = exposure; 057 } 058 059 /** 060 * Get the exppsure of the effect. 061 * @return the exposure 062 * @see #setExposure 063 */ 064 public float getExposure() { 065 return exposure; 066 } 067 068 public BufferedImage filter( BufferedImage src, BufferedImage dst ) { 069 setColorSource( LightFilter.COLORS_CONSTANT ); 070 dst = super.filter( src, dst ); 071 TransferFilter tf = new TransferFilter() { 072 protected float transferFunction( float v ) { 073 v += amount * (float)Math.sin( v * 2 * Math.PI ); 074 return 1 - (float)Math.exp(-v * exposure); 075 } 076 }; 077 return tf.filter( dst, dst ); 078 } 079 080 public String toString() { 081 return "Effects/Chrome..."; 082 } 083} 084