Scopira 20080306

color.h

00001 
00002 /*
00003  *  Copyright (c) 2002    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED__SCOPIRA_BASEKIT_COLOR_H__
00015 #define __INCLUDED__SCOPIRA_BASEKIT_COLOR_H__
00016 
00017 #include <scopira/basekit/narray.h>
00018 #include <scopira/tool/export.h>
00019 
00020 namespace scopira
00021 {
00022   namespace basekit
00023   {
00025     enum {
00026       white_c = 0xFFFFFF,
00027       red_c = 0xFF0000,
00028       green_c = 0xFF00,
00029       blue_c = 0xFF,
00030       yellow_c = 0xFFFF00,
00031       cyan_c = 0xFFFF,
00032       purple_c = 0xFF00FF,
00033       black_c = 0,
00034     };
00036     inline int color_rgb(int r, int g, int b)
00037       { return r<<16 | g<<8 | b; }
00039     inline int color_argb(int a, int r, int g, int b)
00040       { return a<<24 | r<<16 | g<<8 | b; }
00042     inline int color_gray(int v)
00043       { return v<<16 | v<<8 | v; }
00045     inline int color_alpha(int packedcol) { return (packedcol&0xFF0000)>>24; }
00047     inline int color_red(int packedcol) { return (packedcol&0xFF0000)>>16; }
00049     inline int color_green(int packedcol) { return (packedcol&0x00FF00)>>8; }
00051     inline int color_blue(int packedcol) { return (packedcol&0x0000FF); }
00052 
00054     inline int set_alpha(int packedcol, int a) { return (packedcol&0x00FFFFFF) | (a<<24); }
00056     inline int set_red(int packedcol, int r) { return (packedcol&0xFF00FFFF) | (r<<16); }
00058     inline int set_green(int packedcol, int g) { return (packedcol&0xFFFF00FF) | (g<<8); }
00060     inline int set_blue(int packedcol, int b) { return (packedcol&0xFFFFFF00) | b; }
00061 
00063     SCOPIRA_EXPORT int clamp_color(int c);
00065     inline double color_to_double(int c) {
00066       return static_cast<double>(c)/255;
00067     }
00069     SCOPIRA_EXPORT int color_to_gray(int c);
00070 
00072     SCOPIRA_EXPORT int color_scale(int factor, int packedcol);
00073 
00075     SCOPIRA_EXPORT int layer_color(int basecolor, int layercolor);
00076 
00078     SCOPIRA_EXPORT void fill_color_pick(nslice<int> target, int offset = 0);
00080     SCOPIRA_EXPORT void fill_color_gradient(nslice<int> target, int startpcol, int endpcol);
00081 
00083     SCOPIRA_EXPORT void make_gray_palette(const nslice<int> &pal);
00085     SCOPIRA_EXPORT void make_red_palette(const nslice<int> &pal);
00087     SCOPIRA_EXPORT void make_green_palette(const nslice<int> &pal);
00089     SCOPIRA_EXPORT void make_blue_palette(const nslice<int> &pal);
00091     SCOPIRA_EXPORT void make_pick_palette(const nslice<int> &pal);
00093     SCOPIRA_EXPORT void make_heat_palette(const nslice<int> &pal);
00095     SCOPIRA_EXPORT void make_rainbow_palette(const nslice<int> &pal);
00097     SCOPIRA_EXPORT void make_bluered_palette(const nslice<int> &pal);
00099     SCOPIRA_EXPORT void make_bone_palette(const nslice<int> &pal);
00101     SCOPIRA_EXPORT void make_copper_palette(const nslice<int> &pal);
00103     SCOPIRA_EXPORT void make_spectra_palette(const nslice<int> &pal);
00105     SCOPIRA_EXPORT void make_opus_palette(const nslice<int> &pal);   // yes, this is in basekit, even though its opusish
00106   }
00107 }
00108 
00109 #endif
00110