add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / colorbalance / aggregated.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef COLORBALANCE_AGGREGATED
23 #define COLORBALANCE_AGGREGATED
24
25 static const char *colorbalance_get_pixel1 =
26         "vec4 colorbalance_get_pixel()\n"
27         "{\n"
28         "       return gl_FragColor;\n"
29         "}\n";
30
31 static const char *colorbalance_get_pixel2 =
32         "uniform sampler2D tex;\n"
33         "vec4 colorbalance_get_pixel()\n"
34         "{\n"
35         "       return texture2D(tex, gl_TexCoord[0].st);\n"
36         "}\n";
37
38
39 static const char *colorbalance_rgb_shader =
40         "uniform vec3 colorbalance_scale;\n"
41         "void main()\n"
42         "{\n"
43         "       gl_FragColor = colorbalance_get_pixel();\n"
44         "       gl_FragColor.rgb *= colorbalance_scale;\n"
45         "}\n";
46
47 static const char *colorbalance_yuv_shader =
48         "uniform vec3 colorbalance_scale;\n"
49         "void main()\n"
50         "{\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")
55         "}\n";
56
57 static const char *colorbalance_yuv_preserve_shader =
58         "uniform vec3 colorbalance_scale;\n"
59         "void main()\n"
60         "{\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"
67         "}\n";
68
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 ; \
76 } while(0)
77
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)); \
83 } while(0)
84
85 #endif
86