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