Example #1
0
  /**
   * Sets the pixel array used to copy pixels to/from a Canvas3D. This is used when the type is
   * RASTER_COLOR or RASTER_COLOR_DEPTH.
   *
   * @param image the ImageComponent2D object containing the color data
   */
  final void setImage(ImageComponent2D img) {

    if ((img != null) && (img.getImageClass() == ImageComponent.ImageClass.NIO_IMAGE_BUFFER)) {
      throw new IllegalArgumentException(J3dI18N.getString("Background14"));
    }

    TextureRetained oldTex = this.texture;
    if (source.isLive()) {
      if (this.texture != null) {
        this.texture.clearLive(refCount);
      }
    }

    // Issue 370: only hold the geomLock while calling initImage
    // (cannot hold it while sending a message).
    geomLock.getLock();
    initImage(img);
    geomLock.unLock();

    if (source.isLive()) {
      if (texture != null) {
        texture.setLive(inBackgroundGroup, refCount);
      }

      sendChangedMessage(
          (J3dThread.UPDATE_RENDER | J3dThread.UPDATE_RENDERING_ATTRIBUTES), oldTex, this.texture);
    }
  }
Example #2
0
  /**
   * Initializes the raster image to the specified image.
   *
   * @param image new ImageCompoent2D object used as the raster image
   */
  final void initImage(ImageComponent2D img) {

    int texFormat;

    if (img == null) {
      image = null;
      texture = null;
      return;
    }

    image = (ImageComponent2DRetained) img.retained;
    image.setEnforceNonPowerOfTwoSupport(true);
    switch (image.getNumberOfComponents()) {
      case 1:
        texFormat = Texture.INTENSITY;
        break;
      case 2:
        texFormat = Texture.LUMINANCE_ALPHA;
        break;
      case 3:
        texFormat = Texture.RGB;
        break;
      case 4:
        texFormat = Texture.RGBA;
        break;
      default:
        assert false;
        return;
    }

    Texture2D tex2D = new Texture2D(Texture.BASE_LEVEL, texFormat, img.getWidth(), img.getHeight());
    texture = (Texture2DRetained) tex2D.retained;
    texture.setUseAsRaster(true);
    // Fix to issue 372 : ImageComponent.set(BufferedImage) ignored when used by Raster
    image.addUser(texture);
    texture.initImage(0, img);
  }