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 SubtractValue implements IOperator< IImageChannel > { /** * */ private static final long serialVersionUID = -6503593023056401910L; private IImageChannel inputChannel; private float value; private boolean inPlace; public SubtractValue( IImageChannel channel, float value, boolean inPlace ) { this.inputChannel = channel; this.value = value; this.inPlace = inPlace; } public void setInPlace( boolean inPlace ) { this.inPlace = inPlace; } public void setValue( float value ) { this.value = value; } public IImageChannel apply( ) { if ( this.inputChannel == null ) { return null; } IImageChannel 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, this.inputChannel.getValue( i ) - this.value ); } return outputChannel; } }