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