- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / third_party / kraken / hosted / explanations / desaturate.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4
5 <meta charset=utf8>
6
7 <!--
8  Copyright (C) 2007 Apple Inc.  All rights reserved.
9  Copyright (C) 2010 Mozilla Foundation
10
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions
13  are met:
14  1. Redistributions of source code must retain the above copyright
15     notice, this list of conditions and the following disclaimer.
16  2. Redistributions in binary form must reproduce the above copyright
17     notice, this list of conditions and the following disclaimer in the
18     documentation and/or other materials provided with the distribution.
19
20  THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
21  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
24  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
31 -->
32
33 <title>Kraken JavaScript Benchmark: Gaussian Blur</title>
34 <link rel="stylesheet" href="../kraken.css">
35 <script>
36
37 </script>
38 <style> #display { border: 5px solid rgb(0,0,50);}</style>
39 </head>
40
41 <body>
42 <div id="content">
43 <h2>Kraken JavaScript Benchmark: Desaturate</h2>
44 <div id="results">
45     <p>This benchmark <a href="http://en.wikipedia.org/wiki/Colorfulness">desaturates</a> a photo using code from <a href="http://www.pixastic.com/">Pixastic</a>.</p>
46     <p><small>Photo courtesy <a href="http://www.flickr.com/photos/katclay/4296523922/in/photostream/">Kat Clay</a> from Flickr</small>.</p>
47     <img id="image" src="squid.png" width="400" height="267">
48     <canvas id="canvas" width="400" height="267"></canvas>
49     <script>
50       /*
51        * Pixastic Lib - Desaturation filter - v0.1.1
52        * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
53        * License: [http://www.pixastic.com/lib/license.txt] (MPL 1.1)
54        */
55
56       var Pixastic = {};
57       Pixastic.Actions = {};
58       Pixastic.Actions.desaturate = {
59           process : function(params) {
60               var useAverage = !!(params.options.average && params.options.average != "false");
61               var data = params.data;
62               var rect = params.options.rect;
63               var w = rect.width;
64               var h = rect.height;
65
66               var p = w*h;
67               var pix = p*4, pix1, pix2;
68
69               if (useAverage) {
70                   while (p--) 
71                       data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]+data[pix1]+data[pix2])/3
72               } else {
73                   while (p--)
74                       data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]*0.3 + data[pix1]*0.59 + data[pix2]*0.11);
75               }
76               return true;
77           }
78       }
79
80       function desaturateTest() {
81         var results = document.getElementById('blur-result');
82         results.innerHTML = "Running test...";
83
84         window.setTimeout(function() {
85           var canvas = document.getElementById('canvas');
86           var ctx = canvas.getContext('2d');
87           var img = document.getElementById('image')
88           ctx.drawImage(img, 0, 0, img.width, img.height);
89
90           var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
91           var width = imgData.width, height = imgData.height;
92           var data = imgData.data;
93
94           var len = data.length;
95           var startTime = (new Date()).getTime();
96
97           var params = {
98               options: {
99                   rect: { width: width, height: height}
100               },
101               data: imgData.data
102           }
103           Pixastic.Actions.desaturate.process(params);
104
105           var finishTime = Date.now() - startTime;
106           for (var i = 0; i < data.length; i++) {
107               imgData.data[i] = data[i];
108           }
109           //imgData.data = data;
110           ctx.putImageData(imgData, 0, 0);
111           results.innerHTML = "Finished: " + finishTime + "ms";
112         }, 10);
113       }
114     </script>
115     <p><input type="button" value="Desaturate Test" onclick="desaturateTest();">&nbsp;<span id="blur-result"></span></p>
116 </div>
117 </div>
118 </body>
119 </html>