当前位置: 首页>>代码示例>>Java>>正文


Java ComponentSampleModel.getScanlineStride方法代码示例

本文整理汇总了Java中java.awt.image.ComponentSampleModel.getScanlineStride方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentSampleModel.getScanlineStride方法的具体用法?Java ComponentSampleModel.getScanlineStride怎么用?Java ComponentSampleModel.getScanlineStride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.ComponentSampleModel的用法示例。


在下文中一共展示了ComponentSampleModel.getScanlineStride方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBandSize

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:ImageUtil.java

示例2: RectIterCSM

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public RectIterCSM(RenderedImage im, Rectangle bounds) {
    super(im, bounds);

    ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
    
    this.scanlineStride = csm.getScanlineStride();
    this.pixelStride = csm.getPixelStride();
    this.bankIndices = csm.getBankIndices();
    int[] bo = csm.getBandOffsets();

    this.bandOffsets = new int[numBands + 1];
    for (int i = 0; i < numBands; i++) {
        bandOffsets[i] = bo[i];
    }
    bandOffsets[numBands] = 0;

    this.DBOffsets = new int[numBands];

    this.offset = (y - sampleModelTranslateY)*scanlineStride +
        (x - sampleModelTranslateX)*pixelStride;
    this.bandOffset = bandOffsets[0];
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:23,代码来源:RectIterCSM.java

示例3: getBufferSizeCSM

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private 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;
    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;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:18,代码来源:RecyclingTileFactory.java

示例4: createBufferedImageForDisplay

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * Efficiently create a TYPE_3BYTE_BGR for display if possible. This is
 * typically much faster than to create and display than an ARGB buffered
 * image. If the input image is not in RGB format, then the ARGB form will
 * be returned instead.
 * 
 * @param img
 *            the image to convert
 * @param ret
 *            the image to draw into if possible. Can be null.
 * @return the converted image. Might not be the same as the ret parameter.
 */
public static BufferedImage createBufferedImageForDisplay(final MBFImage img, BufferedImage ret) {
	if (img.colourSpace != ColourSpace.RGB)
		return ImageUtilities.createBufferedImage(img, ret);

	final int width = img.getWidth();
	final int height = img.getHeight();

	if (ret == null || ret.getWidth() != width || ret.getHeight() != height
			|| ret.getType() != BufferedImage.TYPE_3BYTE_BGR)
		ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

	final WritableRaster raster = ret.getRaster();

	final float[][] r = img.getBand(0).pixels;
	final float[][] g = img.getBand(1).pixels;
	final float[][] b = img.getBand(2).pixels;

	final ComponentSampleModel sm = (ComponentSampleModel) raster.getSampleModel();
	final DataBufferByte db = (DataBufferByte) raster.getDataBuffer();
	final int scanlineStride = sm.getScanlineStride();
	final int pixelStride = sm.getPixelStride();

	final byte[] data = db.getData();
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			data[y * scanlineStride + x * pixelStride + 2] = (byte)
					Math.max(0, Math.min(255, (int) (r[y][x] * 255)));
			data[y * scanlineStride + x * pixelStride + 1] = (byte)
					Math.max(0, Math.min(255, (int) (g[y][x] * 255)));
			data[y * scanlineStride + x * pixelStride] = (byte)
					Math.max(0, Math.min(255, (int) (b[y][x] * 255)));
		}
	}

	return ret;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:49,代码来源:ImageUtilities.java

示例5: createBufferedImage

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * Efficiently create a TYPE_BYTE_GRAY for display. This is typically much
 * faster than to create and display than an ARGB buffered image.
 * 
 * @param img
 *            the image to convert
 * @param ret
 *            BufferedImage to draw into if possible. Can be null.
 * @return the converted image
 */
public static BufferedImage createBufferedImage(final FImage img, BufferedImage ret) {
	final int width = img.getWidth();
	final int height = img.getHeight();

	if (ret == null || ret.getWidth() != width || ret.getHeight() != height
			|| ret.getType() != BufferedImage.TYPE_BYTE_GRAY)
		ret = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);

	final WritableRaster raster = ret.getRaster();

	final float[][] p = img.pixels;

	final ComponentSampleModel sm = (ComponentSampleModel) raster.getSampleModel();
	final DataBufferByte db = (DataBufferByte) raster.getDataBuffer();
	final int scanlineStride = sm.getScanlineStride();
	final int pixelStride = sm.getPixelStride();

	final byte[] data = db.getData();
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			data[y * scanlineStride + x * pixelStride] = (byte) (Math.max(0, Math.min(255, (int) (p[y][x] * 255))));
		}
	}

	return ret;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:37,代码来源:ImageUtilities.java

示例6: calculateScanlineStrideCSM

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * Calculates scanline stride in bytes
 * @param csm - component sample model
 * @param r - raster
 * @return scanline stride in bytes
 */
private static int calculateScanlineStrideCSM(ComponentSampleModel csm, Raster r) {
    if (csm.getScanlineStride() != csm.getPixelStride()*csm.getWidth()) {
        int dataTypeSize = DataBuffer.getDataTypeSize(r.getDataBuffer().getDataType()) / 8;
        return csm.getScanlineStride()*dataTypeSize;
    }
    return -1;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:14,代码来源:NativeImageFormat.java

示例7: extractComponentRGBInt

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 3 ];

  int[] bankIndices = aSampleModel.getBankIndices();
  int[] bankOffsets = aSampleModel.getBandOffsets();
  int rScanIx = bankOffsets[ 0 ];
  int gScanIx = bankOffsets[ 1 ];
  int bScanIx = bankOffsets[ 2 ];

  int pixelStride = aSampleModel.getPixelStride();
  int scanlineStride = aSampleModel.getScanlineStride();
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int rPixIx = rScanIx;
    int gPixIx = gScanIx;
    int bPixIx = bScanIx;
    for ( int x = 0; x < aWidth; x++, b += 3 ) {
      out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
      rPixIx += pixelStride;
      out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
      gPixIx += pixelStride;
      out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
      bPixIx += pixelStride;
    }
    rScanIx += scanlineStride;
    gScanIx += scanlineStride;
    bScanIx += scanlineStride;
  }
  return out;
}
 
开发者ID:lonnyj,项目名称:webp-imageio,代码行数:30,代码来源:WebP.java

示例8: extractComponentRGBByte

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBByte( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferByte aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 3 ];

  int[] bankIndices = aSampleModel.getBankIndices();
  int[] bankOffsets = aSampleModel.getBandOffsets();
  int rScanIx = bankOffsets[ 0 ];
  int gScanIx = bankOffsets[ 1 ];
  int bScanIx = bankOffsets[ 2 ];

  int pixelStride = aSampleModel.getPixelStride();
  int scanlineStride = aSampleModel.getScanlineStride();
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int rPixIx = rScanIx;
    int gPixIx = gScanIx;
    int bPixIx = bScanIx;
    for ( int x = 0; x < aWidth; x++, b += 3 ) {
      out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
      rPixIx += pixelStride;
      out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
      gPixIx += pixelStride;
      out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
      bPixIx += pixelStride;
    }
    rScanIx += scanlineStride;
    gScanIx += scanlineStride;
    bScanIx += scanlineStride;
  }
  return out;
}
 
开发者ID:lonnyj,项目名称:webp-imageio,代码行数:30,代码来源:WebP.java

示例9: extractComponentRGBAInt

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBAInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 4 ];

  int[] bankIndices = aSampleModel.getBankIndices();
  int[] bankOffsets = aSampleModel.getBandOffsets();
  int rScanIx = bankOffsets[ 0 ];
  int gScanIx = bankOffsets[ 1 ];
  int bScanIx = bankOffsets[ 2 ];
  int aScanIx = bankOffsets[ 3 ];

  int pixelStride = aSampleModel.getPixelStride();
  int scanlineStride = aSampleModel.getScanlineStride();
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int rPixIx = rScanIx;
    int gPixIx = gScanIx;
    int bPixIx = bScanIx;
    int aPixIx = aScanIx;
    for ( int x = 0; x < aWidth; x++, b += 4 ) {
      out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
      rPixIx += pixelStride;
      out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
      gPixIx += pixelStride;
      out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
      bPixIx += pixelStride;
      out[b + 3] = (byte) aDataBuffer.getElem(bankIndices[3], aPixIx);
      aPixIx += pixelStride;
    }
    rScanIx += scanlineStride;
    gScanIx += scanlineStride;
    bScanIx += scanlineStride;
    aScanIx += scanlineStride;
  }
  return out;
}
 
开发者ID:lonnyj,项目名称:webp-imageio,代码行数:35,代码来源:WebP.java

示例10: extractComponentRGBAByte

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBAByte( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferByte aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 4 ];

  int[] bankIndices = aSampleModel.getBankIndices();
  int[] bankOffsets = aSampleModel.getBandOffsets();
  int rScanIx = bankOffsets[ 0 ];
  int gScanIx = bankOffsets[ 1 ];
  int bScanIx = bankOffsets[ 2 ];
  int aScanIx = bankOffsets[ 3 ];

  int pixelStride = aSampleModel.getPixelStride();
  int scanlineStride = aSampleModel.getScanlineStride();
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int rPixIx = rScanIx;
    int gPixIx = gScanIx;
    int bPixIx = bScanIx;
    int aPixIx = aScanIx;
    for ( int x = 0; x < aWidth; x++, b += 4 ) {
      out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
      rPixIx += pixelStride;
      out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
      gPixIx += pixelStride;
      out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
      bPixIx += pixelStride;
      out[b + 3] = (byte) aDataBuffer.getElem(bankIndices[3], aPixIx);
      aPixIx += pixelStride;
    }
    rScanIx += scanlineStride;
    gScanIx += scanlineStride;
    bScanIx += scanlineStride;
    aScanIx += scanlineStride;
  }
  return out;
}
 
开发者ID:lonnyj,项目名称:webp-imageio,代码行数:35,代码来源:WebP.java

示例11: canUseBankDataDirectly

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:scifio,项目名称:scifio,代码行数:31,代码来源:AWTImageTools.java

示例12: getScanlineStride

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * Gets the scanline stride for the given raster
 * 
 * @param raster
 * @return
 */
int getScanlineStride(Raster raster) {
    if (raster.getSampleModel() instanceof ComponentSampleModel) {
        ComponentSampleModel csm = ((ComponentSampleModel) raster.getSampleModel());
        return csm.getScanlineStride();
    } else {
        return raster.getDataBuffer().getSize() / raster.getHeight();
    }
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:15,代码来源:ScanlineCursor.java

示例13: filter

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public WritableRaster filter(Raster src, WritableRaster dest)
{
  if (dest == null)
    dest = createCompatibleDestRaster(src);

  DataBuffer  srcDB =  src.getDataBuffer();
  DataBuffer destDB = dest.getDataBuffer();

  ComponentSampleModel  srcSM = (ComponentSampleModel)  src.getSampleModel();
  ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();


  // Calculate offset to data in the underlying arrays:

  int  srcScanlineStride =  srcSM.getScanlineStride();
  int destScanlineStride = destSM.getScanlineStride();
  int srcX  =  src.getMinX() -  src.getSampleModelTranslateX();
  int srcY  =  src.getMinY() -  src.getSampleModelTranslateY();
  int destX = dest.getMinX() - dest.getSampleModelTranslateX();
  int destY = dest.getMinY() - dest.getSampleModelTranslateY();

  int numBands = srcSM.getNumBands();

  /* We can't use getOffset(x, y) from the sample model since we
     don't want the band offset added in. */

  int srcOffset =
    numBands*srcX + srcScanlineStride*srcY +    // from sample model
    srcDB.getOffset();                          // from data buffer

  int destOffset =
    numBands*destX + destScanlineStride*destY + // from sample model
    destDB.getOffset();                         // from data buffer

  // Determine how much, and how many times to blit.

  int rowSize = src.getWidth()*numBands;
  int h = src.getHeight();

  if ((rowSize == srcScanlineStride) &&
      (rowSize == destScanlineStride))
    {
      // collapse scan line blits to one large blit.
      rowSize *= h;
      h = 1;
    }


  // Do blitting

  Object srcArray  = Buffers.getData(srcDB);
  Object destArray = Buffers.getData(destDB);

  for (int yd = 0; yd<h; yd++)
    {
      System.arraycopy(srcArray, srcOffset,
                       destArray, destOffset,
                       rowSize);
      srcOffset  +=  srcScanlineStride;
      destOffset += destScanlineStride;
    }


  return dest;
}
 
开发者ID:vilie,项目名称:javify,代码行数:66,代码来源:ComponentDataBlitOp.java

示例14: filter

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public WritableRaster filter(Raster src, WritableRaster dest)
 {
   if (dest == null)
     dest = createCompatibleDestRaster(src);
   
   DataBuffer  srcDB =  src.getDataBuffer();
   DataBuffer destDB = dest.getDataBuffer();
   
   ComponentSampleModel  srcSM = (ComponentSampleModel)  src.getSampleModel();
   ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();

   
   // Calculate offset to data in the underlying arrays:

   int  srcScanlineStride =  srcSM.getScanlineStride();
   int destScanlineStride = destSM.getScanlineStride();
   int srcX  =  src.getMinX() -  src.getSampleModelTranslateX();
   int srcY  =  src.getMinY() -  src.getSampleModelTranslateY();
   int destX = dest.getMinX() - dest.getSampleModelTranslateX();
   int destY = dest.getMinY() - dest.getSampleModelTranslateY();

   int numBands = srcSM.getNumBands();

   /* We can't use getOffset(x, y) from the sample model since we
      don't want the band offset added in. */

   int srcOffset = 
     numBands*srcX + srcScanlineStride*srcY +    // from sample model
     srcDB.getOffset();                          // from data buffer

   int destOffset =
     numBands*destX + destScanlineStride*destY + // from sample model
     destDB.getOffset();                         // from data buffer

   // Determine how much, and how many times to blit.
   
   int rowSize = src.getWidth()*numBands;
   int h = src.getHeight();
   
   if ((rowSize == srcScanlineStride) &&
(rowSize == destScanlineStride))
     {
// collapse scan line blits to one large blit.
rowSize *= h;
h = 1;
     }


   // Do blitting
   
   Object srcArray  = Buffers.getData(srcDB);
   Object destArray = Buffers.getData(destDB);
   
   for (int yd = 0; yd<h; yd++)
     {
System.arraycopy(srcArray, srcOffset, 
		 destArray, destOffset,
		 rowSize);
srcOffset  +=  srcScanlineStride;
destOffset += destScanlineStride;
     }
   

   return dest;
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:66,代码来源:ComponentDataBlitOp.java

示例15: areEqualSampleModels

import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
 * Determines whether two SampleModels are "equal", i.e.,
 * assignment-compatible.  This signifies that the two SampleModels
 * are either the very same object or are two different objects
 * with identical characteristics.
 */
public boolean areEqualSampleModels(SampleModel sm1, SampleModel sm2) {
    if(sm1 == sm2) {
        // Identical objects.
        return true;
    } else if(sm1.getClass() == sm2.getClass() &&
              sm1.getDataType() == sm2.getDataType() &&
              sm1.getTransferType() == sm2.getTransferType() &&
              sm1.getWidth() == sm2.getWidth() &&
              sm1.getHeight() == sm2.getHeight()) {
        // At this point all common attributes are equivalent. Next test
        // those specific to the known direct subclasses of SampleModel.
        // Subclasses which are not known will always return false.
        if(sm1 instanceof ComponentSampleModel) {
            ComponentSampleModel csm1 = (ComponentSampleModel)sm1;
            ComponentSampleModel csm2 = (ComponentSampleModel)sm2;
            return csm1.getPixelStride() == csm2.getPixelStride() &&
                csm1.getScanlineStride() == csm2.getScanlineStride() &&
                Arrays.equals(csm1.getBankIndices(),
                              csm2.getBankIndices()) &&
                Arrays.equals(csm1.getBandOffsets(),
                              csm2.getBandOffsets());
        } else if(sm1 instanceof MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel mpp1 =
                (MultiPixelPackedSampleModel)sm1;
            MultiPixelPackedSampleModel mpp2 =
                (MultiPixelPackedSampleModel)sm2;
            return mpp1.getPixelBitStride() == mpp2.getPixelBitStride() &&
                mpp1.getScanlineStride() == mpp2.getScanlineStride() &&
                mpp1.getDataBitOffset() == mpp2.getDataBitOffset();
        } else if(sm1 instanceof SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel spp1 =
                (SinglePixelPackedSampleModel)sm1;
            SinglePixelPackedSampleModel spp2 =
                (SinglePixelPackedSampleModel)sm2;
            return spp1.getScanlineStride() == spp2.getScanlineStride() &&
                Arrays.equals(spp1.getBitMasks(), spp2.getBitMasks());
        }
    }

    return false;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:48,代码来源:ImageUtil.java


注:本文中的java.awt.image.ComponentSampleModel.getScanlineStride方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。