@@ -954,7 +954,7 @@ var JpxImage = (function JpxImageClosure() {
954
954
var magnitudeCorrection = reversible ? 0 : 0.5 ;
955
955
var k , n , nb ;
956
956
position = 0 ;
957
- // Do the interleaving of Section F.3.3 here, so we do not need
957
+ // Do the interleaving of Section F.3.3 here, so we do not need
958
958
// to copy later. LL level is not interleaved, just copied.
959
959
var interleave = (subband .type !== 'LL' );
960
960
for (j = 0 ; j < blockHeight ; j ++) {
@@ -1566,12 +1566,16 @@ var JpxImage = (function JpxImageClosure() {
1566
1566
var oneRowDown = width ;
1567
1567
var twoRowsDown = width * 2 ;
1568
1568
var threeRowsDown = width * 3 ;
1569
- for (var i0 = 0 ; i0 < height ; i0 += 4 ) {
1569
+ var iNext ;
1570
+ for (var i0 = 0 ; i0 < height ; i0 = iNext ) {
1571
+ iNext = Math .min (i0 + 4 , height );
1572
+ var indexBase = i0 * width ;
1573
+ var checkAllEmpty = i0 + 3 < height ;
1570
1574
for (var j = 0 ; j < width ; j ++) {
1571
- var index0 = i0 * width + j ;
1575
+ var index0 = indexBase + j ;
1572
1576
// using the property: labels[neighborsSignificance[index]] == 0
1573
1577
// when neighborsSignificance[index] == 0
1574
- var allEmpty = (i0 + 3 < height &&
1578
+ var allEmpty = (checkAllEmpty &&
1575
1579
processingFlags [index0 ] === 0 &&
1576
1580
processingFlags [index0 + oneRowDown ] === 0 &&
1577
1581
processingFlags [index0 + twoRowsDown ] === 0 &&
@@ -1581,7 +1585,7 @@ var JpxImage = (function JpxImageClosure() {
1581
1585
neighborsSignificance [index0 + twoRowsDown ] === 0 &&
1582
1586
neighborsSignificance [index0 + threeRowsDown ] === 0 );
1583
1587
var i1 = 0 , index = index0 ;
1584
- var i , sign ;
1588
+ var i = i0 , sign ;
1585
1589
if (allEmpty ) {
1586
1590
var hasSignificantCoefficent =
1587
1591
decoder .readBit (contexts , RUNLENGTH_CONTEXT );
@@ -1594,8 +1598,10 @@ var JpxImage = (function JpxImageClosure() {
1594
1598
}
1595
1599
i1 = (decoder .readBit (contexts , UNIFORM_CONTEXT ) << 1 ) |
1596
1600
decoder .readBit (contexts , UNIFORM_CONTEXT );
1597
- i = i0 + i1 ;
1598
- index += i1 * width ;
1601
+ if (i1 !== 0 ) {
1602
+ i = i0 + i1 ;
1603
+ index += i1 * width ;
1604
+ }
1599
1605
1600
1606
sign = this .decodeSignBit (i , j , index );
1601
1607
coefficentsSign [index ] = sign ;
@@ -1610,20 +1616,15 @@ var JpxImage = (function JpxImageClosure() {
1610
1616
1611
1617
i1 ++;
1612
1618
}
1613
- for (; i1 < 4 ; i1 ++, index += width ) {
1614
- i = i0 + i1 ;
1615
- if (i >= height ) {
1616
- break ;
1617
- }
1618
-
1619
+ for (i = i0 + i1 ; i < iNext ; i ++, index += width ) {
1619
1620
if (coefficentsMagnitude [index ] ||
1620
1621
(processingFlags [index ] & processedMask ) !== 0 ) {
1621
1622
continue ;
1622
1623
}
1623
1624
1624
1625
var contextLabel = labels [neighborsSignificance [index ]];
1625
1626
var decision = decoder .readBit (contexts , contextLabel );
1626
- if (decision == 1 ) {
1627
+ if (decision === 1 ) {
1627
1628
sign = this .decodeSignBit (i , j , index );
1628
1629
coefficentsSign [index ] = sign ;
1629
1630
coefficentsMagnitude [index ] = 1 ;
@@ -1678,7 +1679,6 @@ var JpxImage = (function JpxImageClosure() {
1678
1679
};
1679
1680
Transform .prototype .iterate = function Transform_iterate (ll , hl_lh_hh ,
1680
1681
u0 , v0 ) {
1681
-
1682
1682
var llWidth = ll .width , llHeight = ll .height , llItems = ll .items ;
1683
1683
var width = hl_lh_hh .width ;
1684
1684
var height = hl_lh_hh .height ;
@@ -1711,7 +1711,7 @@ var JpxImage = (function JpxImageClosure() {
1711
1711
rowBuffer .set (items .subarray (k , k + width ), bufferPadding );
1712
1712
1713
1713
this .extend (rowBuffer , bufferPadding , width );
1714
- this .filter (rowBuffer , bufferPadding , width , u0 , rowBuffer );
1714
+ this .filter (rowBuffer , bufferPadding , width );
1715
1715
1716
1716
items .set (
1717
1717
rowBuffer .subarray (bufferPadding , bufferPadding + width ),
@@ -1757,7 +1757,7 @@ var JpxImage = (function JpxImageClosure() {
1757
1757
currentBuffer --;
1758
1758
var buffer = colBuffers [currentBuffer ];
1759
1759
this .extend (buffer , bufferPadding , height );
1760
- this .filter (buffer , bufferPadding , height , v0 , buffer );
1760
+ this .filter (buffer , bufferPadding , height );
1761
1761
1762
1762
// If this is last buffer in this group of buffers, flush all buffers.
1763
1763
if (currentBuffer === 0 ) {
@@ -1788,44 +1788,86 @@ var JpxImage = (function JpxImageClosure() {
1788
1788
1789
1789
IrreversibleTransform .prototype = Object .create (Transform .prototype );
1790
1790
IrreversibleTransform .prototype .filter =
1791
- function irreversibleTransformFilter (y , offset , length , i0 , x ) {
1791
+ function irreversibleTransformFilter (x , offset , length ) {
1792
1792
var len = length >> 1 ;
1793
1793
offset = offset | 0 ;
1794
+ var j , n , current , next ;
1794
1795
1795
1796
var alpha = -1.586134342059924 ;
1796
1797
var beta = -0.052980118572961 ;
1797
1798
var gamma = 0.882911075530934 ;
1798
1799
var delta = 0.443506852043971 ;
1799
1800
var K = 1.230174104914001 ;
1800
1801
var K_ = 1 / K ;
1801
- var j , n ;
1802
1802
1803
1803
// step 1 is combined with step 3
1804
1804
1805
1805
// step 2
1806
- for (j = offset - 3 , n = len + 4 ; n --; j += 2 ) {
1807
- x [j ] = K_ * y [j ];
1806
+ j = offset - 3 ;
1807
+ for (n = len + 4 ; n --; j += 2 ) {
1808
+ x [j ] *= K_ ;
1808
1809
}
1809
1810
1810
1811
// step 1 & 3
1811
- for (j = offset - 2 , n = len + 3 ; n --; j += 2 ) {
1812
- x [j ] = K * y [j ] -
1813
- delta * (x [j - 1 ] + x [j + 1 ]);
1812
+ j = offset - 2 ;
1813
+ current = delta * x [j -1 ];
1814
+ for (n = len + 3 ; n --; j += 2 ) {
1815
+ next = delta * x [j + 1 ];
1816
+ x [j ] = K * x [j ] - current - next ;
1817
+ if (n --) {
1818
+ j += 2 ;
1819
+ current = delta * x [j + 1 ];
1820
+ x [j ] = K * x [j ] - current - next ;
1821
+ } else {
1822
+ break ;
1823
+ }
1814
1824
}
1815
1825
1816
1826
// step 4
1817
- for (j = offset - 1 , n = len + 2 ; n --; j += 2 ) {
1818
- x [j ] -= gamma * (x [j - 1 ] + x [j + 1 ]);
1827
+ j = offset - 1 ;
1828
+ current = gamma * x [j - 1 ];
1829
+ for (n = len + 2 ; n --; j += 2 ) {
1830
+ next = gamma * x [j + 1 ];
1831
+ x [j ] -= current + next ;
1832
+ if (n --) {
1833
+ j += 2 ;
1834
+ current = gamma * x [j + 1 ];
1835
+ x [j ] -= current + next ;
1836
+ } else {
1837
+ break ;
1838
+ }
1819
1839
}
1820
1840
1821
1841
// step 5
1822
- for (j = offset , n = len + 1 ; n --; j += 2 ) {
1823
- x [j ] -= beta * (x [j - 1 ] + x [j + 1 ]);
1842
+ j = offset ;
1843
+ current = beta * x [j - 1 ];
1844
+ for (n = len + 1 ; n --; j += 2 ) {
1845
+ next = beta * x [j + 1 ];
1846
+ x [j ] -= current + next ;
1847
+ if (n --) {
1848
+ j += 2 ;
1849
+ current = beta * x [j + 1 ];
1850
+ x [j ] -= current + next ;
1851
+ } else {
1852
+ break ;
1853
+ }
1824
1854
}
1825
1855
1826
1856
// step 6
1827
- for (j = offset + 1 , n = len ; n --; j += 2 ) {
1828
- x [j ] -= alpha * (x [j - 1 ] + x [j + 1 ]);
1857
+ if (len !== 0 ) {
1858
+ j = offset + 1 ;
1859
+ current = alpha * x [j - 1 ];
1860
+ for (n = len ; n --; j += 2 ) {
1861
+ next = alpha * x [j + 1 ];
1862
+ x [j ] -= current + next ;
1863
+ if (n --) {
1864
+ j += 2 ;
1865
+ current = alpha * x [j + 1 ];
1866
+ x [j ] -= current + next ;
1867
+ } else {
1868
+ break ;
1869
+ }
1870
+ }
1829
1871
}
1830
1872
};
1831
1873
@@ -1840,17 +1882,17 @@ var JpxImage = (function JpxImageClosure() {
1840
1882
1841
1883
ReversibleTransform .prototype = Object .create (Transform .prototype );
1842
1884
ReversibleTransform .prototype .filter =
1843
- function reversibleTransformFilter (y , offset , length , i0 , x ) {
1885
+ function reversibleTransformFilter (x , offset , length ) {
1844
1886
var len = length >> 1 ;
1845
1887
offset = offset | 0 ;
1846
1888
var j , n ;
1847
1889
1848
1890
for (j = offset , n = len + 1 ; n --; j += 2 ) {
1849
- x [j ] = y [ j ] - (( y [j - 1 ] + y [j + 1 ] + 2 ) >> 2 ) ;
1891
+ x [j ] -= ( x [j - 1 ] + x [j + 1 ] + 2 ) >> 2 ;
1850
1892
}
1851
1893
1852
1894
for (j = offset + 1 , n = len ; n --; j += 2 ) {
1853
- x [j ] = y [ j ] + (( x [j - 1 ] + x [j + 1 ]) >> 1 ) ;
1895
+ x [j ] += ( x [j - 1 ] + x [j + 1 ]) >> 1 ;
1854
1896
}
1855
1897
};
1856
1898
0 commit comments