00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
#include <volume_io/internal_volume_io.h>
00016
#include <bicpl/objects.h>
00017
00018
#ifndef lint
00019
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Objects/rgb_lookup.c,v 1.12 2000/02/06 15:30:46 stever Exp $";
00020
#endif
00021
00022 #define NUM_PIXELS8 256
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 public Colour *
get_8bit_rgb_pixel_lookup(
void )
00038 {
00039
static BOOLEAN
initialized =
FALSE;
00040
static Colour lookup_table[
NUM_PIXELS8];
00041
int r, g, b, ind, r255, g255, b255;
00042
00043
if( !
initialized )
00044 {
00045
initialized =
TRUE;
00046
00047 for_less( r, 0, 8 )
00048 {
00049 for_less( g, 0, 8 )
00050 {
00051 for_less( b, 0, 4 )
00052 {
00053 ind = ( r | (g << 3) | (b << 6) );
00054
00055 r255 = (
int) (((Real) r + 0.5) * 256.0 / 8.0);
00056 g255 = (
int) (((Real) g + 0.5) * 256.0 / 8.0);
00057 b255 = (
int) (((Real) b + 0.5) * 256.0 / 4.0);
00058
00059 lookup_table[ind] = make_Colour( r255, g255, b255 );
00060 }
00061 }
00062 }
00063 }
00064
00065
return( lookup_table );
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 public int convert_rgb_pixel_to_8bit_lookup(
00082 Colour colour )
00083 {
00084
int ind, r, g, b, r_ind, g_ind, b_ind;
00085
00086 r = get_Colour_r( colour );
00087 g = get_Colour_g( colour );
00088 b = get_Colour_b( colour );
00089
00090 r_ind = 8 * r / 256;
00091 g_ind = 8 * g / 256;
00092 b_ind = 4 * b / 256;
00093 ind = r_ind | (g_ind << 3) | (b_ind << 6);
00094
00095
return( ind );
00096 }