1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | let imagePasses = [
|
15 | {
|
16 |
|
17 | x: [0],
|
18 | y: [0],
|
19 | },
|
20 | {
|
21 |
|
22 | x: [4],
|
23 | y: [0],
|
24 | },
|
25 | {
|
26 |
|
27 | x: [0, 4],
|
28 | y: [4],
|
29 | },
|
30 | {
|
31 |
|
32 | x: [2, 6],
|
33 | y: [0, 4],
|
34 | },
|
35 | {
|
36 |
|
37 | x: [0, 2, 4, 6],
|
38 | y: [2, 6],
|
39 | },
|
40 | {
|
41 |
|
42 | x: [1, 3, 5, 7],
|
43 | y: [0, 2, 4, 6],
|
44 | },
|
45 | {
|
46 |
|
47 | x: [0, 1, 2, 3, 4, 5, 6, 7],
|
48 | y: [1, 3, 5, 7],
|
49 | },
|
50 | ];
|
51 |
|
52 | exports.getImagePasses = function (width, height) {
|
53 | let images = [];
|
54 | let xLeftOver = width % 8;
|
55 | let yLeftOver = height % 8;
|
56 | let xRepeats = (width - xLeftOver) / 8;
|
57 | let yRepeats = (height - yLeftOver) / 8;
|
58 | for (let i = 0; i < imagePasses.length; i++) {
|
59 | let pass = imagePasses[i];
|
60 | let passWidth = xRepeats * pass.x.length;
|
61 | let passHeight = yRepeats * pass.y.length;
|
62 | for (let j = 0; j < pass.x.length; j++) {
|
63 | if (pass.x[j] < xLeftOver) {
|
64 | passWidth++;
|
65 | } else {
|
66 | break;
|
67 | }
|
68 | }
|
69 | for (let j = 0; j < pass.y.length; j++) {
|
70 | if (pass.y[j] < yLeftOver) {
|
71 | passHeight++;
|
72 | } else {
|
73 | break;
|
74 | }
|
75 | }
|
76 | if (passWidth > 0 && passHeight > 0) {
|
77 | images.push({ width: passWidth, height: passHeight, index: i });
|
78 | }
|
79 | }
|
80 | return images;
|
81 | };
|
82 |
|
83 | exports.getInterlaceIterator = function (width) {
|
84 | return function (x, y, pass) {
|
85 | let outerXLeftOver = x % imagePasses[pass].x.length;
|
86 | let outerX =
|
87 | ((x - outerXLeftOver) / imagePasses[pass].x.length) * 8 +
|
88 | imagePasses[pass].x[outerXLeftOver];
|
89 | let outerYLeftOver = y % imagePasses[pass].y.length;
|
90 | let outerY =
|
91 | ((y - outerYLeftOver) / imagePasses[pass].y.length) * 8 +
|
92 | imagePasses[pass].y[outerYLeftOver];
|
93 | return outerX * 4 + outerY * width * 4;
|
94 | };
|
95 | };
|