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


Java SinglePixelPackedSampleModel.getOffset方法代碼示例

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


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

示例1: 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

示例2: applyLut_INT

import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
public static WritableRaster applyLut_INT(WritableRaster wr,
                                          final int []lut) {
    SinglePixelPackedSampleModel sm =
        (SinglePixelPackedSampleModel)wr.getSampleModel();
    DataBufferInt db = (DataBufferInt)wr.getDataBuffer();

    final int     srcBase
        = (db.getOffset() +
           sm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
                        wr.getMinY()-wr.getSampleModelTranslateY()));
    // Access the pixel data array
    final int[] pixels   = db.getBankData()[0];
    final int width      = wr.getWidth();
    final int height     = wr.getHeight();
    final int scanStride = sm.getScanlineStride();

    int end, pix;

    // For alpha premult we need to multiply all comps.
    for (int y=0; y<height; y++) {
        int sp  = srcBase + y*scanStride;
        end = sp + width;

        while (sp<end) {
            pix = pixels[sp];
            pixels[sp] =
                ((     pix      &0xFF000000)|
                 (lut[(pix>>>16)&0xFF]<<16) |
                 (lut[(pix>>> 8)&0xFF]<< 8) |
                 (lut[(pix     )&0xFF]    ));
            sp++;
        }
    }

    return wr;
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:37,代碼來源:Any2sRGBRed.java

示例3: convertIndexColorModelToSRGB

import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
 * Converts pixels from an index color model to the target image.
 *
 * @param x the X coordinate of the source pixel rectangle
 * @param y the Y coordinate of the source pixel rectangle
 * @param w the width of the source pixel rectangle
 * @param h the height of the source pixel rectangle
 * @param model the color model of the source pixels
 * @param pixels the pixel data
 * @param offset the offset in the pixel array
 * @param scansize the scanline size
 * @param transparency the assumed transparency
 *
 * @return the determined transparency
 */
private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
                                         IndexColorModel model,
                                         byte[] pixels, int offset,
                                         int scansize, int transparency)
{

  int mapSize = model.getMapSize();
  int[] colorMap = new int[mapSize];
  for(int i=0; i < mapSize; i++)
    {
      colorMap[i] = model.getRGB(i);
    }

  WritableRaster raster = bImage.getRaster();
  SinglePixelPackedSampleModel sampleMode =
    (SinglePixelPackedSampleModel) raster.getSampleModel();
  DataBuffer dataBuffer = (DataBuffer) raster.getDataBuffer();

  int rasterOffset = sampleMode.getOffset(x,y)+dataBuffer.getOffset();
  int rasterScanline = sampleMode.getScanlineStride();

  for (int yy = 0; yy < h; yy++)
    {
      int xoffset = offset;
      for (int xx = 0; xx < w; xx++)
        {
          int argb  = colorMap[(pixels[xoffset++] & 0xFF)];
          dataBuffer.setElem(rasterOffset+xx, argb);
          int alpha = (argb >>> 24);
          transparency = updateTransparency(alpha, transparency);
        }
      offset += scansize;
      rasterOffset += rasterScanline;
    }

  return transparency;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:53,代碼來源:ImageConverter.java

示例4: convertIndexColorModelToSRGB

import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
 * Converts pixels from an index color model to the target image.
 *
 * @param x the X coordinate of the source pixel rectangle
 * @param y the Y coordinate of the source pixel rectangle
 * @param w the width of the source pixel rectangle
 * @param h the height of the source pixel rectangle
 * @param model the color model of the source pixels
 * @param pixels the pixel data
 * @param offset the offset in the pixel array
 * @param scansize the scanline size
 * @param transparency the assumed transparency
 * 
 * @return the determined transparency
 */
private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
                                         IndexColorModel model,
                                         byte[] pixels, int offset,
                                         int scansize, int transparency)
{

  int mapSize = model.getMapSize();
  int[] colorMap = new int[mapSize];
  for(int i=0; i < mapSize; i++)
    {
      colorMap[i] = model.getRGB(i);
    }

  WritableRaster raster = bImage.getRaster();
  SinglePixelPackedSampleModel sampleMode =
    (SinglePixelPackedSampleModel) raster.getSampleModel();
  DataBuffer dataBuffer = (DataBuffer) raster.getDataBuffer();

  int rasterOffset = sampleMode.getOffset(x,y)+dataBuffer.getOffset();
  int rasterScanline = sampleMode.getScanlineStride();

  for (int yy = 0; yy < h; yy++)
    {
      int xoffset = offset;
      for (int xx = 0; xx < w; xx++)
        {
          int argb  = colorMap[(pixels[xoffset++] & 0xFF)];
          dataBuffer.setElem(rasterOffset+xx, argb);
          int alpha = (argb >>> 24);
          transparency = updateTransparency(alpha, transparency);
        }
      offset += scansize;
      rasterOffset += rasterScanline;
    }

  return transparency;
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:53,代碼來源:ImageConverter.java

示例5: write

import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
public void write(Image image, OutputStream out) throws IOException {

    if (image.awt().getType() == BufferedImage.TYPE_INT_ARGB) {

        ImageInfo imi = new ImageInfo(image.width, image.height, 8, true);

        ar.com.hjg.pngj.PngWriter writer = new ar.com.hjg.pngj.PngWriter(out, imi);
        writer.setCompLevel(compressionLevel);
        writer.setFilterType(FilterType.FILTER_DEFAULT);

        DataBufferInt db = (DataBufferInt) image.awt().getRaster().getDataBuffer();
        if (db.getNumBanks() != 1) throw new RuntimeException("This method expects one bank");

        SinglePixelPackedSampleModel samplemodel = (SinglePixelPackedSampleModel) image.awt().getSampleModel();
        ImageLineInt line = new ImageLineInt(imi);
        int[] dbbuf = db.getData();

        for (int row = 0; row < imi.rows; row++) {
            int elem = samplemodel.getOffset(0, row);
            int j = 0;
            for (int col = 0; col < imi.cols; col++) {
                int sample = dbbuf[elem];
                elem = elem + 1;
                line.getScanline()[j] = (sample & 0xFF0000) >> 16; // R
                j = j + 1;
                line.getScanline()[j] = (sample & 0xFF00) >> 8; // G
                j = j + 1;
                line.getScanline()[j] = sample & 0xFF; // B
                j = j + 1;
                line.getScanline()[j] = ((sample & 0xFF000000) >> 24) & 0xFF; // A
                j = j + 1;
            }
            writer.writeRow(line, row);
        }
        writer.end();// end calls close

    } else {
        ImageIO.write(image.awt(), "png", out);
    }
}
 
開發者ID:sksamuel,項目名稱:scrimage,代碼行數:42,代碼來源:PngWriter.java


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