PNGReader.st
author Claus Gittinger <cg@exept.de>
Wed, 05 Aug 2009 14:27:22 +0200
changeset 2707 e9c5c3ab8c18
parent 2706 3c2c631f9d16
child 2708 c206c9e9bd61
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    12
"{ Package: 'stx:libview2' }"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    13
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ImageReader subclass:#PNGReader
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
    15
	instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
    16
		interlaceMode redBytes greenBytes blueBytes bytesPerScanline
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
    17
		globalDataChunk thisScanline prevScanline'
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
    18
	classVariableNames:'Verbose'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1694
diff changeset
    20
	category:'Graphics-Images-Readers'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    23
!PNGReader class methodsFor:'documentation'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1996 by Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    43
    This class will provide methods for loading PNG pictures.
2700
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
    44
    It is currenty unfinished (interlaced image support is missing).
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    45
    In the meantime, use a pngtoXXX converter.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    [See also:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        Image Form Icon
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
        XBMReader XPMReader XWDReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [author:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
"
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    56
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    58
examples
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    59
"
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    60
    PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
    61
    PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    62
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    63
    PNGReader fromFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png'
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
    64
    PNGReader fromFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png'
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
    65
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png'
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    66
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png'
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    67
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    68
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    69
    |img img2 outStream png|
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    70
    img := ToolbarIconLibrary error32x32Icon.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    71
    outStream := WriteStream on:(ByteArray new:100).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    72
    PNGReader save:img onStream:outStream.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    73
    png := outStream contents.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    74
    img2 := PNGReader fromStream:(png readStream).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    75
    img2 inspect.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    76
    self assert:(img bytes = img2 bytes).
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    77
"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    80
!PNGReader class methodsFor:'initialization'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
initialize
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    83
    "install myself in the Image classes fileFormat table for the `.png' extension."
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    85
    MIMETypes defineImageType:'image/x-png'  suffix:'png' reader:self.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    88
!PNGReader class methodsFor:'queries'!
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    89
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    90
canRepresent:anImage
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    91
    "return true, if anImage can be represented in my file format.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    92
     Any image is supported."
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    93
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    94
    ^ true
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    95
! !
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    96
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    97
!PNGReader class methodsFor:'testing'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
isValidImageFile:aFileName
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "return true, if aFileName contains a PNG image"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    |inStream magic|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    inStream := self streamReadingFile:aFileName.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    inStream isNil ifTrue:[^ false].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    inStream binary.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    magic := ByteArray new:8.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    inStream nextBytes:8 into:magic.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    inStream close.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    ^ (magic = #[137 80 78 71 13 10 26 10])
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   115
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   116
     self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   117
     self isValidImageFile:'C:\Users\cg\Desktop\croquet\cobalt-base-current-build-20090210\cobalt-base-current-build-20090210\content\models\textures\checkerboard.png'
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   118
     self isValidImageFile:'C:\Dokumente und Einstellungen\cg\Desktop\misc\PNGs\Delete.png'
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   119
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   120
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    "Modified: 21.6.1996 / 20:38:46 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   124
!PNGReader methodsFor:'private-chunks'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   126
doPass: pass
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   127
    "Certain interlace passes are skipped with certain small image dimensions"
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   128
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   129
    pass = 1 ifTrue: [ ^ true ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   130
    ((width = 1) and: [height = 1]) ifTrue: [ ^ false ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   131
    pass = 2 ifTrue: [ ^ width >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   132
    pass = 3 ifTrue: [ ^ height >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   133
    pass = 4 ifTrue: [ ^ (width >=3 ) or: [height >= 5] ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   134
    pass = 5 ifTrue: [ ^ height >=3 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   135
    pass = 6 ifTrue: [ ^ width >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   136
    pass = 7 ifTrue: [ ^ height >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   137
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   138
    self error:'invalid argument'.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   139
    ^ true
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   140
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   141
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
processBKGDChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "Created: 21.6.1996 / 21:15:49 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   149
processCHRMChunkLen:len
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   150
    "cHRM Primary chromaticities chunk - currently unhandled"
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   151
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   152
    |whitePointX whitePointY redX redY greenX greenY blueX blueY|
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   153
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   154
    whitePointX := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   155
    whitePointY := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   156
    redX := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   157
    redY := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   158
    greenX := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   159
    greenY := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   160
    blueX := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   161
    blueY := (inStream nextLongMSB:true) / 100000.0.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   162
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   163
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   164
        'PNGReader: CHRM chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   165
        'PNGReader:   whitePointX:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   166
        'PNGReader:   whitePointY:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   167
        'PNGReader:   redX:' infoPrint. redX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   168
        'PNGReader:   redY:' infoPrint. redY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   169
        'PNGReader:   greenX:' infoPrint. greenX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   170
        'PNGReader:   greenY:' infoPrint. greenY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   171
        'PNGReader:   blueX:' infoPrint. blueX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   172
        'PNGReader:   blueY:' infoPrint. blueY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   173
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   174
    ^ true
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   175
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   176
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
processChunk:type len:len
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   178
    |chunk|
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   179
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   180
    type = 'IDAT' ifTrue:[
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   181
        "---since the compressed data can span multiple
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   182
        chunks, stitch them all together first. later,
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   183
        if memory is an issue, we need to figure out how
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   184
        to do this on the fly---"
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   185
        chunk := inStream next:len.
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   186
        globalDataChunk := globalDataChunk isNil 
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   187
                                ifTrue: [chunk] 
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   188
                                ifFalse:[globalDataChunk,chunk].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   189
        ^ true
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   190
"/        ^ self processIDATChunkLen:len
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   191
    ].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   192
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    type = 'tIME' ifTrue:[^ self processTIMEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    type = 'bKGD' ifTrue:[^ self processBKGDChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    type = 'zTXt' ifTrue:[^ self processZTXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    type = 'PLTE' ifTrue:[^ self processPLTEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   201
    type = 'pHYs' ifTrue:[^ self processPHYSChunkLen:len].
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   202
    type = 'cHRM' ifTrue:[^ self processCHRMChunkLen:len].
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   203
    type = 'tRNS' ifTrue:[^ self processTRNSChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   204
    type = 'IHDR' ifTrue:[^ self processIHDRChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   205
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    ('PNGReader: unrecognized chunk: ' , type , ' ignored.') infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    ^ true.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    "Created: 21.6.1996 / 21:10:37 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "Modified: 21.6.1996 / 21:22:37 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
processGAMAChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    "Created: 21.6.1996 / 21:10:52 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   222
processGlobalIDATChunk
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   223
    interlaceMode == 0 ifTrue: [
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   224
        ^ self processNonInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   225
    ]. 
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   226
    ^ self processInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   227
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   228
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
processIDATChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   230
    interlaceMode == 0 ifTrue: [
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   231
        ^ self processNonInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   232
    ]. 
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   233
    ^ self processInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   234
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   235
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   236
processInterlacedDATA:len
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    ^ true
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   239
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   241
processInterlacedGlobalDATA
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   242
    | zlibReader filter bytesPerPass startingCol colIncrement rowIncrement 
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   243
      startingRow cx sc temp "filtersSeen" bitsPerPixel copyMethod|
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   244
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   245
    self error:'interlaced pictures not yet supported'.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   246
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   247
    "/ filtersSeen := Set new.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   248
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   249
    startingCol := #(0 4 0 2 0 1 0 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   250
    colIncrement := #(8 8 4 4 2 2 1 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   251
    rowIncrement := #(8 8 8 4 4 2 2 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   252
    startingRow := #(0 0 4 0 2 0 1 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   253
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   254
    zlibReader := ZipStream readOpenAsZipStreamOn:(globalDataChunk readStream) suppressHeaderAndChecksum:false.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   255
    zlibReader binary.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   256
    bytesPerScanline := self bytesPerRow.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   257
    bitsPerPixel := self bitsPerPixel.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   258
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   259
    copyMethod := #(copyPixelsGray: nil copyPixelsRGB: copyPixelsIndexed:
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   260
                    copyPixelsGrayAlpha: nil copyPixelsRGBA:) at:colorType+1.     
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   261
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   262
    1 to: 7 do: [:pass |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   263
        (self doPass: pass) ifTrue:[
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   264
            cx := colIncrement at: pass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   265
            sc := startingCol at: pass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   266
            bytesPerPass := width - sc + cx - 1 // cx * bitsPerPixel + 7 // 8.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   267
            prevScanline := ByteArray new: bytesPerPass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   268
            thisScanline := ByteArray new: bytesPerScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   269
            (startingRow at: pass) to: height - 1 by: (rowIncrement at: pass) do: [:y |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   270
                filter := zlibReader next.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   271
                "/ filtersSeen add: filter.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   272
                (filter isNil or: [(filter between: 0 and: 4) not])
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   273
                    ifTrue: [^ self].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   274
                zlibReader next: bytesPerPass into: thisScanline startingAt: 1.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   275
                filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerPass ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   276
                self copyPixels:y at:sc by:cx.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   277
                temp := prevScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   278
                prevScanline := thisScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   279
                thisScanline := temp.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   280
            ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   281
        ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   282
    ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   283
    zlibReader atEnd ifFalse:[self error:'Unexpected data'].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   284
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   285
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   286
processNonInterlacedDATA:len
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   287
    self halt:'not used'
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   288
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   289
"/    | zlibReader filter temp prevScanline thisScanline bytesPerScanline filtersSeen|
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   290
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   291
"/    zlibReader := ZipStream readOpenAsZipStreamOn:inStream suppressHeaderAndChecksum:false. 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   292
"/    "/ zlibReader := ZLibReadStream on:inStream from: 1 to:len.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   293
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   294
"/    prevScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   295
"/    thisScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   296
"/    0 to: height - 1 do:[:index | 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   297
"/            filter := (zlibReader next: 1) first.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   298
"/            filtersSeen add: filter.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   299
"/            (filter isNil or: [(filter between: 0 and: 4) not]) ifTrue: [^self].
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   300
"/            thisScanline := zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   301
"/            self filterScanline: filter count: bytesPerScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   302
"/            self copyPixels: index.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   303
"/            temp := prevScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   304
"/            prevScanline := thisScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   305
"/            thisScanline := temp
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   306
"/    ]
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   307
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   308
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   309
processNonInterlacedGlobalDATA
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   310
    | "data n" zlibReader filter temp bytesPerScanline "filtersSeen"|
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   311
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   312
    "/ filtersSeen := Set new.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   313
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   314
"/    data := ByteArray new:(self bytesPerRow * height)+1000.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   315
"/    n := ZipStream uncompress: globalDataChunk into: data.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   316
"/    self halt.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   317
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   318
    zlibReader := ZipStream readOpenAsZipStreamOn:(globalDataChunk readStream) suppressHeaderAndChecksum:false.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   319
    zlibReader binary.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   320
    bytesPerScanline := self bytesPerRow.
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   321
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   322
    prevScanline := ByteArray new: bytesPerScanline.
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   323
    thisScanline := ByteArray new: bytesPerScanline.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   324
    0 to: height - 1 do:[:index | 
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   325
        filter := (zlibReader next: 1) first.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   326
        "/ filtersSeen add: filter.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   327
        (filter isNil or: [(filter between: 0 and: 4) not]) ifTrue: [^self].
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   328
        zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   329
        filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerScanline ].
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   330
        self copyPixels:index.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   331
        temp := prevScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   332
        prevScanline := thisScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   333
        thisScanline := temp
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   334
    ]
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   335
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   336
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   337
processPHYSChunkLen:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   338
    "physical pixel chunk - currently unhandled"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   339
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   340
    |pixelPerUnitX pixelPerUnitY unit|
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   341
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   342
    pixelPerUnitX := inStream nextLongMSB:true.  
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   343
    pixelPerUnitY := inStream nextLongMSB:true.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   344
    unit := inStream nextByte.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   345
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   346
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   347
        'PNGReader: PHYS chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   348
        'PNGReader:   ppuX:' infoPrint. pixelPerUnitX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   349
        'PNGReader:   ppuY:' infoPrint. pixelPerUnitY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   350
        'PNGReader:   unit:' infoPrint. unit infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   351
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   352
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   353
    ^ true
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
processPLTEChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   357
    "read a color palette"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   358
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
    |n "{ Class: SmallInteger }"|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
    (len \\ 3) ~~ 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
        'PNGReader: invalid size of PLTE chunk' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
        ^ false
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    n := len // 3.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    redBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
    greenBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
    blueBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
    1 to:n do:[:i |
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
        redBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
        greenBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
        blueBytes at:i put:(inStream nextByte)
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
    "Created: 21.6.1996 / 21:22:28 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    "Modified: 21.6.1996 / 21:43:01 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
processSBITChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
    "Created: 21.6.1996 / 21:13:09 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
processTEXTChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
    "Modified: 21.6.1996 / 21:15:27 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
processTIMEChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
    "Created: 21.6.1996 / 21:15:43 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
    "Modified: 21.6.1996 / 21:20:42 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   404
processTRNSChunkLen:len
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   405
    inStream skip:len.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   406
    ^ true
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   407
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   408
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
processZTXTChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
    "Created: 21.6.1996 / 21:15:58 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   416
!PNGReader methodsFor:'private-filtering'!
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   417
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   418
filterAverage: count
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   419
    "Use the average of the pixel to the left and the pixel above as a predictor"
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   420
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   421
    | delta |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   422
    delta := self bitsPerPixel // 8 max: 1.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   423
    1 to: delta do: [:i |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   424
        thisScanline at: i put: ((thisScanline at: i) + ((prevScanline at: i) // 2) bitAnd: 255)].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   425
    delta + 1 to: count do: [:i |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   426
        thisScanline at: i put:
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   427
            ((thisScanline at: i)
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   428
            + ((prevScanline at: i)
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   429
            + (thisScanline at: i - delta) // 2) bitAnd: 255)]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   430
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   431
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   432
filterHorizontal:count
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   433
    "use the pixel to the left as a predictor"
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   434
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   435
    |delta|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   436
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   437
    delta := self bitsPerPixel // 8 max:1.
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   438
    delta+1 to:count do:[:i|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   439
        thisScanline at:i put:(((thisScanline at:i)+ (thisScanline at:i-delta)) bitAnd:255) 
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   440
    ]
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   441
!
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   442
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   443
filterNone: count
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   444
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   445
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   446
filterPaeth: count
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   447
    "Select one of (the pixel to the left, the pixel above and the pixel to above left) to
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   448
    predict the value of this pixel"
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   449
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   450
    | delta |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   451
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   452
    delta _ self bitsPerPixel // 8 max: 1.
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   453
    1 to: delta do: [ :i |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   454
        thisScanline at: i put:
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   455
            (((thisScanline at: i) + (prevScanline at: i)) bitAnd: 255)].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   456
    delta+1 to: count do: [ :i |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   457
        thisScanline
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   458
            at: i
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   459
            put: (((thisScanline at: i) + (self
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   460
                paethPredictLeft: (thisScanline at: i-delta)
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   461
                above: (prevScanline at: i)
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   462
                aboveLeft: (prevScanline at: i-delta)))
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   463
                    bitAnd: 255)]
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   464
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   465
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   466
filterScanline:filterType count:count
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   467
    self 
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   468
        perform:(#(filterNone: filterHorizontal: filterVertical: filterAverage: filterPaeth:)
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   469
                    at:filterType+1)
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   470
        with:count
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   471
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   472
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   473
filterVertical: count
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   474
    "Use the pixel above as a predictor"
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   475
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   476
    1 to: count do: [ :i |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   477
        thisScanline at: i put: (((thisScanline at: i) +
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   478
                                 (prevScanline at: i)) bitAnd: 255) 
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   479
    ]
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   480
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   481
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   482
paethPredictLeft: a above: b aboveLeft: c
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   483
    "Predicts the value of a pixel based on nearby pixels, based on Paeth (GG II, 1991)"
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   484
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   485
    | pa pb pc |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   486
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   487
    pa := b > c ifTrue: [b - c] ifFalse: [c - b].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   488
    pb := a > c ifTrue: [a - c] ifFalse: [c - a].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   489
    pc := a + b - c - c.
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   490
    pc < 0 ifTrue: [
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   491
        pc := pc * -1
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   492
    ].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   493
    ((pa <= pb) and: [pa <= pc]) ifTrue: [^ a].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   494
    (pb <= pc) ifTrue: [^ b].
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   495
    ^ c
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   496
! !
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   497
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   498
!PNGReader methodsFor:'private-pixel copy'!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   499
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   500
copyPixels: y
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   501
    "in stx, the same copy method is used for all formats"
2700
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   502
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   503
    |bpr i|
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   504
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   505
    bpr := self bytesPerRow.
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   506
    i := y * bpr.
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   507
1fa3b493b74c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   508
    data replaceFrom:1+i to:(i+bpr) with:thisScanline startingAt:1.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   509
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   510
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   511
copyPixels: y at: startX by: incX
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   512
    "Handle interlaced pixels of supported colorTypes"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   513
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   514
    | s |
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   515
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   516
    s := #(copyPixelsGray:at:by: nil copyPixelsRGB:at:by: copyPixelsIndexed:at:by:
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   517
          copyPixelsGrayAlpha:at:by: nil copyPixelsRGBA:at:by:) at: colorType+1.
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   518
    self perform: s asSymbol with: y with: startX with: incX
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   519
! !
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   520
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   521
!PNGReader methodsFor:'private-reading'!
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   522
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   523
getChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   524
    |len type crc|
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   525
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   526
    inStream atEnd ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   527
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   528
    len := inStream nextLongMSB:true.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   529
    type := String new:4.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   530
    (inStream nextBytes:4 into:type) ~~ 4 ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   531
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   532
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   533
        'len: ' infoPrint. len infoPrint. ' type: ' infoPrint. type infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   534
    ].
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   535
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   536
    type = 'IEND' ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   537
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   538
    (self processChunk:type len:len) ifFalse:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   539
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   540
    crc := inStream nextLongMSB:true.  "/ ignored - for now
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   541
    ^ true
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   542
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   543
    "Created: 21.6.1996 / 21:09:36 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   544
    "Modified: 21.6.1996 / 21:20:26 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   545
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   546
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   547
getIHDRChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   548
    |len type crc|
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   549
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   550
    len := inStream nextLongMSB:true.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   551
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   552
    type := String new:4.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   553
    inStream nextBytes:4 into:type.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   554
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   555
    type = 'IHDR' ifFalse:[self halt. ^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   556
    len == 13 ifFalse:[self halt. ^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   557
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   558
    width := inStream nextLongMSB:true.        
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   559
    height := inStream nextLongMSB:true.        
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   560
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   561
    (width <= 0 or:[height <= 0]) ifTrue:[
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   562
        'PNGReader: invalid dimension(s)' infoPrintCR.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   563
        ^ false.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   564
    ].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   565
    self reportDimension.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   566
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   567
    depth := inStream nextByte.            "/ bits-per-channel
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   568
    colorType := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   569
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   570
    compressionMethod := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   571
    filterMethod := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   572
    interlaceMode := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   573
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   574
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   575
        'PNGReader: IHDR:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   576
        'PNGReader:   width: ' infoPrint. width infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   577
        'PNGReader:   height: ' infoPrint. height infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   578
        'PNGReader:   depth: ' infoPrint. depth infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   579
        'PNGReader:   colorType: ' infoPrint. colorType infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   580
        'PNGReader:   compressionMethod: ' infoPrint. compressionMethod infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   581
        'PNGReader:   filterMethod: ' infoPrint. filterMethod infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   582
        'PNGReader:   interlaceMode: ' infoPrint. interlaceMode infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   583
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   584
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   585
    crc := inStream nextLongMSB:true.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   586
    ^ true
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   587
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   588
    "Modified: 21.6.1996 / 21:38:35 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   589
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   590
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   591
setColorType:colorType
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   592
    colorType == 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   593
        photometric := #blackIs0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   594
        samplesPerPixel := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   595
        bitsPerSample := Array with:depth.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   596
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   597
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   598
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   599
    colorType == 2 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   600
        depth < 8 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   601
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   602
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   603
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   604
        photometric := #rgb.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   605
        samplesPerPixel := 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   606
        bitsPerSample := Array with:depth with:depth with:depth.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   607
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   608
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   609
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   610
    colorType == 3 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   611
        depth == 16 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   612
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   613
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   614
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   615
        photometric := #palette.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   616
        samplesPerPixel := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   617
        bitsPerSample := Array with:depth.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   618
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   619
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   620
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   621
    colorType == 4 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   622
        depth < 8 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   623
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   624
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   625
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   626
        photometric := #blackIs0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   627
        samplesPerPixel := 2.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   628
        bitsPerSample := Array with:depth with:depth.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   629
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   630
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   631
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   632
    colorType == 6 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   633
        depth < 8 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   634
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   635
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   636
        ].
2702
30fb9cf6affa changed #setColorType:
Claus Gittinger <cg@exept.de>
parents: 2701
diff changeset
   637
        photometric := #rgb.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   638
        samplesPerPixel := 4.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   639
        bitsPerSample := Array with:depth with:depth with:depth with:depth.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   640
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   641
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   642
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   643
    ('PNGReader: invalid colorType: ' , colorType printString , '.') infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   644
    ^ false
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   645
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   646
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   647
!PNGReader methodsFor:'reading'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
fromStream:aStream
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
    "read a stream containing a PNG image.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
     Leave image description in instance variables."
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
    |header|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
    inStream := aStream.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
    aStream binary.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   658
    "PNG-files are always msb (network-world)"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
    byteOrder := #msb.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
    header := ByteArray new:8.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
    aStream nextBytes:8 into:header.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   664
    header ~= (self pngHeader) ifTrue:[
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
        'PNGReader: not a png file.' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
    ].
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   668
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
    (self getIHDRChunk) ifFalse:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
        'PNGReader: required IHDR chunk missing.' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
    compressionMethod ~~ 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
        ('PNGReader: compressionMethod ' , compressionMethod printString , ' not supported.') infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
    filterMethod > 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
        'PNGReader: invalid filterMethod' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
        ^ nil.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
    interlaceMode > 1 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
        'PNGReader: invalid interlaceMode' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
        ^ nil.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    ].
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   686
    (self setColorType:colorType) ifFalse:[
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
        ^ nil
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   688
    ].
2706
3c2c631f9d16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2705
diff changeset
   689
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   690
    [self getChunk] whileTrue.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   692
    data := ByteArray new:(self bytesPerRow * height).
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   693
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   694
    globalDataChunk notNil ifTrue:[
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   695
        self processGlobalIDATChunk
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   696
    ].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   697
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
    photometric == #palette ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
        redBytes isNil ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
            'PNGReader: missing palette chunk.' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
            ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
        ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
1759
f52382e5a9b8 slowly getting rid of the Colormap class
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   704
        colorMap := MappedPalette 
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
                        redVector:redBytes 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
                        greenVector:greenBytes 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
                        blueVector:blueBytes.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
    "
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
     PNGReader fromFile:'/home/cg/libpng-0.89c/pngtest.png'
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
    "
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
    "Modified: 21.6.1996 / 21:44:34 / cg"
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   715
! !
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   716
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   717
!PNGReader methodsFor:'writing to file'!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   718
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   719
pngHeader
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   720
    ^ #[137 80 78 71 13 10 26 10]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   721
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   722
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   723
save:image onStream:aStream
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   724
    "save image in PNG-file-format onto aStream"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   725
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   726
    outStream := aStream.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   727
    outStream binary.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   728
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   729
    byteOrder := #msb.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   730
    width := image width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   731
    height := image height.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   732
    photometric := image photometric.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   733
    samplesPerPixel := image samplesPerPixel.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   734
    bitsPerSample := image bitsPerSample.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   735
    colorMap := image colorMap.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   736
    data := image bits.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   737
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   738
    outStream nextPutAll:(self pngHeader).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   739
    self writeIHDRChunk.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   740
    photometric == #palette ifTrue: [self writePaletteChunk].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   741
    self writeImageDataChunk.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   742
    self writeEndChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   743
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   744
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   745
writeChunk:chunkTypeChars size:len with:aBlock
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   746
    outStream nextPutLong:len MSB:true.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   747
    outStream nextPutBytes:4 from:chunkTypeChars startingAt:1.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   748
    aBlock value.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   749
!
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   750
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   751
writeEndChunk
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   752
    self 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   753
        writeChunk: 'IEND'
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   754
        size: 0
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   755
        with:[ ]
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   756
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   757
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   758
writeFileHeader
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   759
    outStream nextPutAll:(self pngHeader)
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   760
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   761
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   762
writeIHDRChunk
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   763
    |colorType|
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   764
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   765
    (photometric == #blackIs0) ifTrue:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   766
        colorType := 0.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   767
        samplesPerPixel size > 1 ifTrue:[ colorType := colorType + 4].  "/ +alpha
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   768
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   769
    (photometric == #rgb) ifTrue:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   770
        colorType := 2.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   771
        samplesPerPixel size > 3 ifTrue:[ colorType := colorType + 4].  "/ +alpha
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   772
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   773
    (photometric == #palette) ifTrue:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   774
        colorType := 3.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   775
        samplesPerPixel size > 1 ifTrue:[ colorType := colorType + 4].  "/ +alpha
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   776
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   777
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   778
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   779
        writeChunk: 'IHDR'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   780
        size: 13
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   781
        with:[ 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   782
            self writeLong:width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   783
            self writeLong:height.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   784
            outStream nextPut: 8.  "Assume that all colors are 24bit"     "/ depth
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   785
            outStream nextPut: colorType.  
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   786
            outStream nextPut: 0.  "Compression"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   787
            outStream nextPut: 0.  "Filter method"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   788
            outStream nextPut: 0   "Non-interlaced"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   789
        ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   790
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   791
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   792
writeImageDataChunk
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   793
    | zlibWriter bytesPerScanline|
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   794
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   795
    zlibWriter := ZipStream writeOpenAsZipStreamOn:outStream suppressHeaderAndChecksum:false.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   796
    zlibWriter binary.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   797
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   798
    bytesPerScanline := self bytesPerRow.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   799
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   800
    bytesPerScanline * height == data size ifTrue:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   801
        zlibWriter nextPutAll:data.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   802
    ] ifFalse:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   803
        self halt.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   804
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   805
!
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   806
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   807
writePaletteChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   808
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   809
        writeChunk: 'PLTE'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   810
        size: 3 * colorMap size
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   811
        with:[
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   812
            colorMap do:[:color | 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   813
                outStream
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   814
                    nextPut: color redByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   815
                    nextPut: color greenByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
   816
                    nextPut: color blueByte
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   817
            ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   818
        ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   819
! !
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   820
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   821
!PNGReader class methodsFor:'documentation'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
version
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   824
    ^ '$Header: /cvs/stx/stx/libview2/PNGReader.st,v 1.25 2009-08-05 12:27:22 cg Exp $'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
! !
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   826
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
PNGReader initialize!