OLD | NEW |
---|---|
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2221 float yuv_to_rgb_rec601[9] = { | 2221 float yuv_to_rgb_rec601[9] = { |
2222 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, | 2222 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, |
2223 }; | 2223 }; |
2224 float yuv_to_rgb_jpeg[9] = { | 2224 float yuv_to_rgb_jpeg[9] = { |
2225 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, | 2225 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, |
2226 }; | 2226 }; |
2227 float yuv_to_rgb_rec709[9] = { | 2227 float yuv_to_rgb_rec709[9] = { |
2228 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, | 2228 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, |
2229 }; | 2229 }; |
2230 | 2230 |
2231 // These values map to 16, 128, and 128 respectively, and are computed | |
2232 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | |
2233 // They are used in the YUV to RGBA conversion formula: | 2231 // They are used in the YUV to RGBA conversion formula: |
2234 // Y - 16 : Gives 16 values of head and footroom for overshooting | 2232 // Y - 16 : Gives 16 values of head and footroom for overshooting |
2235 // U - 128 : Turns unsigned U into signed U [-128,127] | 2233 // U - 128 : Turns unsigned U into signed U [-128,127] |
2236 // V - 128 : Turns unsigned V into signed V [-128,127] | 2234 // V - 128 : Turns unsigned V into signed V [-128,127] |
2237 float yuv_adjust_constrained[3] = { | 2235 float yuv_adjust_constrained[3] = { |
2238 -0.0625f, -0.5f, -0.5f, | 2236 -16.f, -128.f, -128.f, |
2239 }; | 2237 }; |
2240 | 2238 |
2241 // Same as above, but without the head and footroom. | 2239 // Same as above, but without the head and footroom. |
2242 float yuv_adjust_full[3] = { | 2240 float yuv_adjust_full[3] = { |
2243 0.0f, -0.5f, -0.5f, | 2241 0.0f, -128.f, -128.f, |
2244 }; | 2242 }; |
2245 | 2243 |
2246 float* yuv_to_rgb = NULL; | 2244 float* yuv_to_rgb = NULL; |
2247 float* yuv_adjust = NULL; | 2245 float* yuv_adjust = NULL; |
2248 | 2246 |
2249 switch (quad->color_space) { | 2247 switch (quad->color_space) { |
2250 case YUVVideoDrawQuad::REC_601: | 2248 case YUVVideoDrawQuad::REC_601: |
2251 yuv_to_rgb = yuv_to_rgb_rec601; | 2249 yuv_to_rgb = yuv_to_rgb_rec601; |
2252 yuv_adjust = yuv_adjust_constrained; | 2250 yuv_adjust = yuv_adjust_constrained; |
2253 break; | 2251 break; |
2254 case YUVVideoDrawQuad::REC_709: | 2252 case YUVVideoDrawQuad::REC_709: |
2255 yuv_to_rgb = yuv_to_rgb_rec709; | 2253 yuv_to_rgb = yuv_to_rgb_rec709; |
2256 yuv_adjust = yuv_adjust_constrained; | 2254 yuv_adjust = yuv_adjust_constrained; |
2257 break; | 2255 break; |
2258 case YUVVideoDrawQuad::JPEG: | 2256 case YUVVideoDrawQuad::JPEG: |
2259 yuv_to_rgb = yuv_to_rgb_jpeg; | 2257 yuv_to_rgb = yuv_to_rgb_jpeg; |
2260 yuv_adjust = yuv_adjust_full; | 2258 yuv_adjust = yuv_adjust_full; |
2261 break; | 2259 break; |
2262 } | 2260 } |
2263 | 2261 |
2264 float yuv_to_rgb_multiplied[9]; | 2262 float yuv_to_rgb_multiplied[9]; |
2265 float yuv_adjust_with_offset[3]; | 2263 float yuv_adjust_with_offset[3]; |
2266 | 2264 |
2265 // Formula according to BT.601-7 section 2.5.3. | |
2266 DCHECK_LE(8u, quad->bits_per_channel); | |
2267 DCHECK_LE(quad->bits_per_channel, 24u); | |
dcheng
2016/07/30 01:26:37
Would it be possible to do this check in ParamTrai
| |
2268 float adjustment_multiplier = (1 << (quad->bits_per_channel - 8)) * 1.0f / | |
2269 ((1 << quad->bits_per_channel) - 1); | |
2270 | |
2267 for (int i = 0; i < 9; ++i) | 2271 for (int i = 0; i < 9; ++i) |
2268 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; | 2272 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; |
2269 | 2273 |
2270 for (int i = 0; i < 3; ++i) | 2274 for (int i = 0; i < 3; ++i) { |
2271 yuv_adjust_with_offset[i] = | 2275 yuv_adjust_with_offset[i] = |
2272 yuv_adjust[i] / quad->resource_multiplier - quad->resource_offset; | 2276 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier - |
2277 quad->resource_offset; | |
2278 } | |
2273 | 2279 |
2274 // The transform and vertex data are used to figure out the extents that the | 2280 // The transform and vertex data are used to figure out the extents that the |
2275 // un-antialiased quad should have and which vertex this is and the float | 2281 // un-antialiased quad should have and which vertex this is and the float |
2276 // quad passed in via uniform is the actual geometry that gets used to draw | 2282 // quad passed in via uniform is the actual geometry that gets used to draw |
2277 // it. This is why this centered rect is used and not the original quad_rect. | 2283 // it. This is why this centered rect is used and not the original quad_rect. |
2278 auto tile_rect = gfx::RectF(quad->rect); | 2284 auto tile_rect = gfx::RectF(quad->rect); |
2279 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied); | 2285 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied); |
2280 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset); | 2286 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset); |
2281 | 2287 |
2282 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); | 2288 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3777 resource_provider_, contents_texture->id())); | 3783 resource_provider_, contents_texture->id())); |
3778 source_texture = source->texture_id(); | 3784 source_texture = source->texture_id(); |
3779 } | 3785 } |
3780 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, | 3786 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, |
3781 0, contents_texture->size().width(), | 3787 0, contents_texture->size().width(), |
3782 contents_texture->size().height(), GL_TRUE, | 3788 contents_texture->size().height(), GL_TRUE, |
3783 GL_FALSE, GL_FALSE); | 3789 GL_FALSE, GL_FALSE); |
3784 } | 3790 } |
3785 | 3791 |
3786 } // namespace cc | 3792 } // namespace cc |
OLD | NEW |