GIFReader.st
changeset 809 0d39cb7c21a9
parent 757 094c6c7c4ce6
child 882 2913420cab5a
equal deleted inserted replaced
808:495535230e80 809:0d39cb7c21a9
   324 
   324 
   325     "GIF-files are always lsb (intel-world)"
   325     "GIF-files are always lsb (intel-world)"
   326     byteOrder := #lsb.
   326     byteOrder := #lsb.
   327 
   327 
   328     id := ByteArray new:6.
   328     id := ByteArray new:6.
   329     aStream nextBytes:6 into:id startingAt:1.
   329     (aStream nextBytes:6 into:id startingAt:1) ~~ 6 ifTrue:[
       
   330         ^ self fileFormatError:'not a gif file (short read)'.
       
   331     ].
   330     id := id asString.
   332     id := id asString.
   331 
   333 
   332     "all I had for testing where GIF87a files;
   334     "all I had for testing where GIF87a files;
   333      I hope later versions work too ..."
   335      I hope later versions work too ..."
   334 
   336 
   335     isGif89 := false.
   337     isGif89 := false.
   336     (id ~= 'GIF87a') ifTrue:[
   338     (id ~= 'GIF87a') ifTrue:[
   337 	(id startsWith:'GIF') ifFalse:[
   339         (id startsWith:'GIF') ifFalse:[
   338 	    'GIFReader [info]: not a gif file' infoPrintCR.
   340             ^ self fileFormatError:('not a gif file (id=''' , id , ''')').
   339 	    ^ nil
   341         ].
   340 	].
   342         id ~= 'GIF89a' ifTrue:[ 
   341 	id ~= 'GIF89a' ifTrue:[ 
   343             'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
   342 	    'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
   344         ]
   343 	]
       
   344     ].
   345     ].
   345 
   346 
   346     "get screen dimensions (not used)"
   347     "get screen dimensions (not used)"
   347     scrWidth := aStream nextShortMSB:false.
   348     scrWidth := aStream nextShortMSB:false.
   348     scrHeight := aStream nextShortMSB:false.
   349     scrHeight := aStream nextShortMSB:false.
   361     "aspect ratio (not used)"
   362     "aspect ratio (not used)"
   362     aStream nextByte.
   363     aStream nextByte.
   363 
   364 
   364     "get colorMap"
   365     "get colorMap"
   365     hasColorMap ifTrue:[
   366     hasColorMap ifTrue:[
   366 	self readColorMap:colorMapSize.
   367         self readColorMap:colorMapSize.
   367 	fileColorMap := Colormap 
   368         fileColorMap := Colormap 
   368 			redVector:redMap 
   369                         redVector:redMap 
   369 			greenVector:greenMap 
   370                         greenVector:greenMap 
   370 			blueVector:blueMap.
   371                         blueVector:blueMap.
   371     ].
   372     ].
   372     colorMap := fileColorMap.
   373     colorMap := fileColorMap.
   373 
   374 
   374     photometric := #palette.
   375     photometric := #palette.
   375     samplesPerPixel := 1.
   376     samplesPerPixel := 1.
   376     bitsPerSample := #(8).
   377     bitsPerSample := #(8).
   377 
   378 
   378     atEnd := false.
   379     atEnd := false.
   379     [atEnd] whileFalse:[
   380     [atEnd] whileFalse:[
   380 	"gif89a extensions"
   381         "gif89a extensions"
   381 
   382 
   382 	byte := aStream nextByte.
   383         byte := aStream nextByte.
   383 	byte == Extension ifTrue:[
   384         byte == Extension ifTrue:[
   384 	    self readExtension:aStream.
   385             self readExtension:aStream.
   385 	] ifFalse:[
   386         ] ifFalse:[
   386 	    (byte == Terminator) ifTrue:[
   387             (byte == Terminator) ifTrue:[
   387 		atEnd := true
   388                 atEnd := true
   388 	    ] ifFalse:[
   389             ] ifFalse:[
   389 		"must be image separator"
   390                 "must be image separator"
   390 		(byte ~~ ImageSeparator) ifTrue:[
   391                 (byte ~~ ImageSeparator) ifTrue:[
   391 		    ('GIFReader [info]: corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)) infoPrintCR.
   392                     ^ self fileFormatError:('corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)).
   392 		    ^ nil
   393                 ].
   393 		].
   394 
   394 
   395                 fileColorMap notNil ifTrue:[
   395 		fileColorMap notNil ifTrue:[
   396                     colorMap := fileColorMap.
   396 		    colorMap := fileColorMap.
   397                 ].
   397 		].
   398                 self readImage:aStream.
   398 		self readImage:aStream.
   399 
   399 
   400                 imageSequence isNil ifTrue:[
   400 		imageSequence isNil ifTrue:[
   401                     imageSequence := OrderedCollection new.
   401 		    imageSequence := OrderedCollection new.
   402                 ].
   402 		].
   403                 maskPixel notNil ifTrue:[
   403 		maskPixel notNil ifTrue:[
   404                     "/
   404 		    "/
   405                     "/ ok, there is a maskValue
   405 		    "/ ok, there is a maskValue
   406                     "/ build a Depth1Image for it.
   406 		    "/ build a Depth1Image for it.
   407                     "/
   407 		    "/
   408                     self buildMaskFromColor:maskPixel
   408 		    self buildMaskFromColor:maskPixel
   409                 ].
   409 		].
   410 
   410 
   411                 imageSequence add:(self image).
   411 		imageSequence add:(self image).
   412 
   412 
   413                 aStream atEnd ifTrue:[
   413 		aStream atEnd ifTrue:[
   414                     atEnd := true.
   414 		    atEnd := true.
   415                 ]
   415 		]
   416             ]
   416 	    ]
   417         ].
   417 	].
       
   418     ].
   418     ].
   419 
   419 
   420     "Modified: / 5.7.1996 / 17:32:01 / stefan"
   420     "Modified: / 5.7.1996 / 17:32:01 / stefan"
   421     "Modified: / 13.1.1998 / 10:44:26 / cg"
   421     "Modified: / 3.2.1998 / 17:53:37 / cg"
   422 !
   422 !
   423 
   423 
   424 makeGreyscale
   424 makeGreyscale
   425     "not yet implemented/needed"
   425     "not yet implemented/needed"
   426 !
   426 !
   937 ! !
   937 ! !
   938 
   938 
   939 !GIFReader class methodsFor:'documentation'!
   939 !GIFReader class methodsFor:'documentation'!
   940 
   940 
   941 version
   941 version
   942     ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.66 1998-01-16 15:20:10 cg Exp $'
   942     ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.67 1998-02-03 16:54:19 cg Exp $'
   943 ! !
   943 ! !
   944 GIFReader initialize!
   944 GIFReader initialize!