remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / color3way / 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) \
70 { \
71         if(aggregate_prev) \
72                 shader_stack[current_shader++] = colorbalance_get_pixel1; \
73         else \
74                 shader_stack[current_shader++] = colorbalance_get_pixel2; \
75         if(BC_CModels::is_yuv(get_output()->get_color_model())) \
76         {\
77                 if(get_output()->get_params()->get("COLORBALANCE_PRESERVE", (int)0)) \
78                         shader_stack[current_shader++] = colorbalance_yuv_preserve_shader; \
79                 else \
80                         shader_stack[current_shader++] = colorbalance_yuv_shader; \
81         } \
82         else \
83                 shader_stack[current_shader++] = colorbalance_rgb_shader; \
84 }
85
86 #define COLORBALANCE_UNIFORMS(shader) \
87         glUniform3f(glGetUniformLocation(shader, "colorbalance_scale"),  \
88                 get_output()->get_params()->get("COLORBALANCE_CYAN", (float)1), \
89                 get_output()->get_params()->get("COLORBALANCE_MAGENTA", (float)1), \
90                 get_output()->get_params()->get("COLORBALANCE_YELLOW", (float)1));
91
92 #endif
93