@ -15,7 +15,7 @@
* limitations under the License .
* limitations under the License .
* /
* /
/ * g l o b a l s A r i t h m e t i c D e c o d e r , g l o b a l S c o p e , l o g 2 , r e a d U i n t 1 6 , r e a d U i n t 3 2 ,
/ * g l o b a l s A r i t h m e t i c D e c o d e r , g l o b a l S c o p e , l o g 2 , r e a d U i n t 1 6 , r e a d U i n t 3 2 ,
warn * /
info , warn * /
'use strict' ;
'use strict' ;
@ -63,18 +63,52 @@ var JpxImage = (function JpxImageClosure() {
var dataLength = lbox - headerSize ;
var dataLength = lbox - headerSize ;
var jumpDataLength = true ;
var jumpDataLength = true ;
switch ( tbox ) {
switch ( tbox ) {
case 0x6A501A1A : // 'jP\032\032'
// TODO
break ;
case 0x6A703268 : // 'jp2h'
case 0x6A703268 : // 'jp2h'
jumpDataLength = false ; // parsing child boxes
jumpDataLength = false ; // parsing child boxes
break ;
break ;
case 0x636F6C72 : // 'colr'
case 0x636F6C72 : // 'colr'
// TODO
// Colorspaces are not used, the CS from the PDF is used.
var method = data [ position ] ;
var precedence = data [ position + 1 ] ;
var approximation = data [ position + 2 ] ;
if ( method === 1 ) {
// enumerated colorspace
var colorspace = readUint32 ( data , position + 3 ) ;
switch ( colorspace ) {
case 16 : // this indicates a sRGB colorspace
case 17 : // this indicates a grayscale colorspace
case 18 : // this indicates a YUV colorspace
break ;
default :
warn ( 'Unknown colorspace ' + colorspace ) ;
break ;
}
} else if ( method === 2 ) {
info ( 'ICC profile not supported' ) ;
}
break ;
break ;
case 0x6A703263 : // 'jp2c'
case 0x6A703263 : // 'jp2c'
this . parseCodestream ( data , position , position + dataLength ) ;
this . parseCodestream ( data , position , position + dataLength ) ;
break ;
break ;
case 0x6A502020 : // 'jP\024\024'
if ( 0x0d0a870a !== readUint32 ( data , position ) ) {
warn ( 'Invalid JP2 signature' ) ;
}
break ;
// The following header types are valid but currently not used:
case 0x6A501A1A : // 'jP\032\032'
case 0x66747970 : // 'ftyp'
case 0x72726571 : // 'rreq'
case 0x72657320 : // 'res '
case 0x69686472 : // 'ihdr'
break ;
default :
var headerType = String . fromCharCode ( ( tbox >> 24 ) & 0xFF ,
( tbox >> 16 ) & 0xFF ,
( tbox >> 8 ) & 0xFF ,
tbox & 0xFF ) ;
warn ( 'Unsupported header type ' + tbox + ' (' + headerType + ')' ) ;
break ;
}
}
if ( jumpDataLength ) {
if ( jumpDataLength ) {
position += dataLength ;
position += dataLength ;
@ -788,11 +822,11 @@ var JpxImage = (function JpxImageClosure() {
var tile = context . tiles [ tileIndex ] ;
var tile = context . tiles [ tileIndex ] ;
var packetsIterator = tile . packetsIterator ;
var packetsIterator = tile . packetsIterator ;
while ( position < dataLength ) {
while ( position < dataLength ) {
var packet = packetsIterator . nextPacket ( ) ;
alignToByte ( ) ;
if ( ! readBits ( 1 ) ) {
if ( ! readBits ( 1 ) ) {
alignToByte ( ) ;
continue ;
continue ;
}
}
var packet = packetsIterator . nextPacket ( ) ;
var layerNumber = packet . layerNumber ;
var layerNumber = packet . layerNumber ;
var queue = [ ] , codeblock ;
var queue = [ ] , codeblock ;
for ( var i = 0 , ii = packet . codeblocks . length ; i < ii ; i ++ ) {
for ( var i = 0 , ii = packet . codeblocks . length ; i < ii ; i ++ ) {
@ -803,13 +837,13 @@ var JpxImage = (function JpxImageClosure() {
var codeblockIncluded = false ;
var codeblockIncluded = false ;
var firstTimeInclusion = false ;
var firstTimeInclusion = false ;
var valueReady ;
var valueReady ;
if ( 'included' in codeblock ) {
if ( codeblock [ 'included' ] !== undefined ) {
codeblockIncluded = ! ! readBits ( 1 ) ;
codeblockIncluded = ! ! readBits ( 1 ) ;
} else {
} else {
// reading inclusion tree
// reading inclusion tree
precinct = codeblock . precinct ;
precinct = codeblock . precinct ;
var inclusionTree , zeroBitPlanesTree ;
var inclusionTree , zeroBitPlanesTree ;
if ( 'inclusionTree' in precinct ) {
if ( precinct [ 'inclusionTree' ] !== undefined ) {
inclusionTree = precinct . inclusionTree ;
inclusionTree = precinct . inclusionTree ;
} else {
} else {
// building inclusion and zero bit-planes trees
// building inclusion and zero bit-planes trees
@ -874,7 +908,7 @@ var JpxImage = (function JpxImageClosure() {
while ( queue . length > 0 ) {
while ( queue . length > 0 ) {
var packetItem = queue . shift ( ) ;
var packetItem = queue . shift ( ) ;
codeblock = packetItem . codeblock ;
codeblock = packetItem . codeblock ;
if ( ! ( 'data' in codeblock ) ) {
if ( codeblock [ 'data' ] === undefined ) {
codeblock . data = [ ] ;
codeblock . data = [ ] ;
}
}
codeblock . data . push ( {
codeblock . data . push ( {
@ -904,7 +938,7 @@ var JpxImage = (function JpxImageClosure() {
if ( blockWidth === 0 || blockHeight === 0 ) {
if ( blockWidth === 0 || blockHeight === 0 ) {
continue ;
continue ;
}
}
if ( ! ( 'data' in codeblock ) ) {
if ( codeblock [ 'data' ] === undefined ) {
continue ;
continue ;
}
}
@ -1159,10 +1193,10 @@ var JpxImage = (function JpxImageClosure() {
var tile = context . tiles [ tileIndex ] ;
var tile = context . tiles [ tileIndex ] ;
for ( var c = 0 ; c < componentsCount ; c ++ ) {
for ( var c = 0 ; c < componentsCount ; c ++ ) {
var component = tile . components [ c ] ;
var component = tile . components [ c ] ;
var qcdOrQcc = ( c in c ontext . currentTile . QCC ?
var qcdOrQcc = ( context . currentTile . QCC [ c ] !== undefined ?
context . currentTile . QCC [ c ] : context . currentTile . QCD ) ;
context . currentTile . QCC [ c ] : context . currentTile . QCD ) ;
component . quantizationParameters = qcdOrQcc ;
component . quantizationParameters = qcdOrQcc ;
var codOrCoc = ( c in c ontext . currentTile . COC ?
var codOrCoc = ( context . currentTile . COC [ c ] !== undefined ?
context . currentTile . COC [ c ] : context . currentTile . COD ) ;
context . currentTile . COC [ c ] : context . currentTile . COD ) ;
component . codingStyleParameters = codOrCoc ;
component . codingStyleParameters = codOrCoc ;
}
}
@ -1191,7 +1225,7 @@ var JpxImage = (function JpxImageClosure() {
while ( currentLevel < this . levels . length ) {
while ( currentLevel < this . levels . length ) {
level = this . levels [ currentLevel ] ;
level = this . levels [ currentLevel ] ;
var index = i + j * level . width ;
var index = i + j * level . width ;
if ( index in level . items ) {
if ( level . items [ index ] !== undefined ) {
value = level . items [ index ] ;
value = level . items [ index ] ;
break ;
break ;
}
}