]> git.sesse.net Git - movit/blobdiff - util.cpp
Deallocation in YCbCrInput.
[movit] / util.cpp
index 08298c7701b9146fcbd76b9330170b458a80f28b..9eaa262734f284b53aebba1d1c2672538dcc3aee 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 #include <assert.h>
 
 #include <math.h>
@@ -46,6 +47,21 @@ void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
        *b += m;
 }
 
+void hsv2rgb_normalized(float h, float s, float v, float *r, float *g, float *b)
+{
+       float ref_r, ref_g, ref_b;
+       hsv2rgb(h, s, v, r, g, b);
+       hsv2rgb(h, 0.0f, v, &ref_r, &ref_g, &ref_b);
+       float lum = 0.2126 * *r + 0.7152 * *g + 0.0722 * *b;
+       float ref_lum = 0.2126 * ref_r + 0.7152 * ref_g + 0.0722 * ref_b;
+       if (lum > 1e-3) {
+               float fac = ref_lum / lum;
+               *r *= fac;
+               *g *= fac;
+               *b *= fac;
+       }
+}
+
 std::string read_file(const std::string &filename)
 {
        static char buf[131072];
@@ -73,7 +89,9 @@ GLuint compile_shader(const std::string &shader_src, GLenum type)
        GLsizei log_length = sizeof(info_log) - 1;
        glGetShaderInfoLog(obj, log_length, &log_length, info_log);
        info_log[log_length] = 0; 
-       printf("shader compile log: %s\n", info_log);
+       if (strlen(info_log) > 0) {
+               printf("shader compile log: %s\n", info_log);
+       }
 
        GLint status;
        glGetShaderiv(obj, GL_COMPILE_STATUS, &status);