Exemple #1
0
  /**
   * Builds an image data that is based on the released image but has the pressed/enter key area
   * painted with data from the pressed/enter image
   *
   * @param key The pressed key
   * @param isEnter Whether the image being retrieved will be used for enter or pressed
   * @return An image data built the way described at method description
   */
  private ImageData getKeyImageData(IAndroidKey key, boolean isEnter) {

    ImageData resultingImage;
    ImageData releasedImage = getImageData(false, false);
    ImageData keyImage = isEnter ? getImageData(false, true) : getImageData(true, false);

    resultingImage = (ImageData) releasedImage.clone();

    Rectangle keyArea = key.getKeyArea();
    int resultingImageSize = resultingImage.width * keyArea.height;
    int[] keyPixelBuffer = new int[resultingImageSize];

    int startY = keyArea.y < 0 ? 0 : keyArea.y;

    keyImage.getPixels(0, startY, resultingImageSize, keyPixelBuffer, 0);

    for (int line = 0; line < keyArea.height; line++) {
      int pos = (line * resultingImage.width) + Math.abs(keyArea.x);
      int startX = Math.abs(keyArea.x);
      startY = (keyArea.y < 0 ? 0 : keyArea.y) + line;
      if (startY < 0) {
        continue;
      }

      int putWidth = keyArea.x < 0 ? keyArea.width - startX : keyArea.width;
      resultingImage.setPixels(startX, startY, putWidth, keyPixelBuffer, pos);
    }

    return resultingImage;
  }
  private ImageData createHilbertHeapImage(byte pixData[]) {
    int w, h;

    // Pick an image size that the largest of heaps will fit into.
    w = (int) Math.sqrt(((16 * 1024 * 1024) / 8));

    // Space-filling curves require a power-of-2 width.
    w = nextPow2(w);
    h = w;

    // Create the heap image.
    ImageData id = new ImageData(w, h, 8, mMapPalette);

    // Copy the data into the image
    // int maxX = zOrderData(id, pixData);
    Point maxP = hilbertOrderData(id, pixData);

    // update the max size to make it a round number once the zoom is applied
    int factor = 100 / ZOOMS[mZoom.getSelectionIndex()];
    if (factor != 1) {
      int tmp = maxP.x % factor;
      if (tmp != 0) {
        maxP.x += factor - tmp;
      }

      tmp = maxP.y % factor;
      if (tmp != 0) {
        maxP.y += factor - tmp;
      }
    }

    if (maxP.y < id.height) {
      // Crop the image down to the interesting part.
      id = new ImageData(id.width, maxP.y, id.depth, id.palette, id.scanlinePad, id.data);
    }

    if (maxP.x < id.width) {
      // crop the image again. A bit trickier this time.
      ImageData croppedId = new ImageData(maxP.x, id.height, id.depth, id.palette);

      int[] buffer = new int[maxP.x];
      for (int l = 0; l < id.height; l++) {
        id.getPixels(0, l, maxP.x, buffer, 0);
        croppedId.setPixels(0, l, maxP.x, buffer, 0);
      }

      id = croppedId;
    }

    // apply the zoom
    if (factor != 1) {
      id = id.scaledTo(id.width / factor, id.height / factor);
    }

    return id;
  }
 /**
  * Converts an AWT based buffered image into an SWT <code>Image</code>. This will always return an
  * <code>Image</code> that has 24 bit depth regardless of the type of AWT buffered image that is
  * passed into the method.
  *
  * @param awtImage the {@link java.awt.image.BufferedImage} to be converted to an <code>Image
  *     </code>
  * @return an <code>Image</code> that represents the same image data as the AWT <code>
  *     BufferedImage</code> type.
  */
 private static org.eclipse.swt.graphics.Image toSWT(Device device, BufferedImage awtImage) {
   // We can force bitdepth to be 24 bit because BufferedImage getRGB
   // allows us to always retrieve 24 bit data regardless of source color depth.
   PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
   ImageData swtImageData = new ImageData(awtImage.getWidth(), awtImage.getHeight(), 24, palette);
   // Ensure scansize is aligned on 32 bit.
   int scansize = (((awtImage.getWidth() * 3) + 3) * 4) / 4;
   WritableRaster alphaRaster = awtImage.getAlphaRaster();
   byte[] alphaBytes = new byte[awtImage.getWidth()];
   for (int y = 0; y < awtImage.getHeight(); y++) {
     int[] buff = awtImage.getRGB(0, y, awtImage.getWidth(), 1, null, 0, scansize);
     swtImageData.setPixels(0, y, awtImage.getWidth(), buff, 0);
     if (alphaRaster != null) {
       int[] alpha = alphaRaster.getPixels(0, y, awtImage.getWidth(), 1, (int[]) null);
       for (int i = 0; i < awtImage.getWidth(); i++) {
         alphaBytes[i] = (byte) alpha[i];
       }
       swtImageData.setAlphas(0, y, awtImage.getWidth(), alphaBytes, 0);
     }
   }
   return new org.eclipse.swt.graphics.Image(device, swtImageData);
 }
Exemple #4
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");
  }