Java Code Examples for java.awt.Color#getBlue()

The following examples show how to use java.awt.Color#getBlue() . 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: SVGGraphics2D.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @returns the color definition in a string with the format: #RRGGBBAA:
 *          RRGGBB are the color components in hexa in the range 00..FF AA
 *          is the transparency value in hexa in the range 00..FF ex: Solid
 *          light gray : #777777
 */
protected String serializeToString( Color color )
{

	String r = Integer.toHexString( color.getRed( ) );
	if ( color.getRed( ) <= 0xF )
		r = "0" + r; //$NON-NLS-1$
	String g = Integer.toHexString( color.getGreen( ) );
	if ( color.getGreen( ) <= 0xF )
		g = "0" + g; //$NON-NLS-1$
	String b = Integer.toHexString( color.getBlue( ) );
	if ( color.getBlue( ) <= 0xF )
		b = "0" + b; //$NON-NLS-1$

	String ret = "#" + r + g + b; //$NON-NLS-1$
	return ret;
}
 
Example 2
Source File: FixPlatform.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private static String getHtmlColor(@NonNull final Color c) {
    final int r = c.getRed();
    final int g = c.getGreen();
    final int b = c.getBlue();
    final StringBuilder result = new StringBuilder();
    result.append ("#");        //NOI18N
    final String rs = Integer.toHexString (r);
    final String gs = Integer.toHexString (g);
    final String bs = Integer.toHexString (b);
    if (r < 0x10)
        result.append('0');
    result.append(rs);
    if (g < 0x10)
        result.append ('0');
    result.append(gs);
    if (b < 0x10)
        result.append ('0');
    result.append(bs);
    return result.toString();
}
 
Example 3
Source File: ColorUtil.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create color from start and end color
 *
 * @param sColor Start color
 * @param eColor End color
 * @param p Proportion
 * @return Color
 */
public static Color createColor(Color sColor, Color eColor, float p) {
    int sR, sG, sB, eR, eG, eB, r, g, b;
    
    sR = sColor.getRed();
    sG = sColor.getGreen();
    sB = sColor.getBlue();
    eR = eColor.getRed();
    eG = eColor.getGreen();
    eB = eColor.getBlue();
    r = (int) (sR + (eR - sR) * p);
    g = (int) (sG + (eG - sG) * p);
    b = (int) (sB + (eB - sB) * p);        
    
    return new Color(r, g, b);
}
 
Example 4
Source File: ImageMessage.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
private double getDistance(Color c1, Color c2) {
    double rmean = (c1.getRed() + c2.getRed()) / 2.0;
    double r = c1.getRed() - c2.getRed();
    double g = c1.getGreen() - c2.getGreen();
    int b = c1.getBlue() - c2.getBlue();
    double weightR = 2 + rmean / 256.0;
    double weightG = 4.0;
    double weightB = 2 + (255 - rmean) / 256.0;
    return weightR * r * r + weightG * g * g + weightB * b * b;
}
 
Example 5
Source File: PDPageContentStream.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Set the stroking color using an AWT color. Conversion uses the default sRGB color space.
 *
 * @param color The color to set.
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException
{
    float[] components = new float[] {
            color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
    PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE);
    setStrokingColor(pdColor);
}
 
Example 6
Source File: PaletteBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected int getBranchIndex(Color aColor, int aLevel) {
    if (aLevel > MAXLEVEL || aLevel < 0) {
        throw new IllegalArgumentException("Invalid octree node depth: " +
                                           aLevel);
    }

    int shift = MAXLEVEL - aLevel;
    int red_index = 0x1 & ((0xff & aColor.getRed()) >> shift);
    int green_index = 0x1 & ((0xff & aColor.getGreen()) >> shift);
    int blue_index = 0x1 & ((0xff & aColor.getBlue()) >> shift);
    int index = (red_index << 2) | (green_index << 1) | blue_index;
    return index;
}
 
Example 7
Source File: ColorTintFilter.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * <p>Creates a new color mixer filter. The specified color will be used
 * to tint the source image, with a mixing strength defined by
 * <code>mixValue</code>.</p>
 *
 * @param mixColor the solid color to mix with the source image
 * @param mixValue the strength of the mix, between 0.0 and 1.0; if the
 *   specified value lies outside this range, it is clamped
 * @throws IllegalArgumentException if <code>mixColor</code> is null
 */
public ColorTintFilter(Color mixColor, float mixValue) {
    if (mixColor == null) {
        throw new IllegalArgumentException("mixColor cannot be null");
    }

    this.mixColor = mixColor;
    if (mixValue < 0.0f) {
        mixValue = 0.0f;
    } else if (mixValue > 1.0f) {
        mixValue = 1.0f;
    }
    this.mixValue = mixValue;
    
    int mix_r = (int) (mixColor.getRed()   * mixValue);
    int mix_g = (int) (mixColor.getGreen() * mixValue);
    int mix_b = (int) (mixColor.getBlue()  * mixValue);
    
    // Since we use only lookup tables to apply the filter, this filter
    // could be implemented as a LookupOp.
    float factor = 1.0f - mixValue;
    preMultipliedRed   = new int[256];
    preMultipliedGreen = new int[256];
    preMultipliedBlue  = new int[256];

    for (int i = 0; i < 256; i++) {
        int value = (int) (i * factor);
        preMultipliedRed[i]   = value + mix_r;
        preMultipliedGreen[i] = value + mix_g;
        preMultipliedBlue[i]  = value + mix_b;
    }
}
 
Example 8
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static Color rgbInterpolate2(Color c1, Color c2, double k)
{

  if (c1 == null || c2 == null) {
    return Color.gray;
  }

  if (k == 0.0) {
    return c1;
  }
  if (k == 1.0) {
    return c2;
  }

  final int r1 = c1.getRed();
  final int g1 = c1.getGreen();
  final int b1 = c1.getBlue();
  final int r2 = c2.getRed();
  final int g2 = c2.getGreen();
  final int b2 = c2.getBlue();

  final int r = (int) (r1 + (double) (r2 - r1));
  final int g = (int) (g1 + (double) (g2 - g1));
  final int b = (int) (b1 + (double) (b2 - b1));

  final Color c = new Color(r, g, b);
  return c;
}
 
Example 9
Source File: CSSBorder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the color with brightness adjusted by the specified factor.
 *
 * The factor values are between 0.0 (no change) and 1.0 (turn into white).
 * Negative factor values decrease brigthness (ie, 1.0 turns into black).
 */
static Color getAdjustedColor(Color c, double factor) {
    double f = 1 - Math.min(Math.abs(factor), 1);
    double inc = (factor > 0 ? 255 * (1 - f) : 0);
    return new Color((int) (c.getRed() * f + inc),
                     (int) (c.getGreen() * f + inc),
                     (int) (c.getBlue() * f + inc));
}
 
Example 10
Source File: ColorUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert a color to its hex representation.
 * 
 * @param color the color to convert.
 * @return the hex.
 */
public static String asHexWithAlpha( Color color ) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    int a = color.getAlpha();

    String hex = String.format("#%02x%02x%02x%02x", r, g, b, a);
    return hex;
}
 
Example 11
Source File: CSSBorder.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Return the color with brightness adjusted by the specified factor.
 *
 * The factor values are between 0.0 (no change) and 1.0 (turn into white).
 * Negative factor values decrease brigthness (ie, 1.0 turns into black).
 */
static Color getAdjustedColor(Color c, double factor) {
    double f = 1 - Math.min(Math.abs(factor), 1);
    double inc = (factor > 0 ? 255 * (1 - f) : 0);
    return new Color((int) (c.getRed() * f + inc),
                     (int) (c.getGreen() * f + inc),
                     (int) (c.getBlue() * f + inc));
}
 
Example 12
Source File: GradientSlider.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
private static Color tween( Color c1, Color c2, float p) {
	if(p==0)
		return c1;
	if(p==1)
		return c2;
	
	return new Color(
			(int)(c1.getRed()*(1-p)+c2.getRed()*(p)),
			(int)(c1.getGreen()*(1-p)+c2.getGreen()*(p)),
			(int)(c1.getBlue()*(1-p)+c2.getBlue()*(p)),
			(int)(c1.getAlpha()*(1-p)+c2.getAlpha()*(p))
	);
}
 
Example 13
Source File: LayerBlendingModesTest.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static Color invert(Color in) {
    return new Color(
            255 - in.getRed(),
            255 - in.getGreen(),
            255 - in.getBlue(),
            in.getAlpha()
    );
}
 
Example 14
Source File: Tools.java    From cncgcodecontroller with MIT License 4 votes vote down vote up
public static Color setAlpha(Color c,double a){
    return new Color(c.getRed(), c.getGreen(), c.getBlue(),(int)(255*a));
}
 
Example 15
Source File: TerritoryOverLayDrawable.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
TerritoryOverLayDrawable(
    final Color color, final String name, final int alpha, final Operation operation) {
  this.color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
  territoryName = name;
  this.operation = operation;
}
 
Example 16
Source File: WaitGlassPane.java    From chipster with MIT License 4 votes vote down vote up
@Override
public void setBackground(Color background) {
	super.setBackground(background);
	Color messageBackground = new Color(background.getRed(), background.getGreen(), background.getBlue(), MSG_ALPHA);
	messageLabel.setBackground(messageBackground);
}
 
Example 17
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static int luminance(Color c) {
    return (299*c.getRed() + 587*c.getGreen() + 114*c.getBlue()) / 1000;
}
 
Example 18
Source File: XComponentPeer.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
static int[] getRGBvals(Color c) {

        int rgbvals[] = new int[3];

        rgbvals[0] = c.getRed();
        rgbvals[1] = c.getGreen();
        rgbvals[2] = c.getBlue();

        return rgbvals;
    }
 
Example 19
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
static int[] getRGBvals(Color c) {

        int rgbvals[] = new int[3];

        rgbvals[0] = c.getRed();
        rgbvals[1] = c.getGreen();
        rgbvals[2] = c.getBlue();

        return rgbvals;
    }
 
Example 20
Source File: Color3f.java    From SPIM_Registration with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the r,g,b values of this Color3f object to those of the specified
 * AWT Color object. No conversion is done on the color to compensate for
 * gamma correction.
 * 
 * @param color
 *            the AWT color to copy into this Color3f object
 * 
 * @since vecmath 1.2
 */
public final void set( Color color )
{
	x = (float) color.getRed() / 255.0f;
	y = (float) color.getGreen() / 255.0f;
	z = (float) color.getBlue() / 255.0f;
}