Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

rgb_lookup.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- 00002 @COPYRIGHT : 00003 Copyright 1993,1994,1995 David MacDonald, 00004 McConnell Brain Imaging Centre, 00005 Montreal Neurological Institute, McGill University. 00006 Permission to use, copy, modify, and distribute this 00007 software and its documentation for any purpose and without 00008 fee is hereby granted, provided that the above copyright 00009 notice appear in all copies. The author and McGill University 00010 make no representations about the suitability of this 00011 software for any purpose. It is provided "as is" without 00012 express or implied warranty. 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 /* ----------------------------- MNI Header ----------------------------------- 00025 @NAME : get_8bit_rgb_pixel_lookup 00026 @INPUT : 00027 @OUTPUT : 00028 @RETURNS : colour table 00029 @DESCRIPTION: Returns the 8 bit (3-3-2 bit) RGB colour table. 00030 @METHOD : 00031 @GLOBALS : 00032 @CALLS : 00033 @CREATED : 1993 David MacDonald 00034 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00069 @NAME : convert_rgb_pixel_to_8bit_lookup 00070 @INPUT : colour 00071 @OUTPUT : 00072 @RETURNS : index 00073 @DESCRIPTION: Converts an RGB pixel to an 8 bit index. 00074 @METHOD : 00075 @GLOBALS : 00076 @CALLS : 00077 @CREATED : 1993 David MacDonald 00078 @MODIFIED : 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 }

Generated on Wed Jul 28 09:10:58 2004 for BICPL by doxygen 1.3.7