File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -623,6 +623,7 @@ var JpegImage = (function jpegImage() {
623
623
var quantizationTables = [ ] , frames = [ ] ;
624
624
var huffmanTablesAC = [ ] , huffmanTablesDC = [ ] ;
625
625
var fileMarker = readUint16 ( ) ;
626
+ this . comments = [ ] ;
626
627
if ( fileMarker != 0xFFD8 ) { // SOI (Start of Image)
627
628
throw new Error ( "SOI not found" ) ;
628
629
}
@@ -651,6 +652,11 @@ var JpegImage = (function jpegImage() {
651
652
case 0xFFFE : // COM (Comment)
652
653
var appData = readDataBlock ( ) ;
653
654
655
+ if ( fileMarker === 0xFFFE ) {
656
+ var comment = String . fromCharCode . apply ( null , appData ) ;
657
+ this . comments . push ( comment ) ;
658
+ }
659
+
654
660
if ( fileMarker === 0xFFE0 ) {
655
661
if ( appData [ 0 ] === 0x4A && appData [ 1 ] === 0x46 && appData [ 2 ] === 0x49 &&
656
662
appData [ 3 ] === 0x46 && appData [ 4 ] === 0 ) { // 'JFIF\x00'
@@ -1096,6 +1102,9 @@ function decode(jpegData, userOpts = {}) {
1096
1102
new Uint8Array ( bytesNeeded ) :
1097
1103
new Buffer ( bytesNeeded )
1098
1104
} ;
1105
+ if ( decoder . comments . length > 0 ) {
1106
+ image [ "comments" ] = decoder . comments ;
1107
+ }
1099
1108
} catch ( err ) {
1100
1109
if ( err instanceof RangeError ) {
1101
1110
throw new Error ( "Could not allocate enough memory for the image. " +
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ it('should be able to decode a grayscale JPEG', function () {
49
49
var rawImageData = jpeg . decode ( jpegData ) ;
50
50
expect ( rawImageData . width ) . toEqual ( 580 ) ;
51
51
expect ( rawImageData . height ) . toEqual ( 599 ) ;
52
+ expect ( rawImageData . comments ) . toEqual ( [ 'File source: http://commons.wikimedia.org/wiki/File:Apsara-mit-Sitar.jpg' ] ) ;
52
53
var expected = fixture ( 'apsara.rgba' ) ;
53
54
expect ( rawImageData . data ) . toEqual ( expected ) ;
54
55
} ) ;
You can’t perform that action at this time.
0 commit comments