package pl.wroc.pwr.imagechannel.basic; import pl.wroc.pwr.IOperator; import pl.wroc.pwr.imagechannel.IImageChannel; import pl.wroc.pwr.imagechannel.factory.ImageChannelFactory; public class LimitUpper implements IOperator< IImageChannel > { private IImageChannel inputChannel; private boolean inPlace; final private float upperValue; public LimitUpper( IImageChannel channel ) { this(channel,1,false); } public LimitUpper( IImageChannel channel, boolean inPlace ) { this(channel,1,inPlace); } public LimitUpper( IImageChannel channel, float upperValue, boolean inPlace ) { this.inputChannel = channel; this.upperValue = upperValue; this.inPlace = inPlace; System.out.println("LimitUpper on " + this.inputChannel + " with upperValue " + this.upperValue + ", inPlace " + this.inPlace); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } public IImageChannel apply( ) { IImageChannel outputChannel = null; if ( this.inputChannel == null ) { return null; } outputChannel = this.inPlace ? this.inputChannel : new ImageChannelFactory(this.inputChannel).apply(); final int maxIndex = this.inputChannel.getMaxIndex(); for ( int i = 0; i < maxIndex; i++ ) { outputChannel.setValue( i, Math.min( this.inputChannel.getValue( i ), this.upperValue ) ); } return outputChannel; } }