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