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

The following examples show how to use java.awt.image.WritableRaster#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: TIFFDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
Example 2
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 3
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Whether we can return the data buffer's bank data without performing any
 * copy or conversion operations.
 */
private static boolean canUseBankDataDirectly(final WritableRaster r,
	final int transferType, final Class<? extends DataBuffer> dataBufferClass)
{
	final int tt = r.getTransferType();
	if (tt != transferType) return false;
	final DataBuffer buffer = r.getDataBuffer();
	if (!dataBufferClass.isInstance(buffer)) return false;
	final SampleModel model = r.getSampleModel();
	if (!(model instanceof ComponentSampleModel)) return false;
	final ComponentSampleModel csm = (ComponentSampleModel) model;
	final int pixelStride = csm.getPixelStride();
	if (pixelStride != 1) return false;
	final int w = r.getWidth();
	final int scanlineStride = csm.getScanlineStride();
	if (scanlineStride != w) return false;
	final int c = r.getNumBands();
	final int[] bandOffsets = csm.getBandOffsets();
	if (bandOffsets.length != c) return false;
	for (int i = 0; i < bandOffsets.length; i++) {
		if (bandOffsets[i] != 0) return false;
	}
	for (int i = 0; i < bandOffsets.length; i++) {
		if (bandOffsets[i] != i) return false;
	}
	return true;
}
 
Example 4
Source File: TIFFDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
Example 5
Source File: ImageUtil.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 6
Source File: ImageUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 7
Source File: ImageUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 8
Source File: ImageUtil.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 9
Source File: ImageUtil.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 10
Source File: ImageUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 11
Source File: ImageUtil.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 12
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 13
Source File: ImageUtil.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 14
Source File: ImageUtil.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 15
Source File: ImageUtil.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 16
Source File: ImageUtil.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 17
Source File: ImageUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 18
Source File: ImageUtil.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 19
Source File: ImageUtil.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
 
Example 20
Source File: ImageUtil.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns whether the image has contiguous data across rows.
 */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if(image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage)image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }

    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel)sm;

        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }

        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }

        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }

        return true;
    }

    // Otherwise true if and only if it's a bilevel image with
    // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
    // pixel stride.
    return ImageUtil.isBinary(sm);
}