PageRenderTime 62ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

/H264Dec/paint_2.js

http://github.com/mbebenita/Broadway
JavaScript | 51 lines | 47 code | 4 blank | 0 comment | 4 complexity | 95024aab4f9b0120e5f68c0bf70ccb0c MD5 | raw file
 1function getSurface() {
 2  var surface = SDL.surfaces[SDL.screen];
 3  if (!surface.image) {
 4    surface.image = surface.ctx.getImageData(0, 0, surface.width, surface.height);
 5    var data = surface.image.data;
 6    var num = data.length;
 7    for (var i = 0; i < num/4; i++) {
 8      data[i*4+3] = 255; // opacity, as canvases blend alpha
 9    }
10  }
11  return surface;
12}
13
14Module['paint'] = function ($luma, $cb, $cr, w, h) {
15  for (var y1,y2,u,v,ruv,guv,buv,j,w_2=w>>1,W=w*4, surface = getSurface(), d=surface.image.data, r=0; h-=2;) {
16    for (j=w_2; j--;) {
17      u = HEAPU8[$cr++];
18      v = HEAPU8[$cb++];
19      ruv = 409*u-56992;
20      guv = 34784-208*u-100*v;
21      buv = 516*v-70688;
22
23      y2 = HEAPU8[$luma+w]*298;
24      y1 = HEAPU8[$luma++]*298;
25      d[r+W] = y2+ruv>>8;
26      d[r++] = y1+ruv>>8;
27      d[r+W] = y2+guv>>8;
28      d[r++] = y1+guv>>8;
29      d[r+W] = y2+buv>>8;
30      d[r++] = y1+buv>>8;
31      r++;
32
33      y2 = HEAPU8[$luma+w]*298;
34      y1 = HEAPU8[$luma++]*298;
35      d[r+W] = y2+ruv>>8;
36      d[r++] = y1+ruv>>8;
37      d[r+W] = y2+guv>>8;
38      d[r++] = y1+guv>>8;
39      d[r+W] = y2+buv>>8;
40      d[r++] = y1+buv>>8;
41      r++;
42    }
43    r+=W;
44    $luma+=w;
45  }
46  surface.ctx.putImageData(surface.image, 0, 0 );
47}
48
49_paint = function ($luma, $cb, $cr, w, h) {
50  Module['paint'] ($luma, $cb, $cr, w, h);
51}