WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 13:12:01 +0200
changeset 211 3eb140e89e2e
parent 172 ee7d84977c86
child 234 b6352d13e792
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     1
"
3f9277473954 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
     3
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     4
3f9277473954 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3f9277473954 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3f9277473954 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3f9277473954 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3f9277473954 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3f9277473954 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
3f9277473954 Initial revision
claus
parents:
diff changeset
    11
"
3f9277473954 Initial revision
claus
parents:
diff changeset
    12
3f9277473954 Initial revision
claus
parents:
diff changeset
    13
ImageReader subclass:#WindowsIconReader
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    14
	instanceVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    15
	classVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    16
	poolDictionaries:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    17
	category:'Graphics-Images support'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    18
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    19
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    20
!WindowsIconReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    22
copyright
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    23
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    25
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    26
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    27
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    28
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    30
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    31
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    32
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    33
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    34
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    35
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    36
documentation
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    37
"
32
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    38
    this class provides methods for loading Windows and OS2 icon files.
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    39
    Image writing is not supported.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    40
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    41
    The reader tries to figure out which version of BMP/ICO is used.
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    42
    It seems to be able to load most formats, but who knows ...
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    43
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    44
    [See also:]
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    45
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    46
        ST80FormReader SunRasterReader TargaReader TIFFReader  
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    47
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    48
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    49
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    50
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    51
!WindowsIconReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    52
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    53
initialize
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    54
    "tell Image-class, that a new fileReader is present
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    55
     for the '.bmp', '.BMP', '.ico' and '.ICO' extensions."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    56
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    57
    Image fileFormats at:'.bmp'  put:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    58
    Image fileFormats at:'.BMP'  put:self.
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    59
    Image fileFormats at:'.ico'  put:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    60
    Image fileFormats at:'.ICO'  put:self.
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    61
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    62
    "Modified: 23.4.1996 / 13:08:46 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    63
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    64
102
claus
parents: 99
diff changeset
    65
!WindowsIconReader class methodsFor:'testing'!
claus
parents: 99
diff changeset
    66
claus
parents: 99
diff changeset
    67
isValidImageFile:aFileName
claus
parents: 99
diff changeset
    68
    "return true, if aFileName contains a valid windows bitmap-file image"
claus
parents: 99
diff changeset
    69
claus
parents: 99
diff changeset
    70
    |inStream header ok|
claus
parents: 99
diff changeset
    71
claus
parents: 99
diff changeset
    72
    inStream := self streamReadingFile:aFileName.
claus
parents: 99
diff changeset
    73
    inStream isNil ifTrue:[^ false].
claus
parents: 99
diff changeset
    74
claus
parents: 99
diff changeset
    75
    inStream binary.
104
claus
parents: 103
diff changeset
    76
    ok := false.
claus
parents: 103
diff changeset
    77
    inStream size > 16 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    78
        header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    79
        inStream nextBytes:4 into:header.
102
claus
parents: 99
diff changeset
    80
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    81
        (header startsWith:#(66 77)) ifTrue:[     "BM"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    82
            ok := true.
104
claus
parents: 103
diff changeset
    83
"/            'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    84
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    85
        (header startsWith:#(66 65)) ifTrue:[     "BA"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    86
            ok := true.
104
claus
parents: 103
diff changeset
    87
"/            'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    88
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    89
        (header startsWith:#(73 67)) ifTrue:[     "IC"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    90
            ok := true.
104
claus
parents: 103
diff changeset
    91
"/            'WINREADER: OS/2 IC format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    92
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    93
        (header startsWith:#(80 84)) ifTrue:[     "PT"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    94
            ok := true.
104
claus
parents: 103
diff changeset
    95
"/            'WINREADER: OS/2 PT format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    96
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    97
        (header startsWith:#(0 0 1 0)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    98
            ok := true.
104
claus
parents: 103
diff changeset
    99
"/            'WINREADER: Win3.x ICO format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   100
        ].
102
claus
parents: 99
diff changeset
   101
    ].
104
claus
parents: 103
diff changeset
   102
    inStream close.
claus
parents: 103
diff changeset
   103
    ^ ok
102
claus
parents: 99
diff changeset
   104
claus
parents: 99
diff changeset
   105
    "
claus
parents: 99
diff changeset
   106
     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
claus
parents: 99
diff changeset
   107
    "
claus
parents: 99
diff changeset
   108
claus
parents: 99
diff changeset
   109
    "Created: 17.9.1995 / 17:14:20 / claus"
claus
parents: 99
diff changeset
   110
! !
claus
parents: 99
diff changeset
   111
103
claus
parents: 102
diff changeset
   112
!WindowsIconReader methodsFor:'private'!
claus
parents: 102
diff changeset
   113
claus
parents: 102
diff changeset
   114
loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   115
    "helper: load a BMP image"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   116
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   117
    |buff idx1 idx2 bytesPerRow|
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   118
103
claus
parents: 102
diff changeset
   119
    d == 8 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   120
        (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   121
            'BMP: read/decompression failed' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   122
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   123
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   124
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   125
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   126
    d == 4 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   127
        (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   128
            'BMP: read/decompression failed' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   129
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   130
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   131
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   132
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   133
    d == 2 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   134
        (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   135
            'BMP: read failed' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   136
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   137
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   138
        ^ true
103
claus
parents: 102
diff changeset
   139
    ].
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   140
    d == 1 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   141
        (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   142
            'BMP: read failed' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   143
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   144
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   145
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   146
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   147
    d == 24 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   148
        bytesPerRow := w * 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   149
        ((aStream nextBytes:(h * bytesPerRow) into:data) ~~ (h * bytesPerRow)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   150
            'BMP: read failed' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   151
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   152
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   153
        "/ stupid - last row comes first
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   154
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   155
        buff := ByteArray uninitializedNew:bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   156
        idx1 := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   157
        idx2 := 1 + (h-1 * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   158
        [idx1 < idx2] whileTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   159
            buff replaceFrom:1 to:bytesPerRow with:data startingAt:idx1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   160
            data replaceFrom:idx1 to:(idx1 + bytesPerRow - 1) with:data startingAt:idx2.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   161
            data replaceFrom:idx2 to:(idx2 + bytesPerRow - 1) with:buff startingAt:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   162
            idx1 := idx1 + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   163
            idx2 := idx2 - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   164
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   165
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   166
    ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   167
    'BMP: unsupported depth:' infoPrint. d infoPrintNL.
103
claus
parents: 102
diff changeset
   168
claus
parents: 102
diff changeset
   169
    "Created: 17.9.1995 / 18:48:11 / claus"
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   170
    "Modified: 23.4.1996 / 13:09:09 / cg"
103
claus
parents: 102
diff changeset
   171
! !
claus
parents: 102
diff changeset
   172
53
4f5e734bc59f *** empty log message ***
claus
parents: 41
diff changeset
   173
!WindowsIconReader methodsFor:'reading from file'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   174
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   175
fromOS2File:aFilename
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   176
    "read an image from an OS/2 BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   177
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   178
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   179
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   180
    stream := self streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   181
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   182
    reader := (self new) fromOS2Stream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   183
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   184
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   185
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   186
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   187
    "Modified: 23.4.1996 / 13:09:28 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   188
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   189
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   190
fromOS2Stream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   191
    "read an image from an OS/2 BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   192
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   193
    | header inDepth
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   194
      rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   195
      data4 mask tmp bytesPerRow nColors nByte|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   196
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   197
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   198
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   199
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   200
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   201
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   202
    header := ByteArray uninitializedNew:8r110.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   203
    aStream nextBytes:16 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   204
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   205
    (header startsWith:#(73 67)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   206
        "IC format"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   207
        aStream nextBytes:10 into:header startingAt:17.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   208
        width := header at:7.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   209
        height := header at:9.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   210
        inDepth := 2 "header at:11". "where is it"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   211
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   212
        aStream nextBytes:(8r110-16) into:header startingAt:17.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   213
        width := header at:8r101.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   214
        height := header at:8r103.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   215
        inDepth := header at:8r107.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   216
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   217
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   218
    "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   219
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   220
    nColors := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   221
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   222
    rawMap := ByteArray uninitializedNew:(nColors*3).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   223
    aStream nextBytes:(nColors*3) into:rawMap.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   224
    rMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   225
    gMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   226
    bMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   227
    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   228
    1 to:nColors do:[:i |
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   229
        bMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   230
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   231
        gMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   232
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   233
        rMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   234
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   235
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   236
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   237
    "read mask"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   238
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   239
    nByte := width * height + 7 // 8.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   240
    mask := ByteArray uninitializedNew:nByte.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   241
    aStream nextBytes:nByte into:mask.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   242
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   243
    "what is this"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   244
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   245
    aStream nextBytes:nByte into:mask.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   246
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   247
"/    "read the data bits"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   248
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   249
"/    bytesPerRow := width * inDepth + 7 // 8.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   250
"/    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   251
"/    inDepth == 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   252
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   253
"/    aStream nextBytes:(height * bytesPerRow) into:data4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   254
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   255
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   256
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   257
"/    tmp := ByteArray new:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   258
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   259
"/    dstIndex := (height - 1) * bytesPerRow + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   260
"/    1 to:height do:[:row |
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   261
"/        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   262
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   263
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   264
"/        dstIndex := dstIndex - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   265
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   266
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   267
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   268
"/    "expand into bytes"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   269
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   270
"/    data := ByteArray new:(width * height).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   271
"/    data4 expandPixels:inDepth width:width height:height
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   272
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   273
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   274
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   275
    bytesPerRow := width * inDepth + 7 // 8.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   276
    "/ bmp data is always 32bit aligned; if required,
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   277
    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   278
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   279
    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   280
    (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   281
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   282
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   283
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   284
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   285
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   286
    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   287
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   288
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   289
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   290
     i := Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   291
     f := i asFormOn:Display.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   292
     v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   293
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   294
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   295
    "Modified: 17.9.1995 / 18:49:24 / claus"
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   296
    "Modified: 23.4.1996 / 13:09:40 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   297
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   298
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   299
fromStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   300
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   301
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   302
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   303
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   304
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   305
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   306
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   307
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   308
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   309
    fileSize := aStream size.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   310
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   311
    fileSize < 16 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   312
        'WINREADER: short file' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   313
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   314
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   315
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   316
    header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   317
    aStream nextBytes:4 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   318
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   319
    (header startsWith:#(66 77)) ifTrue:[     "BM"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   320
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   321
        'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   322
        ^ self fromWindowsBMPStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   323
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   324
    (header startsWith:#(66 65)) ifTrue:[     "BA"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   325
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   326
        'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   327
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   328
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   329
    (header startsWith:#(73 67)) ifTrue:[     "IC"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   330
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   331
        'WINREADER: OS/2 IC format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   332
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   333
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   334
    (header startsWith:#(80 84)) ifTrue:[     "PT"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   335
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   336
        'WINREADER: OS/2 PT format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   337
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   338
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   339
    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   340
        'WINREADER: SZ format not supported:' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   341
        ^ nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   342
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   343
        'WINREADER: OS/2 PT format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   344
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   345
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   346
    (header startsWith:#(0 0 1 0)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   347
        aStream position:1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   348
        'WINREADER: Win3.x ICO format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   349
        ^ self fromWindowsICOStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   350
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   351
    'WINREADER: format not supported:' infoPrint.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   352
    ((header at:1) printStringRadix:16) infoPrint.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   353
    ' ' infoPrint.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   354
    ((header at:2) printStringRadix:16) infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   355
    ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   356
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   357
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   358
     Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   359
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   360
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   361
    "Modified: 17.9.1995 / 18:59:07 / claus"
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   362
    "Modified: 23.4.1996 / 13:11:10 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   363
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   364
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   365
fromWindowsBMPFile: aFilename 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   366
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   367
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   368
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   369
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   370
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   371
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   372
    reader := (self new) fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   373
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   374
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   375
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   376
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   377
    "Modified: 23.4.1996 / 13:09:53 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   378
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   379
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   380
fromWindowsBMPStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   381
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   382
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   383
    | fileSize header inDepth inPlanes compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   384
      imgSize resH resV numColor numImportantColor
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   385
      dataStart
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   386
      rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   387
      data4 mask tmp bytesPerRow fourBytesPerColorInfo|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   388
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   389
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   390
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   391
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   392
    fileSize := aStream size.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   393
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   394
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   395
    header := ByteArray uninitializedNew:16r54.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   396
    aStream nextBytes:18 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   397
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   398
    ((header at:(16r0E + 1)) == 40) ifTrue:[    "header-size"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   399
        "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   400
         its an Windows3.x BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   401
         or OS/2 vsn 2 BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   402
        "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   403
        'BMP: Win3.x or OS/2 vsn 2 format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   404
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   405
        aStream nextBytes:(40-4) into:header startingAt:19.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   406
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   407
        width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   408
        height := header wordAt:(16r16 + 1) MSB:false. "(header at:23) + ((header at:24) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   409
        inPlanes := header wordAt:(16r1A + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   410
        inDepth := header wordAt:(16r1C + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   411
        compression := header wordAt:(16r1E + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   412
        imgSize := header doubleWordAt:(16r22 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   413
        resH := header doubleWordAt:(16r26 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   414
        resV := header doubleWordAt:(16r2A + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   415
        numColor := header doubleWordAt:(16r2E + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   416
        numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   417
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   418
        numColor == 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   419
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   420
             some bmp-writers seem to leave this as zero (which is wrong)
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   421
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   422
            inDepth <= 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   423
                numColor := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   424
                'BMP: missing nColor in header - assume ' infoPrint. numColor infoPrintNL
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   425
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   426
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   427
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   428
        numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   429
            rawMap := ByteArray uninitializedNew:(numColor * 4).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   430
            aStream nextBytes:(numColor * 4) into:rawMap.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   431
            fourBytesPerColorInfo := true.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   432
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   433
        dataStart := header wordAt:(16r0A + 1) MSB:false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   434
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   435
        ((header at:(16r0E + 1)) == 12) ifTrue:[     "core-info header size"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   436
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   437
             its an OS/2 (vsn1.2) BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   438
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   439
           'BMP: OS/2 vsn 1.2 format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   440
            aStream nextBytes:(12-4) into:header startingAt:19.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   441
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   442
            width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   443
            height := header wordAt:(16r14 + 1) MSB:false. "(header at:21) + ((header at:22) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   444
            inPlanes := header wordAt:(16r16 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   445
            inDepth := header wordAt:(16r18 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   446
            numColor := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   447
            rawMap := ByteArray uninitializedNew:(numColor * 3).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   448
            aStream nextBytes:(numColor * 3) into:rawMap.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   449
            fourBytesPerColorInfo := false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   450
            compression := 0.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   451
            dataStart := header wordAt:(16r0A + 1) MSB:false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   452
        ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   453
            'BMP: unknown format' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   454
            ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   455
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   456
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   457
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   458
    numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   459
        "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   460
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   461
        rMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   462
        gMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   463
        bMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   464
        srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   465
        1 to:numColor do:[:i |
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   466
            bMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   467
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   468
            gMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   469
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   470
            rMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   471
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   472
            fourBytesPerColorInfo ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   473
                srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   474
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   475
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   476
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   477
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   478
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   479
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   480
    compression ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   481
        "/ some compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   482
        compression == 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   483
            "/ RLE8 - must be depth-8
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   484
            inDepth ~~ 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   485
                'BMP: RLE8 compression only allowed with depth8 images' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   486
                ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   487
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   488
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   489
        compression == 2 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   490
            "/ RLE4 - must be depth-4
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   491
            inDepth ~~ 4 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   492
                'BMP: RLE4 compression only allowed with depth4 images' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   493
                ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   494
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   495
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   496
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   497
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   498
    inPlanes ~~ 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   499
        'BMP: only 1 plane images supported' infoPrintNL.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   500
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   501
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   502
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   503
    aStream position:(dataStart + 1).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   504
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   505
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   506
        bytesPerRow := width * 3
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   507
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   508
        bytesPerRow := width
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   509
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   510
    data := ByteArray uninitializedNew:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   511
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   512
    "/ read & possibly decompress
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   513
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   514
    (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   515
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   516
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   517
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   518
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   519
        photometric := #rgb.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   520
        samplesPerPixel := 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   521
        bitsPerSample := #(8 8 8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   522
        ^ self
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   523
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   524
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   525
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   526
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   527
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   528
    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   529
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   530
    "Modified: 17.9.1995 / 18:48:46 / claus"
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   531
    "Modified: 23.4.1996 / 13:10:00 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   532
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   533
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   534
fromWindowsICOFile:aFilename 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   535
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   536
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   537
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   538
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   539
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   540
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   541
    reader := (self new) fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   542
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   543
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   544
    ^ nil
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   545
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   546
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   547
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   548
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   549
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   550
    "Modified: 23.4.1996 / 13:10:11 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   551
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   552
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   553
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   554
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   555
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   556
    | header inDepth
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   557
      rawMap rMap gMap bMap srcIndex dstIndex
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   558
      data4 mask tmp bytesPerRow nColor|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   559
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   560
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   561
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   562
3f9277473954 Initial revision
claus
parents:
diff changeset
   563
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
   564
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   565
    header := ByteArray uninitializedNew:(6 + 16 + 40).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   566
    aStream nextBytes:(6 + 16 + 40) into:header.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   567
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   568
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   569
    nColor := header at:(8+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   570
    "10, 11, 12, 13, 14 ? (reserve)"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   571
    "15, 16, 17, 18       pixel array size"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   572
    "19, 20, 21, 22       offset        "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   573
    "23, ... , 62         ?"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   574
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   575
    inDepth := header at:16r25.
3f9277473954 Initial revision
claus
parents:
diff changeset
   576
3f9277473954 Initial revision
claus
parents:
diff changeset
   577
    "read the colormap"
3f9277473954 Initial revision
claus
parents:
diff changeset
   578
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   579
    rawMap := ByteArray uninitializedNew:(16*4).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   580
    aStream nextBytes:(16*4) into:rawMap.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   581
    rMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   582
    gMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   583
    bMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   584
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   585
    1 to:16 do:[:i |
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   586
        bMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   587
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   588
        gMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   589
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   590
        rMap at:i put:(rawMap at:srcIndex).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   591
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   592
        srcIndex := srcIndex + 1.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   593
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   594
3f9277473954 Initial revision
claus
parents:
diff changeset
   595
    "read the data bits"
3f9277473954 Initial revision
claus
parents:
diff changeset
   596
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   597
    bytesPerRow := width * inDepth + 7 // 8.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   598
    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   599
    aStream nextBytes:(height * bytesPerRow) into:data4.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   600
3f9277473954 Initial revision
claus
parents:
diff changeset
   601
    "read mask"
3f9277473954 Initial revision
claus
parents:
diff changeset
   602
3f9277473954 Initial revision
claus
parents:
diff changeset
   603
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   604
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   605
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   606
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   607
3f9277473954 Initial revision
claus
parents:
diff changeset
   608
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
   609
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   610
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   611
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   612
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   613
    1 to:height do:[:row |
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   614
        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   615
                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   616
        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   617
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   618
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   619
    data4 := tmp.
3f9277473954 Initial revision
claus
parents:
diff changeset
   620
3f9277473954 Initial revision
claus
parents:
diff changeset
   621
    "expand into bytes"
3f9277473954 Initial revision
claus
parents:
diff changeset
   622
3f9277473954 Initial revision
claus
parents:
diff changeset
   623
    data := ByteArray new:(width * height).
3f9277473954 Initial revision
claus
parents:
diff changeset
   624
    data4 expandPixels:inDepth width:width height:height
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   625
                  into:data mapping:nil.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   626
3f9277473954 Initial revision
claus
parents:
diff changeset
   627
    photometric := #palette.
3f9277473954 Initial revision
claus
parents:
diff changeset
   628
    samplesPerPixel := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   629
    bitsPerSample := #(8).
36
3a7ec58dff8e *** empty log message ***
claus
parents: 32
diff changeset
   630
    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   631
3f9277473954 Initial revision
claus
parents:
diff changeset
   632
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   633
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   634
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   635
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   636
    "Modified: 23.4.1996 / 13:10:18 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   637
! !
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   638
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   639
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   640
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   641
version
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   642
    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.23 1996-04-23 11:12:01 cg Exp $'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   643
! !
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   644
WindowsIconReader initialize!