Scopira  20080306
color.h
1 
2 /*
3  * Copyright (c) 2002 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED__SCOPIRA_BASEKIT_COLOR_H__
15 #define __INCLUDED__SCOPIRA_BASEKIT_COLOR_H__
16 
17 #include <scopira/basekit/narray.h>
18 #include <scopira/tool/export.h>
19 
20 namespace scopira
21 {
22  namespace basekit
23  {
25  enum {
26  white_c = 0xFFFFFF,
27  red_c = 0xFF0000,
28  green_c = 0xFF00,
29  blue_c = 0xFF,
30  yellow_c = 0xFFFF00,
31  cyan_c = 0xFFFF,
32  purple_c = 0xFF00FF,
33  black_c = 0,
34  };
36  inline int color_rgb(int r, int g, int b)
37  { return r<<16 | g<<8 | b; }
39  inline int color_argb(int a, int r, int g, int b)
40  { return a<<24 | r<<16 | g<<8 | b; }
42  inline int color_gray(int v)
43  { return v<<16 | v<<8 | v; }
45  inline int color_alpha(int packedcol) { return (packedcol&0xFF0000)>>24; }
47  inline int color_red(int packedcol) { return (packedcol&0xFF0000)>>16; }
49  inline int color_green(int packedcol) { return (packedcol&0x00FF00)>>8; }
51  inline int color_blue(int packedcol) { return (packedcol&0x0000FF); }
52 
54  inline int set_alpha(int packedcol, int a) { return (packedcol&0x00FFFFFF) | (a<<24); }
56  inline int set_red(int packedcol, int r) { return (packedcol&0xFF00FFFF) | (r<<16); }
58  inline int set_green(int packedcol, int g) { return (packedcol&0xFFFF00FF) | (g<<8); }
60  inline int set_blue(int packedcol, int b) { return (packedcol&0xFFFFFF00) | b; }
61 
63  SCOPIRA_EXPORT int clamp_color(int c);
65  inline double color_to_double(int c) {
66  return static_cast<double>(c)/255;
67  }
69  SCOPIRA_EXPORT int color_to_gray(int c);
70 
72  SCOPIRA_EXPORT int color_scale(int factor, int packedcol);
73 
75  SCOPIRA_EXPORT int layer_color(int basecolor, int layercolor);
76 
78  SCOPIRA_EXPORT void fill_color_pick(nslice<int> target, int offset = 0);
80  SCOPIRA_EXPORT void fill_color_gradient(nslice<int> target, int startpcol, int endpcol);
81 
83  SCOPIRA_EXPORT void make_gray_palette(const nslice<int> &pal);
85  SCOPIRA_EXPORT void make_red_palette(const nslice<int> &pal);
87  SCOPIRA_EXPORT void make_green_palette(const nslice<int> &pal);
89  SCOPIRA_EXPORT void make_blue_palette(const nslice<int> &pal);
91  SCOPIRA_EXPORT void make_pick_palette(const nslice<int> &pal);
93  SCOPIRA_EXPORT void make_heat_palette(const nslice<int> &pal);
95  SCOPIRA_EXPORT void make_rainbow_palette(const nslice<int> &pal);
97  SCOPIRA_EXPORT void make_bluered_palette(const nslice<int> &pal);
99  SCOPIRA_EXPORT void make_bone_palette(const nslice<int> &pal);
101  SCOPIRA_EXPORT void make_copper_palette(const nslice<int> &pal);
103  SCOPIRA_EXPORT void make_spectra_palette(const nslice<int> &pal);
105  SCOPIRA_EXPORT void make_opus_palette(const nslice<int> &pal); // yes, this is in basekit, even though its opusish
106  }
107 }
108 
109 #endif
110 
void make_copper_palette(const nslice< int > &pal)
makes a palette
void make_spectra_palette(const nslice< int > &pal)
makes a palette
int color_argb(int a, int r, int g, int b)
converts a ARGB triplet to packed color
Definition: color.h:39
Definition: archiveflow.h:20
int set_red(int packedcol, int r)
sets
Definition: color.h:56
int color_rgb(int r, int g, int b)
converts a RGB triplet to a packed color
Definition: color.h:36
int set_blue(int packedcol, int b)
sets
Definition: color.h:60
void make_rainbow_palette(const nslice< int > &pal)
makes a palette
int clamp_color(int c)
clamps this number between 0 and 255
int color_gray(int v)
expand a single 0..255 to a packed color
Definition: color.h:42
void fill_color_gradient(nslice< int > target, int startpcol, int endpcol)
set a gradient (alpha aware)
void make_green_palette(const nslice< int > &pal)
makes a palette
void make_heat_palette(const nslice< int > &pal)
makes a palette
Definition: narray.h:98
void make_opus_palette(const nslice< int > &pal)
makes a palette
int color_blue(int packedcol)
extracts blue
Definition: color.h:51
void fill_color_pick(nslice< int > target, int offset=0)
set colors, suitable for picking
void make_bone_palette(const nslice< int > &pal)
makes a palette
int color_to_gray(int c)
convert colour into a 0..255 (mean)
int set_alpha(int packedcol, int a)
sets
Definition: color.h:54
int color_alpha(int packedcol)
extracts alpha
Definition: color.h:45
void make_blue_palette(const nslice< int > &pal)
makes a palette
void make_gray_palette(const nslice< int > &pal)
makes a palette
int color_scale(int factor, int packedcol)
sclaes a color. factor is 1000 for no change (alpha aware)
int color_green(int packedcol)
extracts gree
Definition: color.h:49
void make_pick_palette(const nslice< int > &pal)
makes a palette
void make_red_palette(const nslice< int > &pal)
makes a palette
void make_bluered_palette(const nslice< int > &pal)
makes a palette
int color_red(int packedcol)
extracts red
Definition: color.h:47
double color_to_double(int c)
convert a colour to doulbe (0..1)... basically, c/255
Definition: color.h:65
int layer_color(int basecolor, int layercolor)
layers a colour (alpha aware)
int set_green(int packedcol, int g)
sets
Definition: color.h:58