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

Side by Side Diff: conformance/more/demos/video.html

Issue 41503006: Add ToT WebGL conformance tests : part 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « conformance/more/demos/opengl_web.html ('k') | conformance/more/functions/bindBuffer.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <!--
6
7 /*
8 ** Copyright (c) 2012 The Khronos Group Inc.
9 **
10 ** Permission is hereby granted, free of charge, to any person obtaining a
11 ** copy of this software and/or associated documentation files (the
12 ** "Materials"), to deal in the Materials without restriction, including
13 ** without limitation the rights to use, copy, modify, merge, publish,
14 ** distribute, sublicense, and/or sell copies of the Materials, and to
15 ** permit persons to whom the Materials are furnished to do so, subject to
16 ** the following conditions:
17 **
18 ** The above copyright notice and this permission notice shall be included
19 ** in all copies or substantial portions of the Materials.
20 **
21 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
28 */
29
30 -->
31 <script type="application/x-javascript" src="../util.js"></script>
32 <script>
33 "use strict";
34 var processor = {
35 lastTime : new Date,
36 timerCallback: function() {
37 if (this.video.paused || this.video.ended) {
38 return;
39 }
40 this.computeFrame();
41 var t = new Date;
42 var elapsed = t - this.lastTime;
43 this.lastTime = t;
44 var self = this;
45 setTimeout(function () {
46 self.timerCallback();
47 }, Math.max(0, 33-elapsed));
48 },
49
50 init: function() {
51 if (this.initDone) return;
52 this.c2 = document.getElementById("c2");
53 this.ctx2 = getGLContext(this.c2);
54 this.greenScreen = new Filter(this.ctx2, 'identity-flip-vert', 'greenScreen' );
55 this.ctx2.activeTexture(this.ctx2.TEXTURE0);
56 this.tex = loadTexture(this.ctx2, this.c1, false);
57 this.ctx2.activeTexture(this.ctx2.TEXTURE1);
58 this.tex2 = loadTexture(this.ctx2, document.getElementById('i'), false);
59 this.ctx2.activeTexture(this.ctx2.TEXTURE0);
60 this.initDone = true;
61 },
62
63 doLoad: function() {
64 this.video = document.getElementById("video");
65 this.c1 = document.getElementById("c1");
66 this.ctx1 = this.c1.getContext("2d");
67 this.ctx1.globalCompositeOperation = 'copy';
68 this.ctx1.fillRect(0,0,this.c1.width, this.c1.height);
69 var self = this;
70 this.video.addEventListener("play", function() {
71 self.init();
72 self.width = self.video.videoWidth;
73 self.height = self.video.videoHeight;
74 self.lastTime = new Date;
75 self.timerCallback();
76 }, false);
77 },
78
79 computeFrame: function() {
80 // this.ctx1.drawImage(this.video, 0, 0, this.width, this.height);
81 this.ctx2.texImage2D(this.ctx2.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_ BYTE, this.video);
82 this.greenScreen.apply(function(s) {
83 s.uniform1i('Texture', 0);
84 s.uniform1i('Texture2', 1);
85 });
86
87 return;
88 }
89 };
90
91 </script>
92 <script id="identity-flip-vert" type="x-shader/x-vertex">
93 attribute vec3 Vertex;
94 attribute vec2 Tex;
95
96 varying vec4 texCoord0;
97 void main()
98 {
99 texCoord0 = vec4(Tex.s,1.0-Tex.t,0.0,0.0);
100 gl_Position = vec4(Vertex, 1.0);
101 }
102 </script>
103 <script id="greenScreen" type="x-shader/x-fragment">
104 precision mediump float;
105
106 uniform sampler2D Texture;
107 uniform sampler2D Texture2;
108
109 varying vec4 texCoord0;
110 void main()
111 {
112 vec4 c = texture2D(Texture, texCoord0.st);
113 float r = c.r * 0.5;
114 float a = c.g * 6.28;
115 float x = cos(a) * r;
116 float y = sin(a) * r;
117 vec4 c2 = texture2D(Texture2, vec2(0.7+x, 0.5+y));
118 // Shaders with branches are not allowed when dealing with non-SOP conte nt
119 // so instead of "if (b) c2.a = 0;", we use mix()
120 bool b = (c.g > 120.0/255.0 && c.r > 120.0/255.0 && c.b < 50.0/255.0);
121 c2.a = mix(c2.a, 0.0, float(b));
122 gl_FragColor = c2;
123 }
124 </script>
125 <style>
126 body {
127 background: black;
128 color:#CCCCCC;
129 }
130 a {
131 color: white;
132 }
133 #c2 {
134 background-image: url(http://www.mozbox.org/pub/green/foo.png);
135 background-repeat: repeat;
136 }
137 div {
138 float: left;
139 border :1px solid #444444;
140 padding:10px;
141 margin: 10px;
142 background:#3B3B3B;
143 }
144 img { display: none; }
145 </style>
146 </head>
147 <body onload="processor.doLoad()">
148 <div>
149 This is a port of Paul Rouget's <a href="http://blog.mozbox.org/post/200 9/02/25/video-canvas%3A-special-effects">Canvas+Video green screen demo</a>, plu s a texture lookup from the Firefox logo based on the values of the green and re d color channels.
150 </div>
151 <div>
152 <video id="video" controls="true">
153 <source src="http://www.mozbox.org/pub/green/video.ogv"></source>
154 <source src="http://cs.helsinki.fi/u/ilmarihe/c3d/demos/video.mp4"></sou rce>
155 </video>
156 <canvas id="c1" width="320" height="192"></canvas>
157 </div>
158 <div>
159 <canvas id="c2" width="640" height="384"></canvas>
160 </div>
161 <img id="i" src="http://www.mozbox.org/pub/green/foo.png">
162 </body>
163 </html>
OLDNEW
« no previous file with comments | « conformance/more/demos/opengl_web.html ('k') | conformance/more/functions/bindBuffer.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698