| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 */ | 47 */ |
| 48 uniform float imageWidth; | 48 uniform float imageWidth; |
| 49 uniform float imageHeight; | 49 uniform float imageHeight; |
| 50 | 50 |
| 51 /* | 51 /* |
| 52 * This is the texture sampler where the greyscale Y'UV420p image is | 52 * This is the texture sampler where the greyscale Y'UV420p image is |
| 53 * accessed. | 53 * accessed. |
| 54 */ | 54 */ |
| 55 uniform sampler2D textureSampler; | 55 uniform sampler2D textureSampler; |
| 56 | 56 |
| 57 #if defined (USE_UNIFORM_MATRIX) |
| 58 uniform mat4 conversion; |
| 59 #endif |
| 60 |
| 57 varying vec4 v1; | 61 varying vec4 v1; |
| 58 | 62 |
| 59 /** | 63 /** |
| 60 * This fetches an individual Y pixel from the image, given the current | 64 * This fetches an individual Y pixel from the image, given the current |
| 61 * texture coordinates (which range from 0 to 1 on the source texture | 65 * texture coordinates (which range from 0 to 1 on the source texture |
| 62 * image). They are mapped to the portion of the image that contains | 66 * image). They are mapped to the portion of the image that contains |
| 63 * the Y component. | 67 * the Y component. |
| 64 * | 68 * |
| 65 * @param position This is the position of the main image that we're | 69 * @param position This is the position of the main image that we're |
| 66 * trying to render, in parametric coordinates. | 70 * trying to render, in parametric coordinates. |
| 67 */ | 71 */ |
| 68 float getYPixel(vec2 position) { | 72 float getYPixel(vec2 position) { |
| 69 position.y = position.y * 2.0 / 3.0 + 1.0 / 3.0; | 73 position.y = 1. - (position.y * 2.0 / 3.0 + 1.0 / 3.0); |
| 70 return texture2D(textureSampler, position).x; | 74 return texture2D(textureSampler, position).x; |
| 71 } | 75 } |
| 72 | 76 |
| 73 /** | 77 /** |
| 74 * This does the crazy work of calculating the planar position (the | 78 * This does the crazy work of calculating the planar position (the |
| 75 * position in the byte stream of the image) of the U or V pixel, and | 79 * position in the byte stream of the image) of the U or V pixel, and |
| 76 * then converting that back to x and y coordinates, so that we can | 80 * then converting that back to x and y coordinates, so that we can |
| 77 * account for the fact that V is appended to U in the image, and the | 81 * account for the fact that V is appended to U in the image, and the |
| 78 * complications that causes (see below for a diagram). | 82 * complications that causes (see below for a diagram). |
| 79 * | 83 * |
| 80 * @param position This is the position of the main image that we're | 84 * @param position This is the position of the main image that we're |
| 81 * trying to render, in pixels. | 85 * trying to render, in pixels. |
| 82 * | 86 * |
| 83 * @param planarOffset This is an offset to add to the planar address | 87 * @param planarOffset This is an offset to add to the planar address |
| 84 * we calculate so that we can find the U image after the V | 88 * we calculate so that we can find the U image after the V |
| 85 * image. | 89 * image. |
| 86 */ | 90 */ |
| 87 vec2 mapCommon(vec2 position, float planarOffset) { | 91 vec2 mapCommon(vec2 position, float planarOffset) { |
| 88 planarOffset += imageWidth * floor(position.y / 2.0) / 2.0 + | 92 planarOffset += imageWidth * floor(position.y / 2.0) / 2.0 + |
| 89 floor((imageWidth - 1.0 - position.x) / 2.0); | 93 floor((imageWidth - 1.0 - position.x) / 2.0); |
| 90 float x = floor(imageWidth - 1.0 - floor(mod(planarOffset, imageWidth))); | 94 float x = floor(imageWidth - 1.0 - floor(mod(planarOffset, imageWidth))); |
| 91 float y = floor(planarOffset / imageWidth); | 95 float y = floor(planarOffset / imageWidth); |
| 92 return vec2((x + 0.5) / imageWidth, (y + 0.5) / (1.5 * imageHeight)); | 96 return vec2((x + 0.5) / imageWidth, 1. - (y + 0.5) / (1.5 * imageHeight)); |
| 93 } | 97 } |
| 94 | 98 |
| 95 /** | 99 /** |
| 96 * This is a helper function for mapping pixel locations to a texture | 100 * This is a helper function for mapping pixel locations to a texture |
| 97 * coordinate for the U plane. | 101 * coordinate for the U plane. |
| 98 * | 102 * |
| 99 * @param position This is the position of the main image that we're | 103 * @param position This is the position of the main image that we're |
| 100 * trying to render, in pixels. | 104 * trying to render, in pixels. |
| 101 */ | 105 */ |
| 102 vec2 mapU(vec2 position) { | 106 vec2 mapU(vec2 position) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 */ | 206 */ |
| 203 float uChannel = texture2D(textureSampler, mapU(pixelPosition)).x; | 207 float uChannel = texture2D(textureSampler, mapU(pixelPosition)).x; |
| 204 float vChannel = texture2D(textureSampler, mapV(pixelPosition)).x; | 208 float vChannel = texture2D(textureSampler, mapV(pixelPosition)).x; |
| 205 | 209 |
| 206 /* | 210 /* |
| 207 * This does the colorspace conversion from Y'UV to RGB as a matrix | 211 * This does the colorspace conversion from Y'UV to RGB as a matrix |
| 208 * multiply. It also does the offset of the U and V channels from | 212 * multiply. It also does the offset of the U and V channels from |
| 209 * [0,1] to [-.5,.5] as part of the transform. | 213 * [0,1] to [-.5,.5] as part of the transform. |
| 210 */ | 214 */ |
| 211 vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0); | 215 vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0); |
| 216 #if !defined(USE_UNIFORM_MATRIX) |
| 212 mat4 conversion = mat4( 1.0, 1.0, 1.0, 0.0, | 217 mat4 conversion = mat4( 1.0, 1.0, 1.0, 0.0, |
| 213 0.0, -0.344, 1.772, 0.0, | 218 0.0, -0.344, 1.772, 0.0, |
| 214 1.402, -0.714, 0.0, 0.0, | 219 1.402, -0.714, 0.0, 0.0, |
| 215 -0.701, 0.529, -0.886, 1.0); | 220 -0.701, 0.529, -0.886, 1.0); |
| 221 #endif |
| 216 | 222 |
| 217 gl_FragColor = conversion * channels; | 223 gl_FragColor = conversion * channels; |
| 218 } | 224 } |
| OLD | NEW |