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 MultiplyChannel implements IOperator2P { private boolean inPlace; public MultiplyChannel() { this(false); } public MultiplyChannel(boolean inPlace) { this.inPlace = inPlace; } public IImageChannel apply(IImageChannel inputChannel, IImageChannel channel) { if (inputChannel == null) { return null; } IImageChannel outputChannel = this.inPlace ? inputChannel : new ImageChannelFactory(inputChannel).apply(); final int maxIndex = inputChannel.getMaxIndex(); float [] inputRaster = inputChannel.getRaster(); float [] channelRaster = channel.getRaster(); float [] outputRaster = outputChannel.getRaster(); if ((inputRaster != null)&&(outputRaster != null)&&(channelRaster != null)) { for (int i = 0; i < maxIndex; i++) { outputRaster[i] = inputRaster[i] * channelRaster[i]; } } else { for (int i = 0; i < maxIndex; i++) { outputChannel.setValue(i, inputChannel.getValue(i) * channel.getValue(i)); } } return outputChannel; } }