GIFReader.st
author Stefan Vogel <sv@exept.de>
Thu, 15 Jan 1998 16:38:47 +0100
changeset 755 f1135dda53b1
parent 749 49c372aaf613
child 757 094c6c7c4ce6
permissions -rw-r--r--
be carefull when reading from non-fileStreams
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     1
"
6
4ac87e6bf82f *** empty log message ***
claus
parents: 5
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
26
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
     3
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     4
3f9277473954 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3f9277473954 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3f9277473954 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3f9277473954 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3f9277473954 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3f9277473954 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
3f9277473954 Initial revision
claus
parents:
diff changeset
    11
"
3f9277473954 Initial revision
claus
parents:
diff changeset
    12
3f9277473954 Initial revision
claus
parents:
diff changeset
    13
ImageReader subclass:#GIFReader
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    14
	instanceVariableNames:'redMap greenMap blueMap pass xpos ypos rowByteSize remainBitCount
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    15
		bufByte bufStream prefixTable suffixTable clearCode eoiCode
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    16
		freeCode codeSize maxCode interlace'
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    17
	classVariableNames:'ImageSeparator Extension Terminator'
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
    18
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 239
diff changeset
    19
	category:'Graphics-Images-Support'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    20
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    21
339
9b4ece782f6a removed an infoPrint.
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
    22
!GIFReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    23
21
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    24
copyright
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    25
"
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    26
 COPYRIGHT (c) 1991 by Claus Gittinger
26
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
    27
	      All Rights Reserved
21
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    28
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    29
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    30
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    32
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    33
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    34
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    35
"
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    36
!
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    37
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    38
documentation
3f9277473954 Initial revision
claus
parents:
diff changeset
    39
"
3f9277473954 Initial revision
claus
parents:
diff changeset
    40
    this class provides methods for loading and saving GIF pictures.
21
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    41
    It has been tested with some different GIF87a pictures, I dont
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    42
    know, if it works with other GIF versions.
3f9277473954 Initial revision
claus
parents:
diff changeset
    43
    GIF extension blocks are not handled.
3f9277473954 Initial revision
claus
parents:
diff changeset
    44
3f9277473954 Initial revision
claus
parents:
diff changeset
    45
    GIF file writing is not implemented (use TIFF).
3f9277473954 Initial revision
claus
parents:
diff changeset
    46
21
66b31c91177f *** empty log message ***
claus
parents: 20
diff changeset
    47
    legal stuff extracted from GIF87a documentation:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    48
3f9277473954 Initial revision
claus
parents:
diff changeset
    49
    CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free
3f9277473954 Initial revision
claus
parents:
diff changeset
    50
    license for the use of the Graphics Interchange Format(sm) in computer
3f9277473954 Initial revision
claus
parents:
diff changeset
    51
    software; computer software utilizing GIF(sm) must acknowledge ownership of the
3f9277473954 Initial revision
claus
parents:
diff changeset
    52
    Graphics Interchange Format and its Service Mark by CompuServe Incorporated, in
3f9277473954 Initial revision
claus
parents:
diff changeset
    53
    User and Technical Documentation. 
3f9277473954 Initial revision
claus
parents:
diff changeset
    54
3f9277473954 Initial revision
claus
parents:
diff changeset
    55
      The Graphics Interchange Format(c) is the Copyright property of
3f9277473954 Initial revision
claus
parents:
diff changeset
    56
      CompuServe Incorporated. GIF(sm) is a Service Mark property of
3f9277473954 Initial revision
claus
parents:
diff changeset
    57
      CompuServe Incorporated.
194
d4ecb23d7163 commentary
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    58
d4ecb23d7163 commentary
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    59
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
    60
        Image Form Icon
194
d4ecb23d7163 commentary
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    61
        BlitImageReader FaceReader JPEGReader PBMReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    62
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
    63
        XBMReader XPMReader XWDReader 
220
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    64
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    65
    [author:]
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    66
        Claus Gittinger
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    67
"
3f9277473954 Initial revision
claus
parents:
diff changeset
    68
! !
3f9277473954 Initial revision
claus
parents:
diff changeset
    69
339
9b4ece782f6a removed an infoPrint.
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
    70
!GIFReader class methodsFor:'initialization'!
26
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
    71
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
    72
initialize
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
    73
    "install myself in the Image classes fileFormat table
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 355
diff changeset
    74
     for the `.gif' extensions."
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
    75
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    76
    ImageSeparator := $, asciiValue.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    77
    Extension := $!! asciiValue.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    78
    Terminator := $; asciiValue.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    79
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 626
diff changeset
    80
    MIMETypes defineImageType:'image/gif' suffix:'gif' reader:self.
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
    81
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    82
    "Modified: 14.10.1997 / 18:47:27 / cg"
26
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
    83
! !
2fe6294ca833 *** empty log message ***
claus
parents: 25
diff changeset
    84
339
9b4ece782f6a removed an infoPrint.
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
    85
!GIFReader class methodsFor:'testing'!
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
    86
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    87
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    88
    "return true, if anImage can be represented in my file format.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    89
     GIF supports depth 8 images only."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    90
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    91
    ^ anImage depth == 8
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    92
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    93
    "Created: 17.10.1997 / 20:19:20 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    94
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
    95
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
    96
isValidImageFile:aFileName
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
    97
    "return true, if aFileName contains a GIF image"
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
    98
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
    99
    |id inStream|
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   100
9
415b0178ecba *** empty log message ***
claus
parents: 6
diff changeset
   101
    inStream := self streamReadingFile:aFileName.
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   102
    inStream isNil ifTrue:[^ false].
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   103
332
86b45e0f9ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   104
    inStream text.
86b45e0f9ec0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   105
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   106
    id := String new:6.
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   107
    inStream nextBytes:6 into:id.
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   108
    inStream close.
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   109
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   110
    (id = 'GIF87a') ifFalse:[
174
7fafcc56378d nicer message
Claus Gittinger <cg@exept.de>
parents: 154
diff changeset
   111
        (id startsWith:'GIF') ifFalse:[^ false].
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   112
174
7fafcc56378d nicer message
Claus Gittinger <cg@exept.de>
parents: 154
diff changeset
   113
        id ~= 'GIF89a' ifTrue:[ 
355
05eb4e183394 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 354
diff changeset
   114
            'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
174
7fafcc56378d nicer message
Claus Gittinger <cg@exept.de>
parents: 154
diff changeset
   115
        ]
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   116
    ].
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   117
    ^ true
174
7fafcc56378d nicer message
Claus Gittinger <cg@exept.de>
parents: 154
diff changeset
   118
355
05eb4e183394 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 354
diff changeset
   119
    "Modified: 10.1.1997 / 15:40:34 / cg"
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   120
! !
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   121
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   122
!GIFReader methodsFor:'private - writing'!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   123
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   124
assignTransparentPixelIn:image
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   125
    "find an usused pixelValue in the colorMap (or image)."
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   126
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   127
    |cmap usedPixelValues|
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   128
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   129
    (cmap := image colorMap) size > 0 ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   130
        cmap size < 256 ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   131
            maskPixel := cmap size.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   132
            ^ self
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   133
        ]
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   134
    ].
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   135
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   136
    usedPixelValues := image usedValues.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   137
    usedPixelValues size < (1 bitShift:image depth) ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   138
        "/ there must be an unused pixelValue
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   139
        maskPixel := ((0 to:(1 bitShift:image depth)-1) asSet removeAll:(usedPixelValues)) first.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   140
    ] ifFalse:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   141
        Image informationLostQuerySignal
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   142
            raiseWith:image
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   143
            errorString:('GIF writer cannot assign a transparent pixel - all pixelValues used by image').
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   144
    ]
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   145
!
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   146
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   147
checkCodeSize
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   148
    (freeCode > maxCode and: [codeSize < 12])
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   149
            ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   150
                    [codeSize := codeSize + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   151
                    maxCode := (1 bitShift: codeSize) - 1]
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   152
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   153
    "Created: 14.10.1997 / 18:42:01 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   154
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   155
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   156
flushBits
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   157
        remainBitCount = 0
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   158
                ifFalse: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   159
                        [self nextBytePut: bufByte.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   160
                        remainBitCount := 0].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   161
        self flushBuffer
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   162
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   163
    "Modified: 14.10.1997 / 18:58:06 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   164
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   165
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   166
flushBuffer
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   167
    bufStream isEmpty ifTrue: [^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   168
    outStream nextPut: bufStream size.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   169
    outStream nextPutAll: bufStream contents.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   170
    bufStream := WriteStream on: (ByteArray new: 256)
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   171
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   172
    "Modified: 14.10.1997 / 20:46:04 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   173
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   174
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   175
flushCode
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   176
        self flushBits
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   177
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   178
    "Created: 14.10.1997 / 18:57:33 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   179
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   180
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   181
nextBitsPut: anInteger
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   182
        | integer writeBitCount shiftCount |
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   183
        shiftCount _ 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   184
        remainBitCount = 0
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   185
                ifTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   186
                        [writeBitCount _ 8.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   187
                        integer _ anInteger]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   188
                ifFalse:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   189
                        [writeBitCount _ remainBitCount.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   190
                        integer _ bufByte + (anInteger bitShift: 8 - remainBitCount)].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   191
        [writeBitCount < codeSize]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   192
                whileTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   193
                        [self nextBytePut: ((integer bitShift: shiftCount) bitAnd: 255).
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   194
                        shiftCount _ shiftCount - 8.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   195
                        writeBitCount _ writeBitCount + 8].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   196
        (remainBitCount _ writeBitCount - codeSize) = 0
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   197
                ifTrue: [self nextBytePut: (integer bitShift: shiftCount)]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   198
                ifFalse: [bufByte _ integer bitShift: shiftCount].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   199
        ^anInteger
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   200
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   201
    "Modified: 15.10.1997 / 16:50:30 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   202
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   203
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   204
nextBytePut: aByte
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   205
        bufStream nextPut: aByte.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   206
        bufStream size >= 254 ifTrue: [self flushBuffer]
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   207
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   208
    "Modified: 15.10.1997 / 16:50:52 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   209
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   210
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   211
readPixelFrom: bits 
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   212
    | pixel |
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   213
    ypos >= height ifTrue: [^ nil].
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   214
    (maskPixel notNil 
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   215
    and:[(mask pixelAtX:xpos y:ypos) == 0]) ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   216
        pixel := maskPixel
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   217
    ] ifFalse:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   218
        pixel := bits at: ypos * rowByteSize + xpos + 1.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   219
    ].
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   220
    self updatePixelPosition.
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   221
    ^ pixel
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   222
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   223
    "Created: 14.10.1997 / 18:43:50 / cg"
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   224
    "Modified: 15.10.1997 / 16:46:43 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   225
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   226
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   227
setParameters:bitsPerPixel 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   228
    clearCode := 1 bitShift:bitsPerPixel.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   229
    eoiCode := clearCode + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   230
    freeCode := clearCode + 2.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   231
    codeSize := bitsPerPixel + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   232
    maxCode := (1 bitShift: codeSize) - 1
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   233
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   234
    "Modified: 14.10.1997 / 20:09:48 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   235
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   236
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   237
updatePixelPosition
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   238
        (xpos _ xpos + 1) >= width ifFalse: [^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   239
        xpos _ 0.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   240
        interlace == true
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   241
                ifFalse: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   242
                        [ypos _ ypos + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   243
                        ^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   244
        pass = 0
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   245
                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   246
                        [(ypos _ ypos + 8) >= height
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   247
                                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   248
                                        [pass _ pass + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   249
                                        ypos _ 4].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   250
                        ^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   251
        pass = 1
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   252
                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   253
                        [(ypos _ ypos + 8) >= height
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   254
                                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   255
                                        [pass _ pass + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   256
                                        ypos _ 2].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   257
                        ^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   258
        pass = 2
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   259
                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   260
                        [(ypos _ ypos + 4) >= height
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   261
                                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   262
                                        [pass _ pass + 1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   263
                                        ypos _ 1].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   264
                        ^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   265
        pass = 3
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   266
                ifTrue: 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   267
                        [ypos _ ypos + 2.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   268
                        ^ self].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   269
        ^ self error: 'can''t happen'
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   270
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   271
    "Modified: 14.10.1997 / 18:44:27 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   272
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   273
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   274
writeCode: aCode 
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   275
    self nextBitsPut: aCode
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   276
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   277
    "Created: 14.10.1997 / 18:38:35 / cg"
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   278
    "Modified: 15.10.1997 / 17:01:47 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   279
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   280
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   281
writeCodeAndCheckCodeSize: t1 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   282
    self writeCode: t1.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   283
    self checkCodeSize
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   284
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   285
    "Created: 14.10.1997 / 18:38:24 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   286
    "Modified: 14.10.1997 / 18:40:56 / cg"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   287
! !
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   288
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   289
!GIFReader methodsFor:'reading from file'!
3f9277473954 Initial revision
claus
parents:
diff changeset
   290
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   291
checkGreyscaleColormap
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   292
    "return true, if colormap is actually a greymap.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   293
     Could be used to convert it into a greyScale image - which is not yet done."
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   294
20
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   295
    |sz "{ Class: SmallInteger }"
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   296
     redVal|
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   297
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   298
    sz := redMap size.
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   299
7fd1b1ec5f6d *** empty log message ***
claus
parents: 9
diff changeset
   300
    1 to:sz do:[:i |
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   301
        redVal := redMap at:i.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   302
        redVal ~~ (greenMap at:i) ifTrue:[^ false].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   303
        redVal ~~ (blueMap at:i) ifTrue:[^ false].
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   304
    ].
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   305
    ^ true
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   306
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   307
    "Modified: 2.5.1996 / 17:54:40 / cg"
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   308
!
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   309
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   310
fromStream:aStream
192
947cc10f86dc commentary
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   311
    "read a stream containing a GIF image.
947cc10f86dc commentary
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   312
     Leave image description in instance variables."
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   313
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   314
    |byte index flag count fileColorMap
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   315
     colorMapSize bitsPerPixel scrWidth scrHeight
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   316
     hasColorMap hasLocalColorMap interlaced id
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   317
     leftOffs topOffs codeLen
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   318
     compressedData compressedSize
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   319
     tmp srcOffset dstOffset isGif89 atEnd
64
claus
parents: 43
diff changeset
   320
     h "{ Class: SmallInteger }"|
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   321
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   322
    inStream := aStream.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   323
    aStream binary.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   324
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   325
    "GIF-files are always lsb (intel-world)"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   326
    byteOrder := #lsb.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   327
331
304f9c439efa allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   328
    id := ByteArray new:6.
304f9c439efa allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   329
    aStream nextBytes:6 into:id startingAt:1.
304f9c439efa allow reading from ByteArray-readStreams
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   330
    id := id asString.
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   331
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   332
    "all I had for testing where GIF87a files;
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   333
     I hope later versions work too ..."
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   334
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   335
    isGif89 := false.
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   336
    (id ~= 'GIF87a') ifTrue:[
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   337
        (id startsWith:'GIF') ifFalse:[
355
05eb4e183394 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 354
diff changeset
   338
            'GIFReader [info]: not a gif file' infoPrintCR.
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   339
            ^ nil
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   340
        ].
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   341
        id ~= 'GIF89a' ifTrue:[ 
355
05eb4e183394 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 354
diff changeset
   342
            'GIFReader [info]: not a GIF87a/GIF89a file - hope that works' infoPrintCR.
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   343
        ]
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   344
    ].
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   345
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   346
    "get screen dimensions (not used)"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   347
    scrWidth := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   348
    scrHeight := aStream nextShortMSB:false.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   349
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   350
    "get flag byte"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   351
    flag := aStream nextByte.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   352
    hasColorMap :=      (flag bitAnd:2r10000000) ~~ 0.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   353
    "bitsPerRGB :=     ((flag bitAnd:2r01110000) bitShift:-4) + 1. "
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   354
    "colorMapSorted := ((flag bitAnd:2r00001000) ~~ 0.             "
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   355
    bitsPerPixel :=     (flag bitAnd:2r00000111) + 1.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   356
    colorMapSize := 1 bitShift:bitsPerPixel.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   357
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   358
    "get background (not used)"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   359
    aStream nextByte.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   360
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   361
    "aspect ratio (not used)"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   362
    aStream nextByte.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   363
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   364
    "get colorMap"
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   365
    hasColorMap ifTrue:[
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   366
        self readColorMap:colorMapSize.
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   367
        fileColorMap := Colormap 
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   368
                        redVector:redMap 
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   369
                        greenVector:greenMap 
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   370
                        blueVector:blueMap.
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   371
    ].
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   372
    colorMap := fileColorMap.
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   373
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   374
    photometric := #palette.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   375
    samplesPerPixel := 1.
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   376
    bitsPerSample := #(8).
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   377
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   378
    atEnd := false.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   379
    [atEnd] whileFalse:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   380
        "gif89a extensions"
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   381
        byte := aStream nextByte.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   382
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   383
        byte == Extension ifTrue:[
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   384
            self readExtension:aStream.
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   385
        ] ifFalse:[
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   386
            (byte == Terminator) ifTrue:[
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   387
                atEnd := true
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   388
            ] ifFalse:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   389
                "must be image separator"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   390
                (byte ~~ ImageSeparator) ifTrue:[
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   391
                    ('GIFReader [info]: corrupted gif file (no IMAGESEP): ' , (byte printStringRadix:16)) infoPrintCR.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   392
                    ^ nil
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   393
                ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   394
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   395
                "get image data"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   396
                leftOffs := aStream nextShortMSB:false.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   397
                topOffs := aStream nextShortMSB:false.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   398
                width := aStream nextShortMSB:false.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   399
                height := aStream nextShortMSB:false.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   400
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   401
                dimensionCallBack notNil ifTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   402
                    dimensionCallBack value:self
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   403
                ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   404
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   405
"/
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   406
"/              'width ' print. width printNewline.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   407
"/              'height ' print. height printNewline.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   408
"/
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   409
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   410
                "another flag byte"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   411
                flag := aStream nextByte.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   412
                interlaced :=           (flag bitAnd:2r01000000) ~~ 0.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   413
                hasLocalColorMap :=     (flag bitAnd:2r10000000) ~~ 0.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   414
                "localColorMapSorted := (flag bitAnd:2r00100000) ~~ 0.      "
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   415
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   416
                "if image has a local colormap, this one is used"
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   417
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   418
                hasLocalColorMap ifTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   419
                    "local descr. overwrites"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   420
                    bitsPerPixel := (flag bitAnd:2r00000111) + 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   421
                    colorMapSize := 1 bitShift:bitsPerPixel.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   422
                    "overwrite colormap"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   423
                    self readColorMap:colorMapSize.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   424
                    colorMap := Colormap 
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   425
                                    redVector:redMap 
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   426
                                    greenVector:greenMap 
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   427
                                    blueVector:blueMap.
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   428
                ] ifFalse:[
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   429
                    colorMap := fileColorMap
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   430
                ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   431
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   432
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   433
                "get codelen for decompression"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   434
                codeLen := aStream nextByte.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   435
755
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   436
                (aStream respondsTo:#fileSize) ifTrue:[
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   437
                    "get hint about length of compressed data"
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   438
                    count := aStream fileSize.
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   439
                ] ifFalse:[
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   440
                    count := 512.
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   441
                ].
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   442
                compressedData := ByteArray uninitializedNew:count.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   443
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   444
                "get compressed data"
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   445
                index := 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   446
                count := aStream nextByte.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   447
                [count notNil and:[count ~~ 0]] whileTrue:[
755
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   448
                    (compressedData size < (index+count)) ifTrue:[
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   449
                        |c|
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   450
                        c := ByteArray uninitializedNew:(index+count*3//2).
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   451
                        c replaceBytesFrom:1 to:index-1 
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   452
                          with:compressedData startingAt:1.
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   453
                        
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   454
                        compressedData := c.
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   455
                    ].
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   456
                    aStream nextBytes:count into:compressedData startingAt:index blockSize:4096.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   457
                    index := index + count.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   458
                    count := aStream nextByte
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   459
                ].
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   460
                compressedSize := index - 1.
83
claus
parents: 79
diff changeset
   461
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   462
                h := height.
749
49c372aaf613 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 732
diff changeset
   463
                data := ByteArray uninitializedNew:((width + 1) * (h + 1)).
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   464
"/                'GIFReader: decompressing ...' infoPrintCR.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   465
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   466
                self class decompressGIFFrom:compressedData
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   467
                                       count:compressedSize
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   468
                                        into:data
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   469
                                  startingAt:1
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   470
                                     codeLen:(codeLen + 1).
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   471
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   472
                interlaced ifTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   473
"/                    'GIFREADER: deinterlacing ...' infoPrintCR.
749
49c372aaf613 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 732
diff changeset
   474
                    tmp := ByteArray uninitializedNew:(data size).
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   475
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   476
                    "phase 1: 0, 8, 16, 24, ..."
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   477
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   478
                    srcOffset := 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   479
                    0 to:(h - 1) by:8 do:[:dstRow |
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   480
                        dstOffset := dstRow * width + 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   481
                        tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   482
                                   with:data startingAt:srcOffset.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   483
                        srcOffset := srcOffset + width.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   484
                    ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   485
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   486
                    "phase 2: 4, 12, 20, 28, ..."
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   487
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   488
                    4 to:(h - 1) by:8 do:[:dstRow |
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   489
                        dstOffset := dstRow * width + 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   490
                        tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   491
                                   with:data startingAt:srcOffset.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   492
                        srcOffset := srcOffset + width.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   493
                    ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   494
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   495
                    "phase 3: 2, 6, 10, 14, ..."
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   496
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   497
                    2 to:(h - 1) by:4 do:[:dstRow |
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   498
                        dstOffset := dstRow * width + 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   499
                        tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   500
                                   with:data startingAt:srcOffset.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   501
                        srcOffset := srcOffset + width.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   502
                    ].
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   503
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   504
                    "phase 4: 1, 3, 5, 7, ..."
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   505
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   506
                    1 to:(h - 1) by:2 do:[:dstRow |
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   507
                        dstOffset := dstRow * width + 1.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   508
                        tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   509
                                   with:data startingAt:srcOffset.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   510
                        srcOffset := srcOffset + width.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   511
                    ].
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   512
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   513
                    data := tmp.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   514
                    tmp := nil.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   515
                ].
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   516
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   517
                imageSequence isNil ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   518
                    imageSequence := OrderedCollection new.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   519
                ].
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   520
                maskPixel notNil ifTrue:[
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   521
                    "/
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   522
                    "/ ok, there is a maskValue
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   523
                    "/ build a Depth1Image for it.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   524
                    "/
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   525
                    self buildMaskFromColor:maskPixel
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   526
                ].
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   527
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   528
                imageSequence add:(self image).
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   529
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   530
                aStream atEnd ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   531
                    atEnd := true.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   532
                ]
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   533
            ]
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   534
        ].
307
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   535
    ].
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   536
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   537
    "
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   538
     GIFReader fromFile:'../fileIn/bitmaps/claus.gif
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   539
     GIFReader fromFile:'../fileIn/bitmaps/garfield.gif'
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   540
     GIFReader new fromStream:('/home2/cg/.misc/circum.gif' asFilename readStream)
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   541
    "
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   542
749
49c372aaf613 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 732
diff changeset
   543
    "Modified: / 18.12.1997 / 10:23:38 / cg"
755
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   544
    "Modified: / 15.1.1998 / 15:42:19 / stefan"
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   545
!
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   546
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   547
makeGreyscale
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   548
    "not yet implemented/needed"
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   549
!
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   550
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   551
readColorMap:colorMapSize
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   552
    "get gif colormap consisting of colorMapSize entries"
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   553
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   554
    |sz "{ Class: SmallInteger }"|
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   555
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   556
    redMap := ByteArray uninitializedNew:colorMapSize.
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   557
    greenMap := ByteArray uninitializedNew:colorMapSize.
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   558
    blueMap := ByteArray uninitializedNew:colorMapSize.
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   559
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   560
    sz := colorMapSize.
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   561
    1 to:sz do:[:i |
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   562
        redMap at:i put:(inStream nextByte).
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   563
        greenMap at:i put:(inStream nextByte).
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   564
        blueMap at:i put:(inStream nextByte)
307
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   565
    ].
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   566
307
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   567
    "Modified: 21.6.1996 / 12:32:43 / cg"
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   568
!
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   569
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   570
readExtension:aStream
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   571
    "get gif89 extension - this is currently ignored"
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   572
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   573
    |type blockSize subBlockSize
304
c8078fb77706 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 271
diff changeset
   574
     aspNum aspDen left top width height cWidth cHeight fg bg
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   575
     animationType animationTime animationMask
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   576
     appID appAUTH
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   577
     iterationCount b ok|
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   578
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   579
    type := aStream nextByte.
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   580
    type == $R asciiValue ifTrue:[
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   581
        "/
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   582
        "/ Ratio extension
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   583
        "/
354
b4d2ce853c24 stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents: 339
diff changeset
   584
        'GIFREADER [info]: ratio extension ignored' infoPrintCR.
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   585
        blockSize := aStream nextByte.
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   586
        (blockSize == 2) ifTrue:[
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   587
            aspNum := aStream nextByte.
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   588
            aspDen := aStream nextByte
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   589
        ] ifFalse:[
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   590
            aStream skip:blockSize
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   591
        ].
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   592
        "/ eat subblocks
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   593
        
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   594
        [(subBlockSize := aStream nextByte) > 0] whileTrue:[
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   595
            aStream skip:subBlockSize
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   596
        ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   597
        ^ self
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   598
    ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   599
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   600
    type == 16r01 ifTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   601
        "/
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   602
        "/ plaintext extension
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   603
        "/
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   604
"/        'GIFREADER [info]: plaintext extension ignored' infoPrintCR.
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   605
        subBlockSize := aStream nextByte.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   606
        left := aStream nextShortMSB:false.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   607
        top := aStream nextShortMSB:false.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   608
        width := aStream nextShortMSB:false.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   609
        height := aStream nextShortMSB:false.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   610
        cWidth := aStream nextByte.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   611
        cHeight := aStream nextByte.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   612
        fg := aStream nextByte.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   613
        bg := aStream nextByte.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   614
        aStream skip:12.
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   615
        [(subBlockSize := aStream nextByte) > 0] whileTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   616
            aStream skip:subBlockSize
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   617
        ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   618
        ^ self
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   619
    ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   620
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   621
    type == 16rF9 ifTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   622
        "/
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   623
        "/ graphic control extension
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   624
        "/
354
b4d2ce853c24 stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents: 339
diff changeset
   625
"/        'GIFREADER [info]: graphic control extension ignored' infoPrintCR.
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   626
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   627
        [(subBlockSize := aStream nextByte) ~~ 0] whileTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   628
            "/ type bitAnd:1 means: animationMask is transparent pixel
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   629
            "/ to be implemented in Image ...
305
0edebf4ecaa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 304
diff changeset
   630
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   631
            animationType := aStream nextByte.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   632
            animationTime := aStream nextShortMSB:false.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   633
            animationMask := aStream nextByte.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   634
            subBlockSize := subBlockSize - 4.
307
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   635
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   636
           (animationType bitTest: 1) ifTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   637
                maskPixel := animationMask.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   638
"/                'GIFREADER [info]: mask: ' infoPrint. (maskPixel printStringRadix:16) infoPrintCR.
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   639
            ].
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   640
"/            'GIFREADER [info]: animationTime: ' infoPrint. (animationTime * (1/100)) infoPrintCR.
307
9eaeaca798a5 create a mask-image, if present
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
   641
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   642
            subBlockSize ~~ 0 ifTrue:[
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   643
                aStream skip:subBlockSize
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   644
            ].
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   645
        ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   646
        ^ self
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   647
    ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   648
519
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   649
    type == 16rFE ifTrue:[
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   650
        "/
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   651
        "/ comment extension
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   652
        "/
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   653
"/        'GIFREADER [info]: comment extension ignored' infoPrintCR.
519
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   654
        [(blockSize := aStream nextByte) ~~ 0] whileTrue:[
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   655
            aStream skip:blockSize
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   656
        ].
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   657
        ^ self
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   658
    ].
1ee56341ef50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   659
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   660
    type == 16rFF ifTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   661
        "/
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   662
        "/  application extension
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   663
        "/
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   664
        subBlockSize := aStream nextByte.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   665
        appID := (aStream nextBytes:8 ) asString.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   666
        appAUTH := aStream nextBytes:3.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   667
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   668
        subBlockSize := aStream nextByte.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   669
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   670
        ok := false.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   671
        appID = 'NETSCAPE' ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   672
            appAUTH asString = '2.0' ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   673
                subBlockSize == 3 ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   674
                    b := aStream nextByte.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   675
                    iterationCount := aStream nextShortMSB:false.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   676
                    subBlockSize := aStream nextByte.
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   677
                    ok := true.
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   678
                ]
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   679
            ]
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   680
        ].
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   681
625
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   682
        ok ifFalse:[
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   683
            ('GIFREADER [info]: application extension (' , appID , ') ignored') infoPrintCR.
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   684
        ].
72c766a86a0e less info printing
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   685
618
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   686
        [subBlockSize > 0] whileTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   687
            aStream skip:subBlockSize.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   688
            subBlockSize := aStream nextByte.
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   689
        ].
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   690
        ^ self
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   691
    ].
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   692
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   693
    type == 16r2C ifTrue:[
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   694
        "/
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   695
        "/  image descriptor extension
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   696
        "/
ab83e72fd105 support multiple images (animated gif)
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   697
        'GIFREADER [info]: image descriptor extension ignored' infoPrintCR.
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   698
        [(subBlockSize := aStream nextByte) > 0] whileTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   699
            aStream skip:subBlockSize
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   700
        ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   701
        ^ self
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   702
    ].
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   703
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   704
    "/
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   705
    "/ unknown extension
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   706
    "/
354
b4d2ce853c24 stefans suggested info/warning/error/fatal
Claus Gittinger <cg@exept.de>
parents: 339
diff changeset
   707
    'GIFREADER [info]: unknown extension ignored' infoPrintCR.
239
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   708
    [(subBlockSize := aStream nextByte) > 0] whileTrue:[
208108f3c707 comments
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
   709
        aStream skip:subBlockSize
154
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   710
    ]
40bbc62e8d78 added GIF89a support
Claus Gittinger <cg@exept.de>
parents: 136
diff changeset
   711
670
6a7f628ee66c oops - mask was only set for interlaced images (stupid typo)
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   712
    "Modified: 24.7.1997 / 18:02:49 / cg"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   713
! !
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   714
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   715
!GIFReader methodsFor:'writing to file'!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   716
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   717
save:image onFile:aFileName
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   718
    "save image as GIF file on aFileName"
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   719
718
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   720
    image depth ~~ 8 ifTrue:[
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   721
        ^ Image cannotRepresentImageSignal 
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   722
            raiseWith:image
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   723
            errorString:('GIF (currently) only supports depth8 images').
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   724
    ].
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   725
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   726
    outStream := FileStream newFileNamed:aFileName.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   727
    outStream isNil ifTrue:[
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   728
        ^ Image fileCreationErrorSignal 
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   729
            raiseWith:image
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   730
            errorString:('file creation error: ' , aFileName asString).
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   731
    ].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   732
    outStream binary.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   733
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   734
    mask := image mask.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   735
    mask notNil ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   736
        self assignTransparentPixelIn:image
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   737
    ].
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   738
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   739
    byteOrder := #lsb.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   740
    width := image width.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   741
    height := image height.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   742
    photometric := image photometric.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   743
    samplesPerPixel := image samplesPerPixel.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   744
    bitsPerSample := image bitsPerSample.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   745
    colorMap := image colorMap.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   746
    data := image bits.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   747
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   748
    self writeHeaderFor:image.
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   749
    maskPixel notNil ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   750
        self writeMaskExtensionHeaderFor:image.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   751
    ].
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   752
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   753
    self writeBitDataFor:image.
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   754
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   755
    outStream nextPut: Terminator.
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   756
    outStream close.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   757
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   758
    "
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   759
     |i|
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   760
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   761
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   762
     GIFReader save:i onFile:'foo.gif'.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   763
     (Image fromFile:'./foo.gif') inspect
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   764
    "
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   765
718
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   766
    "Created: / 14.10.1997 / 17:40:12 / cg"
41ade132da98 raise an error, if depth is not supported.
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
   767
    "Modified: / 27.10.1997 / 22:42:31 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   768
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   769
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   770
writeBitDataFor: image
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   771
        "using modified Lempel-Ziv Welch algorithm."
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   772
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   773
        | bits bitsPerPixel t1
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   774
          maxBits maxMaxCode tSize initCodeSize ent tShift fCode pixel index disp nomatch |
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   775
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   776
        outStream nextPut:ImageSeparator.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   777
        self writeShort:0.       "/
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   778
        self writeShort:0.       "/
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   779
        self writeShort:width.   "/ image size
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   780
        self writeShort:height.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   781
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   782
        interlace == true ifTrue:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   783
            t1 := 64
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   784
        ] ifFalse:[
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   785
            t1 := 0
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   786
        ].
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   787
        outStream nextPut:t1.       "/ another flag
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   788
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   789
        bitsPerPixel := image bitsPerPixel.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   790
        bits := image bits.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   791
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   792
        pass := 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   793
        xpos := 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   794
        ypos := 0.
712
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   795
        rowByteSize := image bytesPerRow. "/ width * 8 + 31 // 32 * 4.
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   796
        remainBitCount := 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   797
        bufByte := 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   798
        bufStream := WriteStream on: (ByteArray new: 256).
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   799
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   800
        maxBits := 12.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   801
        maxMaxCode := 1 bitShift: maxBits.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   802
        tSize := 5003.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   803
        prefixTable := Array new: tSize.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   804
        suffixTable := Array new: tSize.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   805
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   806
        initCodeSize := bitsPerPixel <= 1 ifTrue: [2] ifFalse: [bitsPerPixel].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   807
        outStream nextPut: initCodeSize.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   808
        self setParameters: initCodeSize.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   809
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   810
        tShift := 0.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   811
        fCode := tSize.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   812
        [fCode < 65536] whileTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   813
                [tShift := tShift + 1.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   814
                fCode := fCode * 2].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   815
        tShift := 8 - tShift.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   816
        1 to: tSize do: [:i | suffixTable at: i put: -1].
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   817
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   818
        self writeCodeAndCheckCodeSize: clearCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   819
        ent := self readPixelFrom: bits.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   820
        [(pixel := self readPixelFrom: bits) == nil] whileFalse:
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   821
                [
710
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   822
                fCode := (pixel bitShift: maxBits) + ent.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   823
                index := ((pixel bitShift: tShift) bitXor: ent) + 1.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   824
                (suffixTable at: index) = fCode
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   825
                        ifTrue: [ent := prefixTable at: index]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   826
                        ifFalse:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   827
                                [nomatch := true.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   828
                                (suffixTable at: index) >= 0
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   829
                                        ifTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   830
                                                [disp := tSize - index + 1.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   831
                                                index = 1 ifTrue: [disp := 1].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   832
                                                "probe"
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   833
                                                [(index := index - disp) < 1 ifTrue: [index := index + tSize].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   834
                                                (suffixTable at: index) = fCode
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   835
                                                        ifTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   836
                                                                [ent := prefixTable at: index.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   837
                                                                nomatch := false.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   838
                                                                "continue whileFalse:"].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   839
                                                nomatch and: [(suffixTable at: index) > 0]]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   840
                                                        whileTrue: ["probe"]].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   841
                                "nomatch"
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   842
                                nomatch ifTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   843
                                        [self writeCodeAndCheckCodeSize: ent.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   844
                                        ent := pixel.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   845
                                        freeCode < maxMaxCode
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   846
                                                ifTrue:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   847
                                                        [prefixTable at: index put: freeCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   848
                                                        suffixTable at: index put: fCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   849
                                                        freeCode := freeCode + 1]
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   850
                                                ifFalse:
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   851
                                                        [self writeCodeAndCheckCodeSize: clearCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   852
                                                        1 to: tSize do: [:i | suffixTable at: i put: -1].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   853
                                                        self setParameters: initCodeSize]]]].
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   854
        prefixTable := suffixTable := nil.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   855
        self writeCodeAndCheckCodeSize: ent.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   856
        self writeCodeAndCheckCodeSize: eoiCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   857
        self flushCode.
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   858
        outStream nextPut: 0.        "zero-length packet"
c644d7932605 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 708
diff changeset
   859
712
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   860
    "Modified: 15.10.1997 / 19:56:28 / cg"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   861
!
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   862
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   863
writeHeaderFor:image
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   864
    "write the gif header"
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   865
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   866
    |bitsPerPixel t1 n|
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   867
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   868
    bitsPerPixel := image bitsPerPixel.
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   869
732
db51a760126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 718
diff changeset
   870
    outStream nextPutAll: 'GIF89a' asByteArray.
712
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   871
    self writeShort:width. "/ screen size
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   872
    self writeShort:height.    
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   873
    t1 := 128.
712
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   874
    t1 := t1 bitOr:(bitsPerPixel - 1 bitShift:5).
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   875
    t1 := t1 bitOr:(bitsPerPixel - 1).
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   876
    outStream nextPut:t1.  "/ flag
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   877
    outStream nextPut:0.   "/ background (not used)
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   878
    outStream nextPut:0.   "/ aspect ratio
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   879
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   880
    0 to:(1 bitShift:bitsPerPixel)-1 do:[:pixel |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   881
        |clr red green blue|
712
6403dd3407eb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 710
diff changeset
   882
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   883
        clr := image colorFromValue:pixel.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   884
        clr isNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   885
            "/ unused colorMap slot
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   886
            red := green := blue := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   887
        ] ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   888
            red := (clr redByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   889
            green := (clr greenByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   890
            blue := (clr blueByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   891
        ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   892
        outStream
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   893
            nextPut:red; nextPut:green; nextPut:blue.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   894
    ].    
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   895
"/    n := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   896
"/    image colorMap notNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   897
"/        image colorMap do:[:clr |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   898
"/            |red green blue|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   899
"/
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   900
"/            clr isNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   901
"/                "/ unused colorMap slot
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   902
"/                red := green := blue := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   903
"/            ] ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   904
"/                red := (clr redByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   905
"/                green := (clr greenByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   906
"/                blue := (clr blueByte).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   907
"/            ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   908
"/            outStream
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   909
"/                nextPut:red; nextPut:green; nextPut:blue.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   910
"/            n := n + 1.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   911
"/        ]
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   912
"/    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   913
"/    n+1 to:(1 bitShift:bitsPerPixel) do:[:i |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   914
"/        outStream nextPut:0; nextPut:0; nextPut:0
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
   915
"/    ].
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   916
732
db51a760126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 718
diff changeset
   917
    "Created: / 14.10.1997 / 17:41:28 / cg"
db51a760126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 718
diff changeset
   918
    "Modified: / 31.10.1997 / 16:12:13 / cg"
714
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   919
!
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   920
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   921
writeMaskExtensionHeaderFor:image
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   922
    "write an extension header for the transparent pixel"
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   923
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   924
    outStream nextPut:Extension.
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   925
    outStream nextPut:16rF9.       "/ graphic control extension
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   926
    outStream nextPut:4.           "/ subBlockSize
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   927
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   928
    outStream nextPut:1.                "/ animationType
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   929
    outStream nextPutShort:1 MSB:false. "/ animationTime
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   930
    outStream nextPut:maskPixel.        "/ animationMask
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   931
c89f5c12538c added transparentPixel support.
ca
parents: 713
diff changeset
   932
    outStream nextPut:0.
708
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   933
! !
47d402971287 added GIF writing capability
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
   934
339
9b4ece782f6a removed an infoPrint.
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   935
!GIFReader class methodsFor:'documentation'!
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   936
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   937
version
755
f1135dda53b1 be carefull when reading from non-fileStreams
Stefan Vogel <sv@exept.de>
parents: 749
diff changeset
   938
    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.65 1998-01-15 15:38:47 stefan Exp $'
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   939
! !
43
e85c7d392833 *** empty log message ***
claus
parents: 34
diff changeset
   940
GIFReader initialize!