@ -1,4 +1,3 @@
/ * C o p y r i g h t 2 0 1 4 M o z i l l a F o u n d a t i o n
/ * C o p y r i g h t 2 0 1 4 M o z i l l a F o u n d a t i o n
*
*
* Licensed under the Apache License , Version 2.0 ( the 'License' ) ;
* Licensed under the Apache License , Version 2.0 ( the 'License' ) ;
@ -18,25 +17,27 @@
( function ( root , factory ) {
( function ( root , factory ) {
if ( typeof define === 'function' && define . amd ) {
if ( typeof define === 'function' && define . amd ) {
define ( 'pdfjs/core/jpg' , [ 'exports' ] , factory ) ;
define ( 'pdfjs/core/jpg' , [ 'exports' , 'pdfjs/shared/util' ] , factory ) ;
} else if ( typeof exports !== 'undefined' ) {
} else if ( typeof exports !== 'undefined' ) {
factory ( exports ) ;
factory ( exports , require ( '../shared/util.js' ) ) ;
} else {
} else {
factory ( ( root . pdfjsCoreJpg = { } ) ) ;
factory ( ( root . pdfjsCoreJpg = { } ) , root . pdfjsSharedUtil ) ;
}
}
} ( this , function ( exports ) {
} ( this , function ( exports , sharedUtil ) {
/ *
var error = sharedUtil . error ;
This code was forked from https : //github.com/notmasteryet/jpgjs. The original
version was created by github user notmasteryet
- The JPEG specification can be found in the ITU CCITT Recommendation T . 81
/ * *
( www . w3 . org / Graphics / JPEG / itu - t81 . pdf )
* This code was forked from https : //github.com/notmasteryet/jpgjs.
- The JFIF specification can be found in the JPEG File Interchange Format
* The original version was created by GitHub user notmasteryet .
( www . w3 . org / Graphics / JPEG / jfif3 . pdf )
*
- The Adobe Application - Specific JPEG markers in the Supporting the DCT Filters
* - The JPEG specification can be found in the ITU CCITT Recommendation T . 81
in PostScript Level 2 , Technical Note # 5116
* ( www . w3 . org / Graphics / JPEG / itu - t81 . pdf )
( partners . adobe . com / public / developer / en / ps / sdk / 5116. DCT _Filter . pdf )
* - The JFIF specification can be found in the JPEG File Interchange Format
* ( www . w3 . org / Graphics / JPEG / jfif3 . pdf )
* - The Adobe Application - Specific JPEG markers in the
* Supporting the DCT Filters in PostScript Level 2 , Technical Note # 5116
* ( partners . adobe . com / public / developer / en / ps / sdk / 5116. DCT _Filter . pdf )
* /
* /
var JpegImage = ( function jpegImage ( ) {
var JpegImage = ( function jpegImage ( ) {
@ -123,8 +124,8 @@ var JpegImage = (function jpegImage() {
if ( bitsData === 0xFF ) {
if ( bitsData === 0xFF ) {
var nextByte = data [ offset ++ ] ;
var nextByte = data [ offset ++ ] ;
if ( nextByte ) {
if ( nextByte ) {
throw 'unexpected marker: ' +
error ( 'JPEG error: unexpected marker ' +
( ( bitsData << 8 ) | nextByte ) . toString ( 16 ) ;
( ( bitsData << 8 ) | nextByte ) . toString ( 16 ) ) ;
}
}
// unstuff 0
// unstuff 0
}
}
@ -140,7 +141,7 @@ var JpegImage = (function jpegImage() {
return node ;
return node ;
}
}
if ( typeof node !== 'object' ) {
if ( typeof node !== 'object' ) {
throw 'invalid huffman sequence' ;
error ( 'JPEG error: invalid huffman sequence' ) ;
}
}
}
}
}
}
@ -247,7 +248,7 @@ var JpegImage = (function jpegImage() {
}
}
} else {
} else {
if ( s !== 1 ) {
if ( s !== 1 ) {
throw 'invalid ACn encoding' ;
error ( 'JPEG error: invalid ACn encoding' ) ;
}
}
successiveACNextValue = receiveAndExtend ( s ) ;
successiveACNextValue = receiveAndExtend ( s ) ;
successiveACState = r ? 2 : 3 ;
successiveACState = r ? 2 : 3 ;
@ -363,7 +364,7 @@ var JpegImage = (function jpegImage() {
bitsCount = 0 ;
bitsCount = 0 ;
marker = ( data [ offset ] << 8 ) | data [ offset + 1 ] ;
marker = ( data [ offset ] << 8 ) | data [ offset + 1 ] ;
if ( marker <= 0xFF00 ) {
if ( marker <= 0xFF00 ) {
throw 'marker was not found' ;
error ( 'JPEG error: marker was not found' ) ;
}
}
if ( marker >= 0xFFD0 && marker <= 0xFFD7 ) { // RSTx
if ( marker >= 0xFFD0 && marker <= 0xFFD7 ) { // RSTx
@ -388,7 +389,7 @@ var JpegImage = (function jpegImage() {
var t ;
var t ;
if ( ! qt ) {
if ( ! qt ) {
throw 'missing required Quantization Table.' ;
error ( 'JPEG error: missing required Quantization Table.' ) ;
}
}
// inverse DCT on rows
// inverse DCT on rows
@ -630,7 +631,7 @@ var JpegImage = (function jpegImage() {
var huffmanTablesAC = [ ] , huffmanTablesDC = [ ] ;
var huffmanTablesAC = [ ] , huffmanTablesDC = [ ] ;
var fileMarker = readUint16 ( ) ;
var fileMarker = readUint16 ( ) ;
if ( fileMarker !== 0xFFD8 ) { // SOI (Start of Image)
if ( fileMarker !== 0xFFD8 ) { // SOI (Start of Image)
throw 'SOI not found' ;
error ( 'JPEG error: SOI not found' ) ;
}
}
fileMarker = readUint16 ( ) ;
fileMarker = readUint16 ( ) ;
@ -705,7 +706,7 @@ var JpegImage = (function jpegImage() {
tableData [ z ] = readUint16 ( ) ;
tableData [ z ] = readUint16 ( ) ;
}
}
} else {
} else {
throw 'DQT: invalid table spec' ;
error ( 'JPEG error: DQT - invalid table spec' ) ;
}
}
quantizationTables [ quantizationTableSpec & 15 ] = tableData ;
quantizationTables [ quantizationTableSpec & 15 ] = tableData ;
}
}
@ -715,7 +716,7 @@ var JpegImage = (function jpegImage() {
case 0xFFC1 : // SOF1 (Start of Frame, Extended DCT)
case 0xFFC1 : // SOF1 (Start of Frame, Extended DCT)
case 0xFFC2 : // SOF2 (Start of Frame, Progressive DCT)
case 0xFFC2 : // SOF2 (Start of Frame, Progressive DCT)
if ( frame ) {
if ( frame ) {
throw 'Only single frame JPEGs supported' ;
error ( 'JPEG error: Only single frame JPEGs supported' ) ;
}
}
readUint16 ( ) ; // skip data length
readUint16 ( ) ; // skip data length
frame = { } ;
frame = { } ;
@ -815,7 +816,7 @@ var JpegImage = (function jpegImage() {
offset -= 3 ;
offset -= 3 ;
break ;
break ;
}
}
throw 'unknown JPEG marker ' + fileMarker . toString ( 16 ) ;
error ( 'JPEG error: unknown marker ' + fileMarker . toString ( 16 ) ) ;
}
}
fileMarker = readUint16 ( ) ;
fileMarker = readUint16 ( ) ;
}
}
@ -1028,7 +1029,7 @@ var JpegImage = (function jpegImage() {
getData : function getData ( width , height , forceRGBoutput ) {
getData : function getData ( width , height , forceRGBoutput ) {
if ( this . numComponents > 4 ) {
if ( this . numComponents > 4 ) {
throw 'Unsupported color mode' ;
error ( 'JPEG error: Unsupported color mode' ) ;
}
}
// type of data: Uint8Array(width * height * numComponents)
// type of data: Uint8Array(width * height * numComponents)
var data = this . _getLinearizedBlockData ( width , height ) ;
var data = this . _getLinearizedBlockData ( width , height ) ;