igor ru.po
[goodguy/history.git] / cinelerra-5.1 / plugins / interpolate / 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 INTERPOLATE_AGGREGATED
23 #define INTERPOLATE_AGGREGATED
24
25 // Interpolation sections performed by other plugins
26
27 static const char *interpolate_shader =
28 "uniform sampler2D tex;\n"
29 "uniform vec2 pattern_offset;\n"
30 "uniform vec2 pattern_size;\n"
31 "uniform vec2 pixel_size;\n"
32 "uniform mat3 color_matrix;\n"
33 "\n"
34 "void main()\n"
35 "{\n"
36 "       vec2 pixel_coord = gl_TexCoord[0].st;\n"
37 "       vec2 pattern_coord = pixel_coord;\n"
38 "       vec3 result;\n"
39 "       pattern_coord -= pattern_offset;\n"
40 "       pattern_coord = fract(pattern_coord / pattern_size);\n"
41 "       if(pattern_coord.x >= 0.5)\n"
42 "       {\n"
43 "               if(pattern_coord.y >= 0.5)\n"
44 "               {\n"
45 /* Bottom right of pattern */
46 /* Bottom right pixels are: */
47 /*    2    */
48 /*   1*3   */
49 /*    4    */
50 "                       vec2 pixel1 = pixel_coord - vec2(pixel_size.x, 0.0);\n"
51 "                       vec2 pixel2 = pixel_coord - vec2(0.0, pixel_size.y);\n"
52 "                       vec2 pixel3 = pixel_coord + vec2(pixel_size.x, 0.0);\n"
53 "                       vec2 pixel4 = pixel_coord + vec2(0.0, pixel_size.y);\n"
54 "                       result = vec3((texture2D(tex, pixel1).r + \n"
55 "                                                               texture2D(tex, pixel3).r) / 2.0, \n"
56 "                                                       texture2D(tex, pixel_coord).g, \n"
57 "                                                       (texture2D(tex, pixel2).b + \n"
58 "                                                               texture2D(tex, pixel4).b) / 2.0);\n"
59 "               }\n"
60 "               else\n"
61 "               {\n"
62 /* Top right of pattern */
63 /* Top right pixels are: */
64 /*   123   */
65 /*   4*5   */
66 /*   678   */
67 "                       vec2 pixel1 = pixel_coord - pixel_size;\n"
68 "                       vec2 pixel2 = pixel_coord - vec2(0.0, pixel_size.y);\n"
69 "                       vec2 pixel3 = pixel_coord + vec2(pixel_size.x, -pixel_size.y);\n"
70 "                       vec2 pixel4 = pixel_coord - vec2(pixel_size.x, 0.0);\n"
71 "                       vec2 pixel5 = pixel_coord + vec2(pixel_size.x, 0.0);\n"
72 "                       vec2 pixel6 = pixel_coord + vec2(-pixel_size.x, pixel_size.y);\n"
73 "                       vec2 pixel7 = pixel_coord + vec2(0.0, pixel_size.y);\n"
74 "                       vec2 pixel8 = pixel_coord + pixel_size;\n"
75 "                       result = vec3((texture2D(tex, pixel1).r + \n"
76 "                                                               texture2D(tex, pixel3).r + \n"
77 "                                                               texture2D(tex, pixel6).r + \n"
78 "                                                               texture2D(tex, pixel8).r) / 4.0, \n"
79 "                                                       (texture2D(tex, pixel4).g + \n"
80 "                                                               texture2D(tex, pixel2).g + \n"
81 "                                                               texture2D(tex, pixel5).g + \n"
82 "                                                               texture2D(tex, pixel7).g) / 4.0, \n"
83 "                                                       texture2D(tex, pixel_coord).b);\n"
84 "               }\n"
85 "       }\n"
86 "       else\n"
87 "       {\n"
88 "               if(pattern_coord.y >= 0.5)\n"
89 "               {\n"
90 /* Bottom left of pattern */
91 /* Bottom left pixels are: */
92 /*   123   */
93 /*   4*5   */
94 /*   678   */
95 "                       vec2 pixel1 = pixel_coord - pixel_size;\n"
96 "                       vec2 pixel2 = pixel_coord - vec2(0.0, pixel_size.y);\n"
97 "                       vec2 pixel3 = pixel_coord + vec2(pixel_size.x, -pixel_size.y);\n"
98 "                       vec2 pixel4 = pixel_coord - vec2(pixel_size.x, 0.0);\n"
99 "                       vec2 pixel5 = pixel_coord + vec2(pixel_size.x, 0.0);\n"
100 "                       vec2 pixel6 = pixel_coord + vec2(-pixel_size.x, pixel_size.y);\n"
101 "                       vec2 pixel7 = pixel_coord + vec2(0.0, pixel_size.y);\n"
102 "                       vec2 pixel8 = pixel_coord + pixel_size;\n"
103 "                       result = vec3(\n"
104 "                                                       texture2D(tex, pixel_coord).r, \n"
105 "                                                       (texture2D(tex, pixel4).g + \n"
106 "                                                               texture2D(tex, pixel2).g + \n"
107 "                                                               texture2D(tex, pixel5).g + \n"
108 "                                                               texture2D(tex, pixel7).g) / 4.0, \n"
109 "                                                       (texture2D(tex, pixel1).b + \n"
110 "                                                               texture2D(tex, pixel3).b + \n"
111 "                                                               texture2D(tex, pixel6).b + \n"
112 "                                                               texture2D(tex, pixel8).b) / 4.0);\n"
113 "               }\n"
114 "               else\n"
115 "               {\n"
116 /* Top left of pattern */
117 /* Top left pixels are: */
118 /*    2    */
119 /*   1 3   */
120 /*    4    */
121 "                       vec2 pixel1 = pixel_coord - vec2(pixel_size.x, 0.0);\n"
122 "                       vec2 pixel2 = pixel_coord - vec2(0.0, pixel_size.y);\n"
123 "                       vec2 pixel3 = pixel_coord + vec2(pixel_size.x, 0.0);\n"
124 "                       vec2 pixel4 = pixel_coord + vec2(0.0, pixel_size.y);\n"
125 "                       result = vec3(\n"
126 "                                                       (texture2D(tex, pixel2).r + \n"
127 "                                                               texture2D(tex, pixel4).r) / 2.0, \n"
128 "                                                       texture2D(tex, pixel_coord).g, \n"
129 "                                                       (texture2D(tex, pixel1).b + \n"
130 "                                                               texture2D(tex, pixel3).b) / 2.0);\n"
131 "               }\n"
132 "       }\n"
133 "\n"
134 "\n"
135 "       gl_FragColor = vec4(result * color_matrix, 1.0);\n"
136 "}\n";
137
138
139 #define INTERPOLATE_COMPILE(shader_stack, current_shader) \
140 { \
141         shader_stack[current_shader++] = interpolate_shader; \
142 }
143
144 #define INTERPOLATE_UNIFORMS(frag) \
145 { \
146         int x_offset = get_output()->get_params()->get("INTERPOLATEPIXELS_X", (int)0); \
147         int y_offset = get_output()->get_params()->get("INTERPOLATEPIXELS_Y", (int)0); \
148         float color_matrix[9]; \
149         for( int i=0; i<9; ++i ) color_matrix[i] = 0; \
150         for( int i=0; i<3; ++i ) color_matrix[i*3 + i] = 1; \
151         char string[BCTEXTLEN]; \
152         string[0] = 0; \
153         get_output()->get_params()->get("DCRAW_MATRIX", string); \
154         sscanf(string,  \
155                 "%f %f %f %f %f %f %f %f %f",  \
156                 &color_matrix[0], \
157                 &color_matrix[1], \
158                 &color_matrix[2], \
159                 &color_matrix[3], \
160                 &color_matrix[4], \
161                 &color_matrix[5], \
162                 &color_matrix[6], \
163                 &color_matrix[7], \
164                 &color_matrix[8]); \
165         glUniformMatrix3fv(glGetUniformLocation(frag, "color_matrix"),  \
166                 1, \
167                 0, \
168                 color_matrix); \
169         glUniform2f(glGetUniformLocation(frag, "pattern_offset"),  \
170                 (float)x_offset / get_output()->get_texture_w(), \
171                 (float)y_offset / get_output()->get_texture_h()); \
172         glUniform2f(glGetUniformLocation(frag, "pattern_size"),  \
173                 2.0 / get_output()->get_texture_w(), \
174                 2.0 / get_output()->get_texture_h()); \
175         glUniform2f(glGetUniformLocation(frag, "pixel_size"),  \
176                 1.0 / get_output()->get_texture_w(), \
177                 1.0 / get_output()->get_texture_h()); \
178 }
179
180
181 #endif