4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef COLORBALANCE_AGGREGATED
23 #define COLORBALANCE_AGGREGATED
25 static const char *colorbalance_get_pixel1 =
26 "vec4 colorbalance_get_pixel()\n"
28 " return gl_FragColor;\n"
31 static const char *colorbalance_get_pixel2 =
32 "uniform sampler2D tex;\n"
33 "vec4 colorbalance_get_pixel()\n"
35 " return texture2D(tex, gl_TexCoord[0].st);\n"
39 static const char *colorbalance_rgb_shader =
40 "uniform vec3 colorbalance_scale;\n"
43 " gl_FragColor = colorbalance_get_pixel();\n"
44 " gl_FragColor.rgb *= colorbalance_scale;\n"
47 static const char *colorbalance_yuv_shader =
48 "uniform vec3 colorbalance_scale;\n"
51 " gl_FragColor = colorbalance_get_pixel();\n"
52 YUV_TO_RGB_FRAG("gl_FragColor")
53 " gl_FragColor.rgb *= colorbalance_scale;\n"
54 RGB_TO_YUV_FRAG("gl_FragColor")
57 static const char *colorbalance_yuv_preserve_shader =
58 "uniform vec3 colorbalance_scale;\n"
61 " gl_FragColor = colorbalance_get_pixel();\n"
62 " float y = gl_FragColor.r;\n"
63 YUV_TO_RGB_FRAG("gl_FragColor")
64 " gl_FragColor.rgb *= colorbalance_scale.rgb;\n"
65 RGB_TO_YUV_FRAG("gl_FragColor")
66 " gl_FragColor.r = y;\n"
69 #define COLORBALANCE_COMPILE(shader_stack, current_shader, aggregate_prev) do { \
70 shader_stack[current_shader++] = \
71 aggregate_prev ? colorbalance_get_pixel1 : colorbalance_get_pixel2; \
72 shader_stack[current_shader++] = \
73 !BC_CModels::is_yuv(get_output()->get_color_model()) ? colorbalance_rgb_shader : \
74 get_output()->get_params()->get("COLORBALANCE_PRESERVE", (int)0) ? \
75 colorbalance_yuv_preserve_shader : colorbalance_yuv_shader ; \
78 #define COLORBALANCE_UNIFORMS(shader) do { \
79 glUniform3f(glGetUniformLocation(shader, "colorbalance_scale"), \
80 get_output()->get_params()->get("COLORBALANCE_CYAN", (float)1), \
81 get_output()->get_params()->get("COLORBALANCE_MAGENTA", (float)1), \
82 get_output()->get_params()->get("COLORBALANCE_YELLOW", (float)1)); \