private void adaptToTextForegroundChange(Highlighting highlighting, PropertyChangeEvent event) {
    RGB rgb = null;

    Object value = event.getNewValue();
    if (value instanceof RGB) rgb = (RGB) value;
    else if (value instanceof String) rgb = StringConverter.asRGB((String) value);

    if (rgb != null) {

      String property = event.getProperty();
      Color color = fColorManager.getColor(property);

      if ((color == null || !rgb.equals(color.getRGB()))
          && fColorManager instanceof IColorManagerExtension) {
        IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
        ext.unbindColor(property);
        ext.bindColor(property, rgb);
        color = fColorManager.getColor(property);
      }

      TextAttribute oldAttr = highlighting.getTextAttribute();
      highlighting.setTextAttribute(
          new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
    }
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
 @Test
 public void testEquality() {
   RGB rgbSalmon = new RGB(250, 128, 114);
   RGB rgbChocolate = new RGB(210, 105, 30);
   assertTrue(rgbSalmon.equals(new RGB(250, 128, 114)));
   assertFalse(rgbSalmon.equals(rgbChocolate));
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
   */
  protected void paintFigure(Graphics graphics) {
    Rectangle area = new Rectangle();
    area.setBounds(getBounds());
    //    area.crop(getInsets());
    if (useLocalCoordinates()) area.setLocation(0, 0);
    //      Rectangle area = getClientArea().getCopy();

    RenderInfo rndInfo = getRenderedImage().getRenderInfo();
    if (!useOriginalColors()) {
      RGB backgroundColor = getBackgroundColor().getRGB();
      RGB foregroundColor = getForegroundColor().getRGB();
      if ((backgroundColor != null && !backgroundColor.equals(rndInfo.getBackgroundColor()))
          || (foregroundColor != null && !foregroundColor.equals(rndInfo.getForegroundColor()))) {
        rndInfo.setValues(
            rndInfo.getWidth(),
            rndInfo.getHeight(),
            rndInfo.shouldMaintainAspectRatio(),
            rndInfo.shouldAntiAlias(),
            getBackgroundColor().getRGB(),
            getForegroundColor().getRGB());
        setRenderedImage(getRenderedImage().getNewRenderedImage(rndInfo));
      }
    }
    setRenderedImage(
        RenderHelper.getInstance(
                DiagramMapModeUtil.getScale(MapModeUtil.getMapMode(this)), false, false, null)
            .drawRenderedImage(graphics, getRenderedImage(), area, renderingListener));
  }
  /**
   * Processes the save action.
   *
   * @param rgb The new RGB value.
   */
  protected void processAction(RGB rgb) {
    String newComboText = predefinedColor;
    if (newComboText == null) newComboText = formatRGB(rgb);

    if (!combo.getText().equals(newComboText)) combo.setText(newComboText);

    if (oldRgb == null && rgb == null) return;

    if (rgb != null && rgb.equals(oldRgb)) return;

    oldRgb = rgb;
    if (rgb == null || !rgb.equals(colorSelector.getColorValue())) colorSelector.setColorValue(rgb);

    notifyListeners(SWT.Modify, null);
  }
Exemplo n.º 6
0
  /** @param rgb New background color */
  public void setPlotBackground(final RGB rgb) {
    if (background.equals(rgb)) return;
    background = rgb;
    // Notify listeners
    System.out.println("**** Model.setPlotBackground() ****");

    for (ModelListener listener : listeners) listener.changedColors();
  }
  /**
   * 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;
      }
    }
  }
Exemplo n.º 8
0
  protected void refreshControls() {
    String colorValue = fDiagramModelObject.getFillColor();
    RGB rgb = ColorFactory.convertStringToRGB(colorValue);
    if (rgb == null) {
      rgb = ColorFactory.getDefaultFillColor(fDiagramModelObject).getRGB();
    }

    fColorChooser.setColorValue(rgb);

    boolean enabled =
        fDiagramModelObject instanceof ILockable
            ? !((ILockable) fDiagramModelObject).isLocked()
            : true;
    fColorChooser.setEnabled(enabled);

    // If user pref is to save the color then it's a different meaning of default
    boolean isDefaultColor = (colorValue == null);
    if (Preferences.STORE.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) {
      isDefaultColor =
          (colorValue != null)
              && rgb.equals(ColorFactory.getDefaultFillColor(fDiagramModelObject).getRGB());
    }
    fColorChooser.setIsDefaultColor(isDefaultColor);
  }
  /**
   * Adds (or replaces) a color to this color registry under the given symbolic name.
   *
   * <p>A property change event is reported whenever the mapping from a symbolic name to a color
   * changes. The source of the event is this registry; the property name is the symbolic color
   * name.
   *
   * @param symbolicName the symbolic color name
   * @param colorData an <code>RGB</code> object
   * @param update - fire a color mapping changed if true. False if this method is called from the
   *     get method as no setting has changed.
   */
  private void put(String symbolicName, RGB colorData, boolean update) {

    Assert.isNotNull(symbolicName);
    Assert.isNotNull(colorData);

    RGB existing = stringToRGB.get(symbolicName);
    if (colorData.equals(existing)) {
      return;
    }

    Color oldColor = stringToColor.remove(symbolicName);
    stringToRGB.put(symbolicName, colorData);
    if (update) {
      fireMappingChanged(symbolicName, existing, colorData);
    }

    if (oldColor != null) {
      staleColors.add(oldColor);
    }
  }
Exemplo n.º 10
0
  @Override
  public Image run(Image input, int imageType) {

    ImageData inData = input.getImageData(); // Die echten Bilddaten sind hier drin

    // RGB zu YUV Umwandlungsmatrix
    //		double[] linear_conversion = {
    //			0.2126, 0.7152, 0.0722,
    //			-0.09991, -0.33609, 0.436,
    //			0.615, -0.55861, -0.05639
    //		};
    double[] linear_conversion = {0.299, 0.587, 0.114, -0.147, -0.289, 0.436, 0.615, -0.515, -0.1};
    Matrix m = new Matrix(3, 3, linear_conversion);

    // YUV zu RGB Umwandlungmatrix (das Inverse)
    //		double[] inv_linear_conversion = {
    //		    1.0000,    0.0000,    1.28033,
    //		    1.0000,   -0.21482,   -0.38059,
    //		    1.0000,    2.12798,   -0.0005
    //		};
    double[] inv_linear_conversion = {
      1.0000, 0.0000, 1.1398, 1.0000, -0.3946, -0.5805, 1.0000, 2.0320, -0.0005
    };
    Matrix minv = new Matrix(3, 3, inv_linear_conversion);

    for (int v = 0; v < inData.height; v++) {
      for (int u = 0; u < inData.width; u++) {
        int pixel = inData.getPixel(u, v);

        RGB rgb = inData.palette.getRGB(pixel);

        // Variante mit Farbwerte U und V von YUV auf 0 setzen
        Vector r = new Vector(rgb.red, rgb.green, rgb.blue);
        double[] y = m.times(r).getV();
        y[2] = 0;
        y[1] = 0;
        r = minv.times(new Vector(y));
        rgb.red = (int) r.x(1);
        rgb.green = (int) r.x(2);
        rgb.blue = (int) r.x(3);

        if (rgb.red < 0) rgb.red = 0;
        else if (rgb.red > 255) rgb.red = 255;

        if (rgb.green < 0) rgb.green = 0;
        else if (rgb.green > 255) rgb.green = 255;

        if (rgb.blue < 0) rgb.blue = 0;
        else if (rgb.blue > 255) rgb.blue = 255;

        // Variante mit der Sättigung auf 0 gesetzt (schlechter)
        //				float[] hsb = inData.palette.getRGB(pixel).getHSB();
        //
        //				hsb[1] = 0; //Sättigung auf 0 setzen
        //
        //				Color c = new Color(Color.HSBtoRGB(hsb[0],hsb[1],hsb[2]));
        //				RGB rgb = new RGB(0,0,0);
        //				rgb.red = c.getRed();
        //				rgb.green = c.getGreen();
        //				rgb.blue = c.getBlue();

        inData.setPixel(u, v, inData.palette.getPixel(rgb));
      }
    }
    return new Image(input.getDevice(), inData);
  }
Exemplo n.º 11
0
 protected void copyRGB(RGB src, RGB dst) {
   dst.red = src.red;
   dst.green = src.green;
   dst.blue = src.blue;
 }
Exemplo n.º 12
0
  /**
   * This methode should be overload by sub class to create the input component for the selection of
   * this input video. The implementation of this class return an empty Composite.
   *
   * @param parent the parent of this Area
   * @return the control created
   */
  protected Control createInputArea(Composite parent) {

    // Setup darker background
    RGB rgb = getBackground().getRGB();
    rgb.red = (int) (rgb.red * DARKER_COLOR_FACTOR);
    rgb.green = (int) (rgb.green * DARKER_COLOR_FACTOR);
    rgb.blue = (int) (rgb.blue * DARKER_COLOR_FACTOR);
    darkerBackground = new Color(Display.getCurrent(), rgb);

    // Create the composite component
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(4, false));

    /*
     * Filename components
     */
    String filenameText = Localization.getString(Localization.INPUTOUTPUT_FILENAME);
    Label label;
    label = new Label(comp, SWT.NONE);
    label.setText(filenameText);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    Composite subComp = new Composite(comp, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    subComp.setLayout(layout);
    subComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));

    inputFileName = new Text(subComp, SWT.READ_ONLY | SWT.BORDER);
    inputFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    createMoreOptionsButton(subComp);

    /*
     * Language selection
     */
    label = new Label(comp, SWT.NONE);
    label.setText(Localization.getString(Localization.INPUTOUTPUT_LANGAGE));
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    languageCombo = createViewer(comp, AUDIO_ID);
    languageCombo.getCombo().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));

    /*
     * Subtitle selection
     */
    String subtitleText = Localization.getString(Localization.INPUTOUTPUT_SUBTITLE);
    label = new Label(comp, SWT.NONE);
    label.setText(subtitleText);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    subtitleCombo = createViewer(comp, SUBTITLE_ID);
    subtitleCombo.getCombo().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));

    /*
     * Description label
     */
    label = new Label(comp, SWT.NONE);
    label.setText(Localization.getString(Localization.INPUTOUTPUT_VIDEO));
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    videoDescription = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.READ_ONLY);
    videoDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    videoDescription.setBackground(darkerBackground);

    label = new Label(comp, SWT.NONE);
    label.setText(Localization.getString(Localization.INPUTOUTPUT_AUDIO));
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    audioDescription = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.READ_ONLY);
    audioDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    audioDescription.setBackground(darkerBackground);

    // Add disposal instruction
    this.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            darkerBackground.dispose();
          }
        });

    return comp;
  }