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