1-
1+ /* eslint-disable */
22// object used to represent array buffer data for a gif file
33
4- var DataParser = require ( '../node_modules /js-binary-schema-parser/src/dataparser' ) ;
5- var gifSchema = require ( './schema' ) ;
4+ import DataParser from '../.. /js-binary-schema-parser/src/dataparser' ;
5+ import gifSchema from './schema' ;
66
77function GIF ( arrayBuffer ) {
88 // convert to byte array
@@ -25,32 +25,48 @@ function GIF(arrayBuffer){
2525// if buildPatch is true, the returned image will be a clamped 8 bit image patch
2626// for use directly with a canvas.
2727GIF . prototype . decompressFrame = function ( index , buildPatch ) {
28+ return this . getFrame ( index , buildPatch , true ) ;
29+ }
30+
31+ // set decompress to false to retrieve the LZW-compressed image data
32+ GIF . prototype . getFrame = function ( index , buildPatch , decompress ) {
2833
2934 // make sure a valid frame is requested
3035 if ( index >= this . raw . frames . length ) { return null ; }
3136
3237 var frame = this . raw . frames [ index ] ;
33- if ( frame . image ) {
38+ if ( frame . image ) {
39+ var isInterlaced = frame . image . descriptor . lct . interlaced ;
40+
3441 // get the number of pixels
3542 var totalPixels = frame . image . descriptor . width * frame . image . descriptor . height ;
43+ var pixels ;
3644
3745 // do lzw decompression
38- var pixels = lzw ( frame . image . data . minCodeSize , frame . image . data . blocks , totalPixels ) ;
46+ if ( decompress !== false || buildPatch || isInterlaced ) {
47+ pixels = lzw ( frame . image . data . minCodeSize , frame . image . data . blocks , totalPixels ) ;
48+ }
3949
4050 // deal with interlacing if necessary
41- if ( frame . image . descriptor . lct . interlaced ) {
51+ if ( isInterlaced ) {
4252 pixels = deinterlace ( pixels , frame . image . descriptor . width ) ;
4353 }
4454
55+ if ( ! pixels ) {
56+ console . log ( 'Returning image data:' , frame . image . data . blocks ) ;
57+ }
58+
4559 // setup usable image object
4660 var image = {
61+ data : ! pixels ? frame . image . data . blocks : undefined ,
4762 pixels : pixels ,
4863 dims : {
4964 top : frame . image . descriptor . top ,
5065 left : frame . image . descriptor . left ,
5166 width : frame . image . descriptor . width ,
5267 height : frame . image . descriptor . height
53- }
68+ } ,
69+ format : pixels ? 'raw' : 'lzw'
5470 } ;
5571
5672 // color table
@@ -80,6 +96,7 @@ GIF.prototype.decompressFrame = function(index, buildPatch){
8096
8197 // frame does not contains image
8298 return null ;
99+ } ;
83100
84101
85102 /**
@@ -230,7 +247,6 @@ GIF.prototype.decompressFrame = function(index, buildPatch){
230247
231248 return patchData ;
232249 }
233- } ;
234250
235251// returns all frames decompressed
236252GIF . prototype . decompressFrames = function ( buildPatch ) {
@@ -244,4 +260,4 @@ GIF.prototype.decompressFrames = function(buildPatch){
244260 return frames ;
245261} ;
246262
247- module . exports = GIF ;
263+ export default GIF ;
0 commit comments