comp.lang.ada
 help / color / mirror / Atom feed
* Color gradients lib
@ 2011-02-08 10:58 Alex R. Mosteo
  2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Alex R. Mosteo @ 2011-02-08 10:58 UTC (permalink / raw)


Hello,

I need to plot some data (2D maps) and I have everything in my drawing 
library except some readily usable gradients. I was wondering if some Ada 
library out there has this before making my custom one.

I would need one to represent bad/good ranges (e.g. the default gradient 
blue-cold to red-hot in matlab), and another to show a density of samples 
(perhaps simple shades of gray).

The second one is straightforward, but the first one seems like something 
pretty standard, so I wouldn't like to create one that is similar but not 
the same.

(e.g. the first example in 
http://www.mathworks.com/help/techdoc/visualize/f0-18164.html#f0-5919 )

Thanks for any suggestions.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 10:58 Color gradients lib Alex R. Mosteo
@ 2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
  2011-02-08 14:52   ` Alex R. Mosteo
  2011-02-08 18:00 ` Dmitry A. Kazakov
  2011-02-08 20:26 ` Gautier write-only
  2 siblings, 1 reply; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 13:16 UTC (permalink / raw)


Hi Alex,

Any graphic capabilities requires an output “device”, either memory  
bitmap, screen, image file, and the latter may be bitmap, PNG, JPEG. I  
feel you miss to provide a context here. Are you seeking for a library to  
generate shapes filled with gradient to which kind of output ? This is  
important to know.

Do not know anything about the context, however an idea : is SVG a valid  
option for you ? For graphs, pies, and other formal representations and  
plotted images, SVG is rather good (if no dynamic features is required),  
and it has gradient capabilities:
http://www.w3.org/TR/SVG/pservers.html

Otherwise, please tell more about the context and any relevant technical  
details.


Le Tue, 08 Feb 2011 11:58:00 +0100, Alex R. Mosteo  
<alejandro@mosteo.invalid> a écrit:

> Hello,
>
> I need to plot some data (2D maps) and I have everything in my drawing
> library except some readily usable gradients. I was wondering if some Ada
> library out there has this before making my custom one.
>
> I would need one to represent bad/good ranges (e.g. the default gradient
> blue-cold to red-hot in matlab), and another to show a density of samples
> (perhaps simple shades of gray).
>
> The second one is straightforward, but the first one seems like something
> pretty standard, so I wouldn't like to create one that is similar but not
> the same.
>
> (e.g. the first example in
> http://www.mathworks.com/help/techdoc/visualize/f0-18164.html#f0-5919 )
>
> Thanks for any suggestions.


-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
@ 2011-02-08 14:52   ` Alex R. Mosteo
  2011-02-08 15:18     ` Yannick Duchêne (Hibou57)
  0 siblings, 1 reply; 13+ messages in thread
From: Alex R. Mosteo @ 2011-02-08 14:52 UTC (permalink / raw)


Yannick Duchêne (Hibou57) wrote:

> Hi Alex,
> 
> Any graphic capabilities requires an output “device”, either memory
> bitmap, screen, image file, and the latter may be bitmap, PNG, JPEG. I
> feel you miss to provide a context here. Are you seeking for a library to
> generate shapes filled with gradient to which kind of output ? This is
> important to know.

Yes, I was a bit scarce on details.

For the output device I have an abstract layer that can output to GTK or a 
simulator or any other backend I could need, so that's not the issue.

I want a function mapping from some arbitrary values (my data, with its 
minimum and maximum values) into the RGB triplets giving that cold-hot 
representation. Let's say:

type My_Data is float range 0.0 .. 100.0;

type RGB_Component is float range 0.0 .. 1.0;
type RGB_Color is record R, G, B : RGB_Component; end record;

function Gradient (Value : My_Data) return RGB_Color;

And that's it. Hope this helps, and thanks for the interest.

Alex.

> Do not know anything about the context, however an idea : is SVG a valid
> option for you ? For graphs, pies, and other formal representations and
> plotted images, SVG is rather good (if no dynamic features is required),
> and it has gradient capabilities:
> http://www.w3.org/TR/SVG/pservers.html
> 
> Otherwise, please tell more about the context and any relevant technical
> details.
> 
> 
> Le Tue, 08 Feb 2011 11:58:00 +0100, Alex R. Mosteo
> <alejandro@mosteo.invalid> a écrit:
> 
>> Hello,
>>
>> I need to plot some data (2D maps) and I have everything in my drawing
>> library except some readily usable gradients. I was wondering if some Ada
>> library out there has this before making my custom one.
>>
>> I would need one to represent bad/good ranges (e.g. the default gradient
>> blue-cold to red-hot in matlab), and another to show a density of samples
>> (perhaps simple shades of gray).
>>
>> The second one is straightforward, but the first one seems like something
>> pretty standard, so I wouldn't like to create one that is similar but not
>> the same.
>>
>> (e.g. the first example in
>> http://www.mathworks.com/help/techdoc/visualize/f0-18164.html#f0-5919 )
>>
>> Thanks for any suggestions.
> 
> 




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 14:52   ` Alex R. Mosteo
@ 2011-02-08 15:18     ` Yannick Duchêne (Hibou57)
  2011-02-08 15:21       ` Yannick Duchêne (Hibou57)
  0 siblings, 1 reply; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 15:18 UTC (permalink / raw)


Le Tue, 08 Feb 2011 15:52:24 +0100, Alex R. Mosteo  
<alejandro@mosteo.invalid> a écrit:
> I want a function mapping from some arbitrary values (my data, with its
> minimum and maximum values) into the RGB triplets giving that cold-hot
> representation. Let's say:
>
> type My_Data is float range 0.0 .. 100.0;
>
> type RGB_Component is float range 0.0 .. 1.0;
> type RGB_Color is record R, G, B : RGB_Component; end record;
>
> function Gradient (Value : My_Data) return RGB_Color;
>
> And that's it. Hope this helps, and thanks for the interest.
>
> Alex.
That's easy enough (or else I'm afraid I've missed something), you don't  
even need a library for that. You just need to compute a function for each  
color channels, y = f(x), where x ranges from 0.0 to 100.0 and where y is  
in turn, amount of red, green and blue. Then you use the rounding method  
of your choice to map it to an integer value which will be the value for  
the associated component of the RGB triplet. The most straightforward  
function would be linear: y = y1 + (x * ((y2 - y1) / 100.0)), where y1 is  
the value for the color channel for the cold color and y2 the value for  
the color channel for the warm color. So if your cold color is (1, 0, 0)  
and your warm color is (0, 0, 1), then for x = 0.0, you will get (1,0,0),  
for x = 100.0 you will get (0,0,1) and for an intermediate value like x =  
50.0 you will get (0.5, 0, 0.5). You may even pre-compute this function at  
the application startup, if this does not change during program execution  
(you may do so, because in the end you will have integer values anyway).  
And voilà, there is no magic :)

Or do I missed something ?

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 15:18     ` Yannick Duchêne (Hibou57)
@ 2011-02-08 15:21       ` Yannick Duchêne (Hibou57)
  2011-02-08 16:27         ` Alex R. Mosteo
  0 siblings, 1 reply; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 15:21 UTC (permalink / raw)


Le Tue, 08 Feb 2011 16:18:06 +0100, Yannick Duchêne (Hibou57)  
<yannick_duchene@yahoo.fr> a écrit:
> cold color is (1, 0, 0) and your warm color is (0, 0, 1)
Oops. Actually, my idea to have the cold color being red and the warm  
color being blue, was not a good idea (cheese). Just imagine the opposite  
please.


-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 15:21       ` Yannick Duchêne (Hibou57)
@ 2011-02-08 16:27         ` Alex R. Mosteo
  2011-02-08 19:30           ` Yannick Duchêne (Hibou57)
  0 siblings, 1 reply; 13+ messages in thread
From: Alex R. Mosteo @ 2011-02-08 16:27 UTC (permalink / raw)


Yannick Duchêne (Hibou57) wrote:

> Le Tue, 08 Feb 2011 16:18:06 +0100, Yannick Duchêne (Hibou57)
> <yannick_duchene@yahoo.fr> a écrit:
>> cold color is (1, 0, 0) and your warm color is (0, 0, 1)
> Oops. Actually, my idea to have the cold color being red and the warm
> color being blue, was not a good idea (cheese). Just imagine the opposite
> please.

Thanks, but I'm not actually worried about the actual computation -- I only 
wonder if I can get that stock palette from matlab from somewhere, just so 
my pics are standard too. In that regard I can see how my giving the spec 
has confused you.

I mean, I'm sure that matplotlib for python has readily usable gradients 
really nice looking. I wondered if I could get the same for Ada or if I 
should roll out mine.

Actually I think the quickest way is to just print out the matlab one. 
Although it would be nice to have a variety of them for different purposes.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 10:58 Color gradients lib Alex R. Mosteo
  2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
@ 2011-02-08 18:00 ` Dmitry A. Kazakov
  2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
  2011-02-09  8:53   ` Alex R. Mosteo
  2011-02-08 20:26 ` Gautier write-only
  2 siblings, 2 replies; 13+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-08 18:00 UTC (permalink / raw)


On Tue, 08 Feb 2011 11:58 +0100, Alex R. Mosteo wrote:

> I need to plot some data (2D maps) and I have everything in my drawing 
> library except some readily usable gradients. I was wondering if some Ada 
> library out there has this before making my custom one.

OK, that is an ill-defined problem because the visual appearance of a
gradient (linear function of position) depends on the color space you are
using. The RGB color space is quite unnatural to human eye. L*a*b is much
better,  but computationally problematic. HLS is a very coarse
approximation of L*a*b. GtkAda contributions has an implementation of
improved HLS model.

http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#8

For building a gradient I would convert the end points to IHLS and then use
linear functions for hue, luminance and saturation between the points. The
obtained IHLS colors are then converted back to RGB.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 18:00 ` Dmitry A. Kazakov
@ 2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
  2011-02-08 19:36     ` Yannick Duchêne (Hibou57)
  2011-02-08 19:54     ` Dmitry A. Kazakov
  2011-02-09  8:53   ` Alex R. Mosteo
  1 sibling, 2 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 19:27 UTC (permalink / raw)


Le Tue, 08 Feb 2011 19:00:08 +0100, Dmitry A. Kazakov  
<mailbox@dmitry-kazakov.de> a écrit:
> The RGB color space is quite unnatural to human eye.
So much true.

> http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#8
Thanks for the link, hope I will find some formulas there (formulas would  
be more interesting than a library). Also thanks for “L*a*b” I was not  
knowing, until now I only knew HLS to create color palettes.

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 16:27         ` Alex R. Mosteo
@ 2011-02-08 19:30           ` Yannick Duchêne (Hibou57)
  0 siblings, 0 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 19:30 UTC (permalink / raw)


Le Tue, 08 Feb 2011 17:27:00 +0100, Alex R. Mosteo  
<alejandro@mosteo.invalid> a écrit:
> In that regard I can see how my giving the spec has confused you.
Yes, this was not clear. But don't bother. May be Dmitry's hint about  
improved HLS over RGB may help you to get something as aesthetic as you  
were expected.

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
@ 2011-02-08 19:36     ` Yannick Duchêne (Hibou57)
  2011-02-08 19:54     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-02-08 19:36 UTC (permalink / raw)


Le Tue, 08 Feb 2011 20:27:41 +0100, Yannick Duchêne (Hibou57)  
<yannick_duchene@yahoo.fr> a écrit:
> Thanks for the link, hope I will find some formulas there (formulas  
> would be more interesting than a library).
Ah, one  part is there (luminance only): 0.2126·R + 0.7152· G + 0.0722· B.  
Seems plausible, at least the weightings are close to the ones I used in  
the past for color to gray-scale transform (every ones, note how we have  
extra sensibility to green and how much we are blind to blue).


-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.

“I am fluent in ASCII” [Warren 2010]



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
  2011-02-08 19:36     ` Yannick Duchêne (Hibou57)
@ 2011-02-08 19:54     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-08 19:54 UTC (permalink / raw)


On Tue, 08 Feb 2011 20:27:41 +0100, Yannick Duch�ne (Hibou57) wrote:

> Thanks for the link, hope I will find some formulas there (formulas would  
> be more interesting than a library).

The link to the original paper:

http://cmm.ensmp.fr/~serra/notes_internes_pdf/NI-230.pdf

Formulae are a bit complicated, as well as the implementation of. Note that
the tick is to ensure RGB (IHLS (x)) = x for all color points.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 10:58 Color gradients lib Alex R. Mosteo
  2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
  2011-02-08 18:00 ` Dmitry A. Kazakov
@ 2011-02-08 20:26 ` Gautier write-only
  2 siblings, 0 replies; 13+ messages in thread
From: Gautier write-only @ 2011-02-08 20:26 UTC (permalink / raw)


> Thanks for any suggestions.

Funny, I've looked for the same thing one month ago and was about to
program it. From what I've found on the Web, these nice color scales
can be obtained with functions that are piecewise constant, piecewise
linear in each fundamental color. More specifically you can imagine a
cube where x=red, y=green, z=blue and you go along the edges from
(0,0,1) to (1,0,0).
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: follow the above link for a working e-mail address



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Color gradients lib
  2011-02-08 18:00 ` Dmitry A. Kazakov
  2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
@ 2011-02-09  8:53   ` Alex R. Mosteo
  1 sibling, 0 replies; 13+ messages in thread
From: Alex R. Mosteo @ 2011-02-09  8:53 UTC (permalink / raw)


Dmitry A. Kazakov wrote:

> On Tue, 08 Feb 2011 11:58 +0100, Alex R. Mosteo wrote:
> 
>> I need to plot some data (2D maps) and I have everything in my drawing
>> library except some readily usable gradients. I was wondering if some Ada
>> library out there has this before making my custom one.
> 
> OK, that is an ill-defined problem because the visual appearance of a
> gradient (linear function of position) depends on the color space you are
> using. The RGB color space is quite unnatural to human eye. L*a*b is much
> better,  but computationally problematic. HLS is a very coarse
> approximation of L*a*b. GtkAda contributions has an implementation of
> improved HLS model.
> 
> http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#8
> 
> For building a gradient I would convert the end points to IHLS and then
> use linear functions for hue, luminance and saturation between the points.
> The obtained IHLS colors are then converted back to RGB.

Thanks everybody for the discussion. I'm going to try this approach.




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-02-09  8:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-08 10:58 Color gradients lib Alex R. Mosteo
2011-02-08 13:16 ` Yannick Duchêne (Hibou57)
2011-02-08 14:52   ` Alex R. Mosteo
2011-02-08 15:18     ` Yannick Duchêne (Hibou57)
2011-02-08 15:21       ` Yannick Duchêne (Hibou57)
2011-02-08 16:27         ` Alex R. Mosteo
2011-02-08 19:30           ` Yannick Duchêne (Hibou57)
2011-02-08 18:00 ` Dmitry A. Kazakov
2011-02-08 19:27   ` Yannick Duchêne (Hibou57)
2011-02-08 19:36     ` Yannick Duchêne (Hibou57)
2011-02-08 19:54     ` Dmitry A. Kazakov
2011-02-09  8:53   ` Alex R. Mosteo
2011-02-08 20:26 ` Gautier write-only

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox