當前位置: 首頁>>代碼示例>>Java>>正文


Java SinglePixelPackedSampleModel類代碼示例

本文整理匯總了Java中java.awt.image.SinglePixelPackedSampleModel的典型用法代碼示例。如果您正苦於以下問題:Java SinglePixelPackedSampleModel類的具體用法?Java SinglePixelPackedSampleModel怎麽用?Java SinglePixelPackedSampleModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SinglePixelPackedSampleModel類屬於java.awt.image包,在下文中一共展示了SinglePixelPackedSampleModel類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyGlyphToBufferedImageIntAlpha

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
static boolean copyGlyphToBufferedImageIntAlpha(FT2Library.FT_Bitmap bitmap, BufferedImage img, int x, int y, Color color) {
	if (x + bitmap.width > img.getWidth()) {
		return false;
	}
	if (y + bitmap.rows > img.getHeight()) {
		return false;
	}

	final DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
	final int[] data = dataBuffer.getData();
	final int stride = ((SinglePixelPackedSampleModel) img.getSampleModel()).getScanlineStride();

	ByteBuffer bb = bitmap.buffer.getByteBuffer(0, Math.abs(bitmap.pitch) * bitmap.rows);
	int bbOff = (bitmap.pitch < 0) ? (-bitmap.pitch * (bitmap.rows - 1)) : 0;
	int dataOff = dataBuffer.getOffset() + y * stride + x;

	int colorValue = (color == null ? Color.WHITE : color).getRGB() & 0xFFFFFF;

	for (int r = 0; r < bitmap.rows; r++, bbOff += bitmap.pitch, dataOff += stride) {
		for (int c = 0; c < bitmap.width; c++) {
			data[dataOff + c] = colorValue | (bb.get(bbOff + c) << 24);
		}
	}

	return true;
}
 
開發者ID:testobject,項目名稱:visual-scripting,代碼行數:27,代碼來源:FT2Helper.java

示例2: extractDirectRGBInt

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
private static byte[] extractDirectRGBInt( int aWidth, int aHeight, DirectColorModel aColorModel, SinglePixelPackedSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 3 ];

  int rMask = aColorModel.getRedMask();
  int gMask = aColorModel.getGreenMask();
  int bMask = aColorModel.getBlueMask();
  int rShift = getShift( rMask );
  int gShift = getShift( gMask );
  int bShift = getShift( bMask );
  int[] bank = aDataBuffer.getBankData()[ 0 ];
  int scanlineStride = aSampleModel.getScanlineStride();
  int scanIx = 0;
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int pixIx = scanIx;
    for ( int x = 0; x < aWidth; x++, b += 3 ) {
      int pixel = bank[ pixIx++ ];
      out[ b ] = ( byte ) ( ( pixel & rMask ) >>> rShift );
      out[ b + 1 ] = ( byte ) ( ( pixel & gMask ) >>> gShift );
      out[ b + 2 ] = ( byte ) ( ( pixel & bMask ) >>> bShift );
    }
    scanIx += scanlineStride;
  }
  return out;
}
 
開發者ID:lonnyj,項目名稱:webp-imageio,代碼行數:25,代碼來源:WebP.java

示例3: canEncodeImage

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:BMPImageWriterSpi.java

示例4: getElementSize

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:ImageUtil.java

示例5: allocateRgbImage

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
/**
 * @param windowWidth
 * @param windowHeight
 * @param pBuffer
 * @param windowSize
 * @param backgroundTransparent
 * @return an Image
 */
static Object allocateRgbImage(int windowWidth, int windowHeight,
                               int[] pBuffer, int windowSize,
                               boolean backgroundTransparent) {
  //backgroundTransparent not working with antialiasDisplay. I have no idea why. BH 9/24/08
  /* DEAD CODE   if (false && backgroundTransparent)
        return new BufferedImage(
            rgbColorModelT,
            Raster.createWritableRaster(
                new SinglePixelPackedSampleModel(
                    DataBuffer.TYPE_INT,
                    windowWidth,
                    windowHeight,
                    sampleModelBitMasksT), 
                new DataBufferInt(pBuffer, windowSize),
                null),
            false, 
            null);
  */
  return new BufferedImage(rgbColorModel, Raster.createWritableRaster(
      new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, windowWidth,
          windowHeight, sampleModelBitMasks), new DataBufferInt(pBuffer,
          windowSize), null), false, null);
}
 
開發者ID:etomica,項目名稱:etomica,代碼行數:32,代碼來源:Image.java

示例6: checkCompatible

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
private void checkCompatible(SampleModel model){
    // Check model is ok: should be SinglePixelPackedSampleModel
    if(!(model instanceof SinglePixelPackedSampleModel))
        throw new IllegalArgumentException
            ("MorphologyOp only works with Rasters " +
             "using SinglePixelPackedSampleModels");
    // Check number of bands
    int nBands = model.getNumBands();
    if(nBands!=4)
        throw new IllegalArgumentException
            ("MorphologyOp only words with Rasters having 4 bands");
    // Check that integer packed.
    if(model.getDataType()!=DataBuffer.TYPE_INT)
        throw new IllegalArgumentException
            ("MorphologyOp only works with Rasters using DataBufferInt");

    // Check bit masks
    int[] bitOffsets=((SinglePixelPackedSampleModel)model).getBitOffsets();
    for(int i=0; i<bitOffsets.length; i++){
        if(bitOffsets[i]%8 != 0)
            throw new IllegalArgumentException
                ("MorphologyOp only works with Rasters using 8 bits " +
                 "per band : " + i + " : " + bitOffsets[i]);
    }
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:26,代碼來源:MorphologyOp.java

示例7: decode

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
public BufferedImage decode(ImageInputStream in) throws IOException, BMPException {
    IndexColorModel palette = readPalette(in);
    skipToImage(in);

    Dimension d = infoHeader.getSize();
    int h = (int)d.getHeight();
    int w = (int)d.getWidth();

    byte[] data = uncompress(w, h, in);
    SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                      w, h,
                                                      new int[] {0xFF});
    DataBuffer db = new DataBufferByte(data, w*h, 0);
    WritableRaster raster = Raster.createWritableRaster(sm, db, null);

    return new BufferedImage(palette, raster, false, null);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:DecodeRLE8.java

示例8: decode

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
public BufferedImage decode(ImageInputStream in) throws IOException, BMPException {
IndexColorModel palette = readPalette(in);
skipToImage(in);

Dimension d = infoHeader.getSize();
int h = (int)d.getHeight();
int w = (int)d.getWidth();

byte[] data = uncompress(w, h, in);
SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 
						  w, h, 
						  new int[] {0xFF});
DataBuffer db = new DataBufferByte(data, w*h, 0);
WritableRaster raster = Raster.createWritableRaster(sm, db, null);
   
return new BufferedImage(palette, raster, false, null);
   }
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:18,代碼來源:DecodeRLE8.java

示例9: createWrappedBufferedImage

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
/**
 * i_rasterとバッファを共有するBufferedImageを生成します。
 * 
 * @param i_raster
 * @return
 * @throws NyARRuntimeException
 */
public static BufferedImage createWrappedBufferedImage(INyARGrayscaleRaster i_raster) throws NyARRuntimeException {
	BufferedImage bfi;
	NyARIntSize s = i_raster.getSize();
	switch (i_raster.getBufferType()) {
	case NyARBufferType.INT1D_GRAY_8: {
		int[] b = (int[]) i_raster.getBuffer();
		DataBufferInt d = new DataBufferInt(b, b.length);
		int[] msk = { 0x0000ff, 0x0000ff, 0x0000ff };
		bfi = new BufferedImage(new DirectColorModel(24, msk[0], msk[1], msk[2]), Raster.createWritableRaster(
				new SinglePixelPackedSampleModel(d.getDataType(), s.w, s.h, msk), d, null), true, null);

	}
		break;
	default:
		throw new NyARRuntimeException();
	}
	return bfi;
}
 
開發者ID:nyatla,項目名稱:NyARToolkit,代碼行數:26,代碼來源:NyARBufferedImageIo.java

示例10: writePngImage

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
/**
     * Writes a {@link BufferedImage} to the specified {@link OutputStream} using the PNGJ library
     * which is much faster than Java's ImageIO library.
     *
     * This implementation was copied from
     * <a href="https://github.com/leonbloy/pngj/wiki/Snippets">
     *     https://github.com/leonbloy/pngj/wiki/Snippets
     * </a>.
     *
     * @param  bufferedImage     image to write.
     * @param  compressionLevel  0 (no compression) - 9 (max compression)
     * @param  filterType        internal prediction filter type.
     * @param  outputStream      target stream.
     *
     * @throws IOException
     *   if the image is not ARGB or it's data buffer contains the wrong number of banks.
     */
    public static void writePngImage(final BufferedImage bufferedImage,
                                     final int compressionLevel,
                                     final FilterType filterType,
                                     final OutputStream outputStream)
            throws IOException {

        if (bufferedImage.getType() != BufferedImage.TYPE_INT_ARGB) {
            throw new IOException("invalid image type (" + bufferedImage.getType() +
                                  "), must be BufferedImage.TYPE_INT_ARGB");
        }

        final ImageInfo imageInfo = new ImageInfo(bufferedImage.getWidth(), bufferedImage.getHeight(), 8, true);

        final PngWriter pngWriter = new PngWriter(outputStream, imageInfo);
        pngWriter.setCompLevel(compressionLevel);
        pngWriter.setFilterType(filterType);

        final DataBufferInt dataBuffer =((DataBufferInt) bufferedImage.getRaster().getDataBuffer());
        if (dataBuffer.getNumBanks() != 1) {
            throw new IOException("invalid number of banks (" + dataBuffer.getNumBanks() + "), must be 1");
        }

        final SinglePixelPackedSampleModel sampleModel = (SinglePixelPackedSampleModel) bufferedImage.getSampleModel();
        final ImageLineInt line = new ImageLineInt(imageInfo);
        final int[] data = dataBuffer.getData();
        for (int row = 0; row < imageInfo.rows; row++) {
            int elem = sampleModel.getOffset(0, row);
            for (int col = 0; col < imageInfo.cols; col++) {
                final int sample = data[elem++];
                ImageLineHelper.setPixelRGBA8(line, col, sample);
            }
            pngWriter.writeRow(line, row);
        }
        pngWriter.end();

//        // This looked like a nicer option, but only works for DataBufferByte (not DataBufferInt)
//        final ImageLineSetARGBbi lines = new ImageLineSetARGBbi(bufferedImage, imageInfo);
//        pngWriter.writeRows(lines);
//        pngWriter.end();
    }
 
開發者ID:saalfeldlab,項目名稱:render,代碼行數:58,代碼來源:BufferedImageStreamingOutput.java

示例11: setUp

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    dbb1 = new DataBufferByte(w * h);
    dbb2 = new DataBufferByte(scanlineStride * (h - 1) + w);
    dbu1 = new DataBufferUShort(w * h);
    dbu2 = new DataBufferUShort(scanlineStride * (h - 1) + w);
    dbi1 = new DataBufferInt(w * h);
    dbi2 = new DataBufferInt(scanlineStride * (h - 1) + w);
    sppsmb1 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, bitMaskB);
    sppsmb2 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, scanlineStride, bitMaskB);
    sppsmu1 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT, w, h, bitMaskUS);
    sppsmu2 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT, w, h, scanlineStride, bitMaskUS);
    sppsmi1 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, bitMaskI);
    sppsmi2 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, scanlineStride, bitMaskI);
    initTestData();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:SinglePixelPackedSampleModelTest.java

示例12: getAlignedImage

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
/**
 * Returns a width- and height-aligned image representation sharing data w/ {@link #image}.
 * @param width
 * @param height
 * @return
 * @throws IllegalArgumentException if requested size exceeds image size
 */
public BufferedImage getAlignedImage(final int width, final int height) throws IllegalArgumentException {
    if( width * height > image.getWidth() * image.getHeight() ) {
        throw new IllegalArgumentException("Requested size exceeds image size: "+width+"x"+height+" > "+image.getWidth()+"x"+image.getHeight());
    }
    if( width == image.getWidth() && height == image.getHeight() ) {
        return image;
    } else {
        final ColorModel cm = image.getColorModel();
        final WritableRaster raster0 = image.getRaster();
        final DataBuffer dataBuffer = raster0.getDataBuffer();
        final SinglePixelPackedSampleModel sppsm0 = (SinglePixelPackedSampleModel) raster0.getSampleModel();
        final SinglePixelPackedSampleModel sppsm1 = new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
                    width, height, width /* scanLineStride */, sppsm0.getBitMasks());
        final WritableRaster raster1 = Raster.createWritableRaster(sppsm1, dataBuffer, null);
        return new BufferedImage (cm, raster1, cm.isAlphaPremultiplied(), null);
    }
}
 
開發者ID:jedwards1211,項目名稱:breakout,代碼行數:25,代碼來源:AWTGLPixelBuffer.java

示例13: getRaster

import java.awt.image.SinglePixelPackedSampleModel; //導入依賴的package包/類
/**
 * Return a Raster containing the colors generated for the graphics
 * operation.
 *
 * @param x
 *            ,y,w,h The area in device space for which colors are
 *            generated.
 */
@Override
public Raster getRaster(int x, int y, int w, int h) {
	Raster rast = saved;
	if (rast == null || rast.getWidth() < w || rast.getHeight() < h) {
		rast = getCachedRaster(model, w, h);
		saved = rast;
	}
	DataBufferInt rasterDB = (DataBufferInt) rast.getDataBuffer();
	int[] pixels = rasterDB.getBankData()[0];
	int off = rasterDB.getOffset();
	int scanlineStride = ((SinglePixelPackedSampleModel) rast.getSampleModel()).getScanlineStride();
	int adjust = scanlineStride - w;

	fillRaster(pixels, off, adjust, x, y, w, h);

	return rast;
}
 
開發者ID:jedwards1211,項目名稱:breakout,代碼行數:26,代碼來源:CheckerPaintContext.java


注:本文中的java.awt.image.SinglePixelPackedSampleModel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。