LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2011, 05:56 PM   #1
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
lightweight C/C++ graphics library with hsl support


Hi. I'm trying to pick a simple, lightweight 2D graphics library for a small Linux project: just drawing points on the screen mostly. It doesn't need to be very fancy (preferably not, actually) but I really did want built in HSL support. (I.e., receives HSL color values instead of just RGB.) I've found some huge libraries that have this capability but nothing small. Would anyone have a recommendation?
 
Old 09-20-2011, 06:29 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Personally, I'd just use whatever library you like.

Who knows: the library you choose might even have an HSL => RGB conversion function.

Otherwise, it's easy enough to write your own:

Code:
http://130.113.54.154/~monger/hsl-rgb.html

Originally from the book Fundamentals of Interactive Computer Graphics by Foley and van Dam (c 1982, Addison-Wesley)

RGB - HSL

   1. Convert the RBG values to the range 0-1
      Example: from the video colors page, colorbar red has R=83%, B=7%, G=7%, or in this scale, R=.83, B=.07, G=.07

   2. Find min and max values of R, B, G
      In the example, maxcolor = .83, mincolor=.07

   3. L = (maxcolor + mincolor)/2
      For the example, L = (.83+.07)/2 = .45

   4. If the max and min colors are the same (ie the color is some kind of grey), S is defined to be 0, and H is undefined but in programs usually written as 0

   5. Otherwise, test L.
      If L < 0.5, S=(maxcolor-mincolor)/(maxcolor+mincolor)
      If L >=0.5, S=(maxcolor-mincolor)/(2.0-maxcolor-mincolor)
      For the example, L=0.45 so S=(.83-.07)/(.83+.07) = .84

   6. If R=maxcolor, H = (G-B)/(maxcolor-mincolor)
      If G=maxcolor, H = 2.0 + (B-R)/(maxcolor-mincolor)
      If B=maxcolor, H = 4.0 + (R-G)/(maxcolor-mincolor)
      For the example, R=maxcolor so H = (.07-.07)/(.83-.07) = 0

   7. To use the scaling shown in the video color page, convert L and S back to percentages, and H into an angle in degrees (ie scale it from 0-360). From the computation in step 6, H will range from 0-6. RGB space is a cube, and HSL space is a double hexacone, where L is the principal diagonal of the RGB cube. Thus corners of the RGB cube; red, yellow, green, cyan, blue, and magenta, become the vertices of the HSL hexagon. Then the value 0-6 for H tells you which section of the hexgon you are in. H is most commonly given as in degrees, so to convert
      H = H*60.0
      If H is negative, add 360 to complete the conversion.
Here's the table:

http://en.wikipedia.org/wiki/HSL_color_space

Last edited by paulsm4; 09-20-2011 at 06:32 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lightweight distro with GUI, support of East Asian languages. sc_ijin Linux - Distributions 5 07-27-2010 03:29 AM
Lightweight GUI/Library for X11 (ideally a C++ interface) cpetzol2 Programming 5 05-02-2008 06:34 PM
Looking for a lightweight distro with good GUI and hardware support senzmail Linux - Newbie 5 01-23-2008 09:59 PM
graphics library... pankaj_iiitian89 Linux - Newbie 2 09-05-2005 08:22 PM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration