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 FastSimpleScale implements IOperator< IImageChannel > { private IImageChannel inputChannel; private int newX; private int newY; public FastSimpleScale( IImageChannel inputChannel, int x, int y ) { this.inputChannel = inputChannel; this.newX = x; this.newY = y; } public IImageChannel apply( ) { if ( this.inputChannel == null ) { return null; } IImageChannel outputChannel = new ImageChannelFactory( this.newX, this.newY ).apply(); double scaleX = this.inputChannel.getXSize( ) / ( double )this.newX; double scaleY = this.inputChannel.getYSize( ) / ( double )this.newY; for ( int x = 0; x < this.newX; x++ ) { for ( int y = 0; y < this.newY; y++ ) { int posX = ( int )( x * scaleX ); int posY = ( int )( y * scaleY ); outputChannel.setValue( x, y, this.inputChannel.getValue( posX, posY ) ); } } return outputChannel; } public void setNewX(int newX) { this.newX = newX; } public void setNewY(int newY) { this.newY = newY; } }