remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / gamma / 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 GAMMA_AGGREGATED
23 #define GAMMA_AGGREGATED
24
25 // Gamma sections performed by other plugins
26
27 // Functions to get pixel from either previous effect or texture
28 static const char *gamma_get_pixel1 =
29         "vec4 gamma_get_pixel()\n"
30         "{\n"
31         "       return gl_FragColor;\n"
32         "}\n";
33
34 static const char *gamma_get_pixel2 =
35         "uniform sampler2D tex;\n"
36         "vec4 gamma_get_pixel()\n"
37         "{\n"
38         "       return texture2D(tex, gl_TexCoord[0].st);\n"
39         "}\n";
40
41 static const char *gamma_pow_frag =
42         "float my_pow(float x, float y, float max)\n"
43         "{\n"
44         "       return (x > 0.0) ? pow(x * 2.0 / max, y) : 0.0;\n"
45         "}\n";
46
47 static const char *gamma_rgb_frag =
48         "uniform float gamma_scale;\n"
49         "uniform float gamma_gamma;\n"
50         "uniform float gamma_max;\n"
51         "void main()\n"
52         "{\n"
53         "       vec4 pixel = gamma_get_pixel();\n"
54         "       pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
55         "       pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
56         "       pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
57         "       gl_FragColor = pixel;\n"
58         "}\n";
59
60 static const char *gamma_yuv_frag =
61         "uniform float gamma_scale;\n"
62         "uniform float gamma_gamma;\n"
63         "uniform float gamma_max;\n"
64         "void main()\n"
65         "{\n"
66         "       vec4 pixel = gamma_get_pixel();\n"
67                 YUV_TO_RGB_FRAG("pixel")
68         "       pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
69         "       pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
70         "       pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
71                 RGB_TO_YUV_FRAG("pixel")
72         "       gl_FragColor = pixel;\n"
73         "}\n";
74
75 #define GAMMA_COMPILE(shader_stack, current_shader, aggregate_interpolation) \
76 { \
77         if(aggregate_interpolation) \
78                 shader_stack[current_shader++] = gamma_get_pixel1; \
79         else \
80                 shader_stack[current_shader++] = gamma_get_pixel2; \
81  \
82         switch(get_output()->get_color_model()) \
83         { \
84                 case BC_YUV888: \
85                 case BC_YUVA8888: \
86                         shader_stack[current_shader++] = gamma_pow_frag; \
87                         shader_stack[current_shader++] = gamma_yuv_frag; \
88                         break; \
89                 default: \
90                         shader_stack[current_shader++] = gamma_pow_frag; \
91                         shader_stack[current_shader++] = gamma_rgb_frag; \
92                         break; \
93         } \
94 }
95
96 #define GAMMA_UNIFORMS(frag) \
97 { \
98         float gamma = get_output()->get_params()->get("GAMMA_GAMMA", (float)1); \
99         float max = get_output()->get_params()->get("GAMMA_MAX", (float)1) * gamma; \
100         gamma -= 1.0; \
101         float scale = 1.0 / max; \
102         glUniform1f(glGetUniformLocation(frag, "gamma_scale"), scale); \
103         glUniform1f(glGetUniformLocation(frag, "gamma_gamma"), gamma); \
104         glUniform1f(glGetUniformLocation(frag, "gamma_max"), max); \
105 printf("GAMMA_UNIFORMS %f %f\n", max, gamma); \
106 }
107
108
109
110
111
112 #endif