Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 216739 Details for
Bug 380894
FigureUtilities lighter produce in certain cases not the correct color
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch as outlined in the previouse comment
fix-380894.patch (text/plain), 4.87 KB, created by
Alois Zoitl
on 2012-06-03 15:51:28 EDT
(
hide
)
Description:
patch as outlined in the previouse comment
Filename:
MIME Type:
Creator:
Alois Zoitl
Created:
2012-06-03 15:51:28 EDT
Size:
4.87 KB
patch
obsolete
>From c269fa40b5e78956f747e8fa6a3fed6fcdd4cd7d Mon Sep 17 00:00:00 2001 >From: Alois Zoitl <alil@users.sourceforge.net> >Date: Sun, 3 Jun 2012 21:46:19 +0200 >Subject: [PATCH] changed lighter and darker functions to use hsl color model > in order to avoid border case issues > >--- > .../src/org/eclipse/draw2d/FigureUtilities.java | 118 ++++++++++++++++++-- > 1 file changed, 107 insertions(+), 11 deletions(-) > >diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java >index 8fb21a8..b42c138 100644 >--- a/org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java >+++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java >@@ -26,7 +26,7 @@ import org.eclipse.draw2d.geometry.Rectangle; > */ > public class FigureUtilities { > >- private static final float RGB_VALUE_MULTIPLIER = 0.6f; >+ private static final float VALUE_MULTIPLIER = 0.6f; > private static GC gc; > private static Font appliedFont; > private static FontMetrics metrics; >@@ -41,10 +41,10 @@ public class FigureUtilities { > * @since 2.0 > */ > public static Color darker(Color color) { >- return new Color(null, (int) (color.getRed() * RGB_VALUE_MULTIPLIER), >- (int) (color.getGreen() * RGB_VALUE_MULTIPLIER), >- (int) (color.getBlue() * RGB_VALUE_MULTIPLIER)); >- } >+ double hsl[] = rgbToHSL(original.getRGB()); >+ hsl[2] = hsl[2] * VALUE_MULTIPLIER; >+ return new Color(null, hslToRGB(hsl)); >+ } > > /** > * Returns the FontMetrics associated with the passed Font. >@@ -195,12 +195,9 @@ public class FigureUtilities { > * @since 2.0 > */ > public static Color lighter(Color rgb) { >- int r = rgb.getRed(), g = rgb.getGreen(), b = rgb.getBlue(); >- >- return new Color(null, Math.max(2, >- Math.min((int) (r / RGB_VALUE_MULTIPLIER), 255)), Math.max(2, >- Math.min((int) (g / RGB_VALUE_MULTIPLIER), 255)), Math.max(2, >- Math.min((int) (b / RGB_VALUE_MULTIPLIER), 255))); >+ double hsl[] = rgbToHSL(original.getRGB()); >+ hsl[2] = Math.min(1.0, hsl[2] / VALUE_MULTIPLIER); >+ return new Color(null, hslToRGB(hsl)); > } > > /** >@@ -447,5 +444,104 @@ public class FigureUtilities { > } > return !figBounds.isEmpty(); > } >+ >+ >+ /** >+ * Transforms the RGB color into the according HSL color space. Algorithm >+ * based on the Book: Computer Graphics: Principles and Practice in C (2nd >+ * Edition) (Systems Programming Series) (Hardcover) by James D. Foley >+ * (Author), Andries van Dam (Author), Steven K. Feiner (Author), John F. >+ * Hughes (Author) >+ * >+ * @param rgb the rgb values of the color to convert >+ * @return the color in hsl space h: 0..360, s: 0..1, l: 0..1 >+ */ >+ public static double[] rgbToHSL(RGB rgb) { >+ >+ double r = rgb.red / 255.f; >+ double g = rgb.green / 255.f; >+ double b = rgb.blue / 255.f; >+ double max = Math.max(Math.max(r, g), b); >+ double min = Math.min(Math.min(r, g), b); >+ >+ double hsl[] = new double[] { 0, 0, (max + min) / 2 }; >+ >+ if (max != min) { >+ // we are not just grey >+ double delta = max - min; >+ >+ if (hsl[2] <= 0.5) { >+ hsl[1] = (delta / (max + min)); >+ } else { >+ hsl[1] = (delta / (2.0 - (max + min))); >+ } >+ >+ if (r == max) { >+ hsl[0] = (g - b) / delta; >+ } else if (g == max) { >+ hsl[0] = 2.0 + (b - r) / delta; >+ } else if (b == max) { >+ hsl[0] = 4.0 + (r - g) / delta; >+ } >+ hsl[0] *= 60.0; >+ >+ if (hsl[0] < 0.0) { >+ hsl[0] += 360.0; >+ } >+ } >+ return hsl; >+ } >+ >+ /** >+ * Transforms the HSL color into the according RGB color space. Algorithm >+ * based on the Book: Computer Graphics: Principles and Practice in C (2nd >+ * Edition) (Systems Programming Series) (Hardcover) by James D. Foley >+ * (Author), Andries van Dam (Author), Steven K. Feiner (Author), John F. >+ * Hughes (Author) >+ * >+ * @param hsl the color in hsl space h: 0..360, s: 0..1, l: 0..1 >+ * @return the color in rgb space >+ */ >+ public static RGB hslToRGB(double[] hsl) { >+ RGB retVal = new RGB(0, 0, 0); >+ >+ if (hsl[1] == 0.0) { >+ if (hsl[0] == 0.0) { >+ retVal.red = retVal.green = retVal.blue = (int) (hsl[2] * 255.0); >+ } else { >+ // in the achromatic (grey) case h must not have a value >+ SWT.error(SWT.ERROR_INVALID_ARGUMENT); >+ } >+ } else { >+ double m2 = ((hsl[2] <= 0.5) ? hsl[2] * (1.0 + hsl[1]) : hsl[2] >+ + hsl[1] - (hsl[2] * hsl[1])); >+ double m1 = 2.0 * hsl[2] - m2; >+ >+ retVal.red = hslValue(m1, m2, hsl[0] + 120.0); >+ retVal.green = hslValue(m1, m2, hsl[0]); >+ retVal.blue = hslValue(m1, m2, hsl[0] - 120.0); >+ } >+ return retVal; >+ } >+ >+ private static int hslValue(double m1, double m2, double hue) { >+ double retVal = m1; >+ >+ if (hue > 360.0) { >+ hue -= 360.0; >+ } else if (hue < 0.0) { >+ hue += 360.0; >+ } >+ >+ if (hue < 60.0) { >+ retVal = m1 + (m2 - m1) * hue / 60.0; >+ } else if (hue < 180.0) { >+ retVal = m2; >+ } else if (hue < 240.0) { >+ retVal = m1 + (m2 - m1) * (240.0 - hue) / 60.0; >+ } >+ >+ return (int) (255.0 * retVal); >+ } > > } >-- >1.7.10 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 380894
: 216739