예제 #1
0
  @Override
  public Image process(Image image) {
    ImageData oldData = image.getImageData();
    ImageData newData = oldData;
    int[] pixelData = ImageUtil.getPixelData(oldData); // 保存了所有的像素值,大小是 width * height
    //		int[] rData = pixelData;
    //		int[] gData = pixelData;
    //		int[] bData = pixelData;
    //		int[][] rgbs = new int[3][pixelData.length];
    int[] rgb = new int[3];
    int width = oldData.width;
    int height = oldData.height;
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        rgb = ImageUtil.getRGBFromPixel(pixelData[i * width + j]);
        newData.setPixel(j, i, ImageUtil.getPixelFromRGB(oldData, new RGB(0, 0, rgb[2])));
      }
    }

    //		for (int i = 0; i < pixelData.length; i++) {
    //			rgb = ImageUtil.getRGBFromPixel(pixelData[i]);
    //			newData.setPixel(x, y, pixelValue) = ImageUtil.getPixelFromRGB(oldData,new
    // int[]{rgb[0],0,0});
    //			rData[i] = ImageUtil.getPixelFromRGB(oldData,new int[]{rgb[0],0,0});
    //			gData[i] = ImageUtil.getPixelFromRGB(oldData,new int[]{0,rgb[1],0});
    //			bData[i] = ImageUtil.getPixelFromRGB(oldData,new int[]{0,0,rgb[2]});
    //		}
    //		ImageUtil.calculateNewDataInRGB(rData, newData);

    Image newImage = new Image(Display.getDefault(), newData);
    Image newGreyImage = new Image(Display.getDefault(), newImage, SWT.IMAGE_GRAY);
    return newGreyImage;
  }
예제 #2
0
  /**
   * Returns a scaled instance of the tile image. Using a MediaTracker instance, this function waits
   * until the scaling operation is done.
   *
   * <p>Internally it caches the scaled image in order to optimize the common case, where the same
   * scale is requested as the last time.
   *
   * @param zoom the requested zoom level
   * @return Image
   */
  public Image getScaledImage(double zoom) {
    if (zoom == 1.0) {
      return getImage();
    } else if (zoom == myZoom && scaledImage != null) {
      return scaledImage;
    } else {
      Image img = getImage();
      Rectangle bounds = img.getBounds();
      if (img != null) {
        ImageData imageData = img.getImageData();
        if (tileset != null && tileset.getTransparentColor() != null) {
          imageData.transparentPixel = imageData.palette.getPixel(tileset.getTransparentColor());
        }
        scaledImage =
            new Image(
                Display.getDefault(),
                imageData.scaledTo(
                    (int) Math.round(bounds.width * zoom), (int) Math.round(bounds.height * zoom)));

        //                MediaTracker mediaTracker = new MediaTracker(new Canvas());
        //                mediaTracker.addImage(scaledImage, 0);
        //                try {
        //                    mediaTracker.waitForID(0);
        //                }
        //                catch (InterruptedException ie) {
        //                    System.err.println(ie);
        //                }
        //                mediaTracker.removeImage(scaledImage);
        myZoom = zoom;
        return scaledImage;
      }
    }

    return null;
  }
  private void setSoldierImage() {
    String bigFilePath =
        Patch.GAME_ROOT
            + "\\alexander\\data\\ui\\unit_info\\"
            + unitFaction
            + "\\"
            + soldierDictionary
            + "_info.tga";
    String smallFilePath =
        Patch.GAME_ROOT
            + "\\alexander\\data\\ui\\units\\"
            + unitFaction
            + "\\#"
            + soldierDictionary
            + ".tga";
    if (soldierImage != null) {
      try {
        TgaLoader.saveImage(new FileOutputStream(bigFilePath), soldierImage.scaledTo(160, 210));

        if (!isSpecialGeneralUnit) {
          if (soldierCardImage != null) {
            TgaLoader.saveImage(
                new FileOutputStream(smallFilePath), soldierCardImage.scaledTo(48, 64));
          } else {
            TgaLoader.saveImage(new FileOutputStream(smallFilePath), soldierImage.scaledTo(48, 64));
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
예제 #4
0
  private Point hilbertOrderData(ImageData id, byte pixData[]) {

    int order = 0;
    for (int n = 1; n < id.width; n *= 2) {
      order++;
    }
    /* Skanky; use an otherwise-unused ImageData field
     * to keep track of maxX.
     */
    Point p = new Point(0, 0);
    int oldIdX = id.x;
    int oldIdY = id.y;
    id.x = id.y = 0;
    try {
      hilbertWalk(id, new ByteArrayInputStream(pixData), order, 0, 0, HILBERT_DIR_E);
      p.x = id.x;
      p.y = id.y;
    } catch (IOException ex) {
      System.err.println("Exception during hilbertWalk()");
      p.x = id.height;
      p.y = id.width;
    }
    id.x = oldIdX;
    id.y = oldIdY;
    return p;
  }
 /* (non-Javadoc)
  * @see org.nightlabs.eclipse.ui.fckeditor.file.ContentFileBasePage#applySourceFile()
  */
 @Override
 protected void applySourceFile() {
   super.applySourceFile();
   if (getSourceFile() != null && imageLabel != null) {
     imageLabel.setImage(null);
     if (previewImage != null) {
       previewImage.dispose();
       previewImage = null;
     }
     try {
       ImageData id = ImageUtil.loadImage(getSourceFile(), new NullProgressMonitor());
       // ImageData id = new ImageData(new FileInputStream(getSourceFile()));
       float m = Math.max(id.width / 200f, id.height / 200f);
       int width = Math.round(id.width / m);
       int height = Math.round(id.height / m);
       previewImage = new Image(getShell().getDisplay(), id.scaledTo(width, height));
       imageLabel.setImage(previewImage);
       if (!disposeListenerRegistered) {
         getShell().addDisposeListener(this);
         disposeListenerRegistered = true;
       }
     } catch (Exception e) {
       Activator.err("Error loading image preview", e); // $NON-NLS-1$
       previewImage = null;
       imageLabel.setText(
           Messages.getString(
               "org.nightlabs.eclipse.ui.fckeditor.file.image.ContentImageFileBasePage.previewLoadingErrorText")); //$NON-NLS-1$
     }
   }
 }
예제 #6
0
 void initResources() {
   final java.lang.Class clazz = this.getClass();
   if (resourceBundle != null) {
     try {
       if (images == null) {
         images = new org.eclipse.swt.graphics.Image[imageLocations.length];
         for (int i = 0; i < imageLocations.length; ++i) {
           java.io.InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
           org.eclipse.swt.graphics.ImageData source =
               new org.eclipse.swt.graphics.ImageData(sourceStream);
           org.eclipse.swt.graphics.ImageData mask = source.getTransparencyMask();
           images[i] = new org.eclipse.swt.graphics.Image(null, source, mask);
           try {
             sourceStream.close();
           } catch (java.io.IOException e) {
             e.printStackTrace();
           }
         }
       }
       return;
     } catch (java.lang.Throwable t) {
     }
   }
   java.lang.String error =
       resourceBundle != null
           ? getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new java.lang.RuntimeException(error);
 }
  /** Loads the resources */
  void initResources() {
    final Class<ControlExample> clazz = ControlExample.class;
    if (resourceBundle != null) {
      try {
        if (images == null) {
          images = new Image[imageLocations.length];

          for (int i = 0; i < imageLocations.length; ++i) {
            InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
            ImageData source = new ImageData(sourceStream);
            if (imageTypes[i] == SWT.ICON) {
              ImageData mask = source.getTransparencyMask();
              images[i] = new Image(null, source, mask);
            } else {
              images[i] = new Image(null, source);
            }
            try {
              sourceStream.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        return;
      } catch (Throwable t) {
      }
    }
    String error =
        (resourceBundle != null)
            ? getResourceString("error.CouldNotLoadResources")
            : "Unable to load resources"; //$NON-NLS-1$
    freeResources();
    throw new RuntimeException(error);
  }
  private Image createTransparentBackground(int width, int height) {
    PaletteData paletteData =
        new PaletteData(new RGB[] {new RGB(204, 204, 204), new RGB(255, 255, 255)});
    System.out.println("createTransparent width,height (" + width + "," + height + ")");
    ImageData imageData = new ImageData(width, height, 8, paletteData);
    RGB grayRGB = new RGB(204, 204, 204);
    RGB whiteRGB = new RGB(255, 255, 255);
    RGB currentColor = null;
    int switchColorNum = 0;
    for (int x = 0; x < width; x++) {
      if (x != 0 && (x % 8) == 0) {
        switchColorNum = switchColorNum == 0 ? 1 : 0;
      }
      for (int y = 0; y < height; y++) {
        if (y < 8) {
          currentColor = switchColorNum == 0 ? grayRGB : whiteRGB;
        } else if ((y % 8) == 0) {
          currentColor = currentColor == grayRGB ? whiteRGB : grayRGB;
        }
        int pixel = paletteData.getPixel(currentColor);
        imageData.setPixel(x, y, pixel);
      }
    }

    return new Image(Display.getDefault(), imageData);
  }
예제 #9
0
 public Region getRegion(Image image) {
   Region region = new Region();
   final ImageData imageData = image.getImageData();
   if (imageData.alphaData != null) {
     Rectangle pixel = new Rectangle(0, 0, 1, 1);
     for (int y = 0; y < imageData.height; y++) {
       for (int x = 0; x < imageData.width; x++) {
         if (imageData.getAlpha(x, y) == 255) {
           pixel.x = imageData.x + x;
           pixel.y = imageData.y + y;
           region.add(pixel);
         }
       }
     }
   } else {
     ImageData mask = imageData.getTransparencyMask();
     Rectangle pixel = new Rectangle(0, 0, 1, 1);
     for (int y = 0; y < mask.height; y++) {
       for (int x = 0; x < mask.width; x++) {
         if (mask.getPixel(x, y) != 0) {
           pixel.x = imageData.x + x;
           pixel.y = imageData.y + y;
           region.add(pixel);
         }
       }
     }
   }
   return region;
 }
예제 #10
0
  private static void setBrightness() {
    if (image.isDisposed()) {
      return;
    }

    ImageData imageData = image.getImageData();

    for (int x = 0; x < imageData.width; x++) {
      for (int y = 0; y < imageData.height; y++) {
        RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y));
        float[] hsb = rgb.getHSB();

        hsb[2] = hsb[2] + 0.1f;
        if (hsb[2] > 1.0f) {
          hsb[2] = 1.0f;
        }

        //				hsb[1] = hsb[1] - 0.1f;
        //				if (hsb[1] < 0.0f) {
        //					hsb[1] = 0.0f;
        //				}
        RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

        int pixel = imageData.palette.getPixel(newRGB);
        imageData.setPixel(x, y, pixel);
      }
    }

    image.dispose();
    image = new Image(Display.getDefault(), imageData);

    imageFigure.setImage(image);
  }
예제 #11
0
 public void initResources() {
   final java.lang.Class clazz = org.eclipse.swt.examples.paint.PaintExample.class;
   if (resourceBundle != null) {
     try {
       for (int i = 0; i < tools.length; ++i) {
         org.eclipse.swt.examples.paint.Tool tool = tools[i];
         java.lang.String id = tool.group + '.' + tool.name;
         java.io.InputStream sourceStream =
             clazz.getResourceAsStream(getResourceString(id + ".image"));
         org.eclipse.swt.graphics.ImageData source =
             new org.eclipse.swt.graphics.ImageData(sourceStream);
         org.eclipse.swt.graphics.ImageData mask = source.getTransparencyMask();
         tool.image = new org.eclipse.swt.graphics.Image(null, source, mask);
         try {
           sourceStream.close();
         } catch (java.io.IOException e) {
           e.printStackTrace();
         }
       }
       return;
     } catch (java.lang.Throwable t) {
     }
   }
   java.lang.String error =
       resourceBundle != null
           ? getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new java.lang.RuntimeException(error);
 }
예제 #12
0
 /** Loads the image resources. */
 public void initResources() {
   final Class clazz = PaintExample.class;
   if (PaintExample.resourceBundle != null)
     try {
       for (int i = 0; i < PaintExample.tools.length; ++i) {
         Tool tool = PaintExample.tools[i];
         String id = tool.group + '.' + tool.name;
         InputStream sourceStream =
             clazz.getResourceAsStream(PaintExample.getResourceString(id + ".image"));
         ImageData source = new ImageData(sourceStream);
         ImageData mask = source.getTransparencyMask();
         tool.image = new Image(null, source, mask);
         try {
           sourceStream.close();
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
       return;
     } catch (Throwable t) {
     }
   String error =
       PaintExample.resourceBundle != null
           ? PaintExample.getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new RuntimeException(error);
 }
예제 #13
0
 /**
  * Returns an image encoded by the specified input stream
  *
  * @param is InputStream The input stream encoding the image data
  * @return Image The image encoded by the specified input stream
  */
 protected static Image getImage(InputStream is) {
   Display display = Display.getCurrent();
   ImageData data = new ImageData(is);
   if (data.transparentPixel > 0) {
     return new Image(display, data, data.getTransparencyMask());
   }
   return new Image(display, data);
 }
예제 #14
0
  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;
  }
예제 #15
0
 /**
  * Converts an SWT ImageData to an AWT BufferedImage.
  *
  * @param bufferedImage
  * @return
  */
 @Override
 public BufferedImage getBufferedImage(ImageData data) {
   ColorModel colorModel = null;
   PaletteData palette = data.palette;
   if (palette.isDirect) {
     colorModel =
         new DirectColorModel(data.depth, palette.redMask, palette.greenMask, palette.blueMask);
     BufferedImage bufferedImage =
         new BufferedImage(
             colorModel,
             colorModel.createCompatibleWritableRaster(data.width, data.height),
             false,
             null);
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         int pixel = data.getPixel(x, y);
         RGB rgb = palette.getRGB(pixel);
         bufferedImage.setRGB(x, y, rgb.red << 16 | rgb.green << 8 | rgb.blue);
       }
     }
     return bufferedImage;
   } else {
     RGB[] rgbs = palette.getRGBs();
     byte[] red = new byte[rgbs.length];
     byte[] green = new byte[rgbs.length];
     byte[] blue = new byte[rgbs.length];
     for (int i = 0; i < rgbs.length; i++) {
       RGB rgb = rgbs[i];
       red[i] = (byte) rgb.red;
       green[i] = (byte) rgb.green;
       blue[i] = (byte) rgb.blue;
     }
     if (data.transparentPixel != -1) {
       colorModel =
           new IndexColorModel(data.depth, rgbs.length, red, green, blue, data.transparentPixel);
     } else {
       colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue);
     }
     BufferedImage bufferedImage =
         new BufferedImage(
             colorModel,
             colorModel.createCompatibleWritableRaster(data.width, data.height),
             false,
             null);
     WritableRaster raster = bufferedImage.getRaster();
     int[] pixelArray = new int[1];
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         int pixel = data.getPixel(x, y);
         pixelArray[0] = pixel;
         raster.setPixel(x, y, pixelArray);
       }
     }
     return bufferedImage;
   }
 }
예제 #16
0
  private ImageData getEmptyImageData() {
    final RGB whiteRGB = new RGB(255, 255, 255); // The transparancy color
    final RGB blackRGB = new RGB(0, 0, 0);

    PaletteData palette = new PaletteData(new RGB[] {whiteRGB, blackRGB});
    ImageData imageData = new ImageData(width, height, 1, palette);
    int whitePixel = imageData.palette.getPixel(whiteRGB);
    imageData.transparentPixel = whitePixel;
    return imageData;
  }
예제 #17
0
 static ImageData convertToSWT(BufferedImage bufferedImage) {
   if (bufferedImage.getColorModel() instanceof DirectColorModel) {
     DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
     PaletteData palette =
         new PaletteData(
             colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask());
     ImageData data =
         new ImageData(
             bufferedImage.getWidth(),
             bufferedImage.getHeight(),
             colorModel.getPixelSize(),
             palette);
     WritableRaster raster = bufferedImage.getRaster();
     int[] pixelArray = new int[3];
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         raster.getPixel(x, y, pixelArray);
         int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
         data.setPixel(x, y, pixel);
       }
     }
     return data;
   } else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
     IndexColorModel colorModel = (IndexColorModel) bufferedImage.getColorModel();
     int size = colorModel.getMapSize();
     byte[] reds = new byte[size];
     byte[] greens = new byte[size];
     byte[] blues = new byte[size];
     colorModel.getReds(reds);
     colorModel.getGreens(greens);
     colorModel.getBlues(blues);
     RGB[] rgbs = new RGB[size];
     for (int i = 0; i < rgbs.length; i++) {
       rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF);
     }
     PaletteData palette = new PaletteData(rgbs);
     ImageData data =
         new ImageData(
             bufferedImage.getWidth(),
             bufferedImage.getHeight(),
             colorModel.getPixelSize(),
             palette);
     data.transparentPixel = colorModel.getTransparentPixel();
     WritableRaster raster = bufferedImage.getRaster();
     int[] pixelArray = new int[1];
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         raster.getPixel(x, y, pixelArray);
         data.setPixel(x, y, pixelArray[0]);
       }
     }
     return data;
   }
   return null;
 }
예제 #18
0
 public Image getSizedImage(String filename, int width, int height) {
   if (filename == null) return null;
   InputStream stream = clazz.getResourceAsStream(filename);
   if (stream == null) throw new RuntimeException(filename + " not found");
   ImageData data = new ImageData(stream);
   if (width != 0 && height != 0 && data.width != width || data.height != height) {
     LogUtility.logDebug("ScaledWidgetFactory", "scaling image for " + filename);
     data = data.scaledTo(width, height);
   }
   return new Image(Display.getCurrent(), data);
 }
예제 #19
0
 /**
  * Returns an {@link Image} encoded by the specified {@link InputStream}.
  *
  * @param stream the {@link InputStream} encoding the image data
  * @return the {@link Image} encoded by the specified input stream
  */
 protected static Image getImage(InputStream stream) throws IOException {
   try {
     Display display = Display.getCurrent();
     ImageData data = new ImageData(stream);
     if (data.transparentPixel > 0) {
       return new Image(display, data, data.getTransparencyMask());
     }
     return new Image(display, data);
   } finally {
     stream.close();
   }
 }
예제 #20
0
  public Image fade(Image image, int alpha) {
    ImageData imageData = image.getImageData();

    byte[] aplhas = new byte[imageData.height * imageData.width];

    for (int i = 0; i < aplhas.length; i++) {
      aplhas[i] = (byte) alpha;
    }

    imageData.alphaData = aplhas;
    return new Image(Display.getCurrent(), imageData);
  }
예제 #21
0
 private ImageData getDownImageData() {
   ImageData imageData = getEmptyImageData();
   int numTransparentPixels = 0;
   for (int row = 0; row < height; ++row) {
     for (int col = numTransparentPixels; col < width / 2; ++col) {
       imageData.setPixel(col, row, 1);
       imageData.setPixel(width - col - 1, row, 1);
     }
     ++numTransparentPixels;
   }
   return imageData;
 }
예제 #22
0
  /**
   * 根据当前的各种条件,获取Image对象
   *
   * @return
   */
  public Image getImage() {
    ImageData data = new ImageData(resPath);

    data.type = this.imageType;
    if (this.imageWidth == 0 && this.imageHeight == 0) {
      data = data.scaledTo((int) (data.width * this.scaling), (int) (data.height * this.scaling));
    } else {
      data = data.scaledTo(imageWidth, imageHeight);
    }

    return new Image(display, data);
  }
 public void testModifyData() throws Exception {
   ImageData originalData = getImageData(Fixture.IMAGE1);
   Image image = ResourceFactory.findImage(originalData);
   cache.putImageData(image, originalData);
   ImageData copyData1 = cache.getImageData(image);
   assertNotSame(originalData, copyData1);
   assertEqualsImageData(originalData, copyData1);
   // modify original data
   originalData.setPixel(0, 0, 23);
   ImageData copyData2 = cache.getImageData(image);
   assertNotSame(copyData1, copyData2);
   assertEqualsImageData(copyData1, copyData2);
 }
예제 #24
0
  @Override
  protected void updateContents(Object value) {
    final Paint paint = value == null ? Color.TRANSPARENT : (Paint) value;

    if (image != null) {
      image.dispose();
    }

    ImageData id = createPaintImage(getDefaultLabel().getParent().getParent(), paint);
    image = new Image(getDefaultLabel().getDisplay(), id, id.getTransparencyMask());

    getDefaultLabel().setImage(image);
  }
예제 #25
0
  /**
   * Returns a corner image for the specified position and color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param position the wanted position of the image
   * @param rgb the wanted color
   * @return the image
   */
  public static Image getCornerImage(DecorationPosition position, RGB rgb) {
    final String key = "CORNER_IMAGE:" + position + ":" + rgb; // $NON-NLS-1$ //$NON-NLS-2$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, 5, 5);
    final GC gc = new GC(image);
    gc.setBackground(color);

    switch (position) {
      case TOP_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 0, 0, 4});
        break;
      case CENTER_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 2, 0, 4});
        break;
      case BOTTOM_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 4, 0, 4});
        break;
      case TOP_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 0, 0, 4, 4});
        break;
      case CENTER_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 2, 0, 4, 4});
        break;
      case BOTTOM_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 4, 0, 4, 4});
        break;
    }

    gc.dispose();
    color.dispose();

    /*
     * Set the transparent color
     */
    final ImageData ideaData = image.getImageData();
    final int whitePixel = ideaData.palette.getPixel(new RGB(255, 255, 255));
    ideaData.transparentPixel = whitePixel;

    ir.put(key, image);

    return image;
  }
예제 #26
0
  public Image overlay(Image buttomImage, Image topImage) {

    ImageData topData = topImage.getImageData();
    ImageData bottomData = buttomImage.getImageData();

    int zeroX = (bottomData.width - topData.width) / 2;
    int zeroY = (bottomData.height - topData.height) / 2;

    for (int y = 0; y < topData.height; y++) {
      for (int x = 0; x < topData.width; x++) {
        bottomData.setPixel(zeroX + x, zeroY + y, topData.getPixel(x, y));
      }
    }

    return new Image(Display.getCurrent(), bottomData);
  }
예제 #27
0
  public static ImageData resize(
      final Display display,
      final ImageData imageData,
      final int width,
      final int height,
      final boolean antiAliasing) {

    if (imageData == null) {
      return null;
    }

    if (imageData.width == width && imageData.height == height) {
      return imageData;
    }

    if (antiAliasing) {
      Image tmpImage = null;
      final Image fullImage = new Image(display, imageData);
      ImageData result = null;
      tmpImage = resize(display, fullImage, width, height);

      result = tmpImage.getImageData();
      tmpImage.dispose();
      fullImage.dispose();
      return result;
    }
    return imageData.scaledTo(width, height);
  }
예제 #28
0
 ImageData[] loadFromByteStream() {
   int[] fileHeader = loadFileHeader();
   byte[] infoHeader = new byte[BMPHeaderFixedSize];
   try {
     inputStream.read(infoHeader);
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8);
   height = (infoHeader[6] & 0xFF) | ((infoHeader[7] & 0xFF) << 8);
   bitCount = (infoHeader[10] & 0xFF) | ((infoHeader[11] & 0xFF) << 8);
   PaletteData palette = loadPalette(infoHeader);
   if (inputStream.getPosition() < fileHeader[4]) {
     // Seek to the specified offset
     try {
       inputStream.skip(fileHeader[4] - inputStream.getPosition());
     } catch (IOException e) {
       SWT.error(SWT.ERROR_IO, e);
     }
   }
   byte[] data = loadData(infoHeader);
   int type = SWT.IMAGE_OS2_BMP;
   return new ImageData[] {
     ImageData.internal_new(
         width, height, bitCount, palette, 4, data, 0, null, null, -1, -1, type, 0, 0, 0, 0)
   };
 }
예제 #29
0
  public static ImageData createImageData(RenderedImage image) {
    ImageData swtdata = null;
    int width = image.getWidth();
    int height = image.getHeight();
    PaletteData palette;
    int depth;

    depth = 24;
    palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
    swtdata = new ImageData(width, height, depth, palette);
    swtdata.transparentPixel = TRANSPARENT;

    byte blueT = (byte) ((TRANSPARENT) & 0xFF);
    byte greenT = (byte) ((TRANSPARENT >> 8) & 0xFF);
    byte redT = (byte) ((TRANSPARENT >> 16) & 0xFF);
    // System.out.println("red="+redT+"blue"+blueT+"green"+greenT);
    // System.out.println("Transparent"+TRANSPARENT);

    // awtImage2.getRGB();
    Raster raster = image.getData();
    int[] awtdata =
        raster.getPixels(
            0, 0, width, height, new int[width * height * 3]); // raster.getNumBands()]);
    int step = swtdata.depth / 8;

    byte[] data = swtdata.data;
    int baseindex = 0;
    // System.out.println( "AWT size:" + awtdata.length );
    for (int y = 0; y < height; y++) {
      int idx = ((0 + y) * swtdata.bytesPerLine) + (0 * step);

      for (int x = 0; x < width; x++) {
        baseindex = (x + (y * width)) * 4;

        if (awtdata[baseindex + 3] == 0) {
          data[idx++] = blueT;
          data[idx++] = greenT;
          data[idx++] = redT;
        } else {
          data[idx++] = (byte) awtdata[baseindex];
          data[idx++] = (byte) awtdata[baseindex + 1];
          data[idx++] = (byte) awtdata[baseindex + 2];
        }
      }
    }
    return swtdata;
  }
  private Image buildContentAreaPreview() {
    if (mContentAreaImage != null) {
      mContentAreaImage.dispose();
    }

    Rectangle rect = mNinePatchedImage.getContentArea();

    int yLen = rect.y + rect.height;
    for (int y = rect.y; y < yLen; y++) {
      int xLen = rect.x + rect.width;
      for (int x = rect.x; x < xLen; x++) {
        mContentAreaImageData.setPixel(x, y, PADDING_COLOR);
        mContentAreaImageData.setAlpha(x, y, PADDING_COLOR_ALPHA);
      }
    }
    return new Image(AdtPlugin.getDisplay(), mContentAreaImageData);
  }