PNGReader.st
author Claus Gittinger <cg@exept.de>
Sun, 29 Jan 2017 02:26:51 +0100
changeset 3853 5a78ffcf69de
parent 3821 940aaefb5f77
child 3854 4afd107bc911
child 3889 b7c261a8614d
permissions -rw-r--r--
#FEATURE by cg class: TypeConverter changed: #timeOfClass:withFormat:orDefault:language:
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
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
    14
"{ NameSpace: Smalltalk }"
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
    15
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
ImageReader subclass:#PNGReader
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    17
        instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    18
                interlaceMode bytesPerScanline globalDataChunk thisScanline
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    19
                prevScanline processTextChunks'
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    20
        classVariableNames:'Verbose'
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    21
        poolDictionaries:''
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
    22
        category:'Graphics-Images-Readers'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    25
!PNGReader class methodsFor:'documentation'!
308
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
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1996 by Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
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
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
documentation
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
"
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    45
    This class will provide methods for loading and saving PNG pictures.
3599
9bc697bd01d9 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3598
diff changeset
    46
    It is currenty unfinished (some interlaced image formats are unsupported, for example: grayscale+alpha)
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
    47
    In the meantime, use a pngtoXXX converter for interlaced images, and read XXX.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    49
    [caveats:]
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    50
        writer ignores any mask (for now).
3599
9bc697bd01d9 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3598
diff changeset
    51
        writer only generates unfiltered non-interlaced data
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    52
        
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [See also:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        Image Form Icon
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        XBMReader XPMReader XWDReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    [author:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
        Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    62
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    64
examples
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    65
"
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    66
    PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
    67
    PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    68
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    69
    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
    70
    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
    71
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png'
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    72
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png'
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    73
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    74
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    75
    |img img2 outStream png|
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    76
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    77
    img := ToolbarIconLibrary error32x32Icon.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    78
    outStream := WriteStream on:(ByteArray new:100).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    79
    PNGReader save:img onStream:outStream.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    80
    png := outStream contents.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    81
    img2 := PNGReader fromStream:(png readStream).
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
    82
    self assert:(img bits = img2 bits).
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
    83
    img inspect.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    84
    img2 inspect.
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    85
"
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
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    88
!PNGReader class methodsFor:'initialization'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
initialize
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    91
    "install myself in the Image classes fileFormat table for the `.png' extension."
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
2709
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    93
    MIMETypes defineImageType:'image/png'  suffix:'png' reader:self.
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    94
    "/ backward compatibility from times when png was not yet so common...
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    95
    MIMETypes defineImageType:'image/x-png' suffix:nil reader:self.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    98
!PNGReader class methodsFor:'queries'!
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
    99
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   100
canRepresent:anImage
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   101
    "return true, if anImage can be represented in my file format.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   102
     Any image is supported."
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   103
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   104
    ^ true
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   105
! !
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   106
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   107
!PNGReader class methodsFor:'testing'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
isValidImageFile:aFileName
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "return true, if aFileName contains a PNG image"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    |inStream magic|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    inStream := self streamReadingFile:aFileName.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    inStream isNil ifTrue:[^ false].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    inStream binary.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    magic := ByteArray new:8.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    inStream nextBytes:8 into:magic.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    inStream close.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ^ (magic = #[137 80 78 71 13 10 26 10])
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   125
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   126
     self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   127
     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
   128
     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
   129
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   130
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    "Modified: 21.6.1996 / 20:38:46 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   134
!PNGReader methodsFor:'private-chunks'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   136
doPass: pass
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   137
    "Certain interlace passes are skipped with certain small image dimensions"
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   138
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   139
    pass = 1 ifTrue: [ ^ true ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   140
    ((width = 1) and: [height = 1]) ifTrue: [ ^ false ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   141
    pass = 2 ifTrue: [ ^ width >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   142
    pass = 3 ifTrue: [ ^ height >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   143
    pass = 4 ifTrue: [ ^ (width >=3 ) or: [height >= 5] ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   144
    pass = 5 ifTrue: [ ^ height >=3 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   145
    pass = 6 ifTrue: [ ^ width >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   146
    pass = 7 ifTrue: [ ^ height >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   147
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   148
    self error:'invalid argument'.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   149
    ^ true
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   150
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   151
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
processBKGDChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    "Created: 21.6.1996 / 21:15:49 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   159
processCHRMChunkLen:len
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   160
    "cHRM Primary chromaticities chunk - currently unhandled"
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   161
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   162
    |whitePointX whitePointY redX redY greenX greenY blueX blueY|
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   163
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   164
    whitePointX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   165
    whitePointY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   166
    redX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   167
    redY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   168
    greenX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   169
    greenY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   170
    blueX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   171
    blueY := (inStream nextInt32MSB:true) / 100000.0.
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   172
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   173
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   174
        'PNGReader: CHRM chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   175
        'PNGReader:   whitePointX:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   176
        'PNGReader:   whitePointY:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   177
        'PNGReader:   redX:' infoPrint. redX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   178
        'PNGReader:   redY:' infoPrint. redY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   179
        'PNGReader:   greenX:' infoPrint. greenX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   180
        'PNGReader:   greenY:' infoPrint. greenY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   181
        'PNGReader:   blueX:' infoPrint. blueX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   182
        'PNGReader:   blueY:' infoPrint. blueY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   183
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   184
    ^ true
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   185
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   186
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
processChunk:type len:len
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   188
    |chunk|
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   189
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   190
    type = 'IDAT' ifTrue:[
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   191
        "---since the compressed data can span multiple
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   192
        chunks, stitch them all together first. later,
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   193
        if memory is an issue, we need to figure out how
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   194
        to do this on the fly---"
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   195
        chunk := inStream next:len.
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   196
        globalDataChunk isNil ifTrue:[
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   197
            globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)).
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   198
        ].
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   199
        globalDataChunk nextPutAll:chunk.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   200
        ^ true
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   201
    ].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   202
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    type = 'tIME' ifTrue:[^ self processTIMEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    type = 'bKGD' ifTrue:[^ self processBKGDChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    type = 'zTXt' ifTrue:[^ self processZTXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    type = 'PLTE' ifTrue:[^ self processPLTEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   211
    type = 'pHYs' ifTrue:[^ self processPHYSChunkLen:len].
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   212
    type = 'cHRM' ifTrue:[^ self processCHRMChunkLen:len].
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   213
    type = 'tRNS' ifTrue:[^ self processTRNSChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   214
    type = 'IHDR' ifTrue:[^ self processIHDRChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   215
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   216
    type = 'iTXt' ifTrue:[^ self processITXTChunkLen:len].
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   217
    type = 'iCCP' ifTrue:[^ self processICCPChunkLen:len].
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   218
    
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    ('PNGReader: unrecognized chunk: ' , type , ' ignored.') infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    ^ true.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "Created: 21.6.1996 / 21:10:37 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "Modified: 21.6.1996 / 21:22:37 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
processGAMAChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "Created: 21.6.1996 / 21:10:52 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   235
processGlobalIDATChunk
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   236
    interlaceMode == 0 ifTrue: [
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   237
        ^ self processNonInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   238
    ]. 
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   239
    ^ self processInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   240
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   241
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   242
processICCPChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   243
    "/ ignored
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   244
    "/ inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   245
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   246
    inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   247
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   248
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   249
    "Created: 21.6.1996 / 21:15:58 / cg"
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   250
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   251
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
processIDATChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   253
    interlaceMode == 0 ifTrue: [
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   254
        ^ self processNonInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   255
    ]. 
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   256
    ^ self processInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   257
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   258
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   259
processIHDRChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   260
    "/ ignored
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   261
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   262
    inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   263
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   264
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   265
    "Created: 21.6.1996 / 21:15:58 / cg"
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   266
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   267
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   268
processITXTChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   269
    "/ international (i.e.utf8) textual data.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   270
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   271
    "/ currently ignored - not needed to display png images
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   272
    "/
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   273
    "/   Keyword:             1-79 bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   274
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   275
    "/   Compression flag:    1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   276
    "/   Compression method:  1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   277
    "/   Language tag:        0 or more bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   278
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   279
    "/   Translated keyword:  0 or more bytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   280
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   281
    "/   Text:                0 or more bytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   282
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   283
    "/ if needed, set processTextChunks to true somewhere...
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   284
    processTextChunks == true ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   285
        |chunkData keyword text i1 i2 i3 
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   286
         compressionFlag compressionMethod languageTag
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   287
         xlatedKeyword textBytes|
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   288
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   289
        chunkData := inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   290
        i1 := chunkData indexOf:0.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   291
        keyword := (chunkData copyTo:i1-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   292
        compressionFlag := chunkData at:i1+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   293
        compressionMethod := chunkData at:i1+2.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   294
        i2 := chunkData indexOf:0 startingAt:i1+3.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   295
        languageTag := (chunkData copyFrom:i1+3 to:i2-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   296
        i3 := chunkData indexOf:0 startingAt:i2+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   297
        xlatedKeyword := (chunkData copyFrom:i2+1 to:i3-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   298
        textBytes := chunkData copyFrom:i3+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   299
        compressionFlag == 0 ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   300
            text := textBytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   301
        ] ifFalse:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   302
            compressionFlag == 1 ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   303
                "/ for now, only zlib compression is supported...
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   304
                'zlib compression currently unsupported' infoPrintCR.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   305
            ] ifFalse:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   306
                'unsupported compression method' infoPrintCR.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   307
            ].    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   308
        ].    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   309
        text := text utf8Decoded.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   310
        self handleText:text keyword:keyword.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   311
    ] ifFalse:[    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   312
        inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   313
    ].
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   314
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   315
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   316
    "Created: 21.6.1996 / 21:15:58 / cg"
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   317
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   318
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   319
processInterlacedDATA:len
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    ^ true
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   322
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   324
processInterlacedGlobalDATA
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   325
    "adam7 interlace method"
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   326
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   327
    | zlibReader filter 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   328
      bytesPerPass startingCol colIncrement rowIncrement 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   329
      startingRow 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   330
      temp "filtersSeen"  
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   331
      cx       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   332
      sc       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   333
      cy       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   334
      startRow "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   335
      w        "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   336
      h        "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   337
    |
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   338
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   339
    interlaceMode == 1 ifFalse: [
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   340
        self error:'unsupported interlaced mode'.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   341
        ^ self
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   342
    ].
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   343
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   344
    "/ filtersSeen := Set new.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   345
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   346
    startingCol := #(0 4 0 2 0 1 0 ).
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   347
    startingRow := #(0 0 4 0 2 0 1 ).
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   348
    colIncrement := #(8 8 4 4 2 2 1 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   349
    rowIncrement := #(8 8 8 4 4 2 2 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   350
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   351
    globalDataChunk reset.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   352
    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   353
    zlibReader binary.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   354
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   355
    h := height.
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   356
    w := width.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   357
    1 to: 7 do: [:pass |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   358
        (self doPass: pass) ifTrue:[
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   359
            cx := colIncrement at: pass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   360
            sc := startingCol at: pass.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   361
            cy := rowIncrement at: pass.
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   362
            bytesPerPass := (((w - sc + cx - 1) // cx * depth) + 7) // 8.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   363
            prevScanline := ByteArray new: bytesPerPass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   364
            thisScanline := ByteArray new: bytesPerScanline.
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   365
            startRow := startingRow at: pass.
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   366
            startRow to: h-1 by: cy do: [:y |
3343
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
   367
                filter := zlibReader nextByte.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   368
                "/ filtersSeen add: filter.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   369
                (filter isNil or: [(filter between: 0 and: 4) not])
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   370
                    ifTrue: [^ self].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   371
                zlibReader next: bytesPerPass into: thisScanline startingAt: 1.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   372
                filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerPass ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   373
                self copyPixels:y at:sc by:cx.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   374
                temp := prevScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   375
                prevScanline := thisScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   376
                thisScanline := temp.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   377
            ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   378
        ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   379
    ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   380
    zlibReader atEnd ifFalse:[self error:'Unexpected data'].
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   381
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   382
    "Modified: / 03-05-2011 / 12:03:33 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   383
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   384
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   385
processNonInterlacedDATA:len
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   386
    self halt:'not used'
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   387
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   388
"/    | zlibReader filter temp prevScanline thisScanline bytesPerScanline filtersSeen|
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   389
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   390
"/    zlibReader := ZipStream readOpenAsZipStreamOn:inStream suppressHeaderAndChecksum:false. 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   391
"/    "/ zlibReader := ZLibReadStream on:inStream from: 1 to:len.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   392
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   393
"/    prevScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   394
"/    thisScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   395
"/    0 to: height - 1 do:[:index | 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   396
"/            filter := (zlibReader next: 1) first.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   397
"/            filtersSeen add: filter.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   398
"/            (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
   399
"/            thisScanline := zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   400
"/            self filterScanline: filter count: bytesPerScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   401
"/            self copyPixels: index.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   402
"/            temp := prevScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   403
"/            prevScanline := thisScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   404
"/            thisScanline := temp
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   405
"/    ]
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   406
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   407
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   408
processNonInterlacedGlobalDATA
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   409
    | "data n" zlibReader filter temp "filtersSeen" i|
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   410
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   411
    "/ filtersSeen := Set new.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   412
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   413
"/    data := ByteArray new:(self bytesPerRow * height)+1000.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   414
"/    n := ZipStream uncompress: globalDataChunk into: data.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   415
"/    self halt.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   416
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   417
    globalDataChunk reset.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   418
    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   419
    zlibReader binary.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   420
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   421
    prevScanline := ByteArray new: bytesPerScanline.
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   422
    thisScanline := ByteArray new: bytesPerScanline.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   423
    0 to: height - 1 do:[:y | 
3343
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
   424
        filter := zlibReader nextByte.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   425
        "/ filtersSeen add: filter.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   426
        (filter notNil and: [filter between: 0 and: 4]) ifFalse: [
3673
22cb72dfcaf9 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 3612
diff changeset
   427
            'PNGReader: unsupported filter: ' infoPrint. filter infoPrintCR.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   428
            ^ self
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   429
        ].
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   430
        zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   431
        filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerScanline ].
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   432
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   433
        i := y * bytesPerScanline.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   434
        data replaceFrom:i+1 to:(i+bytesPerScanline) with:thisScanline startingAt:1.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   435
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   436
        temp := prevScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   437
        prevScanline := thisScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   438
        thisScanline := temp
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   439
    ]
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   440
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   441
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   442
processPHYSChunkLen:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   443
    "physical pixel chunk - currently unhandled"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   444
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   445
    |pixelPerUnitX pixelPerUnitY unit|
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   446
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   447
    pixelPerUnitX := inStream nextInt32MSB:true.  
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   448
    pixelPerUnitY := inStream nextInt32MSB:true.
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   449
    unit := inStream nextByte.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   450
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   451
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   452
        'PNGReader: PHYS chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   453
        'PNGReader:   ppuX:' infoPrint. pixelPerUnitX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   454
        'PNGReader:   ppuY:' infoPrint. pixelPerUnitY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   455
        'PNGReader:   unit:' infoPrint. unit infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   456
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   457
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   458
    ^ true
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
processPLTEChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   462
    "read a color palette"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   463
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   464
    |n "{ Class: SmallInteger }"
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   465
     redBytes greenBytes blueBytes|
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
    (len \\ 3) ~~ 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
        'PNGReader: invalid size of PLTE chunk' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
        ^ false
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
    n := len // 3.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
    redBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    greenBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    blueBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
    1 to:n do:[:i |
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
        redBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
        greenBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
        blueBytes at:i put:(inStream nextByte)
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   482
    colorMap := MappedPalette 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   483
                    redVector:redBytes 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   484
                    greenVector:greenBytes 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   485
                    blueVector:blueBytes.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   486
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
    "Created: 21.6.1996 / 21:22:28 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
    "Modified: 21.6.1996 / 21:43:01 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
processSBITChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    "Created: 21.6.1996 / 21:13:09 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   500
processTEXTChunkLen:len    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   501
    "/ textual data in iso8859 coding.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   502
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   503
    "/ currently ignored - not needed to display png images
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   504
    "/   Keyword:        1-79 bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   505
    "/   Null separator: 1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   506
    "/   Text:           n bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   507
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   508
    "/ if needed, set processTextChunks to true somewhere...
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   509
    processTextChunks == true ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   510
        |chunkData keyword text i|
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   511
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   512
        chunkData := inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   513
        i := chunkData indexOf:0.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   514
        keyword := (chunkData copyTo:i-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   515
        text := (chunkData copyFrom:i+1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   516
        self handleText:text keyword:keyword.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   517
    ] ifFalse:[  
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   518
        inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   519
    ].    
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    "Modified: 21.6.1996 / 21:15:27 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
processTIMEChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    "Created: 21.6.1996 / 21:15:43 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
    "Modified: 21.6.1996 / 21:20:42 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   533
processTRNSChunkLen:len
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   534
    inStream skip:len.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   535
    ^ true
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   536
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   537
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
processZTXTChunkLen:len
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   539
    "/ compressed text
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   540
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   541
    "/ currently ignored - not needed to display png images
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
    "Created: 21.6.1996 / 21:15:58 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   548
!PNGReader methodsFor:'private-filtering'!
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   549
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   550
filterAverage:count 
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   551
    "Use the average of the pixel to the left and the pixel above as a predictor"
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   552
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   553
    |delta|
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   554
3609
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   555
%{
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   556
    if (__isByteArray(__INST(thisScanline))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   557
     && __isByteArray(__INST(prevScanline))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   558
     && __isSmallInteger(__INST(depth))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   559
     && __isSmallInteger(count)) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   560
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   561
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   562
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   563
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   564
        INT __count = __intVal(count);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   565
        INT __delta = __intVal(__INST(depth)) / 8;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   566
        int __i;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   567
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   568
        if (__delta < 1) __delta = 1;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   569
        for (__i=0; __i<__delta; __i++) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   570
            __thisScanline[__i] += (__prevScanline[__i] >> 1);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   571
        }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   572
        for (; __i < __count; __i++) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   573
            __thisScanline[__i] += ((__prevScanline[__i] + __thisScanline[__i-__delta]) >> 1);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   574
        }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   575
        RETURN(self);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   576
    }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   577
%}.
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   578
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   579
    delta := depth // 8 max:1.
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   580
    1 to:delta do:[:i | 
3384
0761606da988 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3343
diff changeset
   581
        thisScanline at:i put:((thisScanline at:i) + ((prevScanline at:i) // 2) bitAnd:255)
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   582
    ].
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   583
    delta + 1 to:count do:[:i | 
3384
0761606da988 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3343
diff changeset
   584
        thisScanline at:i put:((thisScanline at:i) + (((prevScanline at:i) + (thisScanline at:i - delta)) // 2) bitAnd:255)
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   585
    ]
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   586
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   587
    "Modified: / 03-05-2011 / 12:14:01 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   588
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   589
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   590
filterHorizontal:count
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   591
    "use the pixel to the left as a predictor"
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   592
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   593
    |delta|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   594
3608
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   595
%{
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   596
    if (__isByteArray(__INST(thisScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   597
     && __isByteArray(__INST(prevScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   598
     && __isSmallInteger(__INST(depth))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   599
     && __isSmallInteger(count)) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   600
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   601
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   602
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   603
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   604
        INT __count = __intVal(count);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   605
        INT __delta = __intVal(__INST(depth)) / 8;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   606
        int __i;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   607
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   608
        if (__delta < 1) __delta = 1;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   609
        for (__i = __delta; __i < __count; __i++) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   610
            __thisScanline[__i] = __thisScanline[__i] + __thisScanline[__i-__delta];
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   611
        }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   612
        RETURN(self);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   613
    }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   614
%}.
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   615
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   616
    delta := depth // 8 max:1.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   617
    delta+1 to:count do:[:i|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   618
        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
   619
    ]
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   620
!
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   621
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   622
filterNone: count
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   623
    "/ no filter - scanline is as is
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   624
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   625
    "Modified: / 03-05-2011 / 12:14:20 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   626
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   627
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   628
filterPaeth:count 
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   629
    "Select one of (the pixel to the left, the pixel above and the pixel to above left) to
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   630
     predict the value of this pixel"
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   631
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   632
    |delta|
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   633
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   634
%{
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   635
    if (__isByteArray(__INST(thisScanline))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   636
     && __isByteArray(__INST(prevScanline))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   637
     && __isSmallInteger(__INST(depth))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   638
     && __isSmallInteger(count)) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   639
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   640
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   641
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   642
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   643
        INT __count = __intVal(count);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   644
        INT __delta = __intVal(__INST(depth)) / 8;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   645
        int __i;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   646
        
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   647
        if (__delta < 1) __delta = 1;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   648
        for (__i=0; __i<__delta; __i++) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   649
            unsigned int __pix = __thisScanline[__i] + __prevScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   650
            __thisScanline[__i] = __pix;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   651
        }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   652
        for (; __i < __count; __i++) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   653
            int __pCenter = __thisScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   654
            int __pLeft = __thisScanline[__i - __delta];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   655
            int __pAbove = __prevScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   656
            int __pAboveLeft = __prevScanline[__i - __delta];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   657
            int __pa, __pb, __pc;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   658
            int __p;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   659
            
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   660
            __pa = (__pAbove - __pAboveLeft); 
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   661
            __pa = __pa < 0 ? -__pa : __pa;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   662
            __pb = (__pLeft - __pAboveLeft);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   663
            __pb = __pb < 0 ? -__pb : __pb;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   664
            __pc = __pLeft + __pAbove - __pAboveLeft - __pAboveLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   665
            __pc = __pc < 0 ? -__pc : __pc; 
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   666
            if ((__pa <= __pb) && (__pa <= __pc)) __p = __pLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   667
            else if (__pb <= __pc) __p = __pAbove;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   668
            else __p = __pAboveLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   669
            
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   670
            __thisScanline[__i] = __pCenter + __p;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   671
        }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   672
        RETURN(self);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   673
    }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   674
%}.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   675
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   676
    delta := depth // 8 max:1.
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   677
    1 to:delta do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   678
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   679
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   680
            put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   681
    ].
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   682
    delta + 1 to:count do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   683
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   684
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   685
            put:(((thisScanline at:i) + (self 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   686
                            paethPredictLeft:(thisScanline at:i - delta)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   687
                            above:(prevScanline at:i)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   688
                            aboveLeft:(prevScanline at:i - delta))) 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   689
                    bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   690
    ]
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   691
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   692
    "Modified: / 03-05-2011 / 12:14:43 / cg"
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   693
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   694
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   695
filterScanline:filterType count:count
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   696
    filterType == 0 ifTrue:[^ self].
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   697
    
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   698
    self 
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   699
        perform:(#(filterHorizontal: filterVertical: filterAverage: filterPaeth:) at:filterType)
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   700
        with:count
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   701
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   702
    "Modified: / 03-05-2011 / 12:13:31 / cg"
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   703
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   704
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   705
filterVertical:count 
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   706
    "Use the pixel above as a predictor"
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   707
    
3608
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   708
%{
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   709
    if (__isByteArray(__INST(thisScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   710
     && __isByteArray(__INST(prevScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   711
     && __isSmallInteger(count)) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   712
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   713
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   714
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   715
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   716
        INT __count = __intVal(count);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   717
        int __i;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   718
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   719
        for (__i=0; __i<__count; __i++) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   720
            unsigned int __pix = __thisScanline[__i] + __prevScanline[__i];
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   721
            __thisScanline[__i] = __pix;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   722
        }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   723
        RETURN(self);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   724
    }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   725
%}.
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
   726
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   727
    1 to:count do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   728
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   729
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   730
            put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   731
    ]
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   732
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   733
    "Modified: / 03-05-2011 / 12:14:34 / cg"
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   734
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   735
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   736
paethPredictLeft: l above: a aboveLeft: al
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   737
    "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
   738
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   739
    | pa pb pc |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   740
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   741
    pa := a > al ifTrue: [a - al] ifFalse: [al - a].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   742
    pb := l > al ifTrue: [l - al] ifFalse: [al - l].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   743
    pc := l + a - al - al.
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   744
    pc < 0 ifTrue: [
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   745
        pc := pc * -1
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   746
    ].
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   747
    ((pa <= pb) and: [pa <= pc]) ifTrue: [^ l].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   748
    (pb <= pc) ifTrue: [^ a].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   749
    ^ al
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   750
! !
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   751
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   752
!PNGReader methodsFor:'private-pixel copy'!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   753
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   754
copyPixels:y at:startX by:incX 
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
   755
    "Handle interlaced pixels of supported colorTypes"
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   756
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   757
    |s|
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   758
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   759
    "/ per color type copy methods
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   760
    s := #( 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   761
             #copyPixelsGray:at:by:         "/ 0
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   762
             nil
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   763
             #copyPixelsRGB:at:by:          "/ 2
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   764
             #copyPixelsIndexed:at:by:      "/ 3
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   765
             #copyPixelsGrayAlpha:at:by:    "/ 4 
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   766
             nil 
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   767
             #copyPixelsRGBA:at:by:         "/ 6
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   768
        ) at:colorType + 1.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
   769
    self perform:s with:y with:startX with:incX
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   770
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   771
    "Modified: / 03-05-2011 / 12:02:45 / cg"
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   772
!
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   773
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   774
copyPixelsGray:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   775
    "Handle interlaced pixels of supported colorTypes.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   776
     Untested code - please verify"
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   777
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   778
    |srcIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   779
     srcMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   780
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   781
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   782
     dstMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   783
     x        "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   784
     bits     "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   785
     bitMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   786
     rS       "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   787
     lS       "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   788
     rowIndex "{ Class: SmallInteger }"|
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   789
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   790
    nPixels := width // incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   791
    srcIndex := 0. srcMask := 0. x := startX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   792
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   793
    depth == 1 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   794
        dstIndex := (y * bytesPerScanline) + (startX // 8) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   795
        dstMask := 16r80 >> (x \\ 8).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   796
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   797
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   798
            srcMask == 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   799
                srcMask := 16r80.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   800
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   801
                bits := thisScanline at:srcIndex. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   802
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   803
            bitMask := (bits bitAnd:srcMask) == 0 ifTrue:[0] ifFalse:[dstMask].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   804
            bitMask ~~ 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   805
                data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   806
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   807
            x := x + incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   808
            dstMask := dstMask >> incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   809
            dstMask == 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   810
                dstIndex := dstIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   811
                dstMask := 16r80 >> (x \\ 8).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   812
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   813
            srcMask := srcMask bitShift:-1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   814
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   815
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   816
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   817
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   818
    depth == 2 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   819
        dstIndex := (y * bytesPerScanline) + (startX // 4) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   820
        lS := 6 - ((x \\ 4) * 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   821
        rS := -1. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   822
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   823
            rS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   824
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   825
                bits := thisScanline at:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   826
                rS := 6.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   827
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   828
            bitMask := ((bits >> rS) bitAnd:2r11).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   829
            bitMask ~~ 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   830
                bitMask := bitMask << lS.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   831
                data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   832
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   833
            lS := lS - (incX * 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   834
            lS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   835
                lS <= -8 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   836
                    dstIndex := dstIndex + 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   837
                    lS := lS + 8 + 8.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   838
                ] ifFalse:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   839
                    dstIndex := dstIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   840
                    lS := lS + 8.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   841
                ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   842
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   843
            rS := rS - 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   844
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   845
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   846
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   847
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   848
    depth == 4 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   849
        rowIndex := (y * bytesPerScanline) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   850
        dstIndex := rowIndex + (x // 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   851
        rS := -1. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   852
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   853
            rS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   854
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   855
                bits := thisScanline at:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   856
                rS := 4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   857
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   858
            bitMask := ((bits >> rS) bitAnd:2r1111).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   859
            x even ifTrue:[    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   860
                bitMask := bitMask bitShift:4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   861
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   862
            data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   863
            x := x + incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   864
            dstIndex := rowIndex + (x // 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   865
            rS := rS - 4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   866
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   867
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   868
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   869
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   870
    depth == 8 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   871
        srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   872
        dstIndex := (y * bytesPerScanline) + (startX) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   873
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   874
        1 to:nPixels do:[:n |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   875
            data at:dstIndex put:(thisScanline at:srcIndex).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   876
            srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   877
            dstIndex := dstIndex + incX
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   878
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   879
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   880
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   881
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   882
    depth == 16 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   883
        srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   884
        dstIndex := (y * bytesPerScanline) + (startX*2) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   885
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   886
        1 to:nPixels do:[:n |
3601
05caf7f1e324 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   887
            data unsignedInt16At:dstIndex put:(thisScanline unsignedInt16At:srcIndex).
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   888
            srcIndex := srcIndex + 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   889
            dstIndex := dstIndex + (incX * 2)
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   890
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   891
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   892
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   893
    self error:'unsupported depth'.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   894
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   895
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   896
copyPixelsIndexed:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   897
    self copyPixelsGray:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   898
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   899
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   900
copyPixelsRGB:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   901
    "Handle interlaced pixels of supported colorTypes.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   902
     Untested code - please verify"
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   903
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   904
    |srcIndex "{ Class: SmallInteger }" 
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   905
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   906
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   907
     dstInc   "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   908
     bpp      "{ Class: SmallInteger }"|
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   909
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   910
    bpp := bytesPerScanline // width.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   911
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   912
    "/ 1 byte per r,g,b
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   913
    srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   914
    dstIndex := (y * bytesPerScanline) + (startX * bpp) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   915
    dstInc := incX * bpp.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   916
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   917
    nPixels := width // incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   918
    1 to:nPixels do:[:n |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   919
        data replaceFrom:dstIndex to:dstIndex+bpp-1 with:thisScanline startingAt:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   920
        srcIndex := srcIndex + bpp.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   921
        dstIndex := dstIndex + dstInc
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   922
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   923
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
   924
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   925
copyPixelsRGBA:y at:startX by:incX 
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   926
    "Handle interlaced pixels of supported colorTypes.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   927
     Untested code - please verify"
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   928
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   929
    |srcIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   930
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   931
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
   932
     dstInc   "{ Class: SmallInteger }"|
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   933
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   934
    srcIndex := 1.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
   935
    dstIndex := (y * bytesPerScanline) + (startX * 4) + 1.
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
   936
    dstInc := incX * 4.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   937
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   938
    nPixels := thisScanline size.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   939
    [srcIndex < nPixels] whileTrue:[
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
   940
        data replaceFrom:dstIndex to:dstIndex+3 with:thisScanline startingAt:srcIndex.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   941
        srcIndex := srcIndex + 4.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
   942
        dstIndex := dstIndex + dstInc
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   943
    ].
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   944
! !
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   945
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   946
!PNGReader methodsFor:'private-reading'!
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
   947
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   948
getChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   949
    |len type crc|
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   950
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   951
    inStream atEnd ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   952
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   953
    len := inStream nextInt32MSB:true.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   954
    type := String new:4.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   955
    (inStream nextBytes:4 into:type) ~~ 4 ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   956
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   957
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   958
        'len: ' infoPrint. len infoPrint. ' type: ' infoPrint. type infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   959
    ].
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   960
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   961
    type = 'IEND' ifTrue:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   962
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   963
    (self processChunk:type len:len) ifFalse:[^ false].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   964
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   965
    crc := inStream nextInt32MSB:true.  "/ ignored - for now
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   966
    ^ true
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   967
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   968
    "Created: 21.6.1996 / 21:09:36 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   969
    "Modified: 21.6.1996 / 21:20:26 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   970
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   971
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   972
getIHDRChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   973
    |len type crc|
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   974
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   975
    len := inStream nextInt32MSB:true.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   976
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   977
    type := String new:4.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   978
    inStream nextBytes:4 into:type.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   979
3183
434c79bbe0bf class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3100
diff changeset
   980
    type = 'IHDR' ifFalse:[self halt:'expected IHDR magic'. ^ false].
434c79bbe0bf class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3100
diff changeset
   981
    len == 13 ifFalse:[self halt:'unexpected IHDR length'. ^ false].
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   982
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   983
    width := inStream nextInt32MSB:true.        
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   984
    height := inStream nextInt32MSB:true.        
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   985
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   986
    (width <= 0 or:[height <= 0]) ifTrue:[
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   987
        'PNGReader: invalid dimension(s)' infoPrintCR.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   988
        ^ false.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   989
    ].
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   990
    self reportDimension.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   991
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   992
    bitsPerChannel := inStream nextByte.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   993
    depth := bitsPerChannel. "/ will be changed by setColorType.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   994
    colorType := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   995
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   996
    compressionMethod := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   997
    filterMethod := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   998
    interlaceMode := inStream nextByte.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   999
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1000
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1001
        'PNGReader: IHDR:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1002
        'PNGReader:   width: ' infoPrint. width infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1003
        'PNGReader:   height: ' infoPrint. height infoPrintCR.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1004
        'PNGReader:   bitsPerChannel: ' infoPrint. bitsPerChannel infoPrintCR.
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1005
        'PNGReader:   colorType: ' infoPrint. colorType infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1006
        'PNGReader:   compressionMethod: ' infoPrint. compressionMethod infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1007
        'PNGReader:   filterMethod: ' infoPrint. filterMethod infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1008
        'PNGReader:   interlaceMode: ' infoPrint. interlaceMode infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1009
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1010
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1011
    crc := inStream nextInt32MSB:true.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1012
    ^ true
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1013
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1014
    "Modified: 21.6.1996 / 21:38:35 / cg"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1015
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1016
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1017
handleText:text keyword:keyword
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1018
    "/ things like exif data etc.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1019
    "/ self halt.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1020
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1021
    "/Standard keywords for text chunks:
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1022
    "/
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1023
    "/   Title            Short (one line) title or caption for image
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1024
    "/   Author           Name of image's creator
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1025
    "/   Description      Description of image (possibly long)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1026
    "/   Copyright        Copyright notice
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1027
    "/   Creation Time    Time of original image creation
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1028
    "/   Software         Software used to create the image
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1029
    "/   Disclaimer       Legal disclaimer
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1030
    "/   Warning          Warning of nature of content
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1031
    "/   Source           Device used to create the image
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1032
    "/   Comment          Miscellaneous comment; conversion from
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1033
    "/                    GIF comment
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1034
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  1035
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1036
setColorType:colorType
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1037
    colorType == 0 ifTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1038
        photometric := #blackIs0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1039
        samplesPerPixel := 1.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1040
        bitsPerSample := Array with:bitsPerChannel.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1041
        depth := bitsPerChannel.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1042
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1043
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1044
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1045
    colorType == 2 ifTrue:[
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1046
        bitsPerChannel < 8 ifTrue:[
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1047
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1048
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1049
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1050
        photometric := #rgb.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1051
        samplesPerPixel := 3.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1052
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1053
        depth := bitsPerChannel * 3.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1054
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1055
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1056
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1057
    colorType == 3 ifTrue:[
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1058
        bitsPerChannel == 16 ifTrue:[
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1059
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1060
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1061
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1062
        photometric := #palette.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1063
        samplesPerPixel := 1.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1064
        bitsPerSample := Array with:bitsPerChannel.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1065
        depth := bitsPerChannel.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1066
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1067
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1068
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1069
    colorType == 4 ifTrue:[
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1070
        bitsPerChannel < 8 ifTrue:[
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1071
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1072
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1073
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1074
        photometric := #blackIs0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1075
        samplesPerPixel := 2.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1076
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1077
        depth := bitsPerChannel * 2.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1078
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1079
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1080
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1081
    colorType == 6 ifTrue:[
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1082
        bitsPerChannel < 8 ifTrue:[
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1083
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1084
            ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1085
        ].
2702
30fb9cf6affa changed #setColorType:
Claus Gittinger <cg@exept.de>
parents: 2701
diff changeset
  1086
        photometric := #rgb.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1087
        samplesPerPixel := 4.
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1088
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1089
        depth := bitsPerChannel * 4.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1090
        ^ true.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1091
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1092
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1093
    ('PNGReader: invalid colorType: ' , colorType printString , '.') infoPrintCR.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1094
    ^ false
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1095
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1096
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
  1097
!PNGReader methodsFor:'reading'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
fromStream:aStream
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
    "read a stream containing a PNG image.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
     Leave image description in instance variables."
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
    |header|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
    inStream := aStream.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
    aStream binary.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1108
    "PNG-files are always msb (network-world)"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
    byteOrder := #msb.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    header := ByteArray new:8.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
    aStream nextBytes:8 into:header.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1114
    header ~= (self pngHeader) ifTrue:[
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
        'PNGReader: not a png file.' infoPrintCR.
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1116
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: not a png file'.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
    ].
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
  1119
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
    (self getIHDRChunk) ifFalse:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
        'PNGReader: required IHDR chunk missing.' infoPrintCR.
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1122
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: required IHDR chunk missing'.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
    compressionMethod ~~ 0 ifTrue:[
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1127
        ('PNGReader: compressionMethod %s not supported.' printfWith:compressionMethod printString) infoPrintCR.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1128
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: unsupported compression method'.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
        ^ nil
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
    filterMethod > 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
        'PNGReader: invalid filterMethod' infoPrintCR.
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1133
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported filterMethod'.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
        ^ nil.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
    interlaceMode > 1 ifTrue:[
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1137
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported interlaceMode'.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
        'PNGReader: invalid interlaceMode' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
        ^ nil.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
    ].
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1141
    (self setColorType:colorType) ifFalse:[
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
        ^ nil
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1143
    ].
2706
3c2c631f9d16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2705
diff changeset
  1144
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1145
    [self getChunk] whileTrue.
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1147
    bytesPerScanline := self bytesPerRow.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1148
    data := ByteArray new:(bytesPerScanline * height).
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1149
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1150
    globalDataChunk notNil ifTrue:[
3343
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
  1151
        self processGlobalIDATChunk.
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
  1152
        globalDataChunk := nil.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1153
    ].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1154
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
    photometric == #palette ifTrue:[
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
  1156
        colorMap isNil ifTrue:[
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1157
            Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: palette chunk missing'.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1158
            'PNGReader: palette chunk missing.' infoPrintCR.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
  1159
            "/ ^ nil
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1160
        ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
    "
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
     PNGReader fromFile:'/home/cg/libpng-0.89c/pngtest.png'
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
    "
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
2910
d5171b9245e6 comment/format in: #fromStream:
Claus Gittinger <cg@exept.de>
parents: 2909
diff changeset
  1167
    "Modified: / 03-05-2011 / 12:17:34 / cg"
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
  1168
! !
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
  1169
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1170
!PNGReader methodsFor:'writing to file'!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1171
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1172
pngHeader
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1173
    ^ #[137 80 78 71 13 10 26 10]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1174
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1175
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1176
save:image onStream:aStream
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1177
    "save image in PNG-file-format onto aStream"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1178
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1179
    outStream := aStream.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1180
    outStream binary.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1181
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1182
    byteOrder := #msb.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1183
    width := image width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1184
    height := image height.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1185
    photometric := image photometric.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1186
    samplesPerPixel := image samplesPerPixel.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1187
    bitsPerSample := image bitsPerSample.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1188
    colorMap := image colorMap.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1189
    data := image bits.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1190
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1191
    outStream nextPutAll:(self pngHeader).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1192
    self writeIHDRChunk.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1193
    photometric == #palette ifTrue: [self writePaletteChunk].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1194
    self writeImageDataChunk.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1195
    self writeEndChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1196
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1197
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1198
writeChunk:chunkTypeChars size:len with:aBlock
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1199
    |crc realOutStream chunkBytes|
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1200
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1201
    realOutStream := outStream.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1202
    outStream := WriteStream on:(ByteArray new:len).
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1203
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1204
    outStream nextPutBytes:4 from:chunkTypeChars startingAt:1.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1205
    aBlock value.
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1206
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1207
    chunkBytes := outStream contents.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1208
    crc := CRC32Stream hashValueOf:chunkBytes.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1209
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1210
    outStream := realOutStream.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1211
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1212
    realOutStream nextPutInt32:len MSB:true.
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1213
    realOutStream nextPutAll:chunkBytes.
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1214
    realOutStream nextPutInt32:crc MSB:true.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1215
!
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1216
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1217
writeEndChunk
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1218
    self 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1219
        writeChunk: 'IEND'
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1220
        size: 0
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1221
        with:[ ]
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1222
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1223
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1224
writeFileHeader
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1225
    outStream nextPutAll:(self pngHeader)
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1226
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1227
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1228
writeIHDRChunk
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1229
    ((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1230
        colorType := 0.
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
  1231
        samplesPerPixel > 1 ifTrue:[ colorType := colorType + 4].  "/ +alpha
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1232
    ].
3724
4a753c4710c9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3673
diff changeset
  1233
    ((photometric == #rgb) or:[(photometric == #rgba)]) ifTrue:[
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1234
        colorType := 2.
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
  1235
        samplesPerPixel > 3 ifTrue:[ colorType := colorType + 4].  "/ +alpha
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1236
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1237
    (photometric == #palette) ifTrue:[
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1238
        colorType := 3.
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
  1239
        samplesPerPixel > 1 ifTrue:[ colorType := colorType + 4].  "/ +alpha
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1240
    ].
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1241
    colorType isNil ifTrue:[
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
  1242
        self error:'unhandled photometric'
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1243
    ].
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1244
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1245
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1246
        writeChunk: 'IHDR'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1247
        size: 13
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1248
        with:[ 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1249
            self writeLong:width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1250
            self writeLong:height.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1251
            outStream nextPut: 8.  "Assume that all colors are 24bit"     "/ depth
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1252
            outStream nextPut: colorType.  
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1253
            outStream nextPut: 0.  "Compression"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1254
            outStream nextPut: 0.  "Filter method"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1255
            outStream nextPut: 0   "Non-interlaced"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1256
        ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1257
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1258
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1259
writeImageDataChunk
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1260
    |compressedByteStream compressedBytes zlibWriter idx|
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1261
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1262
    bytesPerScanline := self bytesPerRow.
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1263
    
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1264
    compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)).
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1265
    zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1266
    zlibWriter binary.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1267
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1268
    idx := 1.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1269
    0 to:height-1 do:[:y |
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1270
        |row|
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1271
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1272
        row := data copyFrom:idx to:(idx+bytesPerScanline-1).
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1273
        zlibWriter nextPutAll:#[0].       "/ no filter
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1274
        zlibWriter nextPutAll:row.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1275
        idx := idx + bytesPerScanline.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1276
    ].
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1277
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1278
    zlibWriter close.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1279
    compressedBytes := compressedByteStream contents.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1280
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1281
    self 
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1282
        writeChunk: 'IDAT'
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1283
        size:(compressedBytes size)
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1284
        with:[ 
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1285
            outStream nextPutAll:compressedBytes
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1286
        ]
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1287
!
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1288
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1289
writePaletteChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1290
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1291
        writeChunk: 'PLTE'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1292
        size: 3 * colorMap size
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1293
        with:[
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1294
            colorMap do:[:color | 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1295
                outStream
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1296
                    nextPut: color redByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1297
                    nextPut: color greenByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1298
                    nextPut: color blueByte
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1299
            ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1300
        ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1301
! !
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1302
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
  1303
!PNGReader class methodsFor:'documentation'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1304
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
version
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1306
    ^ '$Header$'
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1307
!
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1308
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1309
version_CVS
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1310
    ^ '$Header$'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
! !
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1312
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1313
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
PNGReader initialize!