Java Code Examples for org.pushingpixels.substance.internal.utils.SubstanceColorUtilities#getColorBrightness()

The following examples show how to use org.pushingpixels.substance.internal.utils.SubstanceColorUtilities#getColorBrightness() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrayscaleFilter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void grayScaleColor(int[] pixels) {
	for (int i = 0; i < pixels.length; i++) {
		int argb = pixels[i];
		int brightness = SubstanceColorUtilities.getColorBrightness(argb);
		pixels[i] = (argb & 0xFF000000) | brightness << 16 | brightness << 8 | brightness;
	}
}
 
Example 2
Source File: ColorSchemeFilter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void mixColor(int[] pixels) {
    for (int i = 0; i < pixels.length; i++) {
        int argb = pixels[i];

        int brightness = SubstanceColorUtilities.getColorBrightness(argb);

        int r = (argb >>> 16) & 0xFF;
        int g = (argb >>> 8) & 0xFF;
        int b = (argb >>> 0) & 0xFF;

        float[] hsb = Color.RGBtoHSB(r, g, b, null);
        int pixelColor = interpolated[brightness * MAPSTEPS / 256];

        int ri = (pixelColor >>> 16) & 0xFF;
        int gi = (pixelColor >>> 8) & 0xFF;
        int bi = (pixelColor >>> 0) & 0xFF;
        float[] hsbi = Color.RGBtoHSB(ri, gi, bi, null);

        hsb[0] = hsbi[0];
        hsb[1] = hsbi[1];
        if (this.originalBrightnessFactor >= 0.0f) {
            hsb[2] = this.originalBrightnessFactor * hsb[2]
                    + (1.0f - this.originalBrightnessFactor) * hsbi[2];
        } else {
            hsb[2] = hsb[2] * hsbi[2] * (1.0f + this.originalBrightnessFactor);
        }

        int result = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);

        pixels[i] = (argb & 0xFF000000) | ((result >> 16) & 0xFF) << 16
                | ((result >> 8) & 0xFF) << 8 | (result & 0xFF);
    }
}
 
Example 3
Source File: ColorWheelPanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setColor(Color c) {
	systemColor = null;

	if (c != null) {
		int r = c.getRed();
		int g = c.getGreen();
		int b = c.getBlue();
		if (useWebColors.isSelected()) {
			r = Math.round(r / 51) * 51;
			g = Math.round(g / 51) * 51;
			b = Math.round(b / 51) * 51;
		}
		chooserColor = new ModelColor(r, g, b);
	}
	// else
	c = new Color(chooserColor.R, chooserColor.G, chooserColor.B);

	values = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), values);
	if (values[1] == 0.0F) {
		s = values[1];
		b = values[2];
	} else if (values[2] == 0.0F) {
		b = values[2];
	} else {
		h = values[0];
		s = values[1];
		b = values[2];
	}
	h = Math.min(Math.max(h, 0.0), 1.0);
	s = Math.min(Math.max(s, 0.0), 1.0);
	b = Math.min(Math.max(b, 0.0), 1.0);

	if (values[1] != 0.0F) {
		if (values[1] != 0.0F)
			setHue();
		setSaturation();
	}
	setBrightness();

	busy = true;
	brightnessSlider.setValue(Integer.parseInt(brightEdit.getText()));
	saturationSlider.setValue(Integer.parseInt(satEdit.getText()));
	busy = false;

	baseColorLabel.setBackground(new Color(chooserColor.R, chooserColor.G,
			chooserColor.B));

	if (SubstanceColorUtilities.getColorBrightness(
			baseColorLabel.getBackground().getRGB()) < 128)
		baseColorLabel.setForeground(Color.white);
	else
		baseColorLabel.setForeground(Color.black);

	String colorStr;
	if (decimalRGB.isSelected()) {
		// Output decimal values
		colorStr = " " + c.getRed() + "."
				+ c.getGreen() + "."
				+ c.getBlue();
	} else {
		// Output HEX values
		colorStr = " " + ModelColor.toHexString(c.getRed())
				+ ModelColor.toHexString(c.getGreen())
				+ ModelColor.toHexString(c.getBlue());
	}
	baseColorLabel.setText(colorStr);
	baseColorEdit.setText(colorStr);

	ChangeEvent evt = new ChangeEvent(this);
	int numListeners = changeListeners.size();
	for (int i = 0; i < numListeners; i++) {
		ChangeListener l = changeListeners.get(i);
		l.stateChanged(evt);
	}

	if (hasChooser)
		getColorSelectionModel().setSelectedColor(c);
}