Пример #1
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);
  }
  /**
   * Sets the viewer's background color to the given control's background color. The background
   * color is <em>only</em> set if it's visibly distinct from the default Java source text color.
   *
   * @param control the control with the default background color
   * @since 3.7
   */
  public void adaptBackgroundColor(Control control) {
    // workaround for dark editor background color, see https://bugs.eclipse.org/330680

    Color defaultColor = control.getBackground();
    float[] defaultBgHSB = defaultColor.getRGB().getHSB();

    Color javaDefaultColor = JavaUI.getColorManager().getColor(IJavaColorConstants.JAVA_DEFAULT);
    RGB javaDefaultRGB =
        javaDefaultColor != null ? javaDefaultColor.getRGB() : new RGB(255, 255, 255);
    float[] javaDefaultHSB = javaDefaultRGB.getHSB();

    if (Math.abs(defaultBgHSB[2] - javaDefaultHSB[2]) >= 0.5f) {
      getTextWidget().setBackground(defaultColor);
      if (fBackgroundColor != null) {
        fBackgroundColor.dispose();
        fBackgroundColor = null;
      }
    }
  }