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