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 INTERPOLATE_AGGREGATED
23 #define INTERPOLATE_AGGREGATED
25 // Interpolation sections performed by other plugins
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"
36 " vec2 pixel_coord = gl_TexCoord[0].st;\n"
37 " vec2 pattern_coord = pixel_coord;\n"
39 " pattern_coord -= pattern_offset;\n"
40 " pattern_coord = fract(pattern_coord / pattern_size);\n"
41 " if(pattern_coord.x >= 0.5)\n"
43 " if(pattern_coord.y >= 0.5)\n"
45 /* Bottom right of pattern */
46 /* Bottom right pixels are: */
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"
62 /* Top right of pattern */
63 /* Top right pixels are: */
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"
88 " if(pattern_coord.y >= 0.5)\n"
90 /* Bottom left of pattern */
91 /* Bottom left pixels are: */
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"
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"
116 /* Top left of pattern */
117 /* Top left pixels are: */
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"
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"
135 " gl_FragColor = vec4(result * color_matrix, 1.0);\n"
139 #define INTERPOLATE_COMPILE(shader_stack, current_shader) \
141 shader_stack[current_shader++] = interpolate_shader; \
144 #define INTERPOLATE_UNIFORMS(frag) \
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]; \
153 get_output()->get_params()->get("DCRAW_MATRIX", string); \
155 "%f %f %f %f %f %f %f %f %f", \
165 glUniformMatrix3fv(glGetUniformLocation(frag, "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()); \