Jump to content
  • Advertisement
Sign in to follow this  

Transform texture color range for television

This topic is 2839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all.

I've been using the following code from SOIL to preprocess texture color range from 0-255 values per channel to 16-235 - suitable for television. This is a simple linear conversion, as shown in the lookup table:

#define COLOR_R 0
#define COLOR_G 1
#define COLOR_B 2
#define COLOR_A 3
#define CHANNELS 4

/* Convert the RGB pixels in image to a
range suitable for television display */

extern void IMAGE_TV_Range( struct rgbaImage *const image ) {
const float scale_lo = 16.0f - 0.499f;
const float scale_hi = 235.0f - 0.499f;

* Lookup table for range conversion.

uint8_t lookup[ 256 ];
for ( int i = 0; i < 256; ++i ) {
lookup[ i ] = (uint8_t)( ( scale_hi - scale_lo ) * i / 255.0f + scale_lo );

* Convert all RGB pixel data from 0-255 to 16-235
* using the lookup table above.

const size_t components = image->width * image->height * CHANNELS;
for ( size_t i = 0; i < components; i+= CHANNELS ) {
image->data[ i + COLOR_R ] = lookup[ image->data[ i + COLOR_R ] ];
image->data[ i + COLOR_G ] = lookup[ image->data[ i + COLOR_G ] ];
image->data[ i + COLOR_B ] = lookup[ image->data[ i + COLOR_B ] ];
/* Skip alpha */

However, I recall reading an article some time ago that suggested that a non-linear conversion would give better color, and perhaps each channel should have its own distinct range due to color reproduction on the average television.

Do you know what I'm talking about? Should I just focus on gamma correction and not worry about this? Double plus karma for code examples in C! Any other thoughts or ideas on the subject?

Share this post

Link to post
Share on other sites
Hmm... why to clamp/limit color range?
(modern TV monitors are LCD and not analoque, end there is no forbidden colors!)

Just use gamma correction & linear color space.


Ps. Please don`t save preproced texture files to some weird color space,
do processing on file loading.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!