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