By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

Convert RGB as a float into unsigned chars

P: n/a
I need to convert a colour defined as floats of R,G and B channels into
the same R,G and B channels but defined by unsigned char's. Any help?

Adam
Oct 24 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Adam Teasdale Hartshorne wrote:
I need to convert a colour defined as floats of R,G and B channels into
the same R,G and B channels but defined by unsigned char's. Any help?

Adam


Presumably the values are floats because they're in the range [0..1] or
something like that. If so, just scale it up:

#include <limits>

// ...
typedef unsigned char uchar;
const uchar r = uchar( std::numeric_limits<uchar>::max * r_float );
// etc.

Cheers! --M

Oct 24 '05 #2

P: n/a

mlimber wrote:
Adam Teasdale Hartshorne wrote:
I need to convert a colour defined as floats of R,G and B channels into
the same R,G and B channels but defined by unsigned char's. Any help?

Adam


Presumably the values are floats because they're in the range [0..1] or
something like that. If so, just scale it up:

#include <limits>

// ...
typedef unsigned char uchar;
const uchar r = uchar( std::numeric_limits<uchar>::max * r_float );
// etc.

Cheers! --M


Lastly, I would just verify that the maximum and minimum values (white
and black) in the floating point representation scale to to
{255,255,255} and {0,0,0} exactly.

Greg

Oct 25 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.