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 AddChannel implements IOperator2P { private boolean inPlace; public AddChannel() { this(false); } public AddChannel(boolean inPlace) { this.inPlace = inPlace; } public IImageChannel apply(IImageChannel inputChannel, IImageChannel parameterChannel) { if (inputChannel == 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; } }