OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrYUVEffect.h" | 8 #include "GrYUVEffect.h" |
9 | 9 |
10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 static const float kRec709InverseConversionMatrix[16] = { | 56 static const float kRec709InverseConversionMatrix[16] = { |
57 0.182663f, 0.614473f, 0.061971f, 0.0625f, | 57 0.182663f, 0.614473f, 0.061971f, 0.0625f, |
58 -0.100672f, -0.338658f, 0.43933f, 0.5f, | 58 -0.100672f, -0.338658f, 0.43933f, 0.5f, |
59 0.439142f, -0.39891f, -0.040231f, 0.5f, | 59 0.439142f, -0.39891f, -0.040231f, 0.5f, |
60 0.f, 0.f, 0.f, 1. | 60 0.f, 0.f, 0.f, 1. |
61 }; | 61 }; |
62 | 62 |
63 class YUVtoRGBEffect : public GrFragmentProcessor { | 63 class YUVtoRGBEffect : public GrFragmentProcessor { |
64 public: | 64 public: |
65 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, | 65 static sk_sp<GrFragmentProcessor> Make(GrTexture* yTexture, GrTexture* uText
ure, |
66 GrTexture* vTexture, const SkISize sizes[
3], | 66 GrTexture* vTexture, const SkISize si
zes[3], |
67 SkYUVColorSpace colorSpace) { | 67 SkYUVColorSpace colorSpace) { |
68 SkScalar w[3], h[3]; | 68 SkScalar w[3], h[3]; |
69 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); | 69 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); |
70 h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height(
)); | 70 h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height(
)); |
71 w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width()
); | 71 w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width()
); |
72 h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height(
)); | 72 h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height(
)); |
73 w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width()
); | 73 w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width()
); |
74 h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height(
)); | 74 h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height(
)); |
75 SkMatrix yuvMatrix[3]; | 75 SkMatrix yuvMatrix[3]; |
76 yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture); | 76 yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture); |
77 yuvMatrix[1] = yuvMatrix[0]; | 77 yuvMatrix[1] = yuvMatrix[0]; |
78 yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]); | 78 yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]); |
79 yuvMatrix[2] = yuvMatrix[0]; | 79 yuvMatrix[2] = yuvMatrix[0]; |
80 yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]); | 80 yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]); |
81 GrTextureParams::FilterMode uvFilterMode = | 81 GrTextureParams::FilterMode uvFilterMode = |
82 ((sizes[1].fWidth != sizes[0].fWidth) || | 82 ((sizes[1].fWidth != sizes[0].fWidth) || |
83 (sizes[1].fHeight != sizes[0].fHeight) || | 83 (sizes[1].fHeight != sizes[0].fHeight) || |
84 (sizes[2].fWidth != sizes[0].fWidth) || | 84 (sizes[2].fWidth != sizes[0].fWidth) || |
85 (sizes[2].fHeight != sizes[0].fHeight)) ? | 85 (sizes[2].fHeight != sizes[0].fHeight)) ? |
86 GrTextureParams::kBilerp_FilterMode : | 86 GrTextureParams::kBilerp_FilterMode : |
87 GrTextureParams::kNone_FilterMode; | 87 GrTextureParams::kNone_FilterMode; |
88 return new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFil
terMode, | 88 return sk_sp<GrFragmentProcessor>( |
89 colorSpace); | 89 new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFilter
Mode, colorSpace)); |
90 } | 90 } |
91 | 91 |
92 const char* name() const override { return "YUV to RGB"; } | 92 const char* name() const override { return "YUV to RGB"; } |
93 | 93 |
94 SkYUVColorSpace getColorSpace() const { return fColorSpace; } | 94 SkYUVColorSpace getColorSpace() const { return fColorSpace; } |
95 | 95 |
96 class GLSLProcessor : public GrGLSLFragmentProcessor { | 96 class GLSLProcessor : public GrGLSLFragmentProcessor { |
97 public: | 97 public: |
98 // this class always generates the same code. | 98 // this class always generates the same code. |
99 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} | 99 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // output color rgba = y | 199 // output color rgba = y |
200 kY_OutputChannels, | 200 kY_OutputChannels, |
201 // output color r = u, g = v, b = 0, a = a | 201 // output color r = u, g = v, b = 0, a = a |
202 kUV_OutputChannels, | 202 kUV_OutputChannels, |
203 // output color rgba = u | 203 // output color rgba = u |
204 kU_OutputChannels, | 204 kU_OutputChannels, |
205 // output color rgba = v | 205 // output color rgba = v |
206 kV_OutputChannels | 206 kV_OutputChannels |
207 }; | 207 }; |
208 | 208 |
209 RGBToYUVEffect(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colorSpace, | 209 RGBToYUVEffect(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace colorSpace, |
210 OutputChannels output) | 210 OutputChannels output) |
211 : fColorSpace(colorSpace) | 211 : fColorSpace(colorSpace) |
212 , fOutputChannels(output) { | 212 , fOutputChannels(output) { |
213 this->initClassID<RGBToYUVEffect>(); | 213 this->initClassID<RGBToYUVEffect>(); |
214 this->registerChildProcessor(rgbFP); | 214 this->registerChildProcessor(std::move(rgbFP)); |
215 } | 215 } |
216 | 216 |
217 const char* name() const override { return "RGBToYUV"; } | 217 const char* name() const override { return "RGBToYUV"; } |
218 | 218 |
219 SkYUVColorSpace getColorSpace() const { return fColorSpace; } | 219 SkYUVColorSpace getColorSpace() const { return fColorSpace; } |
220 | 220 |
221 OutputChannels outputChannels() const { return fOutputChannels; } | 221 OutputChannels outputChannels() const { return fOutputChannels; } |
222 | 222 |
223 class GLSLProcessor : public GrGLSLFragmentProcessor { | 223 class GLSLProcessor : public GrGLSLFragmentProcessor { |
224 public: | 224 public: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 SkYUVColorSpace fColorSpace; | 343 SkYUVColorSpace fColorSpace; |
344 OutputChannels fOutputChannels; | 344 OutputChannels fOutputChannels; |
345 | 345 |
346 typedef GrFragmentProcessor INHERITED; | 346 typedef GrFragmentProcessor INHERITED; |
347 }; | 347 }; |
348 | 348 |
349 } | 349 } |
350 | 350 |
351 ////////////////////////////////////////////////////////////////////////////// | 351 ////////////////////////////////////////////////////////////////////////////// |
352 | 352 |
353 const GrFragmentProcessor* | 353 sk_sp<GrFragmentProcessor> |
354 GrYUVEffect::CreateYUVToRGB(GrTexture* yTexture, GrTexture* uTexture, GrTexture*
vTexture, | 354 GrYUVEffect::MakeYUVToRGB(GrTexture* yTexture, GrTexture* uTexture, GrTexture* v
Texture, |
355 const SkISize sizes[3], SkYUVColorSpace colorSpace)
{ | 355 const SkISize sizes[3], SkYUVColorSpace colorSpace)
{ |
356 SkASSERT(yTexture && uTexture && vTexture && sizes); | 356 SkASSERT(yTexture && uTexture && vTexture && sizes); |
357 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); | 357 return YUVtoRGBEffect::Make(yTexture, uTexture, vTexture, sizes, colorSpace)
; |
358 } | 358 } |
359 | 359 |
360 const GrFragmentProcessor* | 360 sk_sp<GrFragmentProcessor> |
361 GrYUVEffect::CreateRGBToYUV(const GrFragmentProcessor* rgbFP, SkYUVColorSpace co
lorSpace) { | 361 GrYUVEffect::MakeRGBToYUV(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace colo
rSpace) { |
362 SkASSERT(rgbFP); | 362 SkASSERT(rgbFP); |
363 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kYUV_OutputChan
nels); | 363 return sk_sp<GrFragmentProcessor>( |
| 364 new RGBToYUVEffect(std::move(rgbFP), colorSpace, RGBToYUVEffect::kYUV_Ou
tputChannels)); |
364 } | 365 } |
365 | 366 |
366 const GrFragmentProcessor* | 367 sk_sp<GrFragmentProcessor> |
367 GrYUVEffect::CreateRGBToY(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { | 368 GrYUVEffect::MakeRGBToY(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace colorS
pace) { |
368 SkASSERT(rgbFP); | 369 SkASSERT(rgbFP); |
369 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kY_OutputChanne
ls); | 370 return sk_sp<GrFragmentProcessor>( |
| 371 new RGBToYUVEffect(std::move(rgbFP), colorSpace, RGBToYUVEffect::kY_Outp
utChannels)); |
370 } | 372 } |
371 | 373 |
372 const GrFragmentProcessor* | 374 sk_sp<GrFragmentProcessor> |
373 GrYUVEffect::CreateRGBToUV(const GrFragmentProcessor* rgbFP, SkYUVColorSpace col
orSpace) { | 375 GrYUVEffect::MakeRGBToUV(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace color
Space) { |
374 SkASSERT(rgbFP); | 376 SkASSERT(rgbFP); |
375 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kUV_OutputChann
els); | 377 return sk_sp<GrFragmentProcessor>( |
| 378 new RGBToYUVEffect(std::move(rgbFP), colorSpace, RGBToYUVEffect::kUV_Out
putChannels)); |
376 } | 379 } |
377 | 380 |
378 const GrFragmentProcessor* | 381 sk_sp<GrFragmentProcessor> |
379 GrYUVEffect::CreateRGBToU(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { | 382 GrYUVEffect::MakeRGBToU(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace colorS
pace) { |
380 SkASSERT(rgbFP); | 383 SkASSERT(rgbFP); |
381 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kU_OutputChanne
ls); | 384 return sk_sp<GrFragmentProcessor>( |
| 385 new RGBToYUVEffect(std::move(rgbFP), colorSpace, RGBToYUVEffect::kU_Outp
utChannels)); |
382 } | 386 } |
383 | 387 |
384 const GrFragmentProcessor* | 388 sk_sp<GrFragmentProcessor> |
385 GrYUVEffect::CreateRGBToV(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { | 389 GrYUVEffect::MakeRGBToV(sk_sp<GrFragmentProcessor> rgbFP, SkYUVColorSpace colorS
pace) { |
386 SkASSERT(rgbFP); | 390 SkASSERT(rgbFP); |
387 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kV_OutputChanne
ls); | 391 return sk_sp<GrFragmentProcessor>( |
| 392 new RGBToYUVEffect(std::move(rgbFP), colorSpace, RGBToYUVEffect::kV_Outp
utChannels)); |
388 } | 393 } |
OLD | NEW |