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