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 Invert implements IOperator< IImageChannel > { private IImageChannel inputChannel; private boolean inPlace; public Invert(IImageChannel channel) { this(channel, false); } public Invert(IImageChannel channel, boolean inPlace) { this.inputChannel = channel; this.inPlace = inPlace; //System.out.println("Invert on " + this.inputChannel + " with inPlace " + this.inPlace); //$NON-NLS-1$ //$NON-NLS-2$ } public IImageChannel apply() { IImageChannel outputChannel = null; if ( this.inputChannel == null ) { return null; } 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, 1 - this.inputChannel.getValue( i ) ); } return outputChannel; } }