protected void setValue(int pos, int val) { int b = (int) (pos / (width * height)); pos -= b * width * height; int y = (int) (pos / width); int x = pos % width; outImage.setSample(x, y, b, val); }
protected void setValue(int pos, int sign, int tt) { int s = (sign == QuadOutputStream.PLUS) ? 1 : -1; int b = (int) (pos / (width * height)); pos -= b * width * height; int y = (int) (pos / width); int x = pos % width; outImage.setSample(x, y, b, s * tt); }
/** Simple method for image creation */ private static RenderedImage createTestImage( int dataType, int width, int height, Number noDataValue, int bands) { // This values could be used for fill all the image byte valueB = 64; short valueUS = Short.MAX_VALUE / 4; short valueS = -50; int valueI = 100; float valueF = (255 / 2) * 5; double valueD = (255 / 1) * 4; // parameter block initialization int tileW = width / 8; int tileH = height / 8; int imageDim = width * height; final SampleModel sm; Byte crossValueByte = null; Short crossValueUShort = null; Short crossValueShort = null; Integer crossValueInteger = null; Float crossValueFloat = null; Double crossValueDouble = null; int numBands = bands; if (numBands == 3) { sm = new ComponentSampleModel( dataType, width, height, 3, width, new int[] {0, imageDim, imageDim * 2}); } else { sm = new ComponentSampleModel(dataType, width, height, 1, width, new int[] {0}); } switch (dataType) { case DataBuffer.TYPE_BYTE: crossValueByte = (Byte) noDataValue; break; case DataBuffer.TYPE_USHORT: crossValueUShort = (Short) noDataValue; break; case DataBuffer.TYPE_SHORT: crossValueShort = (Short) noDataValue; break; case DataBuffer.TYPE_INT: crossValueInteger = (Integer) noDataValue; break; case DataBuffer.TYPE_FLOAT: crossValueFloat = (Float) noDataValue; break; case DataBuffer.TYPE_DOUBLE: crossValueDouble = (Double) noDataValue; break; default: throw new IllegalArgumentException("Wrong data type"); } // Create the constant operation. TiledImage used = new TiledImage(sm, tileW, tileH); for (int b = 0; b < numBands; b++) { for (int j = 0; j < width; j++) { for (int k = 0; k < height; k++) { // Addition of a cross on the image if (j == k || j == width - k - 1) { switch (dataType) { case DataBuffer.TYPE_BYTE: used.setSample(j, k, b, crossValueByte); break; case DataBuffer.TYPE_USHORT: used.setSample(j, k, b, crossValueUShort); break; case DataBuffer.TYPE_SHORT: used.setSample(j, k, b, crossValueShort); break; case DataBuffer.TYPE_INT: used.setSample(j, k, b, crossValueInteger); break; case DataBuffer.TYPE_FLOAT: used.setSample(j, k, b, crossValueFloat); break; case DataBuffer.TYPE_DOUBLE: used.setSample(j, k, b, crossValueDouble); break; default: throw new IllegalArgumentException("Wrong data type"); } // If selected, the image could be filled } else // a little square of no data on the upper left is inserted if ((j >= 20) && (j < 50) && (k >= 20) && (k < 50)) { switch (dataType) { case DataBuffer.TYPE_BYTE: used.setSample(j, k, b, 0); break; case DataBuffer.TYPE_USHORT: used.setSample(j, k, b, 0); break; case DataBuffer.TYPE_SHORT: used.setSample(j, k, b, 0); break; case DataBuffer.TYPE_INT: used.setSample(j, k, b, 0); break; case DataBuffer.TYPE_FLOAT: used.setSample(j, k, b, 0); break; case DataBuffer.TYPE_DOUBLE: used.setSample(j, k, b, 0); break; default: throw new IllegalArgumentException("Wrong data type"); } if ((j >= 30) && (j < 40) && (k >= 20) && (k < 30)) { switch (dataType) { case DataBuffer.TYPE_BYTE: used.setSample(j, k, b, crossValueByte); break; case DataBuffer.TYPE_USHORT: used.setSample(j, k, b, crossValueUShort); break; case DataBuffer.TYPE_SHORT: used.setSample(j, k, b, crossValueShort); break; case DataBuffer.TYPE_INT: used.setSample(j, k, b, crossValueInteger); break; case DataBuffer.TYPE_FLOAT: used.setSample(j, k, b, crossValueFloat); break; case DataBuffer.TYPE_DOUBLE: used.setSample(j, k, b, crossValueDouble); break; default: throw new IllegalArgumentException("Wrong data type"); } } } else { // No Data is set switch (dataType) { case DataBuffer.TYPE_BYTE: used.setSample(j, k, b, valueB + b); break; case DataBuffer.TYPE_USHORT: used.setSample(j, k, b, valueUS + b); break; case DataBuffer.TYPE_SHORT: used.setSample(j, k, b, valueS + b); break; case DataBuffer.TYPE_INT: used.setSample(j, k, b, valueI + b); break; case DataBuffer.TYPE_FLOAT: float data = valueF + b / 3.0f; used.setSample(j, k, b, data); break; case DataBuffer.TYPE_DOUBLE: double dataD = valueD + b / 3.0d; used.setSample(j, k, b, dataD); break; default: throw new IllegalArgumentException("Wrong data type"); } } } } } return used; }