Panda3D
 All Classes Functions Variables Enumerations
colorSpace.cxx
1 // Filename: colorSpace.cxx
2 // Created by: rdb (02Jun14)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "colorSpace.h"
16 #include "config_util.h"
17 #include "configVariableEnum.h"
18 #include "string_utils.h"
19 
20 #include "dconfig.h"
21 #include "pnotify.h"
22 
23 #include <ctype.h>
24 
25 ColorSpace
26 parse_color_space_string(const string &str) {
27  if (cmp_nocase_uh(str, "linear") == 0 ||
28  cmp_nocase_uh(str, "linear-rgb") == 0 ||
29  cmp_nocase_uh(str, "lrgb") == 0) {
30  return CS_linear;
31 
32  } else if (cmp_nocase_uh(str, "srgb") == 0) {
33  return CS_sRGB;
34 
35  } else if (cmp_nocase_uh(str, "scrgb") == 0) {
36  return CS_scRGB;
37 
38  } else if (cmp_nocase_uh(str, "unspecified") == 0) {
39  return CS_unspecified;
40 
41  } else if (cmp_nocase_uh(str, "non-color") == 0) {
42  // In case we want to add this as an enum value in the future.
43  return CS_linear;
44  }
45 
46  util_cat->error()
47  << "Invalid color_space string: " << str << "\n";
48  return CS_linear;
49 }
50 
51 string
52 format_color_space(ColorSpace cs) {
53  ostringstream strm;
54  strm << cs;
55  return strm.str();
56 }
57 
58 ostream &
59 operator << (ostream &out, ColorSpace cs) {
60  switch (cs) {
61  case CS_linear:
62  return out << "linear";
63 
64  case CS_sRGB:
65  return out << "sRGB";
66 
67  case CS_scRGB:
68  return out << "scRGB";
69 
70  case CS_unspecified:
71  return out << "unspecified";
72  }
73 
74  util_cat->error()
75  << "Invalid color_space value: " << (int)cs << "\n";
76  nassertr(false, out);
77  return out;
78 }
79 
80 istream &
81 operator >> (istream &in, ColorSpace &cs) {
82  string word;
83  in >> word;
84  cs = parse_color_space_string(word);
85  return in;
86 }