Original Post
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:
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?
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?