OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <metal_stdlib> |
| 12 #include <simd/simd.h> |
| 13 |
| 14 using namespace metal; |
| 15 |
| 16 typedef struct { |
| 17 packed_float2 position; |
| 18 packed_float2 texcoord; |
| 19 } Vertex; |
| 20 |
| 21 |
| 22 typedef struct { |
| 23 float4 position [[position]]; |
| 24 float2 texcoord; |
| 25 } Varyings; |
| 26 |
| 27 vertex Varyings vertexPassthrough( |
| 28 device Vertex* verticies [[ buffer(0) ]], |
| 29 unsigned int vid [[ vertex_id ]] |
| 30 ) { |
| 31 Varyings out; |
| 32 device Vertex& v = verticies[vid]; |
| 33 out.position = float4(float2(v.position), 0.0, 1.0); |
| 34 out.texcoord = v.texcoord; |
| 35 |
| 36 return out; |
| 37 } |
| 38 |
| 39 fragment half4 fragmentColorConversion( |
| 40 Varyings in [[ stage_in ]], |
| 41 texture2d<float, access::sample> textureY
[[ texture(0) ]], |
| 42 texture2d<float, access::sample> textureC
bCr [[ texture(1) ]] |
| 43 ) { |
| 44 constexpr sampler s(address::clamp_to_edge, filter::linear); |
| 45 float y; |
| 46 float2 uv; |
| 47 y = textureY.sample(s, in.texcoord).r; |
| 48 uv = textureCbCr.sample(s, in.texcoord).rg - float2(0.5, 0.5); |
| 49 |
| 50 float4 out = float4(y + 1.403 * uv.y, |
| 51 y - 0.344 * uv.x - 0.714 * uv.y, |
| 52 y + 1.770 * uv.x, |
| 53 1.0); |
| 54 |
| 55 return half4(out); |
| 56 } |
OLD | NEW |