Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

707 строки
21 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: stackblur.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: stackblur.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * StackBlur - a fast almost Gaussian Blur For Canvas
  21. *
  22. * In case you find this class useful - especially in commercial projects -
  23. * I am not totally unhappy for a small donation to my PayPal account
  24. * mario@quasimondo.de
  25. *
  26. * Or support me on flattr:
  27. * {@link https://flattr.com/thing/72791/StackBlur-a-fast-almost-Gaussian-Blur-Effect-for-CanvasJavascript}
  28. * @module StackBlur
  29. * @version 0.5
  30. * @author Mario Klingemann
  31. * Contact: mario@quasimondo.com
  32. * Website: {@link http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html}
  33. * Twitter: @quasimondo
  34. *
  35. * @copyright (c) 2010 Mario Klingemann
  36. *
  37. * Permission is hereby granted, free of charge, to any person
  38. * obtaining a copy of this software and associated documentation
  39. * files (the "Software"), to deal in the Software without
  40. * restriction, including without limitation the rights to use,
  41. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  42. * copies of the Software, and to permit persons to whom the
  43. * Software is furnished to do so, subject to the following
  44. * conditions:
  45. *
  46. * The above copyright notice and this permission notice shall be
  47. * included in all copies or substantial portions of the Software.
  48. *
  49. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  50. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  51. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  52. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  53. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  54. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  55. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  56. * OTHER DEALINGS IN THE SOFTWARE.
  57. */
  58. const mulTable = [
  59. 512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 512,
  60. 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292, 273, 512,
  61. 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259, 496, 475, 456,
  62. 437, 420, 404, 388, 374, 360, 347, 335, 323, 312, 302, 292, 282, 273, 265, 512,
  63. 497, 482, 468, 454, 441, 428, 417, 405, 394, 383, 373, 364, 354, 345, 337, 328,
  64. 320, 312, 305, 298, 291, 284, 278, 271, 265, 259, 507, 496, 485, 475, 465, 456,
  65. 446, 437, 428, 420, 412, 404, 396, 388, 381, 374, 367, 360, 354, 347, 341, 335,
  66. 329, 323, 318, 312, 307, 302, 297, 292, 287, 282, 278, 273, 269, 265, 261, 512,
  67. 505, 497, 489, 482, 475, 468, 461, 454, 447, 441, 435, 428, 422, 417, 411, 405,
  68. 399, 394, 389, 383, 378, 373, 368, 364, 359, 354, 350, 345, 341, 337, 332, 328,
  69. 324, 320, 316, 312, 309, 305, 301, 298, 294, 291, 287, 284, 281, 278, 274, 271,
  70. 268, 265, 262, 259, 257, 507, 501, 496, 491, 485, 480, 475, 470, 465, 460, 456,
  71. 451, 446, 442, 437, 433, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 388,
  72. 385, 381, 377, 374, 370, 367, 363, 360, 357, 354, 350, 347, 344, 341, 338, 335,
  73. 332, 329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292,
  74. 289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259];
  75. const shgTable = [
  76. 9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17,
  77. 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19,
  78. 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20,
  79. 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
  80. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
  81. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22,
  82. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
  83. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23,
  84. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  85. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  86. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  87. 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  88. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  89. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  90. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  91. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24];
  92. /**
  93. * @param {string|HTMLImageElement} img
  94. * @param {string|HTMLCanvasElement} canvas
  95. * @param {Float} radius
  96. * @param {boolean} blurAlphaChannel
  97. * @returns {undefined}
  98. */
  99. function processImage (img, canvas, radius, blurAlphaChannel) {
  100. if (typeof img === 'string') {
  101. img = document.getElementById(img);
  102. }
  103. if (!img || !('naturalWidth' in img)) {
  104. return;
  105. }
  106. const w = img.naturalWidth;
  107. const h = img.naturalHeight;
  108. if (typeof canvas === 'string') {
  109. canvas = document.getElementById(canvas);
  110. }
  111. if (!canvas || !('getContext' in canvas)) {
  112. return;
  113. }
  114. canvas.style.width = w + 'px';
  115. canvas.style.height = h + 'px';
  116. canvas.width = w;
  117. canvas.height = h;
  118. const context = canvas.getContext('2d');
  119. context.clearRect(0, 0, w, h);
  120. context.drawImage(img, 0, 0);
  121. if (isNaN(radius) || radius &lt; 1) { return; }
  122. if (blurAlphaChannel) {
  123. processCanvasRGBA(canvas, 0, 0, w, h, radius);
  124. } else {
  125. processCanvasRGB(canvas, 0, 0, w, h, radius);
  126. }
  127. }
  128. /**
  129. * @param {string|HTMLCanvasElement} canvas
  130. * @param {Integer} topX
  131. * @param {Integer} topY
  132. * @param {Integer} width
  133. * @param {Integer} height
  134. * @throws {Error|TypeError}
  135. * @returns {ImageData} See {@link https://html.spec.whatwg.org/multipage/canvas.html#imagedata}
  136. */
  137. function getImageDataFromCanvas (canvas, topX, topY, width, height) {
  138. if (typeof canvas === 'string') {
  139. canvas = document.getElementById(canvas);
  140. }
  141. if (!canvas || typeof canvas !== 'object' || !('getContext' in canvas)) {
  142. throw new TypeError('Expecting canvas with `getContext` method in processCanvasRGB(A) calls!');
  143. }
  144. const context = canvas.getContext('2d');
  145. try {
  146. return context.getImageData(topX, topY, width, height);
  147. } catch (e) {
  148. throw new Error('unable to access image data: ' + e);
  149. }
  150. }
  151. /**
  152. * @param {HTMLCanvasElement} canvas
  153. * @param {Integer} topX
  154. * @param {Integer} topY
  155. * @param {Integer} width
  156. * @param {Integer} height
  157. * @param {Float} radius
  158. * @returns {undefined}
  159. */
  160. function processCanvasRGBA (canvas, topX, topY, width, height, radius) {
  161. if (isNaN(radius) || radius &lt; 1) { return; }
  162. radius |= 0;
  163. let imageData = getImageDataFromCanvas(canvas, topX, topY, width, height);
  164. imageData = processImageDataRGBA(imageData, topX, topY, width, height, radius);
  165. canvas.getContext('2d').putImageData(imageData, topX, topY);
  166. }
  167. /**
  168. * @param {ImageData} imageData
  169. * @param {Integer} topX
  170. * @param {Integer} topY
  171. * @param {Integer} width
  172. * @param {Integer} height
  173. * @param {Float} radius
  174. * @returns {ImageData}
  175. */
  176. function processImageDataRGBA (imageData, topX, topY, width, height, radius) {
  177. const pixels = imageData.data;
  178. let x, y, i, p, yp, yi, yw, rSum, gSum, bSum, aSum,
  179. rOutSum, gOutSum, bOutSum, aOutSum,
  180. rInSum, gInSum, bInSum, aInSum,
  181. pr, pg, pb, pa, rbs;
  182. const div = 2 * radius + 1;
  183. // const w4 = width &lt;&lt; 2;
  184. const widthMinus1 = width - 1;
  185. const heightMinus1 = height - 1;
  186. const radiusPlus1 = radius + 1;
  187. const sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2;
  188. const stackStart = new BlurStack();
  189. let stack = stackStart;
  190. let stackEnd;
  191. for (i = 1; i &lt; div; i++) {
  192. stack = stack.next = new BlurStack();
  193. if (i === radiusPlus1) {
  194. stackEnd = stack;
  195. }
  196. }
  197. stack.next = stackStart;
  198. let stackIn = null;
  199. let stackOut = null;
  200. yw = yi = 0;
  201. const mulSum = mulTable[radius];
  202. const shgSum = shgTable[radius];
  203. for (y = 0; y &lt; height; y++) {
  204. rInSum = gInSum = bInSum = aInSum = rSum = gSum = bSum = aSum = 0;
  205. rOutSum = radiusPlus1 * (pr = pixels[yi]);
  206. gOutSum = radiusPlus1 * (pg = pixels[yi + 1]);
  207. bOutSum = radiusPlus1 * (pb = pixels[yi + 2]);
  208. aOutSum = radiusPlus1 * (pa = pixels[yi + 3]);
  209. rSum += sumFactor * pr;
  210. gSum += sumFactor * pg;
  211. bSum += sumFactor * pb;
  212. aSum += sumFactor * pa;
  213. stack = stackStart;
  214. for (i = 0; i &lt; radiusPlus1; i++) {
  215. stack.r = pr;
  216. stack.g = pg;
  217. stack.b = pb;
  218. stack.a = pa;
  219. stack = stack.next;
  220. }
  221. for (i = 1; i &lt; radiusPlus1; i++) {
  222. p = yi + ((widthMinus1 &lt; i ? widthMinus1 : i) &lt;&lt; 2);
  223. rSum += (stack.r = (pr = pixels[p])) * (rbs = radiusPlus1 - i);
  224. gSum += (stack.g = (pg = pixels[p + 1])) * rbs;
  225. bSum += (stack.b = (pb = pixels[p + 2])) * rbs;
  226. aSum += (stack.a = (pa = pixels[p + 3])) * rbs;
  227. rInSum += pr;
  228. gInSum += pg;
  229. bInSum += pb;
  230. aInSum += pa;
  231. stack = stack.next;
  232. }
  233. stackIn = stackStart;
  234. stackOut = stackEnd;
  235. for (x = 0; x &lt; width; x++) {
  236. pixels[yi + 3] = pa = (aSum * mulSum) >> shgSum;
  237. if (pa !== 0) {
  238. pa = 255 / pa;
  239. pixels[yi] = ((rSum * mulSum) >> shgSum) * pa;
  240. pixels[yi + 1] = ((gSum * mulSum) >> shgSum) * pa;
  241. pixels[yi + 2] = ((bSum * mulSum) >> shgSum) * pa;
  242. } else {
  243. pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0;
  244. }
  245. rSum -= rOutSum;
  246. gSum -= gOutSum;
  247. bSum -= bOutSum;
  248. aSum -= aOutSum;
  249. rOutSum -= stackIn.r;
  250. gOutSum -= stackIn.g;
  251. bOutSum -= stackIn.b;
  252. aOutSum -= stackIn.a;
  253. p = (yw + ((p = x + radius + 1) &lt; widthMinus1 ? p : widthMinus1)) &lt;&lt; 2;
  254. rInSum += (stackIn.r = pixels[p]);
  255. gInSum += (stackIn.g = pixels[p + 1]);
  256. bInSum += (stackIn.b = pixels[p + 2]);
  257. aInSum += (stackIn.a = pixels[p + 3]);
  258. rSum += rInSum;
  259. gSum += gInSum;
  260. bSum += bInSum;
  261. aSum += aInSum;
  262. stackIn = stackIn.next;
  263. rOutSum += (pr = stackOut.r);
  264. gOutSum += (pg = stackOut.g);
  265. bOutSum += (pb = stackOut.b);
  266. aOutSum += (pa = stackOut.a);
  267. rInSum -= pr;
  268. gInSum -= pg;
  269. bInSum -= pb;
  270. aInSum -= pa;
  271. stackOut = stackOut.next;
  272. yi += 4;
  273. }
  274. yw += width;
  275. }
  276. for (x = 0; x &lt; width; x++) {
  277. gInSum = bInSum = aInSum = rInSum = gSum = bSum = aSum = rSum = 0;
  278. yi = x &lt;&lt; 2;
  279. rOutSum = radiusPlus1 * (pr = pixels[yi]);
  280. gOutSum = radiusPlus1 * (pg = pixels[yi + 1]);
  281. bOutSum = radiusPlus1 * (pb = pixels[yi + 2]);
  282. aOutSum = radiusPlus1 * (pa = pixels[yi + 3]);
  283. rSum += sumFactor * pr;
  284. gSum += sumFactor * pg;
  285. bSum += sumFactor * pb;
  286. aSum += sumFactor * pa;
  287. stack = stackStart;
  288. for (i = 0; i &lt; radiusPlus1; i++) {
  289. stack.r = pr;
  290. stack.g = pg;
  291. stack.b = pb;
  292. stack.a = pa;
  293. stack = stack.next;
  294. }
  295. yp = width;
  296. for (i = 1; i &lt;= radius; i++) {
  297. yi = (yp + x) &lt;&lt; 2;
  298. rSum += (stack.r = (pr = pixels[yi])) * (rbs = radiusPlus1 - i);
  299. gSum += (stack.g = (pg = pixels[yi + 1])) * rbs;
  300. bSum += (stack.b = (pb = pixels[yi + 2])) * rbs;
  301. aSum += (stack.a = (pa = pixels[yi + 3])) * rbs;
  302. rInSum += pr;
  303. gInSum += pg;
  304. bInSum += pb;
  305. aInSum += pa;
  306. stack = stack.next;
  307. if (i &lt; heightMinus1) {
  308. yp += width;
  309. }
  310. }
  311. yi = x;
  312. stackIn = stackStart;
  313. stackOut = stackEnd;
  314. for (y = 0; y &lt; height; y++) {
  315. p = yi &lt;&lt; 2;
  316. pixels[p + 3] = pa = (aSum * mulSum) >> shgSum;
  317. if (pa > 0) {
  318. pa = 255 / pa;
  319. pixels[p] = ((rSum * mulSum) >> shgSum) * pa;
  320. pixels[p + 1] = ((gSum * mulSum) >> shgSum) * pa;
  321. pixels[p + 2] = ((bSum * mulSum) >> shgSum) * pa;
  322. } else {
  323. pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
  324. }
  325. rSum -= rOutSum;
  326. gSum -= gOutSum;
  327. bSum -= bOutSum;
  328. aSum -= aOutSum;
  329. rOutSum -= stackIn.r;
  330. gOutSum -= stackIn.g;
  331. bOutSum -= stackIn.b;
  332. aOutSum -= stackIn.a;
  333. p = (x + (((p = y + radiusPlus1) &lt; heightMinus1 ? p : heightMinus1) * width)) &lt;&lt; 2;
  334. rSum += (rInSum += (stackIn.r = pixels[p]));
  335. gSum += (gInSum += (stackIn.g = pixels[p + 1]));
  336. bSum += (bInSum += (stackIn.b = pixels[p + 2]));
  337. aSum += (aInSum += (stackIn.a = pixels[p + 3]));
  338. stackIn = stackIn.next;
  339. rOutSum += (pr = stackOut.r);
  340. gOutSum += (pg = stackOut.g);
  341. bOutSum += (pb = stackOut.b);
  342. aOutSum += (pa = stackOut.a);
  343. rInSum -= pr;
  344. gInSum -= pg;
  345. bInSum -= pb;
  346. aInSum -= pa;
  347. stackOut = stackOut.next;
  348. yi += width;
  349. }
  350. }
  351. return imageData;
  352. }
  353. /**
  354. * @param {HTMLCanvasElement} canvas
  355. * @param {Integer} topX
  356. * @param {Integer} topY
  357. * @param {Integer} width
  358. * @param {Integer} height
  359. * @param {Float} radius
  360. * @returns {undefined}
  361. */
  362. function processCanvasRGB (canvas, topX, topY, width, height, radius) {
  363. if (isNaN(radius) || radius &lt; 1) { return; }
  364. radius |= 0;
  365. let imageData = getImageDataFromCanvas(canvas, topX, topY, width, height);
  366. imageData = processImageDataRGB(imageData, topX, topY, width, height, radius);
  367. canvas.getContext('2d').putImageData(imageData, topX, topY);
  368. }
  369. /**
  370. * @param {ImageData} imageData
  371. * @param {Integer} topX
  372. * @param {Integer} topY
  373. * @param {Integer} width
  374. * @param {Integer} height
  375. * @param {Float} radius
  376. * @returns {ImageData}
  377. */
  378. function processImageDataRGB (imageData, topX, topY, width, height, radius) {
  379. const pixels = imageData.data;
  380. let x, y, i, p, yp, yi, yw, rSum, gSum, bSum,
  381. rOutSum, gOutSum, bOutSum,
  382. rInSum, gInSum, bInSum,
  383. pr, pg, pb, rbs;
  384. const div = 2 * radius + 1;
  385. // const w4 = width &lt;&lt; 2;
  386. const widthMinus1 = width - 1;
  387. const heightMinus1 = height - 1;
  388. const radiusPlus1 = radius + 1;
  389. const sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2;
  390. const stackStart = new BlurStack();
  391. let stack = stackStart;
  392. let stackEnd;
  393. for (i = 1; i &lt; div; i++) {
  394. stack = stack.next = new BlurStack();
  395. if (i === radiusPlus1) {
  396. stackEnd = stack;
  397. }
  398. }
  399. stack.next = stackStart;
  400. let stackIn = null;
  401. let stackOut = null;
  402. yw = yi = 0;
  403. const mulSum = mulTable[radius];
  404. const shgSum = shgTable[radius];
  405. for (y = 0; y &lt; height; y++) {
  406. rInSum = gInSum = bInSum = rSum = gSum = bSum = 0;
  407. rOutSum = radiusPlus1 * (pr = pixels[yi]);
  408. gOutSum = radiusPlus1 * (pg = pixels[yi + 1]);
  409. bOutSum = radiusPlus1 * (pb = pixels[yi + 2]);
  410. rSum += sumFactor * pr;
  411. gSum += sumFactor * pg;
  412. bSum += sumFactor * pb;
  413. stack = stackStart;
  414. for (i = 0; i &lt; radiusPlus1; i++) {
  415. stack.r = pr;
  416. stack.g = pg;
  417. stack.b = pb;
  418. stack = stack.next;
  419. }
  420. for (i = 1; i &lt; radiusPlus1; i++) {
  421. p = yi + ((widthMinus1 &lt; i ? widthMinus1 : i) &lt;&lt; 2);
  422. rSum += (stack.r = (pr = pixels[p])) * (rbs = radiusPlus1 - i);
  423. gSum += (stack.g = (pg = pixels[p + 1])) * rbs;
  424. bSum += (stack.b = (pb = pixels[p + 2])) * rbs;
  425. rInSum += pr;
  426. gInSum += pg;
  427. bInSum += pb;
  428. stack = stack.next;
  429. }
  430. stackIn = stackStart;
  431. stackOut = stackEnd;
  432. for (x = 0; x &lt; width; x++) {
  433. pixels[yi] = (rSum * mulSum) >> shgSum;
  434. pixels[yi + 1] = (gSum * mulSum) >> shgSum;
  435. pixels[yi + 2] = (bSum * mulSum) >> shgSum;
  436. rSum -= rOutSum;
  437. gSum -= gOutSum;
  438. bSum -= bOutSum;
  439. rOutSum -= stackIn.r;
  440. gOutSum -= stackIn.g;
  441. bOutSum -= stackIn.b;
  442. p = (yw + ((p = x + radius + 1) &lt; widthMinus1 ? p : widthMinus1)) &lt;&lt; 2;
  443. rInSum += (stackIn.r = pixels[p]);
  444. gInSum += (stackIn.g = pixels[p + 1]);
  445. bInSum += (stackIn.b = pixels[p + 2]);
  446. rSum += rInSum;
  447. gSum += gInSum;
  448. bSum += bInSum;
  449. stackIn = stackIn.next;
  450. rOutSum += (pr = stackOut.r);
  451. gOutSum += (pg = stackOut.g);
  452. bOutSum += (pb = stackOut.b);
  453. rInSum -= pr;
  454. gInSum -= pg;
  455. bInSum -= pb;
  456. stackOut = stackOut.next;
  457. yi += 4;
  458. }
  459. yw += width;
  460. }
  461. for (x = 0; x &lt; width; x++) {
  462. gInSum = bInSum = rInSum = gSum = bSum = rSum = 0;
  463. yi = x &lt;&lt; 2;
  464. rOutSum = radiusPlus1 * (pr = pixels[yi]);
  465. gOutSum = radiusPlus1 * (pg = pixels[yi + 1]);
  466. bOutSum = radiusPlus1 * (pb = pixels[yi + 2]);
  467. rSum += sumFactor * pr;
  468. gSum += sumFactor * pg;
  469. bSum += sumFactor * pb;
  470. stack = stackStart;
  471. for (i = 0; i &lt; radiusPlus1; i++) {
  472. stack.r = pr;
  473. stack.g = pg;
  474. stack.b = pb;
  475. stack = stack.next;
  476. }
  477. yp = width;
  478. for (i = 1; i &lt;= radius; i++) {
  479. yi = (yp + x) &lt;&lt; 2;
  480. rSum += (stack.r = (pr = pixels[yi])) * (rbs = radiusPlus1 - i);
  481. gSum += (stack.g = (pg = pixels[yi + 1])) * rbs;
  482. bSum += (stack.b = (pb = pixels[yi + 2])) * rbs;
  483. rInSum += pr;
  484. gInSum += pg;
  485. bInSum += pb;
  486. stack = stack.next;
  487. if (i &lt; heightMinus1) {
  488. yp += width;
  489. }
  490. }
  491. yi = x;
  492. stackIn = stackStart;
  493. stackOut = stackEnd;
  494. for (y = 0; y &lt; height; y++) {
  495. p = yi &lt;&lt; 2;
  496. pixels[p] = (rSum * mulSum) >> shgSum;
  497. pixels[p + 1] = (gSum * mulSum) >> shgSum;
  498. pixels[p + 2] = (bSum * mulSum) >> shgSum;
  499. rSum -= rOutSum;
  500. gSum -= gOutSum;
  501. bSum -= bOutSum;
  502. rOutSum -= stackIn.r;
  503. gOutSum -= stackIn.g;
  504. bOutSum -= stackIn.b;
  505. p = (x + (((p = y + radiusPlus1) &lt; heightMinus1 ? p : heightMinus1) * width)) &lt;&lt; 2;
  506. rSum += (rInSum += (stackIn.r = pixels[p]));
  507. gSum += (gInSum += (stackIn.g = pixels[p + 1]));
  508. bSum += (bInSum += (stackIn.b = pixels[p + 2]));
  509. stackIn = stackIn.next;
  510. rOutSum += (pr = stackOut.r);
  511. gOutSum += (pg = stackOut.g);
  512. bOutSum += (pb = stackOut.b);
  513. rInSum -= pr;
  514. gInSum -= pg;
  515. bInSum -= pb;
  516. stackOut = stackOut.next;
  517. yi += width;
  518. }
  519. }
  520. return imageData;
  521. }
  522. /**
  523. *
  524. */
  525. export class BlurStack {
  526. constructor () {
  527. this.r = 0;
  528. this.g = 0;
  529. this.b = 0;
  530. this.a = 0;
  531. this.next = null;
  532. }
  533. }
  534. export {
  535. /**
  536. * @function module:StackBlur.image
  537. * @see module:StackBlur~processImage
  538. */
  539. processImage as image,
  540. /**
  541. * @function module:StackBlur.canvasRGBA
  542. * @see module:StackBlur~processCanvasRGBA
  543. */
  544. processCanvasRGBA as canvasRGBA,
  545. /**
  546. * @function module:StackBlur.canvasRGB
  547. * @see module:StackBlur~processCanvasRGB
  548. */
  549. processCanvasRGB as canvasRGB,
  550. /**
  551. * @function module:StackBlur.imageDataRGBA
  552. * @see module:StackBlur~processImageDataRGBA
  553. */
  554. processImageDataRGBA as imageDataRGBA,
  555. /**
  556. * @function module:StackBlur.imageDataRGB
  557. * @see module:StackBlur~processImageDataRGB
  558. */
  559. processImageDataRGB as imageDataRGB
  560. };
  561. </code></pre>
  562. </article>
  563. </section>
  564. </div>
  565. <nav>
  566. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-StackBlur.html">StackBlur</a></li></ul><h3>Classes</h3><ul><li><a href="module-StackBlur.BlurStack.html">BlurStack</a></li></ul>
  567. </nav>
  568. <br class="clear">
  569. <footer>
  570. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Dec 13 2018 09:27:19 GMT+0800 (China Standard Time)
  571. </footer>
  572. <script> prettyPrint(); </script>
  573. <script src="scripts/linenumber.js"> </script>
  574. </body>
  575. </html>