Example #1
0
  /** Carga una imagen en la posiciĆ³n X,Y dada. */
  public void loadImage(int x, int y, int width, int height, String path) {
    //		SVGEvent event = new SVGEvent(SVGEvent.EVENT_LOAD_IMAGE, new SVGLoadImageEventData(x, y,
    // width, height, path));
    //		postEvent(event);

    SVGDocument document = raster.document;
    SVGSVGElem rootElem = (SVGSVGElem) document.root;

    SVGNode selNode = null;
    // Parece que la siguiente linea no es necesaria. La matriz de transformacion es la misma que la
    // del root
    // selNode = rootElem.nodeHitAt(canvas.raster, new TinyPoint(evData.getX(), evData.getY()));
    if (selNode == null) selNode = raster.root;

    // Calculo de la posicion de la imagen en el SVG
    TinyMatrix inverse = selNode.getGlobalTransform().inverse();
    TinyPoint p = new TinyPoint(x << TinyUtil.FIX_BITS, y << TinyUtil.FIX_BITS);
    inverse.transform(p);
    TinyPoint p2 =
        new TinyPoint((x + width) << TinyUtil.FIX_BITS, (y + height) << TinyUtil.FIX_BITS);
    inverse.transform(p2);
    // Nuevo elemento imagen
    SVGImageElem imageElem = (SVGImageElem) document.createElement(SVG.ELEM_IMAGE);
    imageElem.x = p.x;
    imageElem.y = p.y;
    imageElem.width = p2.x - p.x;
    imageElem.height = p2.y - p.y;
    imageElem.xlink_href = new TinyString(path.toCharArray());

    // Insertar la imagen en el root
    rootElem.addChildAndRecordEvent(imageElem, rootElem.children.count);

    drawSVG();
  }
Example #2
0
  public void setPixels(
      final int xmin,
      final int ymin,
      final int width,
      final int height,
      final int[] pixels32,
      final int pixeloffset,
      final int pixelscan) {
    logger.debug("Actualizando imagen de pantalla");
    // Zona actual e imagen de fondo
    if (loaded) {
      SVGNode root = raster.document.root;
      // Zona actual
      TinyMatrix inverse = root.getGlobalTransform().inverse();
      TinyPoint p1 = new TinyPoint(0, 0);
      inverse.transform(p1);
      TinyPoint p2 = new TinyPoint(width << TinyUtil.FIX_BITS, height << TinyUtil.FIX_BITS);
      inverse.transform(p2);

      if (currentZone.isEmpty()
          || currentZone.xmin != p1.x
          || currentZone.ymin != p1.y
          || currentZone.xmax != p2.x
          || currentZone.ymax != p2.y) {
        currentZone.xmin = p1.x;
        currentZone.ymin = p1.y;
        currentZone.xmax = p2.x;
        currentZone.ymax = p2.y;
        // Nueva imagen de fondo
        if (backImage != null && !backImage.isDisposed()) {
          backImage.dispose();
          backImage = null;
        }
        backImage = getBackImage();
      }
    }

    // Imagen del SVG
    int totalHeight = 0;
    try {
      totalHeight = pixels32.length / pixelscan;

      // Establecer los pixeles y los alphas
      ImageData imData =
          new ImageData(pixelscan, totalHeight, 32, new PaletteData(0xFF0000, 0xFF00, 0xFF));

      byte[] alphaData = new byte[pixels32.length];
      for (int i = 0; i < pixels32.length; i++) {
        alphaData[i] = (byte) (pixels32[i] >> 24);
      }
      imData.setPixels(0, 0, pixels32.length, pixels32, 0);
      imData.setAlphas(0, 0, pixels32.length, alphaData, 0);
      if (svgImage != null && !svgImage.isDisposed()) svgImage.dispose();
      // logger.debug("Antes de generar la imagen1:");
      // logger.debug("Antes de generar la imagen2:"+imData.height);
      svgImage = new Image(Display.getDefault(), imData);
      logger.debug("Imagen generada");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      logger.debug("ERROR");
    }

    logger.debug("Verificando clipping");
    // Clipping
    if (width < pixelscan || height < totalHeight) {
      logger.debug("Hay clipping");
      GC gc = new GC(svgImage);
      int rasterBackground = raster.getBackground();
      Color rasterBackgroundColor =
          new Color(
              Display.getDefault(),
              (rasterBackground & 0x00FF0000) >> 16,
              (rasterBackground & 0x0000FF00) >> 8,
              (rasterBackground & 0x000000FF));
      gc.setBackground(rasterBackgroundColor);
      if (xmin > 0) {
        gc.fillRectangle(0, 0, xmin, totalHeight);
      }
      if (xmin + width < pixelscan) {
        gc.fillRectangle(xmin + width, 0, pixelscan - xmin - width, totalHeight);
      }
      if (ymin > 0) {
        gc.fillRectangle(0, 0, pixelscan, ymin);
      }
      if (ymin + height < totalHeight) {
        gc.fillRectangle(0, ymin + height, pixelscan, totalHeight - ymin - height);
      }
      rasterBackgroundColor.dispose();
      gc.dispose();
    }

    // logger.debug("Arrancando thread de display");
    if (synchPaint) {
      getDisplay().syncExec(new redrawThread());
    } else {
      getDisplay().asyncExec(new redrawThread());
    }
    logger.debug("Imagen de pantalla actualizada");
  }