Vuo  2.3.2
VuoImageColorDepth.c
Go to the documentation of this file.
1 
10 #include <stdlib.h>
11 #include <string.h>
12 #include "type.h"
13 #include <OpenGL/CGLMacro.h>
14 
16 #ifdef VUO_COMPILER
18  "title" : "Image Color Depth",
19  "description" : "An image's color bit-depth",
20  "keywords" : [ ],
21  "version" : "1.0.0",
22  "dependencies" : [
23  "VuoList_VuoImageColorDepth",
24  "VuoText",
25  "VuoGlPool"
26  ]
27  });
28 #endif
30 
44 unsigned int VuoImageColorDepth_getGlInternalFormat(unsigned int baseFormat, VuoImageColorDepth imageColorDepth)
45 {
46  if (baseFormat == GL_RGB
47  || baseFormat == GL_BGR
48  || baseFormat == GL_YCBCR_422_APPLE)
49  {
50  if (imageColorDepth == VuoImageColorDepth_16)
51  return GL_RGB16F_ARB;
52  if (imageColorDepth == VuoImageColorDepth_32)
53  return GL_RGB32F_ARB;
54  return GL_RGB;
55  }
56  else if (baseFormat == GL_RGBA
57  || baseFormat == GL_BGRA)
58  {
59  if (imageColorDepth == VuoImageColorDepth_16)
60  return GL_RGBA16F_ARB;
61  if (imageColorDepth == VuoImageColorDepth_32)
62  return GL_RGBA32F_ARB;
63  return GL_RGBA;
64  }
65  else if (baseFormat == GL_LUMINANCE)
66  {
67  if (imageColorDepth == VuoImageColorDepth_16)
68  return GL_LUMINANCE16F_ARB;
69  if (imageColorDepth == VuoImageColorDepth_32)
70  return GL_LUMINANCE32F_ARB;
71  return GL_LUMINANCE8;
72  }
73  else if (baseFormat == GL_LUMINANCE_ALPHA)
74  {
75  if (imageColorDepth == VuoImageColorDepth_16)
76  return GL_LUMINANCE_ALPHA16F_ARB;
77  if (imageColorDepth == VuoImageColorDepth_32)
78  return GL_LUMINANCE_ALPHA32F_ARB;
79  return GL_LUMINANCE8_ALPHA8;
80  }
81 
82  char *formatString = VuoGl_stringForConstant(baseFormat);
83  VUserLog("Error: Unknown baseFormat %x (%s)", baseFormat, formatString);
84  free(formatString);
85  return GL_RGB;
86 }
87 
94 {
95  const char *valueAsString = "";
96  if (json_object_get_type(js) == json_type_string)
97  valueAsString = json_object_get_string(js);
98 
99  VuoImageColorDepth value = VuoImageColorDepth_8;
100 
101  if (! strcmp(valueAsString, "16bpc"))
102  value = VuoImageColorDepth_16;
103  else if (! strcmp(valueAsString, "32bpc"))
104  value = VuoImageColorDepth_32;
105 
106  return value;
107 }
108 
113 {
114  char *valueAsString = "";
115 
116  switch (value)
117  {
118  case VuoImageColorDepth_8:
119  valueAsString = "8bpc";
120  break;
121  case VuoImageColorDepth_16:
122  valueAsString = "16bpc";
123  break;
124  case VuoImageColorDepth_32:
125  valueAsString = "32bpc";
126  break;
127  }
128 
129  return json_object_new_string(valueAsString);
130 }
131 
136 {
138  VuoListAppendValue_VuoImageColorDepth(l, VuoImageColorDepth_8);
139  VuoListAppendValue_VuoImageColorDepth(l, VuoImageColorDepth_16);
140  VuoListAppendValue_VuoImageColorDepth(l, VuoImageColorDepth_32);
141  return l;
142 }
143 
148 {
149  int bits = 0;
150  if (value == VuoImageColorDepth_8)
151  bits = 8;
152  else if (value == VuoImageColorDepth_16)
153  bits = 16;
154  else if (value == VuoImageColorDepth_32)
155  bits = 32;
156 
157  return VuoText_format("%d bits per channel", bits);
158 }