private void newImage(Buffer buffer) {
    Object data = buffer.getData();
    if (!(data instanceof int[])) return;
    RGBFormat format = (RGBFormat) buffer.getFormat();

    DirectColorModel dcm =
        new DirectColorModel(
            format.getBitsPerPixel(),
            format.getRedMask(),
            format.getGreenMask(),
            format.getBlueMask());

    sourceImage =
        new MemoryImageSource(
            format.getLineStride(),
            format.getSize().height,
            dcm,
            (int[]) data,
            0,
            format.getLineStride());
    sourceImage.setAnimated(true);
    sourceImage.setFullBufferUpdates(true);
    if (component != null) {
      destImage = component.createImage(sourceImage);
      component.prepareImage(destImage, component);
    }
  }
Exemple #2
0
  public void putRegion(
      int viewWidth,
      int viewHeight,
      int regWidth,
      int regHeight,
      int regOffX,
      int regOffY,
      int[] regBuffer) {
    if (image == null) {
      setPreferredSize(new Dimension(viewWidth, viewHeight));
      imageBuffer = new int[viewWidth * viewHeight];
      imageSource = new MemoryImageSource(viewWidth, viewHeight, imageBuffer, 0, viewWidth);
      imageSource.setAnimated(true);
      image = createImage(imageSource);
    }

    int destIndex = regOffX + regOffY * viewWidth;
    int srcIndex = 0;
    int extraRowGap = viewWidth - regWidth;
    for (int j = 0; j < regHeight; j++, destIndex += extraRowGap)
      for (int i = 0; i < regWidth; i++, srcIndex++, destIndex++)
        imageBuffer[destIndex] = regBuffer[srcIndex];
    imageSource.newPixels(regOffX, regOffY, regWidth, regHeight);
    repaint(regOffX, regOffY, regWidth, regHeight);
  }