List of usage examples for java.awt.image ComponentSampleModel getScanlineStride
public final int getScanlineStride()
From source file:GraphicsUtil.java
protected static void mult_BYTE_COMP_Data(WritableRaster wr) { // System.out.println("Multiply Int: " + wr); ComponentSampleModel csm; csm = (ComponentSampleModel) wr.getSampleModel(); final int width = wr.getWidth(); final int scanStride = csm.getScanlineStride(); final int pixStride = csm.getPixelStride(); final int[] bandOff = csm.getBandOffsets(); DataBufferByte db = (DataBufferByte) wr.getDataBuffer(); final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(), wr.getMinY() - wr.getSampleModelTranslateY())); int a = 0;// w w w. jav a2 s . c om int aOff = bandOff[bandOff.length - 1]; int bands = bandOff.length - 1; int b, i; // Access the pixel data array final byte pixels[] = db.getBankData()[0]; for (int y = 0; y < wr.getHeight(); y++) { int sp = base + y * scanStride; final int end = sp + width * pixStride; while (sp < end) { a = pixels[sp + aOff] & 0xFF; if (a != 0xFF) for (b = 0; b < bands; b++) { i = sp + bandOff[b]; pixels[i] = (byte) (((pixels[i] & 0xFF) * a) >> 8); } sp += pixStride; } } }
From source file:GraphicsUtil.java
protected static void divide_BYTE_COMP_Data(WritableRaster wr) { // System.out.println("Multiply Int: " + wr); ComponentSampleModel csm; csm = (ComponentSampleModel) wr.getSampleModel(); final int width = wr.getWidth(); final int scanStride = csm.getScanlineStride(); final int pixStride = csm.getPixelStride(); final int[] bandOff = csm.getBandOffsets(); DataBufferByte db = (DataBufferByte) wr.getDataBuffer(); final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(), wr.getMinY() - wr.getSampleModelTranslateY())); int a = 0;//from w w w .j av a 2 s .c om int aOff = bandOff[bandOff.length - 1]; int bands = bandOff.length - 1; int b, i; // Access the pixel data array final byte pixels[] = db.getBankData()[0]; for (int y = 0; y < wr.getHeight(); y++) { int sp = base + y * scanStride; final int end = sp + width * pixStride; while (sp < end) { a = pixels[sp + aOff] & 0xFF; if (a == 0) { for (b = 0; b < bands; b++) pixels[sp + bandOff[b]] = (byte) 0xFF; } else if (a < 255) { int aFP = (0x00FF0000 / a); for (b = 0; b < bands; b++) { i = sp + bandOff[b]; pixels[i] = (byte) (((pixels[i] & 0xFF) * aFP) >>> 16); } } sp += pixStride; } } }
From source file:GraphicsUtil.java
protected static void mult_BYTE_COMP_Data(WritableRaster wr) { // System.out.println("Multiply Int: " + wr); ComponentSampleModel csm; csm = (ComponentSampleModel) wr.getSampleModel(); final int width = wr.getWidth(); final int scanStride = csm.getScanlineStride(); final int pixStride = csm.getPixelStride(); final int[] bandOff = csm.getBandOffsets(); DataBufferByte db = (DataBufferByte) wr.getDataBuffer(); final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(), wr.getMinY() - wr.getSampleModelTranslateY())); int aOff = bandOff[bandOff.length - 1]; int bands = bandOff.length - 1; // Access the pixel data array final byte[] pixels = db.getBankData()[0]; for (int y = 0; y < wr.getHeight(); y++) { int sp = base + y * scanStride; final int end = sp + width * pixStride; while (sp < end) { int a = pixels[sp + aOff] & 0xFF; if (a != 0xFF) for (int b = 0; b < bands; b++) { int i = sp + bandOff[b]; pixels[i] = (byte) (((pixels[i] & 0xFF) * a) >> 8); }/*from w w w . jav a 2 s . c om*/ sp += pixStride; } } }
From source file:GraphicsUtil.java
protected static void divide_BYTE_COMP_Data(WritableRaster wr) { // System.out.println("Multiply Int: " + wr); ComponentSampleModel csm; csm = (ComponentSampleModel) wr.getSampleModel(); final int width = wr.getWidth(); final int scanStride = csm.getScanlineStride(); final int pixStride = csm.getPixelStride(); final int[] bandOff = csm.getBandOffsets(); DataBufferByte db = (DataBufferByte) wr.getDataBuffer(); final int base = (db.getOffset() + csm.getOffset(wr.getMinX() - wr.getSampleModelTranslateX(), wr.getMinY() - wr.getSampleModelTranslateY())); int aOff = bandOff[bandOff.length - 1]; int bands = bandOff.length - 1; // Access the pixel data array final byte[] pixels = db.getBankData()[0]; for (int y = 0; y < wr.getHeight(); y++) { int sp = base + y * scanStride; final int end = sp + width * pixStride; while (sp < end) { int a = pixels[sp + aOff] & 0xFF; if (a == 0) { for (int b = 0; b < bands; b++) pixels[sp + bandOff[b]] = (byte) 0xFF; } else if (a < 255) { // this does NOT include a == 255 (0xff) ! int aFP = (0x00FF0000 / a); for (int b = 0; b < bands; b++) { int i = sp + bandOff[b]; pixels[i] = (byte) (((pixels[i] & 0xFF) * aFP) >>> 16); }//from w w w.j av a 2s .c om } sp += pixStride; } } }
From source file:org.geoserver.jai.ConcurrentTileFactory.java
static long getBufferSizeCSM(ComponentSampleModel csm) { int[] bandOffsets = csm.getBandOffsets(); int maxBandOff = bandOffsets[0]; for (int i = 1; i < bandOffsets.length; i++) maxBandOff = Math.max(maxBandOff, bandOffsets[i]); long size = 0; if (maxBandOff >= 0) size += maxBandOff + 1;/*w w w. j av a2 s. c o m*/ int pixelStride = csm.getPixelStride(); if (pixelStride > 0) size += pixelStride * (csm.getWidth() - 1); int scanlineStride = csm.getScanlineStride(); if (scanlineStride > 0) size += scanlineStride * (csm.getHeight() - 1); return size; }
From source file:org.mrgeo.data.raster.RasterWritable.java
private static void writeHeader(final Raster raster, final OutputStream out) throws IOException { final DataOutputStream dos = new DataOutputStream(out); int headersize = HEADERSIZE; // this is in integers! // MAKE SURE TO KEEP THIS CORRECT IF YOU ADD PARAMETERS TO THE HEADER!!! final SampleModel model = raster.getSampleModel(); final SampleModelType modeltype = toSampleModelType(model); int[] bandOffsets = null; switch (modeltype) { case BANDED:/* w w w . j a v a 2 s . c om*/ break; case PIXELINTERLEAVED: case COMPONENT: bandOffsets = ((ComponentSampleModel) model).getBandOffsets(); // add pixel-stride, scanline-stride, band offset count, & band offsets to // the header count headersize += 3 + bandOffsets.length; break; case MULTIPIXELPACKED: break; case SINGLEPIXELPACKED: break; default: } dos.writeInt(headersize); dos.writeInt(raster.getHeight()); dos.writeInt(raster.getWidth()); dos.writeInt(raster.getNumBands()); dos.writeInt(raster.getTransferType()); dos.writeInt(modeltype.ordinal()); switch (modeltype) { case BANDED: break; case COMPONENT: case PIXELINTERLEAVED: { final ComponentSampleModel pism = (ComponentSampleModel) model; dos.writeInt(pism.getPixelStride()); dos.writeInt(pism.getScanlineStride()); dos.writeInt(bandOffsets.length); for (final int bandOffset : bandOffsets) { dos.writeInt(bandOffset); } } break; case MULTIPIXELPACKED: break; case SINGLEPIXELPACKED: break; default: } }