PNGReader.st
author Claus Gittinger <cg@exept.de>
Tue, 07 Mar 2017 07:31:05 +0100
changeset 3939 a64b6880178b
parent 3935 37eafe77316d
child 3949 4009057d48a3
permissions -rw-r--r--
#FEATURE by cg class: ActiveHelpView changed: #for:onDevice: also look for strings starting with '<body>' (in addition to '<html>')
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
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
    17
	instanceVariableNames:'colorType bitsPerChannel depth compressionMethod filterMethod
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
    18
		interlaceMode bytesPerScanline globalDataChunk thisScanline
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
    19
		prevScanline processTextChunks specialChunkHandlers
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
    20
		paletteAlphaEntries paletteIndexForMaskedPixels image'
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
    21
	classVariableNames:'ColorTypeGray ColorTypeGrayAlpha ColorTypePalette ColorTypeRGB
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
    22
		ColorTypeRGBAlpha Verbose'
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
    23
	poolDictionaries:''
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
    24
	category:'Graphics-Images-Readers'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    27
!PNGReader class methodsFor:'documentation'!
308
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
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 COPYRIGHT (c) 1996 by Claus Gittinger
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
              All Rights Reserved
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 This software is furnished under a license and may be used
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 only in accordance with the terms of that license and with the
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 inclusion of the above copyright notice.   This software may not
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 be provided or otherwise made available to, or used by, any
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 other person.  No title to or ownership of the software is
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 hereby transferred.
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
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
documentation
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
    47
    This class provides methods for loading and saving PNG pictures.
3599
9bc697bd01d9 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3598
diff changeset
    48
    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
    49
    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
    50
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    51
    [caveats:]
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
    52
        writer can only store mask with depth24 images (for now).
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
    53
        writer only generates unfiltered non-interlaced data.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    54
        
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    [See also:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        Image Form Icon
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        XBMReader XPMReader XWDReader 
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    [author:]
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        Claus Gittinger
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
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    66
examples
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    67
"
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    68
    PNGReader fromFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
    69
    PNGReader fromFile:'\\Exeptn\tmp\images\expeccoScreenshot4020_5526507.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    70
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
    71
    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
    72
    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
    73
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Delete.png'
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    74
    PNGReader fromFile:'\\exeptn\unsaved\pd_stuff\PNGs\Down.png'
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    75
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    76
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    77
    |img img2 outStream png|
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
    78
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    79
    img := ToolbarIconLibrary error32x32Icon.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    80
    outStream := WriteStream on:(ByteArray new:100).
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    81
    PNGReader save:img onStream:outStream.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    82
    png := outStream contents.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    83
    img2 := PNGReader fromStream:(png readStream).
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
    84
    self assert:(img bits = img2 bits).
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
    85
    img inspect.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
    86
    img2 inspect.
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
    87
"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
    90
!PNGReader class methodsFor:'initialization'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
initialize
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
    93
    "install myself in the Image classes fileFormat table for the `.png' extension."
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
2709
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    95
    MIMETypes defineImageType:'image/png'  suffix:'png' reader:self.
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    96
    "/ backward compatibility from times when png was not yet so common...
4ecfb8ae5fab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
    97
    MIMETypes defineImageType:'image/x-png' suffix:nil reader:self.
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
    98
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
    99
    ColorTypeGray := 0.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   100
    ColorTypeRGB := 2.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   101
    ColorTypePalette := 3.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   102
    ColorTypeGrayAlpha := 4.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   103
    ColorTypeRGBAlpha := 6.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   104
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   105
    "Modified: / 16-02-2017 / 19:41:40 / cg"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   108
!PNGReader class methodsFor:'accessing'!
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   109
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   110
pngHeader
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   111
    ^ #[137 80 78 71 13 10 26 10]
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   112
! !
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   113
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   114
!PNGReader class methodsFor:'queries'!
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   115
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   116
canRepresent:anImage
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   117
    "return true, if anImage can be represented in my file format.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   118
     Any image without mask is supported;
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   119
     only depth24 images with mask are (currently)."
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   120
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   121
    anImage mask notNil ifTrue:[
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   122
        "/ for now, can only write depth24 images with mask
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   123
        ^ anImage depth == 24
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   124
    ].    
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   125
    ^ true
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   126
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   127
    "Modified (comment): / 16-02-2017 / 16:28:53 / cg"
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   128
! !
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   129
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   130
!PNGReader class methodsFor:'testing'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
isValidImageFile:aFileName
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    "return true, if aFileName contains a PNG image"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    |inStream magic|
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    inStream := self streamReadingFile:aFileName.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    inStream isNil ifTrue:[^ false].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    inStream binary.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    magic := ByteArray new:8.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    inStream nextBytes:8 into:magic.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    inStream close.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    ^ (magic = #[137 80 78 71 13 10 26 10])
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
1694
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   148
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   149
     self isValidImageFile:'/home/cg/AudioExplorer_51_files/use_small.png'
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
   150
     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
   151
     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
   152
    "
3a77d9b69cf7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1671
diff changeset
   153
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    "Modified: 21.6.1996 / 20:38:46 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   157
!PNGReader methodsFor:'accessing'!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   158
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   159
makeImage
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   160
    image isNil ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   161
        image := super makeImage.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   162
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   163
    ^ image
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   164
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   165
    "Created: / 17-02-2017 / 11:14:45 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   166
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   167
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   168
pngHeader
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   169
    <resource: #obsolete>
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   170
    ^ self class pngHeader
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   171
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   172
    "Modified: / 22-02-2017 / 11:00:44 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   173
! !
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   174
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   175
!PNGReader methodsFor:'hooks'!
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   176
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   177
specialChunkHandlerAt:chunkType put:aHandlerBlock
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   178
    "define a handler action, which processes unknown chunks.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   179
     The handler block will be called with one or two arguments:
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   180
     the binary data of the chunk, and optionally the reader itself"
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   181
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   182
    specialChunkHandlers isNil ifTrue:[ 
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   183
        specialChunkHandlers := Dictionary new
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   184
    ].
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   185
    specialChunkHandlers at:chunkType put:aHandlerBlock
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   186
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   187
    "Created: / 14-02-2017 / 11:43:33 / cg"
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   188
! !
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   189
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   190
!PNGReader methodsFor:'reading'!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   191
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   192
fromStream:aStream
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   193
    "read a stream containing a PNG image.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   194
     Leave the image description in instance variables
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   195
     (i.e. to get the image, ask with image)."
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   196
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   197
    |header|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   198
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   199
    inStream := aStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   200
    aStream binary.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   201
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   202
    "PNG-files are always msb (network-world)"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   203
    byteOrder := #msb.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   204
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   205
    header := ByteArray new:8.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   206
    aStream nextBytes:8 into:header.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   207
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   208
    header = (self class pngHeader) ifFalse:[
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   209
        Logger warning:'PNGReader: not a png file (%1)' with:aStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   210
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: not a png file'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   211
        ^ nil
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   212
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   213
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   214
    (self getIHDRChunk) ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   215
        Logger warning:'PNGReader: required IHDR chunk missing (%1)' with:aStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   216
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: required IHDR chunk missing'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   217
        ^ nil
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   218
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   219
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   220
    compressionMethod ~~ 0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   221
        ('PNGReader: compressionMethod %s not supported.' printfWith:compressionMethod printString) infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   222
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: unsupported compression method'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   223
        ^ nil
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   224
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   225
    filterMethod > 0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   226
        'PNGReader: invalid filterMethod' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   227
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported filterMethod'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   228
        ^ nil.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   229
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   230
    interlaceMode > 1 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   231
        Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: invalid/unsupported interlaceMode'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   232
        'PNGReader: invalid interlaceMode' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   233
        ^ nil.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   234
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   235
    (self setColorType:colorType) ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   236
        ^ nil
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   237
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   238
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   239
    [self getChunk] whileTrue.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   240
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   241
    bytesPerScanline := self bytesPerRow.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   242
    data := ByteArray new:(bytesPerScanline * height).
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   243
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   244
    globalDataChunk notNil ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   245
        self processGlobalIDATChunk.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   246
        globalDataChunk := nil.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   247
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   248
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   249
    photometric == #palette ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   250
        colorMap isNil ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   251
            Image badImageFormatQuerySignal raiseRequestErrorString:'PNGReader: palette chunk missing'.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   252
            'PNGReader: palette chunk missing.' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   253
            "/ ^ nil
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   254
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   255
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   256
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   257
    paletteAlphaEntries notNil ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   258
        "/ this vector now provides alpha values.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   259
        "/ for now, we can only deal with 0/255 alpha values...
3903
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   260
        self generateMaskFromPaletteAlphaEntries
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   261
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   262
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   263
    "
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   264
     PNGReader fromFile:'/home/cg/libpng-0.89c/pngtest.png'
3903
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   265
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   266
     Verbose := true.
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   267
     PNGReader fromFile:(RegressionTests::ImageReaderTest packageDirectory construct:'testData/pngImages/tbbn3p08.png')
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   268
     
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   269
    "
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   270
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
   271
    "Modified: / 22-02-2017 / 11:00:19 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   272
! !
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   273
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   274
!PNGReader methodsFor:'reading-private'!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   275
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   276
generateMaskFromPaletteAlphaEntries
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   277
    image isNil ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   278
        self makeImage
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   279
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   280
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   281
    colorType == ColorTypePalette ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   282
        "/ if there is only one entry to care for...
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   283
        (paletteAlphaEntries occurrencesOf:0) == 1 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   284
            (paletteAlphaEntries conform:[:alpha | (alpha == 0) or:[alpha == 255]]) ifTrue:[
3903
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   285
                image mask:(self class buildMaskFromColor:(paletteAlphaEntries indexOf:0)-1 for:data width:width height:height).
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   286
                ^ self
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   287
            ].    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   288
        ].    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   289
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   290
        "/ multiple masked pixels...
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   291
        paletteAlphaEntries keysAndValuesDo:[:pixelIndex :alpha |
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   292
            alpha == 0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   293
                image createMaskForPixelValue:pixelIndex
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   294
            ] ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   295
                alpha == 255 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   296
                    "/ ok; already
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   297
                ] ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   298
                    self error:'should generate an alpha image' 
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   299
                ]    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   300
            ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   301
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   302
        ^ self.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   303
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   304
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   305
    colorType == ColorTypeGray ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   306
        |maskPixel|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   307
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   308
        maskPixel := paletteAlphaEntries unsignedInt16At:1 MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   309
        image createMaskForPixelValue:maskPixel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   310
        ^ self 
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   311
    ].    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   312
    colorType == ColorTypeRGB ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   313
        |mr mg mb maskPixel|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   314
        
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   315
        mr := paletteAlphaEntries unsignedInt16At:1 MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   316
        mg := paletteAlphaEntries unsignedInt16At:3 MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   317
        mb := paletteAlphaEntries unsignedInt16At:5 MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   318
        depth <= 32 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   319
            "/ only use the low bits...
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   320
            mr > 255 ifTrue:[ self error:'only 8bit RGB supported'].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   321
            mg > 255 ifTrue:[ self error:'only 8bit RGB supported'].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   322
            mb > 255 ifTrue:[ self error:'only 8bit RGB supported'].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   323
            maskPixel := ((mr bitShift:16) bitOr:(mg bitShift:8)) bitOr:mb.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   324
        ] ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   325
            maskPixel := ((mr bitShift:32) bitOr:(mg bitShift:16)) bitOr:mb.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   326
        ].   
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   327
        image createMaskForPixelValue:maskPixel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   328
        ^ self 
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   329
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   330
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   331
    "Created: / 17-02-2017 / 08:07:04 / cg"
3903
754f50ffb404 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   332
    "Modified: / 17-02-2017 / 14:17:24 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   333
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   334
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   335
getChunk
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   336
    |len type crc|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   337
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   338
    inStream atEnd ifTrue:[^ false].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   339
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   340
    len := inStream nextInt32MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   341
    type := String new:4.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   342
    (inStream nextBytes:4 into:type) ~~ 4 ifTrue:[^ false].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   343
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   344
    Verbose == true ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   345
        'len: ' infoPrint. len infoPrint. ' type: ' infoPrint. type infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   346
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   347
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   348
    type = 'IEND' ifTrue:[^ false].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   349
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   350
    (self processChunk:type len:len) ifFalse:[^ false].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   351
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   352
    crc := inStream nextInt32MSB:true.  "/ ignored - for now
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   353
    ^ true
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   354
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   355
    "Created: 21.6.1996 / 21:09:36 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   356
    "Modified: 21.6.1996 / 21:20:26 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   357
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   358
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   359
getIHDRChunk
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   360
    |len type crc|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   361
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   362
    len := inStream nextInt32MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   363
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   364
    type := String new:4.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   365
    inStream nextBytes:4 into:type.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   366
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   367
    type = 'IHDR' ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   368
        Logger warning:'PNGReader: expected IHDR magic (%1)' with:inStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   369
        ^ false
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   370
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   371
    len == 13 ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   372
        Logger warning:'PNGReader: bad IHDR size (%1)' with:inStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   373
        ^ false
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   374
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   375
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   376
    width := inStream nextInt32MSB:true.        
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   377
    height := inStream nextInt32MSB:true.        
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   378
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   379
    (width <= 0 or:[height <= 0]) ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   380
        Logger warning:'PNGReader: invalid dimension(s) (%1)' with:inStream.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   381
        ^ false.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   382
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   383
    self reportDimension.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   384
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   385
    bitsPerChannel := inStream nextByte.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   386
    depth := bitsPerChannel. "/ will be changed by setColorType.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   387
    colorType := inStream nextByte.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   388
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   389
    compressionMethod := inStream nextByte.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   390
    filterMethod := inStream nextByte.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   391
    interlaceMode := inStream nextByte.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   392
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   393
    Verbose == true ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   394
        'PNGReader: IHDR:' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   395
        'PNGReader:   width: ' infoPrint. width infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   396
        'PNGReader:   height: ' infoPrint. height infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   397
        'PNGReader:   bitsPerChannel: ' infoPrint. bitsPerChannel infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   398
        'PNGReader:   colorType: ' infoPrint. colorType infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   399
        'PNGReader:   compressionMethod: ' infoPrint. compressionMethod infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   400
        'PNGReader:   filterMethod: ' infoPrint. filterMethod infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   401
        'PNGReader:   interlaceMode: ' infoPrint. interlaceMode infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   402
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   403
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   404
    crc := inStream nextInt32MSB:true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   405
    ^ true
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   406
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   407
    "Modified: / 17-02-2017 / 11:35:20 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   408
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   409
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   410
handleText:text keyword:keyword
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   411
    "/ things like exif data etc.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   412
    "/ self halt.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   413
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   414
    "/Standard keywords for text chunks:
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   415
    "/
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   416
    "/   Title            Short (one line) title or caption for image
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   417
    "/   Author           Name of image's creator
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   418
    "/   Description      Description of image (possibly long)
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   419
    "/   Copyright        Copyright notice
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   420
    "/   Creation Time    Time of original image creation
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   421
    "/   Software         Software used to create the image
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   422
    "/   Disclaimer       Legal disclaimer
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   423
    "/   Warning          Warning of nature of content
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   424
    "/   Source           Device used to create the image
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   425
    "/   Comment          Miscellaneous comment; conversion from
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   426
    "/                    GIF comment
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   427
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   428
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   429
setColorType:colorType
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   430
    colorType == 0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   431
        photometric := #blackIs0.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   432
        samplesPerPixel := 1.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   433
        bitsPerSample := Array with:bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   434
        depth := bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   435
        ^ true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   436
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   437
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   438
    colorType == 2 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   439
        bitsPerChannel < 8 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   440
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   441
            ^ false.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   442
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   443
        photometric := #rgb.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   444
        samplesPerPixel := 3.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   445
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   446
        depth := bitsPerChannel * 3.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   447
        ^ true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   448
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   449
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   450
    colorType == 3 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   451
        bitsPerChannel == 16 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   452
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   453
            ^ false.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   454
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   455
        photometric := #palette.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   456
        samplesPerPixel := 1.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   457
        bitsPerSample := Array with:bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   458
        depth := bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   459
        ^ true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   460
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   461
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   462
    colorType == 4 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   463
        bitsPerChannel < 8 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   464
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   465
            ^ false.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   466
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   467
        photometric := #blackIs0.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   468
        samplesPerPixel := 2.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   469
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   470
        depth := bitsPerChannel * 2.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   471
        ^ true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   472
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   473
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   474
    colorType == 6 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   475
        bitsPerChannel < 8 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   476
            'PNGReader: invalid colorType/depth combination' infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   477
            ^ false.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   478
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   479
        photometric := #rgba.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   480
        samplesPerPixel := 4.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   481
        bitsPerSample := Array with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel with:bitsPerChannel.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   482
        depth := bitsPerChannel * 4.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   483
        ^ true.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   484
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   485
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   486
    ('PNGReader: invalid colorType: ' , colorType printString , '.') infoPrintCR.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   487
    ^ false
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   488
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   489
    "Modified: / 16-02-2017 / 17:19:19 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   490
! !
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   491
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   492
!PNGReader methodsFor:'reading-private chunks'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   494
doPass: pass
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   495
    "Certain interlace passes are skipped with certain small image dimensions"
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   496
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   497
    pass = 1 ifTrue: [ ^ true ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   498
    ((width = 1) and: [height = 1]) ifTrue: [ ^ false ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   499
    pass = 2 ifTrue: [ ^ width >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   500
    pass = 3 ifTrue: [ ^ height >= 5 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   501
    pass = 4 ifTrue: [ ^ (width >=3 ) or: [height >= 5] ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   502
    pass = 5 ifTrue: [ ^ height >=3 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   503
    pass = 6 ifTrue: [ ^ width >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   504
    pass = 7 ifTrue: [ ^ height >=2 ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   505
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   506
    self error:'invalid argument'.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   507
    ^ true
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   508
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   509
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
processBKGDChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
    "Created: 21.6.1996 / 21:15:49 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   517
processCHRMChunkLen:len
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   518
    "cHRM Primary chromaticities chunk - currently unhandled"
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   519
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   520
    |whitePointX whitePointY redX redY greenX greenY blueX blueY|
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   521
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   522
    whitePointX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   523
    whitePointY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   524
    redX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   525
    redY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   526
    greenX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   527
    greenY := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   528
    blueX := (inStream nextInt32MSB:true) / 100000.0.
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   529
    blueY := (inStream nextInt32MSB:true) / 100000.0.
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   530
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   531
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   532
        'PNGReader: CHRM chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   533
        'PNGReader:   whitePointX:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   534
        'PNGReader:   whitePointY:' infoPrint. whitePointX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   535
        'PNGReader:   redX:' infoPrint. redX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   536
        'PNGReader:   redY:' infoPrint. redY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   537
        'PNGReader:   greenX:' infoPrint. greenX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   538
        'PNGReader:   greenY:' infoPrint. greenY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   539
        'PNGReader:   blueX:' infoPrint. blueX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   540
        'PNGReader:   blueY:' infoPrint. blueY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   541
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   542
    ^ true
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   543
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   544
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
processChunk:type len:len
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   546
    |chunk|
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   547
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   548
    type = 'IDAT' ifTrue:[
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   549
        "---since the compressed data can span multiple
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   550
        chunks, stitch them all together first. later,
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   551
        if memory is an issue, we need to figure out how
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   552
        to do this on the fly---"
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   553
        chunk := inStream next:len.
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   554
        globalDataChunk isNil ifTrue:[
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   555
            globalDataChunk := ReadWriteStream on:(ByteArray new:(height * self bytesPerRow)).
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   556
        ].
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   557
        globalDataChunk nextPutAll:chunk.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   558
        ^ true
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   559
    ].
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   560
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
    type = 'gAMA' ifTrue:[^ self processGAMAChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
    type = 'sBIT' ifTrue:[^ self processSBITChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
    type = 'tEXt' ifTrue:[^ self processTEXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    type = 'tIME' ifTrue:[^ self processTIMEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
    type = 'bKGD' ifTrue:[^ self processBKGDChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
    type = 'zTXt' ifTrue:[^ self processZTXTChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
    type = 'PLTE' ifTrue:[^ self processPLTEChunkLen:len].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   569
    type = 'pHYs' ifTrue:[^ self processPHYSChunkLen:len].
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   570
    type = 'cHRM' ifTrue:[^ self processCHRMChunkLen:len].
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   571
    type = 'tRNS' ifTrue:[^ self processTRNSChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   572
    type = 'IHDR' ifTrue:[^ self processIHDRChunkLen:len].
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   573
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   574
    type = 'iTXt' ifTrue:[^ self processITXTChunkLen:len].
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   575
    type = 'iCCP' ifTrue:[^ self processICCPChunkLen:len].
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   576
    type = 'hIST' ifTrue:[^ self processHISTChunkLen:len].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   577
    type = 'spAL' ifTrue:[^ self processSPALChunkLen:len].
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   578
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   579
    specialChunkHandlers notNil ifTrue:[
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   580
        |handler chunkData|
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   581
        
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   582
        handler := specialChunkHandlers at:type ifAbsent:nil.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   583
        handler notNil ifTrue:[
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   584
            chunkData := inStream nextBytes:len.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   585
            handler value:chunkData optionalArgument:self.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   586
            ^ true.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   587
        ].
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   588
    ].
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   589
3891
1fea387a7b01 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3890
diff changeset
   590
    type = 'niVI' ifTrue:[^ self processNIVIChunkLen:len].
1fea387a7b01 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3890
diff changeset
   591
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
    ('PNGReader: unrecognized chunk: ' , type , ' ignored.') infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
    ^ true.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   597
    "Created: / 21-06-1996 / 21:10:37 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   598
    "Modified: / 17-02-2017 / 11:32:06 / cg"
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
processGAMAChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
    "Created: 21.6.1996 / 21:10:52 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   608
processGlobalIDATChunk
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   609
    interlaceMode == 0 ifTrue: [
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   610
        ^ self processNonInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   611
    ]. 
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   612
    ^ self processInterlacedGlobalDATA
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   613
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   614
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   615
processHISTChunkLen:len
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   616
    "/ ignored
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   617
    "/ inStream nextBytes:len.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   618
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   619
    inStream skip:len.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   620
    ^ true
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   621
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   622
    "Created: / 17-02-2017 / 11:31:36 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   623
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   624
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   625
processICCPChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   626
    "/ ignored
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   627
    "/ inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   628
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   629
    inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   630
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   631
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   632
    "Created: 21.6.1996 / 21:15:58 / cg"
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   633
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   634
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
processIDATChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   636
    interlaceMode == 0 ifTrue: [
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   637
        ^ self processNonInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   638
    ]. 
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   639
    ^ self processInterlacedDATA:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   640
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   641
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   642
processIHDRChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   643
    "/ ignored
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   644
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   645
    inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   646
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   647
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   648
    "Created: 21.6.1996 / 21:15:58 / cg"
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   649
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   650
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   651
processITXTChunkLen:len
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   652
    "/ international (i.e.utf8) textual data.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   653
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   654
    "/ currently ignored - not needed to display png images
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   655
    "/
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   656
    "/   Keyword:             1-79 bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   657
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   658
    "/   Compression flag:    1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   659
    "/   Compression method:  1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   660
    "/   Language tag:        0 or more bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   661
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   662
    "/   Translated keyword:  0 or more bytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   663
    "/   Null separator:      1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   664
    "/   Text:                0 or more bytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   665
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   666
    "/ if needed, set processTextChunks to true somewhere...
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   667
    processTextChunks == true ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   668
        |chunkData keyword text i1 i2 i3 
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   669
         compressionFlag compressionMethod languageTag
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   670
         xlatedKeyword textBytes|
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   671
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   672
        chunkData := inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   673
        i1 := chunkData indexOf:0.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   674
        keyword := (chunkData copyTo:i1-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   675
        compressionFlag := chunkData at:i1+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   676
        compressionMethod := chunkData at:i1+2.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   677
        i2 := chunkData indexOf:0 startingAt:i1+3.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   678
        languageTag := (chunkData copyFrom:i1+3 to:i2-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   679
        i3 := chunkData indexOf:0 startingAt:i2+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   680
        xlatedKeyword := (chunkData copyFrom:i2+1 to:i3-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   681
        textBytes := chunkData copyFrom:i3+1.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   682
        compressionFlag == 0 ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   683
            text := textBytes
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   684
        ] ifFalse:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   685
            compressionFlag == 1 ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   686
                "/ for now, only zlib compression is supported...
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   687
                "/ ... no - not even that is
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   688
                Logger warning:'PNG: zlib compressed text currently unsupported'.
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   689
            ] ifFalse:[
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   690
                Logger warning:'PNG: unsupported text compression method'.
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   691
            ].    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   692
        ].    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   693
        text := text utf8Decoded.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   694
        self handleText:text keyword:keyword.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   695
    ] ifFalse:[    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   696
        inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   697
    ].
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   698
    ^ true
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   699
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   700
    "Created: / 21-06-1996 / 21:15:58 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   701
    "Modified: / 16-02-2017 / 19:51:21 / cg"
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   702
!
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   703
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   704
processInterlacedDATA:len
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
    ^ true
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   707
!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   709
processInterlacedGlobalDATA
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   710
    "adam7 interlace method"
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   711
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   712
    | zlibReader filter 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   713
      bytesPerPass startingCol colIncrement rowIncrement 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   714
      startingRow 
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   715
      temp "filtersSeen"  
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   716
      cx       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   717
      sc       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   718
      cy       "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   719
      startRow "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   720
      w        "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   721
      h        "{ Class: SmallInteger }"
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   722
    |
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   723
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   724
    interlaceMode == 1 ifFalse: [
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   725
        self error:'unsupported interlaced mode'.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   726
        ^ self
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   727
    ].
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   728
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   729
    "/ filtersSeen := Set new.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   730
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   731
    startingCol := #(0 4 0 2 0 1 0 ).
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   732
    startingRow := #(0 0 4 0 2 0 1 ).
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   733
    colIncrement := #(8 8 4 4 2 2 1 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   734
    rowIncrement := #(8 8 8 4 4 2 2 ).
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   735
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   736
    globalDataChunk reset.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   737
    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   738
    zlibReader binary.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   739
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   740
    h := height.
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   741
    w := width.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   742
    1 to: 7 do: [:pass |
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   743
        (self doPass: pass) ifTrue:[
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   744
            cx := colIncrement at: pass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   745
            sc := startingCol at: pass.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
   746
            cy := rowIncrement at: pass.
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   747
            bytesPerPass := (((w - sc + cx - 1) // cx * depth) + 7) // 8.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   748
            prevScanline := ByteArray new: bytesPerPass.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   749
            thisScanline := ByteArray new: bytesPerScanline.
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   750
            startRow := startingRow at: pass.
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
   751
            startRow to: h-1 by: cy do: [:y |
3343
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
   752
                filter := zlibReader nextByte.
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   753
                "/ filtersSeen add: filter.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   754
                (filter isNil or: [(filter between: 0 and: 4) not])
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   755
                    ifTrue: [^ self].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   756
                zlibReader next: bytesPerPass into: thisScanline startingAt: 1.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   757
                filter ~~ 0 ifTrue:[ self filterScanline: filter count: bytesPerPass ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   758
                self copyPixels:y at:sc by:cx.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   759
                temp := prevScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   760
                prevScanline := thisScanline.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   761
                thisScanline := temp.
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   762
            ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   763
        ]
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   764
    ].
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   765
    zlibReader atEnd ifFalse:[self error:'Unexpected data'].
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   766
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   767
    "Modified: / 03-05-2011 / 12:03:33 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   768
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   769
3890
37131d0d77c6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3889
diff changeset
   770
processNIVIChunkLen:len    
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   771
    "/ this cunk contains a labView vi.
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   772
    "/ ignored for now...
3890
37131d0d77c6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3889
diff changeset
   773
    "/ ...to read it (using the expecco importer),
37131d0d77c6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3889
diff changeset
   774
    "/ create a reader with a chunkHook and extract it there.
3891
1fea387a7b01 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3890
diff changeset
   775
    Logger info:('PNG: skip niVI chunk').
3890
37131d0d77c6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3889
diff changeset
   776
    inStream skip:len.
37131d0d77c6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3889
diff changeset
   777
    ^ true.
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   778
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   779
    "Created: / 14-02-2017 / 08:57:29 / cg"
3891
1fea387a7b01 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3890
diff changeset
   780
    "Modified: / 14-02-2017 / 22:36:34 / cg"
3889
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   781
!
b7c261a8614d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3821
diff changeset
   782
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   783
processNonInterlacedDATA:len
2701
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   784
    self halt:'not used'
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   785
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   786
"/    | zlibReader filter temp prevScanline thisScanline bytesPerScanline filtersSeen|
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   787
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   788
"/    zlibReader := ZipStream readOpenAsZipStreamOn:inStream suppressHeaderAndChecksum:false. 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   789
"/    "/ zlibReader := ZLibReadStream on:inStream from: 1 to:len.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   790
"/
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   791
"/    prevScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   792
"/    thisScanline := ByteArray new: self bytesPerRow.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   793
"/    0 to: height - 1 do:[:index | 
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   794
"/            filter := (zlibReader next: 1) first.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   795
"/            filtersSeen add: filter.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   796
"/            (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
   797
"/            thisScanline := zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   798
"/            self filterScanline: filter count: bytesPerScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   799
"/            self copyPixels: index.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   800
"/            temp := prevScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   801
"/            prevScanline := thisScanline.
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   802
"/            thisScanline := temp
8ca05242522e adapt to zlib changes
Claus Gittinger <cg@exept.de>
parents: 2700
diff changeset
   803
"/    ]
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   804
!
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   805
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   806
processNonInterlacedGlobalDATA
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   807
    | "data n" zlibReader filter temp "filtersSeen" i|
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   808
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   809
    "/ filtersSeen := Set new.
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   810
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   811
"/    data := ByteArray new:(self bytesPerRow * height)+1000.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   812
"/    n := ZipStream uncompress: globalDataChunk into: data.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   813
"/    self halt.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   814
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   815
    globalDataChunk reset.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
   816
    zlibReader := ZipStream readOpenAsZipStreamOn:globalDataChunk suppressHeaderAndChecksum:false.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   817
    zlibReader binary.
2509
866b56cabe7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   818
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   819
    prevScanline := ByteArray new: bytesPerScanline.
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   820
    thisScanline := ByteArray new: bytesPerScanline.
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   821
    0 to: height - 1 do:[:y | 
3343
ca3446a105d2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3327
diff changeset
   822
        filter := zlibReader nextByte.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   823
        zlibReader next: bytesPerScanline into: thisScanline startingAt: 1.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   824
        filter ~~ 0 ifTrue:[ 
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   825
            "/ filtersSeen add: filter.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   826
            (filter notNil and: [filter between: 0 and: 4]) ifFalse: [
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   827
                'PNGReader: unsupported filter: ' infoPrint. filter infoPrintCR.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   828
                ^ self
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   829
            ].
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   830
            self filterScanline: filter count: bytesPerScanline 
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   831
        ].
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   832
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   833
        i := y * bytesPerScanline.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   834
        data replaceFrom:i+1 to:(i+bytesPerScanline) with:thisScanline startingAt:1.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   835
2695
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   836
        temp := prevScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   837
        prevScanline := thisScanline.
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   838
        thisScanline := temp
6197b6af7f4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2683
diff changeset
   839
    ]
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   840
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
   841
    "Modified: / 16-02-2017 / 16:45:52 / cg"
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   842
!
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   843
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   844
processPHYSChunkLen:len
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   845
    "physical pixel chunk - currently unhandled"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   846
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   847
    |pixelPerUnitX pixelPerUnitY unit|
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   848
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   849
    pixelPerUnitX := inStream nextInt32MSB:true.  
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
   850
    pixelPerUnitY := inStream nextInt32MSB:true.
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   851
    unit := inStream nextByte.
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   852
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   853
    Verbose == true ifTrue:[
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   854
        'PNGReader: PHYS chunk ignored:' infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   855
        'PNGReader:   ppuX:' infoPrint. pixelPerUnitX infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   856
        'PNGReader:   ppuY:' infoPrint. pixelPerUnitY infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   857
        'PNGReader:   unit:' infoPrint. unit infoPrintCR.
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   858
    ].
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   859
2705
7ff2e44e44af *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   860
    ^ true
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
processPLTEChunkLen:len
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   864
    "read a color palette"
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   865
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   866
    |n "{ Class: SmallInteger }"
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   867
     redBytes greenBytes blueBytes|
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
    (len \\ 3) ~~ 0 ifTrue:[
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
        'PNGReader: invalid size of PLTE chunk' infoPrintCR.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
        ^ false
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    n := len // 3.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
    redBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
    greenBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
    blueBytes := ByteArray new:n.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
    1 to:n do:[:i |
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
        redBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
        greenBytes at:i put:(inStream nextByte).
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
        blueBytes at:i put:(inStream nextByte)
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
    ].
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
2725
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   884
    colorMap := MappedPalette 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   885
                    redVector:redBytes 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   886
                    greenVector:greenBytes 
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   887
                    blueVector:blueBytes.
a480f3671588 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2709
diff changeset
   888
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    "Created: 21.6.1996 / 21:22:28 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
    "Modified: 21.6.1996 / 21:43:01 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
processSBITChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
    "Created: 21.6.1996 / 21:13:09 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   902
processSPALChunkLen:len
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   903
    "/ ignored
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   904
    "/ inStream nextBytes:len.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   905
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   906
    inStream skip:len.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   907
    ^ true
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   908
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   909
    "Created: / 17-02-2017 / 11:31:40 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   910
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   911
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   912
processTEXTChunkLen:len    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   913
    "/ textual data in iso8859 coding.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   914
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   915
    "/ currently ignored - not needed to display png images
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   916
    "/   Keyword:        1-79 bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   917
    "/   Null separator: 1 byte
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   918
    "/   Text:           n bytes (character string)
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   919
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   920
    "/ if needed, set processTextChunks to true somewhere...
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   921
    processTextChunks == true ifTrue:[
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   922
        |chunkData keyword text i|
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   923
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   924
        chunkData := inStream nextBytes:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   925
        i := chunkData indexOf:0.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   926
        keyword := (chunkData copyTo:i-1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   927
        text := (chunkData copyFrom:i+1) asString.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   928
        self handleText:text keyword:keyword.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   929
    ] ifFalse:[  
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   930
        inStream skip:len.
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   931
    ].    
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
    "Modified: 21.6.1996 / 21:15:27 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
processTIMEChunkLen:len
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
    "Created: 21.6.1996 / 21:15:43 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
    "Modified: 21.6.1996 / 21:20:42 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
!
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   945
processTRNSChunkLen:len
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   946
    paletteAlphaEntries := inStream nextBytes:len.
3904
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   947
    
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   948
    colorType == ColorTypeRGB ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   949
        len ~~ 3 ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   950
            Logger warning:'PNG: bad trns chunk size'.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   951
            paletteAlphaEntries := nil.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   952
        ].
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   953
        ^ true
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   954
    ].    
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   955
    colorType == ColorTypePalette ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   956
        len ~~ 1 ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   957
            Logger warning:'PNG: bad trns chunk size'.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   958
            paletteAlphaEntries := nil.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   959
        ].
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   960
        ^ true
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   961
    ].        
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   962
    colorType == ColorTypeGray ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   963
        len ~~ 2 ifTrue:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   964
            Logger warning:'PNG: bad trns chunk size'.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   965
            paletteAlphaEntries := nil.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   966
        ].
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   967
        ^ true
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   968
    ].        
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   969
    paletteAlphaEntries := nil.
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   970
    ^ true
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   971
3904
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   972
    "Modified (format): / 17-02-2017 / 16:57:27 / cg"
2707
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   973
!
e9c5c3ab8c18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   974
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
processZTXTChunkLen:len
3762
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   976
    "/ compressed text
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   977
    
036884e46f66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
   978
    "/ currently ignored - not needed to display png images
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
    inStream skip:len.
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
    ^ true
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
    "Created: 21.6.1996 / 21:15:58 / cg"
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
! !
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
   985
!PNGReader methodsFor:'reading-private filtering'!
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
   986
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   987
filterAverage:count 
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   988
    "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
   989
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
   990
    |delta|
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
   991
3609
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   992
%{
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   993
    if (__isByteArray(__INST(thisScanline))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   994
     && __isByteArray(__INST(prevScanline))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   995
     && __isSmallInteger(__INST(depth))
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   996
     && __isSmallInteger(count)) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   997
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   998
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
   999
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1000
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1001
        INT __count = __intVal(count);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1002
        INT __delta = __intVal(__INST(depth)) / 8;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1003
        int __i;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1004
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1005
        if (__delta < 1) __delta = 1;
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1006
        for (__i=0; __i<__delta; __i++) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1007
            __thisScanline[__i] += (__prevScanline[__i] >> 1);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1008
        }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1009
        for (; __i < __count; __i++) {
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1010
            __thisScanline[__i] += ((__prevScanline[__i] + __thisScanline[__i-__delta]) >> 1);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1011
        }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1012
        RETURN(self);
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1013
    }
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1014
%}.
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1015
1619ea562333 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3608
diff changeset
  1016
    delta := depth // 8 max:1.
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1017
    1 to:delta do:[:i | 
3384
0761606da988 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3343
diff changeset
  1018
        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
  1019
    ].
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1020
    delta + 1 to:count do:[:i | 
3384
0761606da988 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3343
diff changeset
  1021
        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
  1022
    ]
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1023
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1024
    "Modified: / 03-05-2011 / 12:14:01 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1025
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1026
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1027
filterHorizontal:count
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1028
    "use the pixel to the left as a predictor"
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1029
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1030
    |delta|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1031
3608
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1032
%{
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1033
    if (__isByteArray(__INST(thisScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1034
     && __isByteArray(__INST(prevScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1035
     && __isSmallInteger(__INST(depth))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1036
     && __isSmallInteger(count)) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1037
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1038
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1039
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1040
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1041
        INT __count = __intVal(count);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1042
        INT __delta = __intVal(__INST(depth)) / 8;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1043
        int __i;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1044
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1045
        if (__delta < 1) __delta = 1;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1046
        for (__i = __delta; __i < __count; __i++) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1047
            __thisScanline[__i] = __thisScanline[__i] + __thisScanline[__i-__delta];
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1048
        }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1049
        RETURN(self);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1050
    }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1051
%}.
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1052
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1053
    delta := depth // 8 max:1.
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1054
    delta+1 to:count do:[:i|
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1055
        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
  1056
    ]
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1057
!
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1058
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1059
filterNone: count
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1060
    "/ no filter - scanline is as is
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1061
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1062
    "Modified: / 03-05-2011 / 12:14:20 / cg"
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1063
!
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1064
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1065
filterPaeth:count 
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1066
    "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
  1067
     predict the value of this pixel"
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1068
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1069
    |delta|
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1070
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1071
%{
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1072
    if (__isByteArray(__INST(thisScanline))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1073
     && __isByteArray(__INST(prevScanline))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1074
     && __isSmallInteger(__INST(depth))
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1075
     && __isSmallInteger(count)) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1076
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1077
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1078
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1079
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1080
        INT __count = __intVal(count);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1081
        INT __delta = __intVal(__INST(depth)) / 8;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1082
        int __i;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1083
        
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1084
        if (__delta < 1) __delta = 1;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1085
        for (__i=0; __i<__delta; __i++) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1086
            unsigned int __pix = __thisScanline[__i] + __prevScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1087
            __thisScanline[__i] = __pix;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1088
        }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1089
        for (; __i < __count; __i++) {
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1090
            int __pCenter = __thisScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1091
            int __pLeft = __thisScanline[__i - __delta];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1092
            int __pAbove = __prevScanline[__i];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1093
            int __pAboveLeft = __prevScanline[__i - __delta];
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1094
            int __pa, __pb, __pc;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1095
            int __p;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1096
            
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1097
            __pa = (__pAbove - __pAboveLeft); 
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1098
            __pa = __pa < 0 ? -__pa : __pa;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1099
            __pb = (__pLeft - __pAboveLeft);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1100
            __pb = __pb < 0 ? -__pb : __pb;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1101
            __pc = __pLeft + __pAbove - __pAboveLeft - __pAboveLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1102
            __pc = __pc < 0 ? -__pc : __pc; 
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1103
            if ((__pa <= __pb) && (__pa <= __pc)) __p = __pLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1104
            else if (__pb <= __pc) __p = __pAbove;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1105
            else __p = __pAboveLeft;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1106
            
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1107
            __thisScanline[__i] = __pCenter + __p;
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1108
        }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1109
        RETURN(self);
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1110
    }
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1111
%}.
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1112
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1113
    delta := depth // 8 max:1.
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1114
    1 to:delta do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1115
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1116
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1117
            put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1118
    ].
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1119
    delta + 1 to:count do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1120
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1121
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1122
            put:(((thisScanline at:i) + (self 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1123
                            paethPredictLeft:(thisScanline at:i - delta)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1124
                            above:(prevScanline at:i)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1125
                            aboveLeft:(prevScanline at:i - delta))) 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1126
                    bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1127
    ]
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1128
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1129
    "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
  1130
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1131
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1132
filterScanline:filterType count:count
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
  1133
    filterType == 0 ifTrue:[^ self].
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
  1134
    
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1135
    self 
3612
0784a518d8f4 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3611
diff changeset
  1136
        perform:(#(filterHorizontal: filterVertical: filterAverage: filterPaeth:) at:filterType)
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1137
        with:count
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1138
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1139
    "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
  1140
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1141
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1142
filterVertical:count 
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1143
    "Use the pixel above as a predictor"
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1144
    
3608
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1145
%{
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1146
    if (__isByteArray(__INST(thisScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1147
     && __isByteArray(__INST(prevScanline))
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1148
     && __isSmallInteger(count)) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1149
        unsigned char *__thisScanline = __byteArrayVal(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1150
        unsigned int __sz_this = __byteArraySize(__INST(thisScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1151
        unsigned char *__prevScanline = __byteArrayVal(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1152
        unsigned int __sz_prev = __byteArraySize(__INST(prevScanline));
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1153
        INT __count = __intVal(count);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1154
        int __i;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1155
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1156
        for (__i=0; __i<__count; __i++) {
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1157
            unsigned int __pix = __thisScanline[__i] + __prevScanline[__i];
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1158
            __thisScanline[__i] = __pix;
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1159
        }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1160
        RETURN(self);
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1161
    }
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1162
%}.
ffd67647a98b #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3607
diff changeset
  1163
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1164
    1 to:count do:[:i | 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1165
        thisScanline 
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1166
            at:i
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1167
            put:(((thisScanline at:i) + (prevScanline at:i)) bitAnd:255)
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1168
    ]
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1169
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1170
    "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
  1171
!
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1172
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1173
paethPredictLeft: l above: a aboveLeft: al
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1174
    "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
  1175
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1176
    | pa pb pc |
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1177
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1178
    pa := a > al ifTrue: [a - al] ifFalse: [al - a].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1179
    pb := l > al ifTrue: [l - al] ifFalse: [al - l].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1180
    pc := l + a - al - al.
2697
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1181
    pc < 0 ifTrue: [
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1182
        pc := pc * -1
8e8223bf25af more stuff added (but still not complete)
Claus Gittinger <cg@exept.de>
parents: 2696
diff changeset
  1183
    ].
3607
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1184
    ((pa <= pb) and: [pa <= pc]) ifTrue: [^ l].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1185
    (pb <= pc) ifTrue: [^ a].
a1b3d6654923 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
  1186
    ^ al
2696
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1187
! !
99339f07db68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2695
diff changeset
  1188
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1189
!PNGReader methodsFor:'reading-private pixel copy'!
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1190
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1191
copyPixels:y at:startX by:incX 
2704
bbcc771de65c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2703
diff changeset
  1192
    "Handle interlaced pixels of supported colorTypes"
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1193
    
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1194
    |s|
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1195
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1196
    "/ per color type copy methods
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1197
    s := #( 
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1198
             #copyPixelsGray:at:by:         "/ 0 = ColorTypeGray
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1199
             nil
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1200
             #copyPixelsRGB:at:by:          "/ 2 = ColorTypeRGB
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1201
             #copyPixelsIndexed:at:by:      "/ 3 = ColorTypePalette
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1202
             #copyPixelsGrayAlpha:at:by:    "/ 4 = ColorTypeGrayAlpha
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1203
             nil 
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1204
             #copyPixelsRGBA:at:by:         "/ 6 = ColorTypeRGBA
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1205
        ) at:colorType + 1.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
  1206
    self perform:s with:y with:startX with:incX
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1207
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1208
    "Modified: / 03-05-2011 / 12:02:45 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1209
    "Modified (comment): / 16-02-2017 / 19:42:47 / cg"
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1210
!
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1211
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1212
copyPixelsGray:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1213
    "Handle interlaced pixels of supported colorTypes.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1214
     Untested code - please verify"
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1215
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1216
    |srcIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1217
     srcMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1218
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1219
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1220
     dstMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1221
     x        "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1222
     bits     "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1223
     bitMask  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1224
     rS       "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1225
     lS       "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1226
     rowIndex "{ Class: SmallInteger }"|
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1227
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1228
    nPixels := width // incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1229
    srcIndex := 0. srcMask := 0. x := startX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1230
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1231
    depth == 1 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1232
        dstIndex := (y * bytesPerScanline) + (startX // 8) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1233
        dstMask := 16r80 >> (x \\ 8).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1234
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1235
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1236
            srcMask == 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1237
                srcMask := 16r80.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1238
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1239
                bits := thisScanline at:srcIndex. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1240
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1241
            bitMask := (bits bitAnd:srcMask) == 0 ifTrue:[0] ifFalse:[dstMask].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1242
            bitMask ~~ 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1243
                data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1244
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1245
            x := x + incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1246
            dstMask := dstMask >> incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1247
            dstMask == 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1248
                dstIndex := dstIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1249
                dstMask := 16r80 >> (x \\ 8).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1250
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1251
            srcMask := srcMask bitShift:-1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1252
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1253
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1254
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1255
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1256
    depth == 2 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1257
        dstIndex := (y * bytesPerScanline) + (startX // 4) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1258
        lS := 6 - ((x \\ 4) * 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1259
        rS := -1. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1260
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1261
            rS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1262
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1263
                bits := thisScanline at:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1264
                rS := 6.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1265
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1266
            bitMask := ((bits >> rS) bitAnd:2r11).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1267
            bitMask ~~ 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1268
                bitMask := bitMask << lS.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1269
                data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1270
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1271
            lS := lS - (incX * 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1272
            lS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1273
                lS <= -8 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1274
                    dstIndex := dstIndex + 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1275
                    lS := lS + 8 + 8.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1276
                ] ifFalse:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1277
                    dstIndex := dstIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1278
                    lS := lS + 8.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1279
                ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1280
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1281
            rS := rS - 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1282
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1283
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1284
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1285
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1286
    depth == 4 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1287
        rowIndex := (y * bytesPerScanline) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1288
        dstIndex := rowIndex + (x // 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1289
        rS := -1. 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1290
        1 to:nPixels do:[:cnt |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1291
            rS < 0 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1292
                srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1293
                bits := thisScanline at:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1294
                rS := 4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1295
            ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1296
            bitMask := ((bits >> rS) bitAnd:2r1111).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1297
            x even ifTrue:[    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1298
                bitMask := bitMask bitShift:4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1299
            ].    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1300
            data at:dstIndex put:((data at:dstIndex) bitOr:bitMask).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1301
            x := x + incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1302
            dstIndex := rowIndex + (x // 2).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1303
            rS := rS - 4.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1304
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1305
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1306
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1307
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1308
    depth == 8 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1309
        srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1310
        dstIndex := (y * bytesPerScanline) + (startX) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1311
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1312
        1 to:nPixels do:[:n |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1313
            data at:dstIndex put:(thisScanline at:srcIndex).
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1314
            srcIndex := srcIndex + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1315
            dstIndex := dstIndex + incX
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1316
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1317
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1318
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1319
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1320
    depth == 16 ifTrue:[
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1321
        srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1322
        dstIndex := (y * bytesPerScanline) + (startX*2) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1323
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1324
        1 to:nPixels do:[:n |
3601
05caf7f1e324 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
  1325
            data unsignedInt16At:dstIndex put:(thisScanline unsignedInt16At:srcIndex).
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1326
            srcIndex := srcIndex + 2.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1327
            dstIndex := dstIndex + (incX * 2)
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1328
        ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1329
        ^ self.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1330
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1331
    self error:'unsupported depth'.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1332
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1333
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1334
copyPixelsIndexed:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1335
    self copyPixelsGray:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1336
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1337
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1338
copyPixelsRGB:y at:startX by:incX 
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1339
    "Handle interlaced pixels of supported colorTypes.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1340
     Untested code - please verify"
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1341
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1342
    |srcIndex "{ Class: SmallInteger }" 
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1343
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1344
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1345
     dstInc   "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1346
     bpp      "{ Class: SmallInteger }"|
3598
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1347
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1348
    bpp := bytesPerScanline // width.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1349
    
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1350
    "/ 1 byte per r,g,b
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1351
    srcIndex := 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1352
    dstIndex := (y * bytesPerScanline) + (startX * bpp) + 1.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1353
    dstInc := incX * bpp.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1354
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1355
    nPixels := width // incX.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1356
    1 to:nPixels do:[:n |
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1357
        data replaceFrom:dstIndex to:dstIndex+bpp-1 with:thisScanline startingAt:srcIndex.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1358
        srcIndex := srcIndex + bpp.
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1359
        dstIndex := dstIndex + dstInc
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1360
    ].
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1361
!
bdd7048a0f2e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
  1362
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1363
copyPixelsRGBA:y at:startX by:incX 
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1364
    "Handle interlaced pixels of supported colorTypes.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1365
     Untested code - please verify"
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1366
3611
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1367
    |srcIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1368
     nPixels  "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1369
     dstIndex "{ Class: SmallInteger }"
310db973356e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3609
diff changeset
  1370
     dstInc   "{ Class: SmallInteger }"|
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1371
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1372
    srcIndex := 1.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
  1373
    dstIndex := (y * bytesPerScanline) + (startX * 4) + 1.
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
  1374
    dstInc := incX * 4.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1375
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1376
    nPixels := thisScanline size.
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1377
    [srcIndex < nPixels] whileTrue:[
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
  1378
        data replaceFrom:dstIndex to:dstIndex+3 with:thisScanline startingAt:srcIndex.
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1379
        srcIndex := srcIndex + 4.
3437
4e1cf7b6b492 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3384
diff changeset
  1380
        dstIndex := dstIndex + dstInc
3327
4758853d1abe class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 3183
diff changeset
  1381
    ].
2699
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1382
! !
84b52c63e242 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2698
diff changeset
  1383
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1384
!PNGReader methodsFor:'writing'!
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1385
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1386
save:image onStream:aStream
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1387
    "save image in PNG-file-format onto aStream"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1388
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1389
    outStream := aStream.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1390
    outStream binary.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1391
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1392
    byteOrder := #msb.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1393
    width := image width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1394
    height := image height.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1395
    photometric := image photometric.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1396
    samplesPerPixel := image samplesPerPixel.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1397
    bitsPerSample := image bitsPerSample.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1398
    colorMap := image colorMap.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1399
    data := image bits.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1400
    mask := image mask.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1401
    depth := self bitsPerPixel.
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1402
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
  1403
    outStream nextPutAll:(self class pngHeader).
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1404
    
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1405
    image mask notNil ifTrue:[
3904
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
  1406
        ((photometric ~~ #rgb) and:[(photometric ~~ #rgba)]) ifTrue: [
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1407
            image maskedPixelsAre0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1408
                paletteIndexForMaskedPixels := 0
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1409
            ] ifFalse:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1410
                self determinePaletteIndexForMaskedPixels
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1411
            ]
3904
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
  1412
        ] ifFalse:[
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
  1413
            photometric := #rgba.
f9baf7a194d9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
  1414
        ].    
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1415
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1416
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1417
    self writeIHDRChunk.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1418
    photometric == #palette ifTrue: [self writePaletteChunk].
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1419
    paletteIndexForMaskedPixels notNil ifTrue: [self writeTRNSChunk].
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1420
    self writeImageDataChunk.
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1421
    self writeEndChunk
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1422
3909
a275bdd921fc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3904
diff changeset
  1423
    "Modified: / 22-02-2017 / 11:00:26 / cg"
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1424
! !
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1425
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1426
!PNGReader methodsFor:'writing-private'!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1427
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1428
determinePaletteIndexForMaskedPixels
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1429
    "/ if all masked pixels are 0, and 0 is not used elsewhere in the image,
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1430
    "/ write it as such.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1431
    "/ Otherwise, find an unallocated palette index, and assign masked pixels to it.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1432
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1433
    |usedPixels freePixels pixelIdx|
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1434
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1435
    colorMap size < 256 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1436
        paletteIndexForMaskedPixels := colorMap size.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1437
    ] ifFalse:[    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1438
        usedPixels := data usedValues.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1439
        usedPixels size == 256 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1440
            self error:'cannot represent image (no palette slot for mask)'
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1441
        ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1442
        freePixels := (0 to:255) asSet removeAllFoundIn:usedPixels.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1443
        paletteIndexForMaskedPixels := freePixels first.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1444
    ].    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1445
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1446
    "/ rewrite data: wherever masked, change pixel to paletteIndexForMaskedPixels
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1447
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1448
    data := data copy.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1449
    pixelIdx := 1.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1450
    0 to:height-1 do:[:y |
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1451
        0 to:width-1 do:[:x |
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1452
            (mask pixelAtX:x y:y) == 0 ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1453
                data at:pixelIdx put:paletteIndexForMaskedPixels.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1454
            ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1455
            pixelIdx := pixelIdx + 1
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1456
        ]
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1457
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1458
    
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1459
    "       
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1460
     PNGReader save:(ToolbarIconLibrary systemBrowserIcon) onFile:'/tmp/icon.png'
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1461
     ImageEditor openOnFile:'/tmp/icon.png'
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1462
    "
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1463
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1464
    "Created: / 16-02-2017 / 19:59:39 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1465
    "Modified: / 17-02-2017 / 09:25:57 / cg"
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1466
! !
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1467
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1468
!PNGReader methodsFor:'writing-private chunks'!
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1469
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1470
writeChunk:chunkTypeChars size:len with:aBlock
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1471
    |crc realOutStream chunkBytes|
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1472
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1473
    realOutStream := outStream.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1474
    outStream := WriteStream on:(ByteArray new:len).
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1475
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1476
    outStream nextPutBytes:4 from:chunkTypeChars startingAt:1.
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1477
    aBlock value.
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1478
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1479
    chunkBytes := outStream contents.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1480
    crc := CRC32Stream hashValueOf:chunkBytes.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1481
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1482
    outStream := realOutStream.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1483
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1484
    realOutStream nextPutInt32:len MSB:true.
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1485
    realOutStream nextPutAll:chunkBytes.
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1486
    realOutStream nextPutInt32:crc MSB:true.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1487
!
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1488
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1489
writeEndChunk
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1490
    self 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1491
        writeChunk: 'IEND'
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1492
        size: 0
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1493
        with:[ ]
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1494
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1495
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1496
writeIHDRChunk
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1497
    |hasMask|
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1498
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1499
    hasMask := 0.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1500
    
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1501
    ((photometric == #whiteIs0) or:[ (photometric == #blackIs0)]) ifTrue:[
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1502
        colorType := ColorTypeGray.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1503
        hasMask := (samplesPerPixel > 1)
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1504
    ].
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1505
    (photometric == #rgb) ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1506
        colorType := ColorTypeRGB.
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1507
        hasMask := (samplesPerPixel > 3)
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1508
    ].
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1509
    (photometric == #rgba) ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1510
        colorType := ColorTypeRGBAlpha.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1511
        hasMask := (samplesPerPixel > 3)
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1512
    ].
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1513
    (photometric == #palette) ifTrue:[
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1514
        colorType := ColorTypePalette.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1515
        hasMask := (samplesPerPixel > 1)
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1516
    ].
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1517
    colorType isNil ifTrue:[
3461
eb5a53c6b5b2 class: PNGReader
Stefan Vogel <sv@exept.de>
parents: 3437
diff changeset
  1518
        self error:'unhandled photometric'
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1519
    ].
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1520
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1521
    mask notNil ifTrue:[
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1522
        hasMask := true.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1523
    ].
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1524
    hasMask ifTrue:[
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1525
        "/ make it grayAlpha / rgba
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1526
        ((colorType == ColorTypeGray) or:[colorType == ColorTypeGray]) ifTrue:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1527
            colorType := colorType bitOr:4.  "/ +alpha
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1528
        ].
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1529
    ].
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1530
    
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1531
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1532
        writeChunk: 'IHDR'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1533
        size: 13
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1534
        with:[ 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1535
            self writeLong:width.
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1536
            self writeLong:height.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1537
            outStream nextPut: 8.  "Assume that all colors are 24bit"     "/ depth
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1538
            outStream nextPut: colorType.  
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1539
            outStream nextPut: 0.  "Compression"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1540
            outStream nextPut: 0.  "Filter method"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1541
            outStream nextPut: 0   "Non-interlaced"
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1542
        ]
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1543
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1544
    "Modified (format): / 16-02-2017 / 21:24:22 / cg"
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1545
!
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1546
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1547
writeImageDataChunk
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1548
    |compressedByteStream compressedBytes zlibWriter idx 
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1549
     row32 bytesPerPixel|
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1550
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1551
    bytesPerScanline := self bytesPerRow.
3821
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1552
    
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1553
    compressedByteStream := WriteStream on:(ByteArray new:(bytesPerScanline*height)).
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1554
    zlibWriter := ZipStream writeOpenAsZipStreamOn:compressedByteStream suppressHeaderAndChecksum:false.
940aaefb5f77 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 3819
diff changeset
  1555
    zlibWriter binary.
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1556
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1557
    (mask notNil and:[photometric ~~ #palette]) ifTrue:[
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1558
        (depth == 32) ifTrue:[
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1559
            "/ on-the-fly put mask into the alpha channel.
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1560
            
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1561
            bytesPerPixel := 4
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1562
        ] ifFalse:[
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1563
            "/ for now - only support depth24 + mask
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1564
            self assert:(depth == 24).
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1565
            bytesPerPixel := 3.
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1566
        ].
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1567
        
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1568
        "/ on-the-fly place mask into the alpha channel.
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1569
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1570
        row32 := ByteArray new:(4 * width).
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1571
        self assert:(bytesPerScanline == (bytesPerPixel * width)).
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1572
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1573
        idx := 1.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1574
        0 to:height-1 do:[:y |
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1575
            |dstIdx maskRow|
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1576
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1577
            "/ expand rgb to rgba
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1578
            maskRow := mask rowAt:y.
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1579
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1580
            dstIdx := 1.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1581
            1 to:width do:[:x |
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1582
                row32 at:dstIdx put:(data at:idx).
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1583
                row32 at:dstIdx+1 put:(data at:idx+1).
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1584
                row32 at:dstIdx+2 put:(data at:idx+2).
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1585
                row32 at:dstIdx+3 put:((maskRow at:x) == 0 ifTrue:[0] ifFalse:[16rFF]).
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1586
                idx := idx + bytesPerPixel.
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1587
                dstIdx := dstIdx + 4.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1588
            ].
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1589
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1590
            zlibWriter nextPutAll:#[0].       "/ no filter
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1591
            zlibWriter nextPutAll:row32.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1592
        ].
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1593
    ] ifFalse:[
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1594
        idx := 1.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1595
        0 to:height-1 do:[:y |
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1596
            |row|
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1597
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1598
            row := data copyFrom:idx to:(idx+bytesPerScanline-1).
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1599
            zlibWriter nextPutAll:#[0].       "/ no filter
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1600
            zlibWriter nextPutAll:row.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1601
            idx := idx + bytesPerScanline.
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1602
        ].
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1603
    ].
2708
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1604
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1605
    zlibWriter close.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1606
    compressedBytes := compressedByteStream contents.
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1607
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1608
    self 
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1609
        writeChunk: 'IDAT'
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1610
        size:(compressedBytes size)
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1611
        with:[ 
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1612
            outStream nextPutAll:compressedBytes
c206c9e9bd61 more for writing
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  1613
        ]
3893
f485ae4fced3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3891
diff changeset
  1614
3935
37eafe77316d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
  1615
    "Modified: / 25-02-2017 / 14:27:34 / cg"
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1616
!
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1617
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1618
writePaletteChunk
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1619
    self 
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1620
        writeChunk: 'PLTE'
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1621
        size: 3 * colorMap size
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1622
        with:[
2703
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1623
            colorMap do:[:color | 
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1624
                outStream
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1625
                    nextPut: color redByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1626
                    nextPut: color greenByte;
ebf1067a3289 unfinished writing
Claus Gittinger <cg@exept.de>
parents: 2702
diff changeset
  1627
                    nextPut: color blueByte
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1628
            ]
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1629
        ]
3900
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1630
!
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1631
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1632
writeTRNSChunk
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1633
    self 
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1634
        writeChunk: 'tRNS'
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1635
        size: 1
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1636
        with:[
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1637
            outStream nextPut: paletteIndexForMaskedPixels
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1638
        ]
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1639
a95276d36ce8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  1640
    "Created: / 16-02-2017 / 19:58:06 / cg"
2683
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1641
! !
8c7880d9cedb preps for writing
Claus Gittinger <cg@exept.de>
parents: 2509
diff changeset
  1642
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
  1643
!PNGReader class methodsFor:'documentation'!
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1644
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1645
version
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1646
    ^ '$Header$'
2909
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1647
!
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1648
3f9856162142 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 2725
diff changeset
  1649
version_CVS
3554
f1820748e4a9 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3461
diff changeset
  1650
    ^ '$Header$'
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1651
! !
1671
6fbb20a4af3a more but still unfinished
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
  1652
3100
0c82f117bb45 class: PNGReader
Claus Gittinger <cg@exept.de>
parents: 2910
diff changeset
  1653
308
ba8b8191d8b6 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1654
PNGReader initialize!