Programming Idiom 
Author Message
 Programming Idiom

Hi.

I am working on a set of colour classes (to teach myself some more Dylan
at the same time as some Foley & van Dam). At the moment I am using
<single-float>s to represent colour component values.
I would like to gracefully handle the cases where an attempt is made to
set a component to an invalid value, usually  < 0.0 or > 1.0.
At the moment I just clamp the values in the constructor, which doesn't
give any feedback.
Is it better to have the colour components as limited <single-float>s,
and to make the user responsible for handling any resultant errors, or
to come up with an exception scheme for colour value
overflow/underflows?
Any advice gratefully received. :-)

- Rob.



Sat, 02 Feb 2002 03:00:00 GMT  
 Programming Idiom

Quote:

> Hi.

> I am working on a set of colour classes (to teach myself some more Dylan
> at the same time as some Foley & van Dam). At the moment I am using
> <single-float>s to represent colour component values.
> I would like to gracefully handle the cases where an attempt is made to
> set a component to an invalid value, usually  < 0.0 or > 1.0.
> At the moment I just clamp the values in the constructor, which doesn't
> give any feedback.
> Is it better to have the colour components as limited <single-float>s,
> and to make the user responsible for handling any resultant errors, or
> to come up with an exception scheme for colour value
> overflow/underflows?
> Any advice gratefully received. :-)

There is nothing especially illegal about having colour components outside
the 0 .. 1 range.  All it means is that the colour in question is outside
the gamut of your particular system.  In particular, in an RGB system
*all* pure monochromatic colours have either a negative R or a negative B
component.  (Except for those colours exactly equal to your R, G and B
primaries).

Probably the best thing to do is to take the entire RGB value as a vector
and project towards the White Point until all components are within
range.  That way you'll keep the right hue, while losing saturation and/or
brightness.

-- Bruce



Sun, 03 Feb 2002 03:00:00 GMT  
 Programming Idiom

Quote:

> The CIE 1931 Chromacity diagrams that you see everywhere (including in the
> Photoshop manual) are really wierd, and *no one* ever explains where they
> come from.
>snip!<

Thanks for all the info. I am happy (for now) to work with gross
over-simplifications of systems ( like the basic min( c, m, y ) RGB to CMYK
conversion ), I still wonder about signalling to the calling code that it has
tried to make an invalid (or out of gamut) object and that its efforts have been
intercepted and rendered harmless. Anything that leads to loss of, or invalid,
information should not go through silently.

- Rob



Sun, 03 Feb 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Smalltalk programming idioms and styles

2. Smalltalk programming idioms and styles

3. A few idioms and programs for new J'ers

4. Pythonic idioms / Programming Puzzle

5. Are there any J idiom lists?

6. Finn Idiom problems and Re: {rho} problem

7. Want convolution idioms

8. Adrian Smith's spanned cells idiom challenge

9. seek idioms for Emacs online J doc

10. Translating Idioms

11. Translating Idioms

12. Idioms

 

 
Powered by phpBB® Forum Software