XBMReader.st
author Claus Gittinger <cg@exept.de>
Fri, 07 Jan 2005 15:35:42 +0100
changeset 2030 cfe668c44a8c
parent 1844 85c539787d5b
child 2051 502fbd99483d
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     1
"
6
4ac87e6bf82f *** empty log message ***
claus
parents: 5
diff changeset
     2
 COPYRIGHT (c) 1992 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
1495
100e4e782f71 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
    13
"{ Package: 'stx:libview2' }"
100e4e782f71 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
    14
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    15
ImageReader subclass:#XBMReader
195
7975a2c4a890 commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    16
	instanceVariableNames:''
7975a2c4a890 commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    17
	classVariableNames:''
7975a2c4a890 commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    18
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1710
diff changeset
    19
	category:'Graphics-Images-Readers'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    20
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    21
21
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    22
!XBMReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    23
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    24
copyright
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    25
"
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    26
 COPYRIGHT (c) 1992 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    27
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    28
21
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    29
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    30
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    32
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    33
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    34
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    35
"
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    36
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    37
21
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    38
documentation
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    39
"
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    40
    this class provides methods for loading and saving x-bitmap-file images.
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    41
    These images can (for example) be created using the bitmap editor supplied
24
6bc436eb4c4a *** empty log message ***
claus
parents: 21
diff changeset
    42
    with X. 
6bc436eb4c4a *** empty log message ***
claus
parents: 21
diff changeset
    43
    Only monochrome images can be represented in this format.
203
a38debd57097 commentary
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
    44
    Both reading and writing of images is supported.
195
7975a2c4a890 commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    45
7975a2c4a890 commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    46
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
    47
        Image Form Icon
197
50812e81d86f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 195
diff changeset
    48
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    49
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
197
50812e81d86f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 195
diff changeset
    50
        XPMReader XWDReader 
220
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    51
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    52
    [author:]
4106d9ce7e02 documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    53
        Claus Gittinger
21
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    54
"
1812
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    55
!
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    56
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    57
examples
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    58
"
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    59
  Reading from a file:
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    60
                                                                        [exBegin]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    61
    |image|
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    62
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    63
    image := Image fromFile:('../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm').
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    64
    image inspect
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    65
                                                                        [exEnd]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    66
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    67
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    68
  Saving to a file:
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    69
                                                                        [exBegin]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    70
    |image|
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    71
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    72
    image := Image fromScreen:(0@0 corner:30@30).
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    73
    image := image asThresholdMonochromeImage.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    74
    XBMReader save:image onFile:'/tmp/test.xbm'.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    75
    '/tmp/test.xbm' asFilename contents asString inspect.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    76
    (Image fromFile:('/tmp/test.xbm')) inspect.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    77
                                                                        [exEnd]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    78
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    79
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    80
  Or directly into a stream:
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    81
                                                                        [exBegin]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    82
    |image stream|
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    83
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    84
    image := Image fromScreen:(0@0 corner:30@30).
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    85
    image := image asThresholdMonochromeImage.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    86
    stream := WriteStream on:(String new).
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    87
    XPMReader save:image onStream:stream.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    88
    stream contents inspect.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    89
                                                                        [exEnd]
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
    90
"
21
66b31c91177f *** empty log message ***
claus
parents: 12
diff changeset
    91
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    92
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    93
!XBMReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    94
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    95
initialize
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    96
    "tell Image-class, that a new fileReader is present
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    97
     for the '.xbm' extension."
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    98
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    99
    MIMETypes defineImageType:'image/x-xbitmap' suffix:'xbm' reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   100
    MIMETypes defineImageType:nil               suffix:'bm'  reader:self.
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   101
399
f87821ab7b30 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   102
    "Modified: 1.2.1997 / 15:08:18 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   103
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   104
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   105
!XBMReader class methodsFor:'testing'!
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   106
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   107
canRepresent:anImage
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   108
    "return true, if anImage can be represented in my file format"
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   109
1046
8670e67344de fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   110
    |photometric clr0 clr1|
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   111
1521
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   112
    (anImage depth == 1) ifTrue:[
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   113
        photometric := anImage photometric.
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   114
        ((photometric == #blackIs0) or:[photometric == #whiteIs0]) ifTrue:[^ true].
1495
100e4e782f71 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1144
diff changeset
   115
1521
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   116
        photometric == #palette ifTrue:[
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   117
            clr0 := anImage colorFromValue:0.
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   118
            clr1 := anImage colorFromValue:1.
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   119
            (clr0 = Color white and:[clr1 = Color black]) ifTrue:[^true].
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   120
            (clr1 = Color white and:[clr0 = Color black]) ifTrue:[^true].
3c54279a418c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   121
        ].
1046
8670e67344de fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   122
    ].
2030
cfe668c44a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
   123
    ('XBMReader [info]: image is not a b&w (depth 1) image.') infoPrintCR.
1046
8670e67344de fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   124
    ^ false
8670e67344de fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   125
8670e67344de fixed canRepresent for palette images.
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   126
    "Modified: / 17.8.1998 / 10:17:01 / cg"
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   127
!
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   128
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   129
isValidImageFile:aFileName
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   130
    "return true, if aFileName contains an x-bitmap-file image"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   131
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   132
    |line inStream index1 index2 keyword|
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   133
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   134
    inStream := self streamReadingFile:aFileName.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   135
    inStream isNil ifTrue:[^ false].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   136
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   137
    Stream readErrorSignal handle:[:ex |
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   138
        line := nil.
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   139
    ] do:[
1510
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   140
        Stream lineTooLongErrorSignal handle:[:ex |
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   141
            line := nil.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   142
            Transcript showCR:'long line'.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   143
            ex return.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   144
        ] do:[
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   145
            line := inStream nextLine.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   146
        ].
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   147
        [line notNil and:[line isEmpty]] whileTrue:[
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   148
            line := inStream nextLine.
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   149
        ].
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   150
    ].
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   151
    line isNil ifTrue:[
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   152
        inStream close.
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   153
        ^ false
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   154
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   155
    [line startsWith:'#'] whileFalse:[
558
98c4c983a02b oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   156
        Stream readErrorSignal handle:[:ex |
98c4c983a02b oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   157
            line := nil.
98c4c983a02b oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   158
        ] do:[
1510
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   159
            Stream lineTooLongErrorSignal handle:[:ex |
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   160
                line := nil.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   161
                Transcript showCR:'long line'.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   162
                ex return.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   163
            ] do:[
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   164
                line := inStream nextLine.
4e0133eec046 care for invalid format (long line)
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
   165
            ].
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   166
            [line notNil and:[line isEmpty]] whileTrue:[
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   167
                line := inStream nextLine.
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   168
            ].
558
98c4c983a02b oops - handle read of binaries
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   169
        ].
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   170
        line isNil ifTrue:[
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   171
            inStream close.
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   172
            ^ false
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   173
        ]
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   174
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   175
    index1 := line indexOf:(Character space).
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   176
    index2 := line indexOf:(Character space) startingAt:(index1 + 1).
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   177
    (index2 == 0) ifTrue:[
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   178
        inStream close.
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   179
        ^ false
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   180
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   181
    keyword := line copyFrom:index1 to:(index2 - 1).
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   182
    (keyword endsWith:'_width') ifFalse:[
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   183
        inStream close.
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   184
        ^ false
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   185
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   186
    inStream close.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   187
    ^ true
550
254480517864 handle long line read error.
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   188
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   189
    "Modified: / 18.3.1999 / 11:33:39 / cg"
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   190
! !
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   191
1844
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   192
!XBMReader methodsFor:'private-reading'!
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   193
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   194
extractValueFor:keyword fromLine:lineString
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   195
    |index value restString|
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   196
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   197
    index := lineString indexOf:(Character space).
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   198
    index := lineString indexOf:(Character space) startingAt:(index + 1).
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   199
    (index == 0) ifTrue:[
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   200
        ^ nil.
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   201
    ].
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   202
    ((lineString copyTo:index - 1) endsWith:keyword) ifFalse:[
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   203
        ^ nil.
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   204
    ].
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   205
    restString := lineString copyFrom:(index + 1).
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   206
    value := Number readFromString:restString onError:nil.
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   207
    value isNil ifTrue:[
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   208
        ^ nil.
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   209
    ].
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   210
    ^ value
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   211
! !
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   212
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   213
!XBMReader methodsFor:'reading'!
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   214
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   215
fromStream:aStream
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   216
    "read an image in xbm format from aStream"
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   217
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   218
    |lineString 
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   219
     index    "{ Class: SmallInteger }"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   220
     dstIndex "{ Class: SmallInteger }"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   221
     bytesPerRow
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   222
     lo       "{ Class: SmallInteger }"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   223
     hi       "{ Class: SmallInteger }"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   224
     val      "{ Class: SmallInteger }"
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   225
     reverseBits|
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   226
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   227
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   228
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   229
    lineString := aStream nextLine.
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   230
    lineString isNil ifTrue:[
816
fe0abc1f956d use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   231
        ^ self fileFormatError:'short file'.
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   232
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   233
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   234
    [lineString startsWith:'#'] whileFalse:[
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   235
        lineString := aStream nextLine.
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   236
        lineString isNil ifTrue:[
816
fe0abc1f956d use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   237
            ^ self fileFormatError:'short file'.
493
d6392d88c552 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   238
        ].
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   239
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   240
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   241
    (lineString startsWith:'#define') ifFalse:[
816
fe0abc1f956d use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   242
        ^ self fileFormatError:'format error (expected #define)'.
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   243
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   244
1844
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   245
    width := self extractValueFor:'width' fromLine:lineString.
1049
1afeefeedd14 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   246
    width isNil ifTrue:[
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   247
        ^ self fileFormatError:'format error (expected width)'.
1049
1afeefeedd14 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   248
    ].
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   249
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   250
    lineString := aStream nextLine.
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   251
    [lineString notNil and:[lineString isEmpty]] whileTrue:[
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   252
        lineString := aStream nextLine.   
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   253
    ].
1844
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   254
    height := self extractValueFor:'height' fromLine:lineString.
1049
1afeefeedd14 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   255
    height isNil ifTrue:[
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   256
        ^ self fileFormatError:'format error (expected height)'.
1049
1afeefeedd14 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
   257
    ].
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   258
1844
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   259
    self reportDimension.
85c539787d5b dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   260
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   261
    bytesPerRow := width // 8.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   262
    ((width \\ 8) ~~ 0) ifTrue:[
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   263
        bytesPerRow := bytesPerRow + 1
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   264
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   265
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   266
    reverseBits := self class reverseBits.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   267
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   268
    data := ByteArray new:(bytesPerRow * height).
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   269
    dstIndex := 1.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   270
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   271
    lineString := aStream nextLine.
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   272
    [(lineString startsWith:'#')
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   273
     or:[lineString isEmpty]] whileTrue:[
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   274
        lineString := aStream nextLine.
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   275
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   276
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   277
    [lineString notNil and:[(lineString startsWith:'static') not]] whileTrue:[
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   278
        lineString := aStream nextLine.
53
4f5e734bc59f *** empty log message ***
claus
parents: 51
diff changeset
   279
    ].
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   280
    lineString := aStream nextLine.
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   281
    [lineString notNil and:[lineString isEmpty]] whileTrue:[
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   282
        lineString := aStream nextLine.
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   283
    ].
53
4f5e734bc59f *** empty log message ***
claus
parents: 51
diff changeset
   284
524
2911c30d10b3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 493
diff changeset
   285
    [lineString notNil] whileTrue:[
1506
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   286
        dstIndex <= data size ifTrue:[
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   287
            index := 1.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   288
            [index ~~ 0] whileTrue:[
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   289
                dstIndex <= data size ifTrue:[
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   290
                    index := lineString indexOf:$x startingAt:index.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   291
                    (index ~~ 0) ifTrue:[
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   292
                        index := index + 1.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   293
                        hi := (lineString at:index) digitValue.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   294
                        index := index + 1.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   295
                        lo := (lineString at:index) digitValue.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   296
                        val := (hi bitShift:4) bitOr:lo.
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   297
                        data at:dstIndex put:(reverseBits at:(val + 1)).
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   298
                        dstIndex := dstIndex + 1
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   299
                    ]
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   300
                ] ifFalse:[
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   301
                    index := 0. "/ break loop
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   302
                ] 
60e56746dce6 ignore junk at the end of the bitmap (comments etc)
Claus Gittinger <cg@exept.de>
parents: 1495
diff changeset
   303
            ].
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   304
        ].
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   305
        lineString := aStream nextLine.
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   306
        [lineString notNil and:[lineString isEmpty]] whileTrue:[
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   307
            lineString := aStream nextLine.
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   308
        ].
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   309
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   310
    ].
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   311
    photometric := #whiteIs0.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   312
    samplesPerPixel := 1.
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   313
    bitsPerSample := #(1).
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   314
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   315
    "
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   316
     XBMReader fromFile:'bitmaps/globe1.xbm'
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   317
    "
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   318
1144
c86a1e3e3884 ignore empty lines in input.
Claus Gittinger <cg@exept.de>
parents: 1049
diff changeset
   319
    "Modified: / 18.3.1999 / 11:32:46 / cg"
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   320
! !
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   321
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   322
!XBMReader methodsFor:'writing'!
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   323
1812
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   324
save:image onStream:aStream
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   325
    "save image as XBM cdata on aStream.
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   326
     Only depth1 b&w images can be represented in this format."
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   327
33
be90784ee668 *** empty log message ***
claus
parents: 28
diff changeset
   328
    |reverseBits bits byte
66
claus
parents: 53
diff changeset
   329
     h        "{ Class: SmallInteger }"
33
be90784ee668 *** empty log message ***
claus
parents: 28
diff changeset
   330
     srcIndex "{ Class: SmallInteger }"
be90784ee668 *** empty log message ***
claus
parents: 28
diff changeset
   331
     rowBytes "{ Class: SmallInteger }" |
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   332
51
ac84315b8181 *** empty log message ***
claus
parents: 41
diff changeset
   333
    (self class canRepresent:image) ifFalse:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   334
        ^ Image cannotRepresentImageSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   335
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   336
            errorString:('XBM format only supports monochrome images').
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   337
    ].
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   338
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   339
    image mask notNil ifTrue:[
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   340
        Image informationLostQuerySignal
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   341
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
   342
            errorString:('XBM format does not support an imageMask').
51
ac84315b8181 *** empty log message ***
claus
parents: 41
diff changeset
   343
    ].
ac84315b8181 *** empty log message ***
claus
parents: 41
diff changeset
   344
1812
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   345
    outStream := aStream.
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   346
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   347
    width := image width.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   348
    height := image height.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   349
    photometric := image photometric.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   350
    samplesPerPixel := image samplesPerPixel.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   351
    bitsPerSample := image bitsPerSample.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   352
    colorMap := image colorMap.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   353
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   354
    outStream nextPutAll: '#define xbm_width '.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   355
    outStream nextPutAll:(width printString).
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   356
    outStream cr.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   357
    outStream nextPutAll: '#define xbm_height '.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   358
    outStream nextPutAll:(height printString).
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   359
    outStream cr.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   360
    outStream nextPutAll: 'static char xbm_bits[] = {'; cr.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   361
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   362
    reverseBits := self class reverseBits.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   363
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   364
    rowBytes := width + 7 // 8.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   365
    data := image bits.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   366
    srcIndex := 1.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   367
66
claus
parents: 53
diff changeset
   368
    h := height.
claus
parents: 53
diff changeset
   369
    h timesRepeat:[
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   370
        rowBytes timesRepeat:[
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   371
            outStream nextPutAll: '0x'.
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   372
            bits := data at:srcIndex. srcIndex := srcIndex + 1.
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   373
            photometric == #blackIs0 ifTrue:[
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   374
                bits := bits bitInvert bitAnd:16rFF
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   375
            ].
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   376
            byte := (reverseBits at:(bits + 1)).
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   377
            byte < 16 ifTrue:[
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   378
                outStream nextPut:$0
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   379
            ].
272
477aeb0d62b6 printOn:radix: -> printOn:base:
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   380
            byte printOn:outStream base:16.
202
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   381
            outStream nextPutAll: ', '.
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   382
        ].
651db5018d9c commentary
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
   383
        outStream cr
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   384
    ].
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   385
    outStream nextPutAll: '};'; cr.
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   386
33
be90784ee668 *** empty log message ***
claus
parents: 28
diff changeset
   387
    "
1812
5c902c4135f1 writing onto a stream
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   388
     XBMReader save:(Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm') onStream:Transcript
33
be90784ee668 *** empty log message ***
claus
parents: 28
diff changeset
   389
    "
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   390
! !
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   391
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   392
!XBMReader class methodsFor:'documentation'!
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   393
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   394
version
2030
cfe668c44a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
   395
    ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.52 2005-01-07 14:35:23 cg Exp $'
135
ff507d9a242b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   396
! !
1710
ad35e6a18e98 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1521
diff changeset
   397
41
66edc847b9c8 *** empty log message ***
claus
parents: 33
diff changeset
   398
XBMReader initialize!