WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Mon, 17 Feb 1997 11:10:50 +0100
changeset 430 50b841f4851d
parent 398 aef700d15416
child 445 899af8ff2a5d
permissions -rw-r--r--
commentary
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
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
    58
    Image addReader:self suffix:'bmp'.
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
    59
    Image addReader:self suffix:'ico'.
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
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   204
    (header startsWith:#(73 67)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   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:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   211
        aStream nextBytes:(8r110-16) into:header startingAt:17.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   212
        width := header at:8r101.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   213
        height := header at:8r103.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   214
        inDepth := header at:8r107.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   215
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   216
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   217
    "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   218
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   219
    nColors := 1 bitShift:inDepth.
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
    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
   222
    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
   223
    rMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   224
    gMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   225
    bMap := Array new:nColors.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   226
    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   227
    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
   228
        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
   229
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   230
        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
   231
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   232
        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
   233
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   234
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   235
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   236
    "read mask"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   237
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   238
    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
   239
    mask := ByteArray uninitializedNew:nByte.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   240
    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
   241
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   242
    "what is this"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   243
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   244
    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
   245
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   246
"/    "read the data bits"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   247
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   248
"/    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
   249
"/    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
   250
"/    inDepth == 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   251
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   252
"/    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
   253
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   254
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   255
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   256
"/    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
   257
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   258
"/    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
   259
"/    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
   260
"/        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
   261
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   262
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   263
"/        dstIndex := dstIndex - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   264
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   265
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   266
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   267
"/    "expand into bytes"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   268
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   269
"/    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
   270
"/    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
   271
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   272
"/
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
    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
   275
    "/ 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
   276
    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
   277
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   278
    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
   279
    (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
   280
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   281
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   282
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   283
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   284
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   285
    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
   286
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   287
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   288
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   289
     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
   290
     f := i asFormOn:Display.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   291
     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
   292
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   293
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   294
    "Modified: 17.9.1995 / 18:49:24 / claus"
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   295
    "Modified: 23.4.1996 / 13:09:40 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   296
!
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
fromStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   299
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   300
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   301
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   302
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   303
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   304
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   305
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   306
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   307
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   308
    fileSize := aStream size.
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
    fileSize < 16 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   311
        '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
   312
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   313
    ].
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
    header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   316
    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
   317
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   318
    (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
   319
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   320
"/        '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
   321
        ^ self fromWindowsBMPStream:aStream
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 65)) ifTrue:[     "BA"
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]: 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
   326
        ^ self fromOS2Stream: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:#(73 67)) ifTrue:[     "IC"
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 IC 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
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   332
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   333
    (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
   334
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   335
"/        '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
   336
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   337
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   338
    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   339
        'WinIconReader [warning]: 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
   340
        ^ nil.
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 PT 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:#(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
   346
        aStream position:1.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   347
"/        '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
   348
        ^ self fromWindowsICOStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   349
    ].
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   350
    '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
   351
    ((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
   352
    ' ' infoPrint.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   353
    ((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
   354
    ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   355
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
     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
   358
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   359
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   360
    "Modified: 17.9.1995 / 18:59:07 / claus"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   361
    "Modified: 28.1.1997 / 01:48:31 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   362
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   363
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   364
fromWindowsBMPFile: aFilename 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   365
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   366
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   367
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   368
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   369
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   370
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   371
    reader := (self new) fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   372
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   373
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   374
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   375
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   376
    "Modified: 23.4.1996 / 13:09:53 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   377
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   378
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   379
fromWindowsBMPStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   380
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   381
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   382
    | fileSize header inDepth inPlanes compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   383
      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
   384
      dataStart
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   385
      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
   386
      data4 mask tmp bytesPerRow fourBytesPerColorInfo|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   387
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   388
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   389
    aStream binary.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   390
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   391
    fileSize := aStream size.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   392
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   393
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   394
    header := ByteArray uninitializedNew:16r54.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   395
    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
   396
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   397
    ((header at:(16r0E + 1)) == 40) ifTrue:[    "header-size"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   398
        "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   399
         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
   400
         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
   401
        "
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   402
"/        '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
   403
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   404
        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
   405
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   406
        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
   407
        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
   408
        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
   409
        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
   410
        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
   411
        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
   412
        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
   413
        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
   414
        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
   415
        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
   416
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   417
        numColor == 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   418
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   419
             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
   420
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   421
            inDepth <= 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   422
                numColor := 1 bitShift:inDepth.
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   423
                '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
   424
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   425
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   426
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   427
        numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   428
            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
   429
            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
   430
            fourBytesPerColorInfo := true.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   431
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   432
        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
   433
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   434
        ((header at:(16r0E + 1)) == 12) ifTrue:[     "core-info header size"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   435
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   436
             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
   437
            "
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   438
"/           '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
   439
            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
   440
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   441
            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
   442
            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
   443
            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
   444
            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
   445
            numColor := 1 bitShift:inDepth.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   446
            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
   447
            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
   448
            fourBytesPerColorInfo := false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   449
            compression := 0.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   450
            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
   451
        ] ifFalse:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   452
            '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
   453
            ^ nil
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
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   456
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   457
    numColor ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   458
        "read the colormap"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   459
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   460
        rMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   461
        gMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   462
        bMap := Array new:numColor.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   463
        srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   464
        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
   465
            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
   466
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   467
            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
   468
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   469
            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
   470
            srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   471
            fourBytesPerColorInfo ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   472
                srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   473
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   474
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   475
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   476
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   477
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   478
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   479
    compression ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   480
        "/ some compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   481
        compression == 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   482
            "/ 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
   483
            inDepth ~~ 8 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   484
                '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
   485
                ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   486
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   487
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   488
        compression == 2 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   489
            "/ 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
   490
            inDepth ~~ 4 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   491
                '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
   492
                ^ nil
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
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   495
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   496
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   497
    inPlanes ~~ 1 ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   498
        '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
   499
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   500
    ].
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
    aStream position:(dataStart + 1).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   503
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   504
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   505
        bytesPerRow := width * 3
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   506
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   507
        bytesPerRow := width
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
    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
   510
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   511
    "/ read & possibly decompress
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   512
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   513
    (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
   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
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   517
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   518
        photometric := #rgb.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   519
        samplesPerPixel := 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   520
        bitsPerSample := #(8 8 8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   521
        ^ self
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   522
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   523
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   524
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   525
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   526
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   527
    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
   528
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   529
    "Modified: 17.9.1995 / 18:48:46 / claus"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   530
    "Modified: 28.1.1997 / 01:47:18 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   531
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   532
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   533
fromWindowsICOFile:aFilename 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   534
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   535
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   536
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   537
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   538
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   539
    stream isNil ifTrue:[^ nil].
83
claus
parents: 53
diff changeset
   540
    reader := (self new) fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   541
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   542
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   543
    ^ nil
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   544
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   545
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   546
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   547
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   548
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   549
    "Modified: 23.4.1996 / 13:10:11 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   550
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   551
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   552
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   553
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   554
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   555
    | header inDepth
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   556
      rawMap rMap gMap bMap srcIndex dstIndex
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   557
      data4 mask tmp bytesPerRow nColor|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   558
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   559
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   560
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   561
3f9277473954 Initial revision
claus
parents:
diff changeset
   562
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
   563
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   564
    header := ByteArray uninitializedNew:(6 + 16 + 40).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   565
    aStream nextBytes:(6 + 16 + 40) into:header.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   566
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   567
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   568
    nColor := header at:(8+1).
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   569
    "/ reserved := header at:(9+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   570
    "/ nPlanes := header wordAt:(10+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   571
    "/ nBitsPerPel := header wordAt:(12+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   572
    "/ nBytesInResource := header doubleWordAt:(14+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   573
    "/ ordinal := header wordAt:(18+1).
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   574
    "21, 22               ?"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   575
    "23, ... , 62         ?"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   576
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   577
    inDepth := header at:16r25.
3f9277473954 Initial revision
claus
parents:
diff changeset
   578
3f9277473954 Initial revision
claus
parents:
diff changeset
   579
    "read the colormap"
3f9277473954 Initial revision
claus
parents:
diff changeset
   580
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   581
    rawMap := ByteArray uninitializedNew:(16*4).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   582
    aStream nextBytes:(16*4) into:rawMap.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   583
    rMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   584
    gMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   585
    bMap := Array new:16.
3f9277473954 Initial revision
claus
parents:
diff changeset
   586
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   587
    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
   588
        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
   589
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   590
        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
   591
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   592
        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
   593
        srcIndex := srcIndex + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   594
        srcIndex := srcIndex + 1.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   595
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   596
3f9277473954 Initial revision
claus
parents:
diff changeset
   597
    "read the data bits"
3f9277473954 Initial revision
claus
parents:
diff changeset
   598
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   599
    bytesPerRow := width * inDepth + 7 // 8.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   600
    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   601
    aStream nextBytes:(height * bytesPerRow) into:data4.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   602
3f9277473954 Initial revision
claus
parents:
diff changeset
   603
    "read mask"
3f9277473954 Initial revision
claus
parents:
diff changeset
   604
3f9277473954 Initial revision
claus
parents:
diff changeset
   605
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   606
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   607
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   608
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   609
3f9277473954 Initial revision
claus
parents:
diff changeset
   610
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
   611
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   612
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   613
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   614
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   615
    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
   616
        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
   617
                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   618
        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   619
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   620
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   621
    data4 := tmp.
3f9277473954 Initial revision
claus
parents:
diff changeset
   622
3f9277473954 Initial revision
claus
parents:
diff changeset
   623
3f9277473954 Initial revision
claus
parents:
diff changeset
   624
    photometric := #palette.
3f9277473954 Initial revision
claus
parents:
diff changeset
   625
    samplesPerPixel := 1.
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   626
36
3a7ec58dff8e *** empty log message ***
claus
parents: 32
diff changeset
   627
    colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   628
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   629
    false ifTrue:[
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   630
    "expand into bytes"
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   631
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   632
        data := ByteArray new:(width * height).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   633
        data4 expandPixels:inDepth width:width height:height
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   634
                      into:data mapping:nil.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   635
        bitsPerSample := #(8).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   636
    ] ifFalse:[
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   637
        data := data4.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   638
        bitsPerSample := #(4).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   639
    ].
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   640
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   641
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   642
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   643
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   644
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   645
    "Modified: 15.2.1997 / 13:52:52 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   646
! !
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   647
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   648
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   649
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   650
version
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   651
    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.29 1997-02-17 10:10:50 cg Exp $'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   652
! !
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   653
WindowsIconReader initialize!