Java 类java.awt.image.DataBufferInt 实例源码

项目:PS3Eye    文件:PS3Eye_Basic.java   
@Override
  public void run() {
    FrameRate framerate = new FrameRate();
    int[] pixels = ((DataBufferInt) ps3eye_frame.getRaster().getDataBuffer()).getData();
//    ps3eye.waitAvailable(false);
    while (true) {

//      if(ps3eye.isAvailable()){
        ps3eye.getFrame(pixels);
        repaint();
        jframe.setTitle(""+framerate.update());
//      }

//      try {
//        Thread.sleep(0);
//      } catch (InterruptedException e) {
//        e.printStackTrace();
//      }
    }

  }
项目:VASSAL-src    文件:TileUtils.java   
/**
 * Write a tile image to a stream.
 *
 * @param tile the image
 * @param out the stream
 *
 * @throws ImageIOException if the write fails
 */
public static void write(BufferedImage tile, OutputStream out)
                                                         throws IOException {
  ByteBuffer bb;

  // write the header
  bb = ByteBuffer.allocate(18);

  bb.put("VASSAL".getBytes())
    .putInt(tile.getWidth())
    .putInt(tile.getHeight())
    .putInt(tile.getType());

  out.write(bb.array());

  // write the tile data
  final DataBufferInt db = (DataBufferInt) tile.getRaster().getDataBuffer();
  final int[] data = db.getData();

  bb = ByteBuffer.allocate(4*data.length);
  bb.asIntBuffer().put(data);

  final GZIPOutputStream zout = new GZIPOutputStream(out);
  zout.write(bb.array());
  zout.finish();
}
项目:StreamDeckCore    文件:IconHelper.java   
/**
 * Converts the given image to the stream deck format.<br>
 * Format is:<br>
 * Color Schema: BGR<br>
 * Image size: 72 x 72 pixel<br>
 * Stored in an array with each byte stored seperatly (Size of each array is
 * 72 x 72 x 3 = 15_552).
 * 
 * @param img
 *            Image to be converted
 * @return Byte arraythat contains the given image, ready to be sent to the
 *         stream deck
 */
public static byte[] convertImage(BufferedImage img) {
    img = IconHelper.createResizedCopy(IconHelper.fillBackground(IconHelper.rotate180(img), Color.BLACK));
    if (APPLY_FRAME) {
        BufferedImage frame = getImageFromResource("/resources/frame.png");
        if (frame != null) {
            Graphics2D g = img.createGraphics();
            g.drawImage(frame, 0, 0, null);
            g.dispose();
        }
    }
    int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
    byte[] imgData = new byte[StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE * 3];
    int imgDataCount = 0;
    // remove the alpha channel
    for (int i = 0; i < StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE; i++) {
        // RGB -> BGR
        imgData[imgDataCount++] = (byte) ((pixels[i] >> 16) & 0xFF);
        imgData[imgDataCount++] = (byte) (pixels[i] & 0xFF);
        imgData[imgDataCount++] = (byte) ((pixels[i] >> 8) & 0xFF);
    }
    return imgData;
}
项目:jaer    文件:AbstractAviWriter.java   
/**
 * Turns gl to BufferedImage with fixed format
 *
 * @param gl
 * @param w
 * @param h
 * @return
 */
protected BufferedImage toImage(GL2 gl, int w, int h) {

    gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK
    ByteBuffer glBB = Buffers.newDirectByteBuffer(4 * w * h);
    gl.glReadPixels(0, 0, w, h, GL2.GL_BGRA, GL.GL_BYTE, glBB);

    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
    int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int b = 2 * glBB.get();
            int g = 2 * glBB.get();
            int r = 2 * glBB.get();
            int a = glBB.get(); // not using

            bd[(h - y - 1) * w + x] = (b << 16) | (g << 8) | r | 0xFF000000;
        }
    }

    return bi;
}
项目:jaer    文件:DvsSliceAviWriter.java   
private BufferedImage toImage(DvsFramerSingleFrame subSampler) {
    BufferedImage bi = new BufferedImage(dvsFrame.getWidth(), dvsFrame.getHeight(), BufferedImage.TYPE_INT_BGR);
    int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();

    for (int y = 0; y < dvsFrame.getHeight(); y++) {
        for (int x = 0; x < dvsFrame.getWidth(); x++) {
            int b = (int) (255 * subSampler.getValueAtPixel(x, y));
            int g = b;
            int r = b;
            int idx = (dvsFrame.getHeight() - y - 1) * dvsFrame.getWidth() + x;
            if (idx >= bd.length) {
                throw new RuntimeException(String.format("index %d out of bounds for x=%d y=%d", idx, x, y));
            }
            bd[idx] = (b << 16) | (g << 8) | r | 0xFF000000;
        }
    }

    return bi;

}
项目:OpenJSharp    文件:ImageTests.java   
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
项目:OpenJSharp    文件:JLightweightFrame.java   
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
    content.paintLock();
    try {
        int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
        if (reset) {
            copyBuffer = new int[srcBuffer.length];
        }
        int linestride = bbImage.getWidth();

        x *= scale;
        y *= scale;
        w *= scale;
        h *= scale;

        for (int i=0; i<h; i++) {
            int from = (y + i) * linestride + x;
            System.arraycopy(srcBuffer, from, copyBuffer, from, w);
        }
    } finally {
        content.paintUnlock();
    }
}
项目:OpenJSharp    文件:Buffers.java   
/**
  * Create a data buffer of a particular type.
  *
  * @param dataType the desired data type of the buffer.
  * @param size the size of the data buffer bank
  * @param numBanks the number of banks the buffer should have
  */
 public static DataBuffer createBuffer(int dataType, int size, int numBanks)
 {
   switch (dataType)
     {
     case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
     case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
     case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
     case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
     case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
     case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
     default:
throw new UnsupportedOperationException();
     }
 }
项目:OpenJSharp    文件:Buffers.java   
/**
  * Create a data buffer of a particular type.
  *
  * @param dataType the desired data type of the buffer
  * @param data an array containing the data
  * @param size the size of the data buffer bank
  */
 public static DataBuffer createBufferFromData(int dataType, Object data,
                    int size)
 {
   switch (dataType)
     {
     case DataBuffer.TYPE_BYTE:
return new DataBufferByte((byte[]) data, size);
     case DataBuffer.TYPE_SHORT:
return new DataBufferShort((short[]) data, size);
     case DataBuffer.TYPE_USHORT:
return new DataBufferUShort((short[]) data, size);
     case DataBuffer.TYPE_INT:
return new DataBufferInt((int[]) data, size);
     case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat((float[]) data, size);
     case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble((double[]) data, size);
     default:
throw new UnsupportedOperationException();
     }
 }
项目:DicomViewer    文件:OpenCLWithJOCL.java   
private cl_mem initImageMem(BufferedImage img) {
    cl_image_format imageFormat = new cl_image_format();
    imageFormat.image_channel_order = CL_RGBA;
    imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;

    // Create the memory object for the input image
    DataBufferInt dataBufferSrc = (DataBufferInt)img.getRaster().getDataBuffer();
    int dataSrc[] = dataBufferSrc.getData();

    cl_mem inputImageMem = CL.clCreateImage2D(
        context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
        new cl_image_format[]{imageFormat}, img.getWidth(), img.getHeight(),
        img.getWidth() * Sizeof.cl_uint, Pointer.to(dataSrc), null);

    return  inputImageMem;
}
项目:etomica    文件:Image.java   
/**
 * @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);
}
项目:jdk8u-jdk    文件:ImageTests.java   
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
项目:jdk8u-jdk    文件:JLightweightFrame.java   
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
    content.paintLock();
    try {
        int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
        if (reset) {
            copyBuffer = new int[srcBuffer.length];
        }
        int linestride = bbImage.getWidth();

        x *= scale;
        y *= scale;
        w *= scale;
        h *= scale;

        for (int i=0; i<h; i++) {
            int from = (y + i) * linestride + x;
            System.arraycopy(srcBuffer, from, copyBuffer, from, w);
        }
    } finally {
        content.paintUnlock();
    }
}
项目:jdk8u-jdk    文件:IncorrectAlphaConversionBicubic.java   
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
项目:jdk8u-jdk    文件:UnmanagedDrawImagePerformance.java   
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
项目:jdk8u-jdk    文件:IncorrectClipXorModeSW2Surface.java   
private static BufferedImage getBufferedImage(int sw) {
    final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    g2d.dispose();

    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:jdk8u-jdk    文件:IncorrectUnmanagedImageRotatedClip.java   
private static BufferedImage makeUnmanagedBI() {
    final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:jdk8u-jdk    文件:IncorrectUnmanagedImageSourceOffset.java   
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage bi = new BufferedImage(511, 255, type);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:tf-ispn-demo    文件:MnistListener.java   
/**
 * Converts raw data into JPG image and encode it into Base64 string for sending it to the JS client
 * 
 * @param rawImg
 *            raw image bytes
 * @return Base64 encoded string with JPG image
 */
private String bufferAsJpgString(byte[] rawImg) {
    int[] pixels = new int[rawImg.length];
    for (int i = 0; i < rawImg.length; i++) {
        pixels[i] = (int) rawImg[i];
    }
    DataBufferInt buffer = new DataBufferInt(pixels, pixels.length);
    WritableRaster raster = Raster.createPackedRaster(buffer, IMG_SIZE, IMG_SIZE, IMG_SIZE, BAND_MASKS, null);
    ColorModel cm = ColorModel.getRGBdefault();
    BufferedImage image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);

    byte[] imgBytes = null;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ImageIO.write(image, "JPG", baos);
        baos.flush();
        imgBytes = baos.toByteArray();
    } catch (IOException e) {
        // TODO log exception
    }

    byte[] encoded = Base64.getEncoder().encode(imgBytes);
    return new String(encoded);
}
项目:openjdk-jdk10    文件:ImageTests.java   
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
项目:openjdk-jdk10    文件:WTaskbarPeer.java   
private static int[] imageToArray(Image image) {
    if (image == null) {
        return null;
    }

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    if (w < 0 || h < 0) {
        return null;
    }

    BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g2 = bimg.createGraphics();
    g2.setComposite(AlphaComposite.Src);
    g2.drawImage(image, 0, 0, null);
    g2.dispose();

    return ((DataBufferInt) bimg.getRaster().getDataBuffer()).getData();
}
项目:openjdk-jdk10    文件:IncorrectAlphaConversionBicubic.java   
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
项目:openjdk-jdk10    文件:IncorrectClipXorModeSW2Surface.java   
private static BufferedImage getBufferedImage(int sw) {
    final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    g2d.dispose();

    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:openjdk-jdk10    文件:IncorrectUnmanagedImageRotatedClip.java   
private static BufferedImage makeUnmanagedBI() {
    final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:openjdk-jdk10    文件:IncorrectUnmanagedImageSourceOffset.java   
private static BufferedImage makeUnmanagedBI(final int type) {
    final BufferedImage bi = new BufferedImage(511, 255, type);
    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
项目:incubator-netbeans    文件:ImageBuilder.java   
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    //int[] data = fa.getIntArray(instance, "data", false);     // NOI18N
    int[][] bankdata = fa.getIntArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferInt(bankdata, size, offsets);
}
项目:VASSAL-src    文件:ImageIOImageLoader.java   
protected BufferedImage fix_tRNS(Reference<BufferedImage> ref,
                                 int tRNS, int type) throws ImageIOException {
  BufferedImage img = ref.obj;

  // Ensure that we are working with integer ARGB data. Whether it's
  // premultiplied doesn't matter, since fully transparent black pixels
  // are the same in both.
  if (img.getType() != BufferedImage.TYPE_INT_ARGB &&
      img.getType() != BufferedImage.TYPE_INT_ARGB_PRE) {

    // If the requested type is not an ARGB one, then we convert to ARGB
    // for applying this fix.
    if (type != BufferedImage.TYPE_INT_ARGB &&
        type != BufferedImage.TYPE_INT_ARGB_PRE) {
      type = BufferedImage.TYPE_INT_ARGB;
    }

    img = null;
    img = tconv.convert(ref, type);
  }

  // NB: This unmanages the image.
  final DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
  final int[] data = db.getData();

  // Set all pixels of the transparent color to have alpha 0.
  for (int i = 0; i < data.length; ++i) {
    if (data[i] == tRNS) data[i] = 0x00000000;
  }

  return img;
}
项目:VASSAL-src    文件:ImageIOImageLoader.java   
protected BufferedImage fix_YCbCr(Reference<BufferedImage> ref, int type)
                                                    throws ImageIOException {
  BufferedImage img = ref.obj;

  // Ensure that we are working with RGB or ARGB data.
  if (img.getType() != BufferedImage.TYPE_INT_RGB &&
      img.getType() != BufferedImage.TYPE_INT_ARGB) {

    if (type != BufferedImage.TYPE_INT_RGB &&
        type != BufferedImage.TYPE_INT_ARGB) {
      type = BufferedImage.TYPE_INT_ARGB;
    }

    img = null;
    img = tconv.convert(ref, type);
  }

  // NB: This unmanages the image.
  final DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
  final int[] data = db.getData();

  for (int i = 0; i < data.length; ++i) {
    final int y  =  (data[i] >> 16) & 0xFF;
    final int pb = ((data[i] >>  8) & 0xFF) - 128;
    final int pr = ( data[i]        & 0xFF) - 128;

    final int a  = (data[i] >> 24) & 0xFF;
    final int r = (int) Math.round(y + 1.402*pr);
    final int g = (int) Math.round(y - 0.34414*pb - 0.71414*pr);
    final int b = (int) Math.round(y + 1.772*pb);

    data[i] = (a << 24) |
              ((r < 0 ? 0 : (r > 0xFF ? 0xFF : r)) << 16) |
              ((g < 0 ? 0 : (g > 0xFF ? 0xFF : g)) <<  8) |
               (b < 0 ? 0 : (b > 0xFF ? 0xFF : b));
  }

  return img;
}
项目:StreamDeckCore    文件:StreamButton.java   
public void drawImage(BufferedImage img) {
        Graphics2D g = canvas.createGraphics();
        g.setColor(background);
        g.fillRect(0, 0, ICON_SIZE, ICON_SIZE);
        if (img != null)
            g.drawImage(img, 0, 0, null);
        g.dispose();
        int[] pixels = ((DataBufferInt) canvas.getRaster().getDataBuffer()).getData();
        byte[] imgData = new byte[ICON_SIZE * ICON_SIZE * 3];
        int imgDataCount=0;
        // remove the alpha channel
        for(int i=0;i<ICON_SIZE*ICON_SIZE; i++) {
            //RGB -> BGR
            imgData[imgDataCount++] = (byte)((pixels[i]>>16) & 0xFF);
            imgData[imgDataCount++] = (byte)(pixels[i] & 0xFF);
            imgData[imgDataCount++] = (byte)((pixels[i]>>8) & 0xFF);            
        }
        byte[] page1 = generatePage1(this.buttenNo, imgData);
        byte[] page2 = generatePage2(this.buttenNo, imgData);
        System.out.println(page1.length);
        System.out.println(page2.length);
        System.out.println("Write page 1");
        System.out.println(this.streamDeck.setOutputReport((byte)0x02, page1, page1.length));
        System.out.println("Write page 2");
        System.out.println(this.streamDeck.setOutputReport((byte)0x02, page2, page2.length));
//      _writePage2(imgDataPage2);
        System.out.println("Done 1");

    }
项目:StreamDeckCore    文件:IconHelper.java   
/**
 * Converts given image to bgr color schema and caches the resulting image
 * data.
 * 
 * @param path
 *            Path to be caches
 * @param img
 *            Image to be cached, must be fo TYPE_INT_*RGB*
 * @return Returns the cached image data
 */
public static byte[] cacheImage(String path, BufferedImage img) {
    int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
    byte[] imgData = new byte[StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE * 3];
    int imgDataCount = 0;
    // remove the alpha channel
    for (int i = 0; i < StreamDeck.ICON_SIZE * StreamDeck.ICON_SIZE; i++) {
        // RGB -> BGR
        imgData[imgDataCount++] = (byte) ((pixels[i] >> 16) & 0xFF);
        imgData[imgDataCount++] = (byte) (pixels[i] & 0xFF);
        imgData[imgDataCount++] = (byte) ((pixels[i] >> 8) & 0xFF);
    }
    cache(path, imgData);
    return imgData;
}
项目:Koyaanisqatsi    文件:Life.java   
protected Life(int w, int h, int t, int p, boolean v) {
    Width = w;
    Height = h;
    maxTime = T0 + t;
    nThreads = p;
    vis = v;

    // Initialize visualization
    if (vis) {
        BufferedImage img = new BufferedImage(Width, Height, BufferedImage.TYPE_INT_RGB);
        imgData = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();

        JFrame frame = new JFrame() {
            public void paint(Graphics g) {
                g.drawImage(img, 0, 0, getWidth(), getHeight(), null);
            }
        };
        frame.setSize(Width, Height);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setVisible(true);

        Timer timer = new Timer(40, (e) -> frame.repaint());
        timer.start();
    }
}
项目:PengueeBot    文件:Frag.java   
int[][] getIntRGB(BufferedImage image) {
    final int[] pixels = ((DataBufferInt) image.getData().getDataBuffer())
            .getData();
    final int width = image.getWidth();
    final int height = image.getHeight();
    this.image = image;
    if (rgbData == null)
        rgbData = new int[height][width];
    for (int i = 0; i < height; i++)
        System.arraycopy(pixels, (i * width), rgbData[i], 0, width);
    return rgbData;
}
项目:PengueeBot    文件:Frag.java   
int[][] getIntRGB(BufferedImage image, int x, int y) {
    final int[] pixels = ((DataBufferInt) image.getData().getDataBuffer())
            .getData();
    final int width = image.getWidth();
    final int height = image.getHeight();
    for (int i = 0; i < height; i++)
        System.arraycopy(pixels, (i * width), rgbData[i + y], x, width);

    return rgbData;
}
项目:ConvNetCL4J    文件:Dcci.java   
private UnderlyingArray(BufferedImage bufferedImage) {
    rowLength = bufferedImage.getWidth();
    colLength = bufferedImage.getHeight();
    xBound = rowLength - 1;
    yBound = colLength - 1;
    array = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();
}
项目:connor41-etfuturum2    文件:NewImageBufferDownload.java   
@Override
public BufferedImage parseUserSkin(BufferedImage buffImg) {
    if (buffImg == null)
        return null;
    oldStyleImage = super.parseUserSkin(buffImg);

    imageWidth = 64;
    imageHeight = 64;
    BufferedImage buffImg2 = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = buffImg2.getGraphics();
    graphics.drawImage(buffImg, 0, 0, null);

    if (buffImg.getHeight() == 32) {
        graphics.drawImage(buffImg2, 24, 48, 20, 52, 4, 16, 8, 20, null);
        graphics.drawImage(buffImg2, 28, 48, 24, 52, 8, 16, 12, 20, null);
        graphics.drawImage(buffImg2, 20, 52, 16, 64, 8, 20, 12, 32, null);
        graphics.drawImage(buffImg2, 24, 52, 20, 64, 4, 20, 8, 32, null);
        graphics.drawImage(buffImg2, 28, 52, 24, 64, 0, 20, 4, 32, null);
        graphics.drawImage(buffImg2, 32, 52, 28, 64, 12, 20, 16, 32, null);
        graphics.drawImage(buffImg2, 40, 48, 36, 52, 44, 16, 48, 20, null);
        graphics.drawImage(buffImg2, 44, 48, 40, 52, 48, 16, 52, 20, null);
        graphics.drawImage(buffImg2, 36, 52, 32, 64, 48, 20, 52, 32, null);
        graphics.drawImage(buffImg2, 40, 52, 36, 64, 44, 20, 48, 32, null);
        graphics.drawImage(buffImg2, 44, 52, 40, 64, 40, 20, 44, 32, null);
        graphics.drawImage(buffImg2, 48, 52, 44, 64, 52, 20, 56, 32, null);
    }

    graphics.dispose();
    imageData = ((DataBufferInt) buffImg2.getRaster().getDataBuffer()).getData();
    setAreaOpaque(0, 0, 32, 16);
    setAreaTransparent(32, 0, 64, 32);
    setAreaOpaque(0, 16, 64, 32);
    setAreaTransparent(0, 32, 16, 48);
    setAreaTransparent(16, 32, 40, 48);
    setAreaTransparent(40, 32, 56, 48);
    setAreaTransparent(0, 48, 16, 64);
    setAreaOpaque(16, 48, 48, 64);
    setAreaTransparent(48, 48, 64, 64);
    return buffImg2;
}
项目:OpenJSharp    文件:MultipleGradientPaintContext.java   
/**
 * {@inheritDoc}
 */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null ||
        raster.getWidth() < w || raster.getHeight() < h)
    {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel)
                          raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass

    return raster;
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
项目:OpenJSharp    文件:ImageRepresentation.java   
public BufferedImage getOpaqueRGBImage() {
    if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
        int w = bimage.getWidth();
        int h = bimage.getHeight();
        int size = w * h;

        // Note that we steal the data array here, but only for reading...
        DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
        int[] pixels = SunWritableRaster.stealData(db, 0);

        for (int i = 0; i < size; i++) {
            if ((pixels[i] >>> 24) != 0xff) {
                return bimage;
            }
        }

        ColorModel opModel = new DirectColorModel(24,
                                                  0x00ff0000,
                                                  0x0000ff00,
                                                  0x000000ff);

        int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
        WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
                                                            bandmasks,
                                                            null);

        try {
            BufferedImage opImage = createImage(opModel, opRaster,
                                                false, null);
            return opImage;
        } catch (Exception e) {
            return bimage;
        }
    }
    return bimage;
}
项目:OpenJSharp    文件:JLightweightFrame.java   
private void resizeBuffer(int width, int height, int newScaleFactor) {
        bbImage = new BufferedImage(width*newScaleFactor,height*newScaleFactor,
                                    BufferedImage.TYPE_INT_ARGB_PRE);
    int[] pixels= ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
    if (copyBufferEnabled) {
        syncCopyBuffer(true, 0, 0, width, height, newScaleFactor);
        pixels = copyBuffer;
    }
    content.imageBufferReset(pixels, 0, 0, width, height,
                             width * newScaleFactor, newScaleFactor);
}
项目:OpenJSharp    文件:WDataTransferer.java   
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
@Override
protected Image platformImageBytesToImage(byte[] bytes, long format)
        throws IOException {
    String mimeType = null;
    if (format == CF_PNG) {
        mimeType = "image/png";
    } else if (format == CF_JFIF) {
        mimeType = "image/jpeg";
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    }

    int[] imageData = platformImageBytesToImageData(bytes, format);
    if (imageData == null) {
        throw new IOException("data translation failed");
    }

    int len = imageData.length - 2;
    int width = imageData[len];
    int height = imageData[len + 1];

    DataBufferInt buffer = new DataBufferInt(imageData, len);
    WritableRaster raster = Raster.createPackedRaster(buffer, width,
            height, width,
            bandmasks, null);

    return new BufferedImage(directColorModel, raster, false, null);
}