GIFReader.st
changeset 64 ea02b0bdc674
parent 43 e85c7d392833
child 79 454362f799f5
equal deleted inserted replaced
63:23617db5f7db 64:ea02b0bdc674
    21 
    21 
    22 GIFReader comment:'
    22 GIFReader comment:'
    23 COPYRIGHT (c) 1991 by Claus Gittinger
    23 COPYRIGHT (c) 1991 by Claus Gittinger
    24 	      All Rights Reserved
    24 	      All Rights Reserved
    25 
    25 
    26 $Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.13 1995-02-18 15:57:13 claus Exp $
    26 $Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.14 1995-05-03 00:02:53 claus Exp $
    27 '!
    27 '!
    28 
    28 
    29 !GIFReader class methodsFor:'documentation'!
    29 !GIFReader class methodsFor:'documentation'!
    30 
    30 
    31 copyright
    31 copyright
    42 "
    42 "
    43 !
    43 !
    44 
    44 
    45 version
    45 version
    46 "
    46 "
    47 $Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.13 1995-02-18 15:57:13 claus Exp $
    47 $Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.14 1995-05-03 00:02:53 claus Exp $
    48 "
    48 "
    49 !
    49 !
    50 
    50 
    51 documentation
    51 documentation
    52 "
    52 "
   102 
   102 
   103 !GIFReader methodsFor:'reading from file'!
   103 !GIFReader methodsFor:'reading from file'!
   104 
   104 
   105 readColorMap:colorMapSize
   105 readColorMap:colorMapSize
   106     "get gif colormap consisting of colorMapSize entries"
   106     "get gif colormap consisting of colorMapSize entries"
       
   107 
       
   108     |sz "{ Class: SmallInteger }"|
   107 
   109 
   108 "/    redMap := Array new:colorMapSize.
   110 "/    redMap := Array new:colorMapSize.
   109 "/    greenMap := Array new:colorMapSize.
   111 "/    greenMap := Array new:colorMapSize.
   110 "/    blueMap := Array new:colorMapSize.
   112 "/    blueMap := Array new:colorMapSize.
   111     redMap := ByteArray uninitializedNew:colorMapSize.
   113     redMap := ByteArray uninitializedNew:colorMapSize.
   112     greenMap := ByteArray uninitializedNew:colorMapSize.
   114     greenMap := ByteArray uninitializedNew:colorMapSize.
   113     blueMap := ByteArray uninitializedNew:colorMapSize.
   115     blueMap := ByteArray uninitializedNew:colorMapSize.
   114     1 to:colorMapSize do:[:i |
   116     sz := colorMapSize.
       
   117     1 to:sz do:[:i |
   115 	redMap at:i put:(inStream nextByte).
   118 	redMap at:i put:(inStream nextByte).
   116 	greenMap at:i put:(inStream nextByte).
   119 	greenMap at:i put:(inStream nextByte).
   117 	blueMap at:i put:(inStream nextByte)
   120 	blueMap at:i put:(inStream nextByte)
   118     ]
   121     ]
   119 !
   122 !
   144     |byte index flag count
   147     |byte index flag count
   145      colorMapSize bitsPerPixel scrWidth scrHeight
   148      colorMapSize bitsPerPixel scrWidth scrHeight
   146      hasColorMap hasLocalColorMap interlaced id
   149      hasColorMap hasLocalColorMap interlaced id
   147      leftOffs topOffs codeLen
   150      leftOffs topOffs codeLen
   148      compressedData compressedSize
   151      compressedData compressedSize
   149      tmp srcOffset dstOffset|
   152      tmp srcOffset dstOffset
       
   153      h "{ Class: SmallInteger }"|
   150 
   154 
   151     inStream := aStream.
   155     inStream := aStream.
   152     aStream binary.
   156     aStream binary.
   153 
   157 
   154     "GIF-files are always lsb (intel-world)"
   158     "GIF-files are always lsb (intel-world)"
   240         index := index + count.
   244         index := index + count.
   241         count := aStream nextByte
   245         count := aStream nextByte
   242     ].
   246     ].
   243     compressedSize := index - 1.
   247     compressedSize := index - 1.
   244 
   248 
   245     data := ByteArray new:((width + 1) * (height + 1)).
   249     h := height.
       
   250     data := ByteArray new:((width + 1) * (h + 1)).
   246     'GIFReader: decompressing ...' errorPrintNL.
   251     'GIFReader: decompressing ...' errorPrintNL.
   247 
   252 
   248     self class decompressGIFFrom:compressedData
   253     self class decompressGIFFrom:compressedData
   249                            count:compressedSize
   254                            count:compressedSize
   250                             into:data
   255                             into:data
   256         tmp := ByteArray new:(data size).
   261         tmp := ByteArray new:(data size).
   257 
   262 
   258         "phase 1: 0, 8, 16, 24, ..."
   263         "phase 1: 0, 8, 16, 24, ..."
   259 
   264 
   260         srcOffset := 1.
   265         srcOffset := 1.
   261         0 to:(height - 1) by:8 do:[:dstRow |
   266         0 to:(h - 1) by:8 do:[:dstRow |
   262             dstOffset := dstRow * width + 1.
   267             dstOffset := dstRow * width + 1.
   263             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   268             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   264                        with:data startingAt:srcOffset.
   269                        with:data startingAt:srcOffset.
   265             srcOffset := srcOffset + width.
   270             srcOffset := srcOffset + width.
   266         ].
   271         ].
   267 
   272 
   268         "phase 2: 4, 12, 20, 28, ..."
   273         "phase 2: 4, 12, 20, 28, ..."
   269 
   274 
   270         4 to:(height - 1) by:8 do:[:dstRow |
   275         4 to:(h - 1) by:8 do:[:dstRow |
   271             dstOffset := dstRow * width + 1.
   276             dstOffset := dstRow * width + 1.
   272             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   277             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   273                        with:data startingAt:srcOffset.
   278                        with:data startingAt:srcOffset.
   274             srcOffset := srcOffset + width.
   279             srcOffset := srcOffset + width.
   275         ].
   280         ].
   276 
   281 
   277         "phase 3: 2, 6, 10, 14, ..."
   282         "phase 3: 2, 6, 10, 14, ..."
   278 
   283 
   279         2 to:(height - 1) by:4 do:[:dstRow |
   284         2 to:(h - 1) by:4 do:[:dstRow |
   280             dstOffset := dstRow * width + 1.
   285             dstOffset := dstRow * width + 1.
   281             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   286             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   282                        with:data startingAt:srcOffset.
   287                        with:data startingAt:srcOffset.
   283             srcOffset := srcOffset + width.
   288             srcOffset := srcOffset + width.
   284         ].
   289         ].
   285 
   290 
   286         "phase 4: 1, 3, 5, 7, ..."
   291         "phase 4: 1, 3, 5, 7, ..."
   287 
   292 
   288         1 to:(height - 1) by:2 do:[:dstRow |
   293         1 to:(h - 1) by:2 do:[:dstRow |
   289             dstOffset := dstRow * width + 1.
   294             dstOffset := dstRow * width + 1.
   290             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   295             tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
   291                        with:data startingAt:srcOffset.
   296                        with:data startingAt:srcOffset.
   292             srcOffset := srcOffset + width.
   297             srcOffset := srcOffset + width.
   293         ].
   298         ].