package pl.wroc.pwr.imagechannel.model; import java.util.Arrays; import pl.wroc.pwr.imagechannel.IImageChannel; import pl.wroc.pwr.imagechannel.IPixel; public class ImageChannel implements IImageChannel { /** * */ private static final long serialVersionUID = -2314468080041485971L; private int sizeX; private int sizeY; private float[] values; private int[] size; private float minimum; private float maximum; public ImageChannel(int x, int y) { this( x, y, 0, 1 ); } public ImageChannel(int[] size) { this( size[ IPixel.X ], size[ IPixel.Y ] ); } public ImageChannel(int x, int y, float minimum, float maximum) { this.sizeX = x; this.sizeY = y; this.values = new float[ this.sizeX * this.sizeY ]; this.size = new int[ ]{ this.sizeX, this.sizeY }; this.minimum = minimum; this.maximum = maximum; } public final float getMinimumValue() { return this.minimum; } public final float getMaximumValue() { return this.maximum; } public final int getIndex(int x, int y) { return x + this.sizeX * y; } public final int getIndex(int[] position) { return position[ IPixel.X ] + this.sizeX * position[ IPixel.Y ]; } public final int[ ] getSize( ) { return this.size; } public final int getXSize( ) { return this.sizeX; } public final int getYSize( ) { return this.sizeY; } public final float getValue( int x, int y ) { return this.values[ this.getIndex( x, y ) ]; } public final void setValue( int x, int y, float value ) { this.values[ this.getIndex( x, y ) ] = value; } public final float getValue(int[] position) { return this.values[ this.getIndex( position ) ]; } public final void setValue(int[] position, float value) { this.values[ this.getIndex( position ) ] = value; } public final int getMaxIndex() { return this.values.length; } public final float getValue(int index) { return this.values[index]; } public final void setValue(int index, float value) { this.values[index] = value; } public final boolean inRange(int x, int y) { return ( x >= 0 )&&( y >= 0 )&&( x < this.sizeX )&&( y < this.sizeY ); } public final boolean inIndexRange( int index ) { return ( ( index >= 0 )&&( index < this.getMaxIndex( ) ) ); } public final void reset() { Arrays.fill(this.values, 0); } public final float [] getRaster() { return this.values; } @Override public String toString() { return "ImageChannel[" + this.getXSize() + ", " + this.getYSize() + "]"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } }