GIFReader.st
changeset 239 208108f3c707
parent 234 b6352d13e792
child 259 62b1bbafd9ba
equal deleted inserted replaced
238:a179b5d6152e 239:208108f3c707
   104 ! !
   104 ! !
   105 
   105 
   106 !GIFReader methodsFor:'reading from file'!
   106 !GIFReader methodsFor:'reading from file'!
   107 
   107 
   108 checkGreyscaleColormap
   108 checkGreyscaleColormap
   109     "return true, if colormap is really a greymap"
   109     "return true, if colormap is actually a greymap.
       
   110      Could be used to convert it into a greyScale image - which is not yet done."
   110 
   111 
   111     |sz "{ Class: SmallInteger }"
   112     |sz "{ Class: SmallInteger }"
   112      redVal|
   113      redVal|
   113 
   114 
   114     sz := redMap size.
   115     sz := redMap size.
   115 
   116 
   116     1 to:sz do:[:i |
   117     1 to:sz do:[:i |
   117 	redVal := redMap at:i.
   118         redVal := redMap at:i.
   118 	redVal ~~ (greenMap at:i) ifTrue:[^ false].
   119         redVal ~~ (greenMap at:i) ifTrue:[^ false].
   119 	redVal ~~ (blueMap at:i) ifTrue:[^ false].
   120         redVal ~~ (blueMap at:i) ifTrue:[^ false].
   120     ].
   121     ].
   121     ^ true
   122     ^ true
       
   123 
       
   124     "Modified: 2.5.1996 / 17:54:40 / cg"
   122 !
   125 !
   123 
   126 
   124 fromStream:aStream
   127 fromStream:aStream
   125     "read a stream containing a GIF image.
   128     "read a stream containing a GIF image.
   126      Leave image description in instance variables."
   129      Leave image description in instance variables."
   301 
   304 
   302 "/    self checkGreyscaleColormap ifTrue:[
   305 "/    self checkGreyscaleColormap ifTrue:[
   303 "/        self makeGreyscale
   306 "/        self makeGreyscale
   304 "/    ].
   307 "/    ].
   305 
   308 
   306     colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap.
   309     colorMap := Colormap 
       
   310                     redVector:redMap 
       
   311                     greenVector:greenMap 
       
   312                     blueVector:blueMap.
   307 
   313 
   308     "
   314     "
   309      GIFReader fromFile:'../fileIn/bitmaps/claus.gif
   315      GIFReader fromFile:'../fileIn/bitmaps/claus.gif
   310      GIFReader fromFile:'../fileIn/bitmaps/garfield.gif'
   316      GIFReader fromFile:'../fileIn/bitmaps/garfield.gif'
   311     "
   317     "
   312 
   318 
   313     "Modified: 22.4.1996 / 19:11:12 / cg"
   319     "Modified: 2.5.1996 / 17:50:20 / cg"
   314 !
   320 !
   315 
   321 
   316 makeGreyscale
   322 makeGreyscale
   317     "not yet implemented/needed"
   323     "not yet implemented/needed"
   318 !
   324 !
   320 readColorMap:colorMapSize
   326 readColorMap:colorMapSize
   321     "get gif colormap consisting of colorMapSize entries"
   327     "get gif colormap consisting of colorMapSize entries"
   322 
   328 
   323     |sz "{ Class: SmallInteger }"|
   329     |sz "{ Class: SmallInteger }"|
   324 
   330 
   325 "/    redMap := Array new:colorMapSize.
       
   326 "/    greenMap := Array new:colorMapSize.
       
   327 "/    blueMap := Array new:colorMapSize.
       
   328     redMap := ByteArray uninitializedNew:colorMapSize.
   331     redMap := ByteArray uninitializedNew:colorMapSize.
   329     greenMap := ByteArray uninitializedNew:colorMapSize.
   332     greenMap := ByteArray uninitializedNew:colorMapSize.
   330     blueMap := ByteArray uninitializedNew:colorMapSize.
   333     blueMap := ByteArray uninitializedNew:colorMapSize.
       
   334 
   331     sz := colorMapSize.
   335     sz := colorMapSize.
   332     1 to:sz do:[:i |
   336     1 to:sz do:[:i |
   333 	redMap at:i put:(inStream nextByte).
   337         redMap at:i put:(inStream nextByte).
   334 	greenMap at:i put:(inStream nextByte).
   338         greenMap at:i put:(inStream nextByte).
   335 	blueMap at:i put:(inStream nextByte)
   339         blueMap at:i put:(inStream nextByte)
   336     ]
   340     ]
       
   341 
       
   342     "Modified: 2.5.1996 / 17:53:56 / cg"
   337 !
   343 !
   338 
   344 
   339 readExtension:aStream
   345 readExtension:aStream
   340     "get gif89 extension"
   346     "get gif89 extension - this is currently ignored"
   341 
   347 
   342     |type blockSize subBlockSize
   348     |type blockSize subBlockSize
   343      aspNum aspDen left top width height cWidth cHeight fg bg|
   349      aspNum aspDen left top width height cWidth cHeight fg bg|
   344 
   350 
   345     type := aStream nextByte.
   351     type := aStream nextByte.
   346     type == $R asciiValue ifTrue:[
   352     type == $R asciiValue ifTrue:[
       
   353         "/
   347         "/ Ratio extension
   354         "/ Ratio extension
       
   355         "/
   348         'GIFREADER: ratio extension ignored' infoPrintNL.
   356         'GIFREADER: ratio extension ignored' infoPrintNL.
   349         blockSize := aStream nextByte.
   357         blockSize := aStream nextByte.
   350         (blockSize == 2) ifTrue:[
   358         (blockSize == 2) ifTrue:[
   351             aspNum := aStream nextByte.
   359             aspNum := aStream nextByte.
   352             aspDen := aStream nextByte
   360             aspDen := aStream nextByte
   355         ].
   363         ].
   356         "/ eat subblocks
   364         "/ eat subblocks
   357         
   365         
   358         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   366         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   359             aStream skip:subBlockSize
   367             aStream skip:subBlockSize
   360         ]
   368         ].
   361     ] ifFalse:[
   369         ^ self
   362         type == 16rFE ifTrue:[
   370     ].
   363             "/ comment extension
   371 
   364             'GIFREADER: comment extension ignored' infoPrintNL.
   372     type == 16rFE ifTrue:[
   365             [(blockSize := aStream nextByte) ~~ 0] whileTrue:[
   373         "/
   366                 aStream skip:blockSize
   374         "/ comment extension
   367             ].
   375         "/
   368         ] ifFalse:[
   376         'GIFREADER: comment extension ignored' infoPrintNL.
   369             type == 16r01 ifTrue:[
   377         [(blockSize := aStream nextByte) ~~ 0] whileTrue:[
   370                 "/ plaintext extension
   378             aStream skip:blockSize
   371                 'GIFREADER: plaintext extension ignored' infoPrintNL.
   379         ].
   372                 subBlockSize := aStream nextByte.
   380         ^ self
   373                 left := aStream nextShortMSB:false.
   381     ].
   374                 top := aStream nextShortMSB:false.
   382 
   375                 width := aStream nextShortMSB:false.
   383     type == 16r01 ifTrue:[
   376                 height := aStream nextShortMSB:false.
   384         "/
   377                 cWidth := aStream nextByte.
   385         "/ plaintext extension
   378                 cHeight := aStream nextByte.
   386         "/
   379                 fg := aStream nextByte.
   387         'GIFREADER: plaintext extension ignored' infoPrintNL.
   380                 bg := aStream nextByte.
   388         subBlockSize := aStream nextByte.
   381                 aStream skip:12.
   389         left := aStream nextShortMSB:false.
   382                 [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   390         top := aStream nextShortMSB:false.
   383                     aStream skip:subBlockSize
   391         width := aStream nextShortMSB:false.
   384                 ]
   392         height := aStream nextShortMSB:false.
   385             ] ifFalse:[
   393         cWidth := aStream nextByte.
   386                 type == 16rF9 ifTrue:[
   394         cHeight := aStream nextByte.
   387                     "/ graphic control extension
   395         fg := aStream nextByte.
   388                     'GIFREADER: plaintext extension ignored' infoPrintNL.
   396         bg := aStream nextByte.
   389                     [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   397         aStream skip:12.
   390                         aStream skip:subBlockSize
   398         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   391                     ]
   399             aStream skip:subBlockSize
   392                 ] ifFalse:[
   400         ].
   393                     type == 16rFF ifTrue:[
   401         ^ self
   394                         "/  application extension
   402     ].
   395                         'GIFREADER: application extension ignored' infoPrintNL.
   403 
   396                         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   404     type == 16rF9 ifTrue:[
   397                             aStream skip:subBlockSize
   405         "/
   398                         ]
   406         "/ graphic control extension
   399                     ] ifFalse:[
   407         "/
   400                         "/ unknown extension
   408         'GIFREADER: plaintext extension ignored' infoPrintNL.
   401                         'GIFREADER: unknown extension ignored' infoPrintNL.
   409         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   402                         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
   410             aStream skip:subBlockSize
   403                             aStream skip:subBlockSize
   411         ].
   404                         ]
   412         ^ self
   405                     ]
   413     ].
   406                 ]
   414 
   407             ]
   415     type == 16rFF ifTrue:[
   408         ]
   416         "/
       
   417         "/  application extension
       
   418         "/
       
   419         'GIFREADER: application extension ignored' infoPrintNL.
       
   420         [(subBlockSize := aStream nextByte) > 0] whileTrue:[
       
   421             aStream skip:subBlockSize
       
   422         ].
       
   423         ^ self
       
   424     ].
       
   425 
       
   426     "/
       
   427     "/ unknown extension
       
   428     "/
       
   429     'GIFREADER: unknown extension ignored' infoPrintNL.
       
   430     [(subBlockSize := aStream nextByte) > 0] whileTrue:[
       
   431         aStream skip:subBlockSize
   409     ]
   432     ]
   410 
   433 
   411     "Created: 18.1.1996 / 22:00:51 / cg"
   434     "Modified: 2.5.1996 / 17:53:49 / cg"
   412     "Modified: 18.1.1996 / 22:12:07 / cg"
       
   413 ! !
   435 ! !
   414 
   436 
   415 !GIFReader class methodsFor:'documentation'!
   437 !GIFReader class methodsFor:'documentation'!
   416 
   438 
   417 version
   439 version
   418     ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.30 1996-04-29 08:47:15 cg Exp $'
   440     ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.31 1996-05-02 15:54:50 cg Exp $'
   419 ! !
   441 ! !
   420 GIFReader initialize!
   442 GIFReader initialize!