Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2004

Tip: Looking for answers? Try searching our database.

Change Brightness via HSB

Thread view: 
Petra Neumann - 29 Jul 2004 09:54 GMT
Hi,

I would like to change the brightness of a Color object in Java. To do
so I change the Color to the HSB color space, increase the brightness
and convert it back to RGB. However, the output color is NOT brighter,
it seems rather strange.

I have written the following code to do the conversion:

/////////////////
Color c = color.get(); (conversion from a Color3f - Java3D color)
System.out.println(c);

float[] hsb = Color.RGBtoHSB(c.getRed(),c.getGreen(),c.getBlue(),null);
hsb[2]=0.8f;

System.out.println(hsb[0]+" "+hsb[1]+" "+hsb[2]);

Color rgb = Color.getHSBColor(hsb[0],hsb[1],hsb[2]);
System.out.println(rgb);
/////////////////

This is an example output:
-----------------------------
java.awt.Color[r=95,g=28,b=0]
0.04912281 1.0 0.8
java.awt.Color[r=204,g=60,b=0]
------------------------------

The strange thing is that the "b" value always remains zero, but
shouldn't be because the original color should mereley becomes
brighter with a color close to white.

I appreciate any suggestions to solve my problem.
Thank you,

Cheers,
Petra
Thomas Weidenfeller - 29 Jul 2004 11:50 GMT
> I would like to change the brightness of a Color object in Java. To do
> so I change the Color to the HSB color space, increase the brightness
> and convert it back to RGB. However, the output color is NOT brighter,
> it seems rather strange.

The output is correct. You are assuming properties of the transformation
and a meaning of brightness which are not there (brightness in HSB is
more like spectral power). The transformation is non-linear, and in your
case, due to the fact that you end up with a saturation of 1.0 (100%
saturation), and a hue close to 0 degree (which is red), you end up with
a very much saturated red and no blue at all. Reduce the saturation, and
you will start to get some blue.

If you need a brighter color, "simply" multiply the r, g, and b values
with the same factor. There are some special cases (e.g. if you do this
for black (0,0,0) you still end up with black). If you don't want to
take care of such things, consider using Color.brighter().

/Thomas
Petra Neumann - 29 Jul 2004 13:03 GMT
Thanks. I see the problem now. I was led to believe this was the way to
do it by the example of the PaintShopPro Color Chooser Dialog.
In this dialog there are three information fields about the current
color (one RGB, one  HSV (at least that's what I thought), and one HTML
color). I changed the "value or brightness" slider and the effect on the
current color was exactly what I wanted. The same color just a bit
brighter in the "white" direction. I wonder what the calculation for
changing the brightness of a color behind this field is. It would be
very helpful to know.

Petra

>> I would like to change the brightness of a Color object in Java. To do
>> so I change the Color to the HSB color space, increase the brightness
[quoted text clipped - 15 lines]
>
> /Thomas
Thomas Weidenfeller - 29 Jul 2004 14:15 GMT
> Thanks. I see the problem now. I was led to believe this was the way to
> do it by the example of the PaintShopPro Color Chooser Dialog.
> In this dialog there are three information fields about the current
> color (one RGB, one  HSV (at least that's what I thought), and one HTML
> color). I changed the "value or brightness" slider and the effect on the
> current color was exactly what I wanted.

It is, until you run into saturation. HSB is popular, because it is
similar to how humans perceive color. And a red will not become white
when it gets brighter, it will become a bright red :-)

I don't remember all the details, but if I am not mistaken you always
get a 100% saturation when converting from RGB to HSB if at least one of
the RGB components is zero. And a saturation of 100% in any conversion
from HSB to RGB will render one RGB component zero, independent of
brightness.

> It would be very helpful to know.

Observe the values. Maybe they manipulate the saturation, too. Or they
don't use HSB.

/Thomas


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.