WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Mon, 28 Jul 1997 12:57:41 +0200
changeset 678 26ff1d0b739c
parent 647 6f26c76aa0c9
child 692 e6af4c70e066
permissions -rw-r--r--
*** empty log message ***
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:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
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:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 211
diff changeset
    45
        Image Form Icon
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    46
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    47
        ST80FormReader SunRasterReader TargaReader TIFFReader  
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    48
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    49
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    50
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    51
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    52
!WindowsIconReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    53
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    54
initialize
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    55
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
    56
     for the '.bmp' and '.ico' extensions."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    57
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    58
    MIMETypes defineImageType:'image/x-MS-bitmap' suffix:'bmp' reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    59
    MIMETypes defineImageType:nil                 suffix:'ico' reader:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    60
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
    61
    "Modified: 1.2.1997 / 15:03:59 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    62
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    63
102
claus
parents: 99
diff changeset
    64
!WindowsIconReader class methodsFor:'testing'!
claus
parents: 99
diff changeset
    65
claus
parents: 99
diff changeset
    66
isValidImageFile:aFileName
claus
parents: 99
diff changeset
    67
    "return true, if aFileName contains a valid windows bitmap-file image"
claus
parents: 99
diff changeset
    68
claus
parents: 99
diff changeset
    69
    |inStream header ok|
claus
parents: 99
diff changeset
    70
claus
parents: 99
diff changeset
    71
    inStream := self streamReadingFile:aFileName.
claus
parents: 99
diff changeset
    72
    inStream isNil ifTrue:[^ false].
claus
parents: 99
diff changeset
    73
claus
parents: 99
diff changeset
    74
    inStream binary.
104
claus
parents: 103
diff changeset
    75
    ok := false.
claus
parents: 103
diff changeset
    76
    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
    77
        header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    78
        inStream nextBytes:4 into:header.
102
claus
parents: 99
diff changeset
    79
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    80
        (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
    81
            ok := true.
104
claus
parents: 103
diff changeset
    82
"/            '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
    83
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    84
        (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
    85
            ok := true.
104
claus
parents: 103
diff changeset
    86
"/            '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
    87
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    88
        (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
    89
            ok := true.
104
claus
parents: 103
diff changeset
    90
"/            '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
    91
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    92
        (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
    93
            ok := true.
104
claus
parents: 103
diff changeset
    94
"/            '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
    95
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    96
        (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
    97
            ok := true.
104
claus
parents: 103
diff changeset
    98
"/            '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
    99
        ].
102
claus
parents: 99
diff changeset
   100
    ].
104
claus
parents: 103
diff changeset
   101
    inStream close.
claus
parents: 103
diff changeset
   102
    ^ ok
102
claus
parents: 99
diff changeset
   103
claus
parents: 99
diff changeset
   104
    "
claus
parents: 99
diff changeset
   105
     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
claus
parents: 99
diff changeset
   106
    "
claus
parents: 99
diff changeset
   107
claus
parents: 99
diff changeset
   108
    "Created: 17.9.1995 / 17:14:20 / claus"
claus
parents: 99
diff changeset
   109
! !
claus
parents: 99
diff changeset
   110
103
claus
parents: 102
diff changeset
   111
!WindowsIconReader methodsFor:'private'!
claus
parents: 102
diff changeset
   112
claus
parents: 102
diff changeset
   113
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
   114
    "helper: load a BMP image"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   115
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   116
    |buff idx1 idx2 bytesPerRow|
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   117
103
claus
parents: 102
diff changeset
   118
    d == 8 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   119
        (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   120
            'WinIconReader [warning]: read/decompression failed' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   121
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   122
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   123
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   124
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   125
    d == 4 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   126
        (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   127
            'WinIconReader [warning]: read/decompression failed' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   128
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   129
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   130
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   131
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   132
    d == 2 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   133
        (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   134
            'WinIconReader [warning]: read failed' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   135
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   136
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   137
        ^ true
103
claus
parents: 102
diff changeset
   138
    ].
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   139
    d == 1 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   140
        (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   141
            'WinIconReader [warning]: read failed' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   142
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   143
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   144
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   145
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   146
    d == 24 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   147
        bytesPerRow := w * 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   148
        ((aStream nextBytes:(h * bytesPerRow) into:data) ~~ (h * bytesPerRow)) ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   149
            'WinIconReader [warning]: read failed' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   150
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   151
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   152
        "/ stupid - last row comes first
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   153
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   154
        buff := ByteArray uninitializedNew:bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   155
        idx1 := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   156
        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
   157
        [idx1 < idx2] whileTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   158
            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
   159
            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
   160
            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
   161
            idx1 := idx1 + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   162
            idx2 := idx2 - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   163
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   164
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   165
    ].
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   166
    'WinIconReader [warning]: unsupported depth:' infoPrint. d infoPrintNL.
103
claus
parents: 102
diff changeset
   167
claus
parents: 102
diff changeset
   168
    "Created: 17.9.1995 / 18:48:11 / claus"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   169
    "Modified: 28.1.1997 / 01:46:07 / cg"
103
claus
parents: 102
diff changeset
   170
! !
claus
parents: 102
diff changeset
   171
53
4f5e734bc59f *** empty log message ***
claus
parents: 41
diff changeset
   172
!WindowsIconReader methodsFor:'reading from file'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   173
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   174
fromOS2File:aFilename
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   175
    "read an image from an OS/2 BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   176
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   177
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   178
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   179
    stream := self streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   180
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   181
    reader := (self new) fromOS2Stream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   182
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   183
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   184
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   185
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   186
    "Modified: 23.4.1996 / 13:09:28 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   187
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   188
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   189
fromOS2Stream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   190
    "read an image from an OS/2 BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   191
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   192
    | header inDepth
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   193
      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
   194
      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
   195
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   196
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   197
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   198
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   199
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   200
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   201
    header := ByteArray uninitializedNew:8r110.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   202
    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
   203
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   204
    (header startsWith:#(73 67)) ifTrue:[         "IC"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   205
        "IC format"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   206
        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
   207
        width := header at:7.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   208
        height := header at:9.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   209
        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
   210
    ] ifFalse:[
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   211
        (header startsWith:#(67 73)) ifTrue:[     "CI"
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   212
            self error:'unsupported format: CI'.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   213
            ^ nil.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   214
        ] ifFalse:[
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   215
            aStream nextBytes:(8r110-16) into:header startingAt:17.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   216
            width := header at:8r101.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   217
            height := header at:8r103.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   218
            inDepth := header at:8r107.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   219
        ]
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   220
    ].
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
    "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   223
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   224
    nColors := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   225
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   226
    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
   227
    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
   228
    rMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   229
    gMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   230
    bMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   231
    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   232
    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
   233
        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
   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
        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
   236
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   237
        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
   238
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   239
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   240
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   241
    "read 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
    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
   244
    mask := ByteArray uninitializedNew:nByte.
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
    "what is this"
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
    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
   250
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   251
"/    "read the data bits"
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
"/    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
   254
"/    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
   255
"/    inDepth == 8 ifTrue:[
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
"/    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
   258
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   259
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   260
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   261
"/    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
   262
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   263
"/    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
   264
"/    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
   265
"/        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
   266
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   267
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   268
"/        dstIndex := dstIndex - bytesPerRow.
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
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   271
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   272
"/    "expand into bytes"
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
"/    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
   275
"/    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
   276
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   277
"/
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
    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
   280
    "/ 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
   281
    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
   282
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   283
    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
   284
    (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
   285
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   286
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   287
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   288
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   289
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   290
    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
   291
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   292
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   293
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   294
     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
   295
     f := i asFormOn:Display.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   296
     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
   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
    "Modified: 17.9.1995 / 18:49:24 / claus"
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   300
    "Modified: 24.2.1997 / 12:11:39 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   301
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   302
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   303
fromStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   304
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   305
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   306
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   307
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   308
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   309
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   310
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   311
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   312
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   313
    fileSize := aStream size.
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
    fileSize < 16 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   316
        'WinIconReader [warning]: short file' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   317
        ^ nil
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
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   320
    header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   321
    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
   322
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   323
    (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
   324
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   325
"/        'WinIconReader [info]: 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
   326
        ^ self fromWindowsBMPStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   327
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   328
    (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
   329
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   330
"/        'WinIconReader [info]: 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
   331
        ^ self fromOS2Stream:aStream
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   332
    ].                    
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   333
    (header startsWith:#(67 73)) ifTrue:[     "CI"
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   334
        'WinIconReader [warning]: OS/2 CI format not supported:' infoPrintNL.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   335
        ^ nil.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   336
        aStream position:1.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   337
"/        'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   338
        ^ self fromOS2Stream:aStream
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   339
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   340
    (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
   341
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   342
"/        'WinIconReader [info]: 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
   343
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   344
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   345
    (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
   346
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   347
"/        'WinIconReader [info]: 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
   348
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   349
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   350
    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   351
        'WinIconReader [warning]: OS/2 SZ format not supported:' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   352
        ^ nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   353
        aStream position:1.
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   354
        'WinIconReader [info]: OS/2 SZ format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   355
        ^ self fromOS2Stream:aStream
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
    (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
   358
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   359
"/        'WinIconReader [info]: 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
   360
        ^ self fromWindowsICOStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   361
    ].
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   362
    'WinIconReader [warning]: format not supported:' infoPrint.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   363
    ((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
   364
    ' ' infoPrint.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   365
    ((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
   366
    ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   367
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   368
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   369
     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
   370
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   371
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   372
    "Modified: 17.9.1995 / 18:59:07 / claus"
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   373
    "Modified: 24.2.1997 / 12:12:41 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   374
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   375
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   376
fromWindowsBMPFile: aFilename 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   377
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   378
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   379
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   380
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   381
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   382
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   383
    reader := (self new) fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   384
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   385
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   386
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   387
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   388
    "Modified: 23.4.1996 / 13:09:53 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   389
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   390
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   391
fromWindowsBMPStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   392
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   393
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   394
    | fileSize header iSize inDepth inPlanes compression
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   395
      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
   396
      dataStart
678
26ff1d0b739c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   397
      rawMap rMap gMap bMap srcIndex
26ff1d0b739c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   398
      bytesPerRow fourBytesPerColorInfo|
172
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
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   401
    aStream binary.
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
    fileSize := aStream size.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   404
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   405
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   406
    header := ByteArray uninitializedNew:16r54.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   407
    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
   408
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   409
    iSize := header at:(16r0E + 1).
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   410
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   411
    (iSize == 40) ifTrue:[    "header-size"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   412
        "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   413
         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
   414
         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
   415
        "
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   416
"/        'WinIconReader [info]: Win3.x or OS/2 vsn 2 format' infoPrintNL.
172
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
        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
   419
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   420
        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
   421
        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
   422
        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
   423
        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
   424
        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
   425
        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
   426
        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
   427
        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
   428
        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
   429
        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
   430
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   431
        numColor == 0 ifTrue:[
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
             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
   434
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   435
            inDepth <= 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   436
                numColor := 1 bitShift:inDepth.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   437
                'WinIconReader [warning]: missing nColor in header - assume ' infoPrint. numColor infoPrintNL
172
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
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   440
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   441
        numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   442
            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
   443
            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
   444
            fourBytesPerColorInfo := true.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   445
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   446
        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
   447
    ] ifFalse:[
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   448
        (iSize == 12) ifTrue:[     "core-info header size"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   449
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   450
             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
   451
            "
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   452
"/           'WinIconReader [info]: OS/2 vsn 1.2 format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   453
            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
   454
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   455
            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
   456
            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
   457
            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
   458
            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
   459
            numColor := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   460
            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
   461
            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
   462
            fourBytesPerColorInfo := false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   463
            compression := 0.
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   464
            "/ dataStart := header wordAt:(16r0A + 1) MSB:false.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   465
            dataStart := nil.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   466
        ] ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   467
            'WinIconReader [warning]: unknown format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   468
            ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   469
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   470
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   471
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   472
    numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   473
        "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   474
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   475
        rMap := ByteArray new:numColor.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   476
        gMap := ByteArray new:numColor.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   477
        bMap := ByteArray new:numColor.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   478
        srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   479
        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
   480
            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
   481
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   482
            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
   483
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   484
            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
   485
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   486
            fourBytesPerColorInfo ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   487
                srcIndex := srcIndex + 1.
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
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   490
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   491
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   492
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   493
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   494
    compression ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   495
        "/ some compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   496
        compression == 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   497
            "/ 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
   498
            inDepth ~~ 8 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   499
                'WinIconReader [warning]: RLE8 compression only allowed with depth8 images' infoPrintNL.
172
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
        compression == 2 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   504
            "/ 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
   505
            inDepth ~~ 4 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   506
                'WinIconReader [warning]: RLE4 compression only allowed with depth4 images' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   507
                ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   508
            ].
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
    ].
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
    inPlanes ~~ 1 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   513
        'WinIconReader [warning]: only 1 plane images supported' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   514
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   515
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   516
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   517
    dataStart notNil ifTrue:[
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   518
        aStream position:(dataStart + 1).
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   519
    ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   520
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   521
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   522
        bytesPerRow := width * 3
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   523
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   524
        bytesPerRow := width
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   525
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   526
    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
   527
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   528
    "/ read & possibly decompress
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
    (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
   531
        ^ nil
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
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   534
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   535
        photometric := #rgb.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   536
        samplesPerPixel := 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   537
        bitsPerSample := #(8 8 8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   538
        ^ self
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   539
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   540
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   541
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   542
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   543
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   544
    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
   545
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   546
    "Modified: 17.9.1995 / 18:48:46 / claus"
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   547
    "Modified: 24.4.1997 / 22:09:23 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   548
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   549
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   550
fromWindowsICOFile:aFilename 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   551
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   552
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   553
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   554
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   555
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   556
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   557
    reader := (self new) fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   558
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   559
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   560
    ^ nil
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   561
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   562
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   563
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   564
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   565
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   566
    "Modified: 23.4.1996 / 13:10:11 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   567
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   568
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   569
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   570
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   571
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   572
    | header inDepth
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   573
      rawMap rMap gMap bMap srcIndex dstIndex
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   574
      data4 mask tmp bytesPerRow nColor|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   575
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   576
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   577
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   578
3f9277473954 Initial revision
claus
parents:
diff changeset
   579
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
   580
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   581
    header := ByteArray uninitializedNew:(6 + 16 + 40).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   582
    aStream nextBytes:(6 + 16 + 40) into:header.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   583
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   584
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   585
    nColor := header at:(8+1).
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   586
    "/ reserved := header at:(9+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   587
    "/ nPlanes := header wordAt:(10+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   588
    "/ nBitsPerPel := header wordAt:(12+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   589
    "/ nBytesInResource := header doubleWordAt:(14+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   590
    "/ ordinal := header wordAt:(18+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   591
    "21, 22               ?"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   592
    "23, ... , 62         ?"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   593
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   594
    inDepth := header at:16r25.
3f9277473954 Initial revision
claus
parents:
diff changeset
   595
3f9277473954 Initial revision
claus
parents:
diff changeset
   596
    "read the colormap"
3f9277473954 Initial revision
claus
parents:
diff changeset
   597
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   598
    rawMap := ByteArray uninitializedNew:(16*4).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   599
    aStream nextBytes:(16*4) into:rawMap.
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   600
    rMap := ByteArray new:16.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   601
    gMap := ByteArray new:16.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   602
    bMap := ByteArray new:16.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   603
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   604
    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
   605
        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
   606
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   607
        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
   608
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   609
        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
   610
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   611
        srcIndex := srcIndex + 1.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   612
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   613
3f9277473954 Initial revision
claus
parents:
diff changeset
   614
    "read the data bits"
3f9277473954 Initial revision
claus
parents:
diff changeset
   615
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   616
    inDepth == 0 ifTrue:[
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   617
        inDepth := 4.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   618
    ].
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   619
    bytesPerRow := width * inDepth + 7 // 8.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   620
    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   621
    aStream nextBytes:(height * bytesPerRow) into:data4.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   622
3f9277473954 Initial revision
claus
parents:
diff changeset
   623
    "read mask"
3f9277473954 Initial revision
claus
parents:
diff changeset
   624
3f9277473954 Initial revision
claus
parents:
diff changeset
   625
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   626
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   627
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   628
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   629
3f9277473954 Initial revision
claus
parents:
diff changeset
   630
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
   631
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   632
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   633
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   634
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   635
    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
   636
        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
   637
                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   638
        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   639
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   640
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   641
    data4 := tmp.
3f9277473954 Initial revision
claus
parents:
diff changeset
   642
3f9277473954 Initial revision
claus
parents:
diff changeset
   643
3f9277473954 Initial revision
claus
parents:
diff changeset
   644
    photometric := #palette.
3f9277473954 Initial revision
claus
parents:
diff changeset
   645
    samplesPerPixel := 1.
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   646
36
3a7ec58dff8e *** empty log message ***
claus
parents: 32
diff changeset
   647
    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   648
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   649
    false ifTrue:[
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   650
    "expand into bytes"
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   651
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   652
        data := ByteArray new:(width * height).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   653
        data4 expandPixels:inDepth width:width height:height
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   654
                      into:data mapping:nil.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   655
        bitsPerSample := #(8).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   656
    ] ifFalse:[
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   657
        data := data4.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   658
        bitsPerSample := #(4).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   659
    ].
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   660
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   661
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   662
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   663
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   664
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   665
    "Modified: 24.4.1997 / 22:03:48 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   666
! !
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   667
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   668
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   669
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   670
version
678
26ff1d0b739c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   671
    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.35 1997-07-28 10:57:41 cg Exp $'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   672
! !
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   673
WindowsIconReader initialize!