Java Code Examples for java.awt.image.Raster#getSampleModel()

The following examples show how to use java.awt.image.Raster#getSampleModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AWTImageUtils.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get datasets from an image
 * @param image
 * @param keepBitWidth if true, then use signed primitives of same bit width for possibly unsigned data
 * @return array of datasets
 */
static public Dataset[] makeDatasets(final BufferedImage image, boolean keepBitWidth) {
	// make raster from buffered image
	final Raster ras = image.getData();
	final SampleModel sm = ras.getSampleModel();
	int[] dtype = getDTypeFromImage(sm, keepBitWidth);

	final int bands = ras.getNumBands();
	Dataset[] data = new Dataset[bands];

	createDatasets(ras, data, dtype[0]);
	if (dtype[1] == 1) {
		for (int i = 0; i < bands; i++) {
			tagIntForShortDataset(data[i]);
		}
	}
	return data;
}
 
Example 2
Source File: VncComponent.java    From jfxvnc with Apache License 2.0 6 votes vote down vote up
private void updateRaster(Raster raster, int x, int y, int w, int h, ByteBuf img) {

    final DataBuffer data = raster.getDataBuffer();
    final SampleModel model = raster.getSampleModel();
    int x1 = x + w;
    int y1 = y + h;

    byte[] buffer = new byte[model.getNumDataElements()];

    for (int i = y; i < y1; i++) {
      for (int j = x; j < x1; j++) {
        img.readBytes(buffer);
        model.setDataElements(j, i, buffer, data);
      }
    }
  }
 
Example 3
Source File: MediaLibAccessor.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
/**
 *  Returns the most efficient FormatTag that is compatible with
 *  the destination raster and all source rasters.
 *
 *  @param srcs the source <code>Raster</code>; may be <code>null</code>.
 *  @param dst  the destination <code>Raster</code>.
 */
public static int findCompatibleTag(Raster src) {
    SampleModel dstSM = src.getSampleModel();
    int dstDT = dstSM.getDataType();

    int defaultDataType = dstSM.getDataType();

    boolean allComponentSampleModel =
         dstSM instanceof ComponentSampleModel;
    boolean allBinary = ImageUtil.isBinary(dstSM);

    if(allBinary) {
        // The copy flag is not set until the mediaLibImage is
        // created as knowing this information requires too much
        // processing to determine here.
        return DataBuffer.TYPE_BYTE | BINARY;
    }

    if (!allComponentSampleModel) {
        if ((defaultDataType == DataBuffer.TYPE_BYTE) ||
            (defaultDataType == DataBuffer.TYPE_USHORT) ||
            (defaultDataType == DataBuffer.TYPE_SHORT)) {
            defaultDataType = DataBuffer.TYPE_INT;
        }
    }

    int tag = defaultDataType | COPIED;

    if (!allComponentSampleModel) {
        return tag;
    }

    if (isPixelSequential(dstSM))
        return dstDT | UNCOPIED;
    return tag;
}
 
Example 4
Source File: BlackOrOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Bytewise OR of the black pixels */

  private void byteLoop(Raster src0, Raster src1, 
			WritableRaster dst, Rectangle dstRect) {
    int w = dst.getWidth();
    int h = dst.getHeight();

    DataBufferByte src0db = (DataBufferByte) src0.getDataBuffer();
    DataBufferByte src1db = (DataBufferByte) src1.getDataBuffer();
    DataBufferByte dstdb = (DataBufferByte) dst.getDataBuffer();

    byte src0Data[] = src0db.getData();
    byte src1Data[] = src1db.getData();
    byte dstData[] = dstdb.getData();

    MultiPixelPackedSampleModel src0sm = 
      (MultiPixelPackedSampleModel) src0.getSampleModel();
    MultiPixelPackedSampleModel src1sm = 
      (MultiPixelPackedSampleModel) src1.getSampleModel();
    MultiPixelPackedSampleModel dstsm = 
      (MultiPixelPackedSampleModel) dst.getSampleModel();

    int src0ScanlineStride = src0sm.getScanlineStride();
    int src1ScanlineStride = src1sm.getScanlineStride();
    int dstScanlineStride = dstsm.getScanlineStride();

    int white = getWhite();

    if (white == 0) {
      for (int offset = 0; offset < h*dstScanlineStride; offset++) {
	dstData[offset] = (byte) (src0Data[offset] | src1Data[offset]);
      }
    } else {
      for (int offset = 0; offset < h*dstScanlineStride; offset++) {
	dstData[offset] = (byte) (src0Data[offset] & src1Data[offset]);
      }
    }
  }
 
Example 5
Source File: SingleTileRenderedImage.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a SingleTileRenderedImage based on a Raster
 * and a ColorModel.
 *
 * @param ras A Raster that will define tile (0, 0) of the image.
 * @param colorModel A ColorModel that will serve as the image's
 *           ColorModel.
 */
public SingleTileRenderedImage(Raster ras, ColorModel colorModel) {
    this.ras = ras;

    this.tileGridXOffset = this.minX = ras.getMinX();
    this.tileGridYOffset = this.minY = ras.getMinY();
    this.tileWidth = this.width = ras.getWidth();
    this.tileHeight = this.height = ras.getHeight();
    this.sampleModel = ras.getSampleModel();
    this.colorModel = colorModel;
}
 
Example 6
Source File: DirectRasterAccessor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a DirectRasterAccessor object */

  public DirectRasterAccessor(Raster raster, ColorModel cm) {
    DataBuffer db = raster.getDataBuffer();

    offsetX = raster.getMinX()-raster.getSampleModelTranslateX();
    offsetY = raster.getMinY()-raster.getSampleModelTranslateY();

    if (!(db instanceof DataBufferByte)) {
      throw new RuntimeException("DataBuffer of Raster not of correct type " +
				 "(expected DataBufferByte, got " +
				 db.getClass().getName() + ")");
    }

    DataBufferByte dbb = (DataBufferByte) db;

    SampleModel sm = raster.getSampleModel();

    if (!(sm instanceof MultiPixelPackedSampleModel)) {
      throw new RuntimeException("SampleModel of Raster not of correct type " +
				 "(expected MultiPixelPackedSampleModel, got " +
				 sm.getClass().getName() + ")");
    }

    MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) sm;
    
    data = dbb.getData();
    scanlineStride = mppsm.getScanlineStride();

    if (cm.getRGB(0) == Color.white.getRGB()) {
      white = 0;
      black = 1;
    } else {
      white = 1;
      black = 0;
    }
  }
 
Example 7
Source File: SingleTileRenderedImage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a SingleTileRenderedImage based on a Raster
 * and a ColorModel.
 *
 * @param ras A Raster that will define tile (0, 0) of the image.
 * @param colorModel A ColorModel that will serve as the image's
 *           ColorModel.
 */
public SingleTileRenderedImage(Raster ras, ColorModel colorModel) {
    this.ras = ras;

    this.tileGridXOffset = this.minX = ras.getMinX();
    this.tileGridYOffset = this.minY = ras.getMinY();
    this.tileWidth = this.width = ras.getWidth();
    this.tileHeight = this.height = ras.getHeight();
    this.sampleModel = ras.getSampleModel();
    this.colorModel = colorModel;
}
 
Example 8
Source File: LCMSImageLayout.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 9
Source File: LCMSImageLayout.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 10
Source File: RLSAOpImage.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
/** Does vertical RLSA */

  private void byteLoop_v(Raster src, WritableRaster dst) {
    int minX = getMinX();
    int maxX = getMaxX();
    int minY = getMinY();
    int maxY = getMaxY();

    DataBufferByte srcdb = (DataBufferByte) src.getDataBuffer();
    DataBufferByte dstdb = (DataBufferByte) dst.getDataBuffer();

    byte srcData[] = srcdb.getData();
    byte dstData[] = dstdb.getData();

    MultiPixelPackedSampleModel srcsm = (MultiPixelPackedSampleModel) src.getSampleModel();
    MultiPixelPackedSampleModel dstsm = (MultiPixelPackedSampleModel) dst.getSampleModel();

    int srcScanlineStride = srcsm.getScanlineStride();
    int dstScanlineStride = dstsm.getScanlineStride();

    int srcScanlineOffset = minY*srcScanlineStride;
    int dstScanlineOffset = 0;

    int[] column = new int[maxY];

    int white = getWhite();

    for (int x = minX, dstx = 0; x < maxX; x++, dstx++) {
      int srcxOffset = x / 8;
      int srcxBit = x % 8;
      int dstxOffset = dstx / 8;
      int dstxBit = dstx % 8;

      int srcLineOffset = srcScanlineOffset;
      int dstLineOffset = dstScanlineOffset;

      int lasty = minY-(threshold+2);

      if (white == 0) {
	for (int y = minY; y < maxY; y++) {
	  if ((srcData[srcLineOffset+srcxOffset] & bitAccess[srcxBit]) != 0) {
	    column[y] = 1;
	    if (y < lasty+threshold+2) {
	      for (int i = lasty; i<y; i++) {
		column[i] = 1;
	      }
	    }
	    lasty = y;
	  } else {
	    column[y] = 0;
	  }
	  srcLineOffset += srcScanlineStride;
	}
      } else {
	for (int y = minY; y < maxY; y++) {
	  if ((srcData[srcLineOffset+srcxOffset] & bitAccess[srcxBit]) == 0) {
	    column[y] = 0;
	    if (y < lasty+threshold+2) {
	      for (int i = lasty; i<y; i++) {
		column[i] = 0;
	      }
	    }
	    lasty = y;
	  } else {
	    column[y] = 1;
	  }
	  srcLineOffset += srcScanlineStride;
	}
      }

      // Copy resulting column onto image

      for (int srcy = minY, lineOffset = 0; srcy < maxY; srcy++, lineOffset += dstScanlineStride) {
	if (column[srcy] == 1) {
	  dstData[lineOffset+dstxOffset] |= bitAccess[dstxBit];
	} else {
	  dstData[lineOffset+dstxOffset] &= ~bitAccess[dstxBit];
	}
      }
    }
  }
 
Example 11
Source File: ModifiedRaster.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public ModifiedRaster(Raster r) {
    super(r.getSampleModel(), r.getDataBuffer(), r.getBounds(), new Point(r.getSampleModelTranslateX(), r.getSampleModelTranslateY()), r.getParent());
}
 
Example 12
Source File: LCMSImageLayout.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 13
Source File: LCMSImageLayout.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 14
Source File: LCMSImageLayout.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 15
Source File: RenderableImageProducer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The runnable method for this class. This will produce an image using
 * the current RenderableImage and RenderContext and send it to all the
 * ImageConsumer currently registered with this class.
 */
public void run() {
    // First get the rendered image
    RenderedImage rdrdImage;
    if (rc != null) {
        rdrdImage = rdblImage.createRendering(rc);
    } else {
        rdrdImage = rdblImage.createDefaultRendering();
    }

    // And its ColorModel
    ColorModel colorModel = rdrdImage.getColorModel();
    Raster raster = rdrdImage.getData();
    SampleModel sampleModel = raster.getSampleModel();
    DataBuffer dataBuffer = raster.getDataBuffer();

    if (colorModel == null) {
        colorModel = ColorModel.getRGBdefault();
    }
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();

    Enumeration<ImageConsumer> icList;
    ImageConsumer ic;
    // Set up the ImageConsumers
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = icList.nextElement();
        ic.setDimensions(width,height);
        ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
                    ImageConsumer.COMPLETESCANLINES |
                    ImageConsumer.SINGLEPASS |
                    ImageConsumer.SINGLEFRAME);
    }

    // Get RGB pixels from the raster scanline by scanline and
    // send to consumers.
    int pix[] = new int[width];
    int i,j;
    int numBands = sampleModel.getNumBands();
    int tmpPixel[] = new int[numBands];
    for (j = 0; j < height; j++) {
        for(i = 0; i < width; i++) {
            sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
            pix[i] = colorModel.getDataElement(tmpPixel, 0);
        }
        // Now send the scanline to the Consumers
        icList = ics.elements();
        while (icList.hasMoreElements()) {
            ic = icList.nextElement();
            ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
        }
    }

    // Now tell the consumers we're done.
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = icList.nextElement();
        ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
    }
}
 
Example 16
Source File: LCMSImageLayout.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 17
Source File: RenderableImageProducer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * The runnable method for this class. This will produce an image using
 * the current RenderableImage and RenderContext and send it to all the
 * ImageConsumer currently registered with this class.
 */
public void run() {
    // First get the rendered image
    RenderedImage rdrdImage;
    if (rc != null) {
        rdrdImage = rdblImage.createRendering(rc);
    } else {
        rdrdImage = rdblImage.createDefaultRendering();
    }

    // And its ColorModel
    ColorModel colorModel = rdrdImage.getColorModel();
    Raster raster = rdrdImage.getData();
    SampleModel sampleModel = raster.getSampleModel();
    DataBuffer dataBuffer = raster.getDataBuffer();

    if (colorModel == null) {
        colorModel = ColorModel.getRGBdefault();
    }
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();

    Enumeration<ImageConsumer> icList;
    ImageConsumer ic;
    // Set up the ImageConsumers
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = icList.nextElement();
        ic.setDimensions(width,height);
        ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
                    ImageConsumer.COMPLETESCANLINES |
                    ImageConsumer.SINGLEPASS |
                    ImageConsumer.SINGLEFRAME);
    }

    // Get RGB pixels from the raster scanline by scanline and
    // send to consumers.
    int[] pix = new int[width];
    int i,j;
    int numBands = sampleModel.getNumBands();
    int[] tmpPixel = new int[numBands];
    for (j = 0; j < height; j++) {
        for(i = 0; i < width; i++) {
            sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
            pix[i] = colorModel.getDataElement(tmpPixel, 0);
        }
        // Now send the scanline to the Consumers
        icList = ics.elements();
        while (icList.hasMoreElements()) {
            ic = icList.nextElement();
            ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
        }
    }

    // Now tell the consumers we're done.
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = icList.nextElement();
        ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
    }
}
 
Example 18
Source File: LCMSImageLayout.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 19
Source File: LCMSImageLayout.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
 
Example 20
Source File: LCMSImageLayout.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster &&
            r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster)r;

        ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();

        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);

        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);

        int firstBand = 0;
        switch (order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand  = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }

        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();

        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;

        l.width = br.getWidth();
        l.height = br.getHeight();

        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}