Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: src/gpu/effects/GrYUVtoRGBEffect.cpp

Issue 378503006: YUV to RGB converter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrYUVtoRGBEffect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrYUVtoRGBEffect.h"
9
10 #include "GrCoordTransform.h"
11 #include "GrEffect.h"
12 #include "gl/GrGLEffect.h"
13 #include "GrTBackendEffectFactory.h"
14
15 class YUVtoRGBEffect : public GrEffect {
Stephen White 2014/07/07 17:57:06 Since this doesn't have the Sk or Gr prefix, perha
sugoi1 2014/07/07 20:52:35 Done.
16 public:
17 static GrEffectRef* Create(GrTexture* yTexture, GrTexture* uTexture, GrTextu re* vTexture) {
18 AutoEffectUnref effect(SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, v Texture)));
19 return CreateEffectRef(effect);
20 }
21
22 static const char* Name() { return "YUV to RGB"; }
23
24 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
25 return GrTBackendEffectFactory<YUVtoRGBEffect>::getInstance();
26 }
27
28 virtual void getConstantColorComponents(GrColor* color,
29 uint32_t* validFlags) const SK_OVERR IDE {
30 // YUV is opaque
31 *validFlags = kA_GrColorComponentFlag;
bsalomon 2014/07/07 17:57:11 You have to assign a value to the "color" param's
sugoi1 2014/07/07 20:52:35 Done.
32 }
33
34 class GLEffect : public GrGLEffect {
35 public:
36 // this class always generates the same code.
37 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0 ; }
38
39 GLEffect(const GrBackendEffectFactory& factory,
40 const GrDrawEffect&)
41 : INHERITED(factory) {
42 }
43
44 virtual void emitCode(GrGLShaderBuilder* builder,
45 const GrDrawEffect&,
46 EffectKey,
47 const char* outputColor,
48 const char* inputColor,
49 const TransformedCoordsArray& coords,
50 const TextureSamplerArray& samplers) SK_OVERRIDE {
51 const char* yuvMatrix = "yuvMatrix";
52 builder->fsCodeAppendf("\tconst mat4 %s = mat4(1.0, 0.0, 1.402, -0.701,\n\t\t\t"
53 "1.0, -0.344, -0.714, 0.529,\n\t\t\t"
54 "1.0, 1.772, 0.0, -0.886,\n\t\t\t"
55 "0.0, 0.0, 0.0, 1.0);\n",
56 yuvMatrix);
57 builder->fsCodeAppendf("\t%s = vec4(\n\t\t", outputColor);
58 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coord s[0].type());
59 builder->fsCodeAppend(".r,\n\t\t");
60 builder->fsAppendTextureLookup(samplers[1], coords[0].c_str(), coord s[0].type());
61 builder->fsCodeAppend(".r,\n\t\t");
62 builder->fsAppendTextureLookup(samplers[2], coords[0].c_str(), coord s[0].type());
63 builder->fsCodeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix);
64 }
65
66 typedef GrGLEffect INHERITED;
67 };
68
69 private:
70 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture )
71 : fCoordTransform(kLocal_GrCoordSet, MakeDivByTextureWHMatrix(yTexture), yTe xture)
72 , fYAccess(yTexture)
73 , fUAccess(uTexture)
74 , fVAccess(vTexture) {
75 this->addCoordTransform(&fCoordTransform);
76 this->addTextureAccess(&fYAccess);
77 this->addTextureAccess(&fUAccess);
78 this->addTextureAccess(&fVAccess);
79 }
80
81 virtual bool onIsEqual(const GrEffect& sBase) const {
82 const YUVtoRGBEffect& s = CastEffect<YUVtoRGBEffect>(sBase);
83 return fYAccess.getTexture() == s.fYAccess.getTexture() &&
84 fUAccess.getTexture() == s.fUAccess.getTexture() &&
85 fVAccess.getTexture() == s.fVAccess.getTexture();
86 }
87
88 GrCoordTransform fCoordTransform;
89 GrTextureAccess fYAccess;
90 GrTextureAccess fUAccess;
91 GrTextureAccess fVAccess;
92
93 typedef GrEffect INHERITED;
94 };
95
96 //////////////////////////////////////////////////////////////////////////////
97
98 GrEffectRef* GrYUVtoRGBEffect::Create(GrTexture* yTexture,
99 GrTexture* uTexture,
100 GrTexture* vTexture) {
101 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture);
102 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrYUVtoRGBEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698