OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 15 matching lines...) Expand all Loading... |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 /* | 32 /* |
33 * This is a conversion of a cg shader from Chrome: | 33 * This is a conversion of a cg shader from Chrome: |
34 * http://src.chromium.org/viewvc/chrome/trunk/src/o3d/samples/shaders/yuv2rgb.s
hader | 34 * http://src.chromium.org/viewvc/chrome/trunk/src/o3d/samples/shaders/yuv2rgb.s
hader |
35 */ | 35 */ |
36 #define I915_WORKAROUND 1 | |
37 | 36 |
38 /* | 37 /* |
39 * This shader takes a Y'UV420p image as a single greyscale plane, and | 38 * This shader takes a Y'UV420p image as a single greyscale plane, and |
40 * converts it to RGB by sampling the correct parts of the image, and | 39 * converts it to RGB by sampling the correct parts of the image, and |
41 * by converting the colorspace to RGB on the fly. | 40 * by converting the colorspace to RGB on the fly. |
42 */ | 41 */ |
43 | 42 |
44 /* | 43 /* |
45 * These represent the image dimensions of the SOURCE IMAGE (not the | 44 * These represent the image dimensions of the SOURCE IMAGE (not the |
46 * Y'UV420p image). This is the same as the dimensions of the Y' | 45 * Y'UV420p image). This is the same as the dimensions of the Y' |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 * 0 +---+---+---+---+ | 170 * 0 +---+---+---+---+ |
172 * 0 1 | 171 * 0 1 |
173 * | 172 * |
174 */ | 173 */ |
175 void main() { | 174 void main() { |
176 /* | 175 /* |
177 * Calculate what image pixel we're on, since we have to calculate | 176 * Calculate what image pixel we're on, since we have to calculate |
178 * the location in the image stream, using floor in several places | 177 * the location in the image stream, using floor in several places |
179 * which makes it hard to use parametric coordinates. | 178 * which makes it hard to use parametric coordinates. |
180 */ | 179 */ |
181 #if I915_WORKAROUND | 180 #if defined(I915_WORKAROUND) |
182 vec2 pixelPosition = vec2(floor(imageWidth * gl_TexCoord[0].x), | 181 vec2 pixelPosition = vec2(floor(imageWidth * gl_TexCoord[0].x), |
183 floor(imageHeight * gl_TexCoord[0].y)); | 182 floor(imageHeight * gl_TexCoord[0].y)); |
184 #else | 183 #else |
185 vec2 pixelPosition = vec2(floor(imageWidth * v1.x), | 184 vec2 pixelPosition = vec2(floor(imageWidth * v1.x), |
186 floor(imageHeight * v1.y)); | 185 floor(imageHeight * v1.y)); |
187 #endif | 186 #endif |
188 | 187 |
189 /* | 188 /* |
190 * We can use the parametric coordinates to get the Y channel, since it's | 189 * We can use the parametric coordinates to get the Y channel, since it's |
191 * a relatively normal image. | 190 * a relatively normal image. |
192 */ | 191 */ |
193 #if I915_WORKAROUND | 192 #if defined(I915_WORKAROUND) |
194 float yChannel = getYPixel(vec2(gl_TexCoord[0])); | 193 float yChannel = getYPixel(vec2(gl_TexCoord[0])); |
195 #else | 194 #else |
196 float yChannel = getYPixel(vec2(v1)); | 195 float yChannel = getYPixel(vec2(v1)); |
197 #endif | 196 #endif |
198 | 197 |
199 /* | 198 /* |
200 * As noted above, the U and V planes are smashed onto the end of | 199 * As noted above, the U and V planes are smashed onto the end of |
201 * the image in an odd way (in our 2D texture mapping, at least), so | 200 * the image in an odd way (in our 2D texture mapping, at least), so |
202 * these mapping functions take care of that oddness. | 201 * these mapping functions take care of that oddness. |
203 */ | 202 */ |
204 float uChannel = texture2D(textureSampler, mapU(pixelPosition)).x; | 203 float uChannel = texture2D(textureSampler, mapU(pixelPosition)).x; |
205 float vChannel = texture2D(textureSampler, mapV(pixelPosition)).x; | 204 float vChannel = texture2D(textureSampler, mapV(pixelPosition)).x; |
206 | 205 |
207 /* | 206 /* |
208 * This does the colorspace conversion from Y'UV to RGB as a matrix | 207 * This does the colorspace conversion from Y'UV to RGB as a matrix |
209 * multiply. It also does the offset of the U and V channels from | 208 * multiply. It also does the offset of the U and V channels from |
210 * [0,1] to [-.5,.5] as part of the transform. | 209 * [0,1] to [-.5,.5] as part of the transform. |
211 */ | 210 */ |
212 vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0); | 211 vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0); |
213 mat4 conversion = mat4( 1.0, 1.0, 1.0, 0.0, | 212 mat4 conversion = mat4( 1.0, 1.0, 1.0, 0.0, |
214 0.0, -0.344, 1.772, 0.0, | 213 0.0, -0.344, 1.772, 0.0, |
215 1.402, -0.714, 0.0, 0.0, | 214 1.402, -0.714, 0.0, 0.0, |
216 -0.701, 0.529, -0.886, 1.0); | 215 -0.701, 0.529, -0.886, 1.0); |
217 | 216 |
218 gl_FragColor = conversion * channels; | 217 gl_FragColor = conversion * channels; |
219 } | 218 } |
OLD | NEW |