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 AddValue implements IOperator< IImageChannel > { private IImageChannel inputChannel; private float value; private boolean inPlace; public AddValue() { this.inputChannel = null; this.value = 0; this.inPlace = false; } public AddValue( IImageChannel channel, float value ) { this.inputChannel = channel; this.value = value; this.inPlace = false; } public AddValue( 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; } }