package pl.wroc.pwr.imagechannel.basic; import pl.wroc.pwr.IOperator2P; import pl.wroc.pwr.imagechannel.IImageChannel; import pl.wroc.pwr.imagechannel.factory.ImageChannelFactory; public class SubtractChannel implements IOperator2P { private boolean inPlace; public SubtractChannel() { this(false); } public SubtractChannel(boolean inPlace) { this.inPlace = inPlace; } public IImageChannel apply(IImageChannel inputChannel, IImageChannel parameterChannel) { if ((inputChannel == null)||(parameterChannel == null)) { return null; } IImageChannel outputChannel = this.inPlace ? inputChannel : new ImageChannelFactory(inputChannel).apply(); final int maxIndex = inputChannel.getMaxIndex(); for (int i = 0; i < maxIndex; i++) { outputChannel.setValue(i, inputChannel.getValue(i) - parameterChannel.getValue(i)); } return outputChannel; } }