FaceReader.st
author ca
Tue, 11 Feb 1997 20:02:28 +0100
changeset 410 2d21748e0d9c
parent 398 aef700d15416
child 647 6f26c76aa0c9
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
claus
parents: 1
diff changeset
     1
"
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
     3
	      All Rights Reserved
5
claus
parents: 1
diff changeset
     4
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 1
diff changeset
    10
 hereby transferred.
claus
parents: 1
diff changeset
    11
"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    12
3f9277473954 Initial revision
claus
parents:
diff changeset
    13
ImageReader subclass:#FaceReader
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    14
	instanceVariableNames:''
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    15
	classVariableNames:''
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    16
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
    17
	category:'Graphics-Images-Support'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    18
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    19
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    20
!FaceReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    22
copyright
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    23
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    25
	      All Rights Reserved
5
claus
parents: 1
diff changeset
    26
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    27
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    28
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    30
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    31
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    32
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    33
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    34
!
5
claus
parents: 1
diff changeset
    35
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    36
documentation
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    37
"
218
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
    38
    This class knows how to read face files.
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
    39
    This format is used for people's faces - which can be obtained from some
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
    40
     ftp-servers, to improve mail- and/or newsreaders :-).
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    41
    Other than above, that format is not used often.
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    42
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    43
    The file format is (ascii):
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    44
        ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    45
        FirstName: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    46
        LastName: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    47
        E-mail: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    48
        PicData: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    49
        Image: <width> <height> <depth>
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    50
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    51
        bits; encoded in uppercase hex ascii; 2 chars/pixel
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    52
        pixel values are greyscale-value; 0..255
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    53
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    54
    Only 8-bit greyscale is supported 
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    55
    - I have never encountered any other face-file-format.
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    56
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    57
    Only file reading is supported.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    58
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    59
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    60
    Notice: 
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    61
        Face files come in two formats: the first is the one implemented here,
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    62
        the other is the blitImage file format, which only supports 48x48x1 images.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    63
        The latter is supported by the BlitImageReader class.
114
e577a2f332d0 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    64
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    65
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 218
diff changeset
    66
        Image Form Icon
197
50812e81d86f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 196
diff changeset
    67
        BlitImageReader GIFReader JPEGReader PBMReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    68
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
    69
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    70
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    71
! !
5
claus
parents: 1
diff changeset
    72
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    73
!FaceReader class methodsFor:'initialization'!
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    74
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    75
initialize
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    76
    "install myself in the Image classes fileFormat table
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    77
     for the `.face' extension."
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    78
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
    79
    Image addReader:self suffix:'face'
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    80
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
    81
    "Modified: 1.2.1997 / 15:01:25 / cg"
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    82
! !
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    83
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    84
!FaceReader methodsFor:'reading from file'!
3f9277473954 Initial revision
claus
parents:
diff changeset
    85
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    86
fromStream:aStream
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    87
    "read an image in my format from aStream"
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    88
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    89
    |line 
3f9277473954 Initial revision
claus
parents:
diff changeset
    90
     dstIndex "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    91
     bytesPerRow
3f9277473954 Initial revision
claus
parents:
diff changeset
    92
     lo       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    93
     hi       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    94
     val      "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    95
     inHeader s depth|
3f9277473954 Initial revision
claus
parents:
diff changeset
    96
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    97
    inStream := aStream.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    98
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    99
    line := aStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   100
    line isNil ifTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   101
        ^ nil
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   102
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   103
3f9277473954 Initial revision
claus
parents:
diff changeset
   104
    inHeader := true.
3f9277473954 Initial revision
claus
parents:
diff changeset
   105
    [inHeader] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   106
        (line startsWith:'Image:') ifTrue:[
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   107
            s := ReadStream on:line.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   108
            s position:7.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   109
            width := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   110
            height := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   111
            depth := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   112
            inHeader := false.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   113
        ].
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   114
        line := aStream nextLine
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   115
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   116
3f9277473954 Initial revision
claus
parents:
diff changeset
   117
    depth == 8 ifFalse:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   118
        self error:'only depth 8 supported'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   119
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   120
3f9277473954 Initial revision
claus
parents:
diff changeset
   121
    [line isEmpty] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   122
        line := aStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   123
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   124
3f9277473954 Initial revision
claus
parents:
diff changeset
   125
    bytesPerRow := width * depth // 8.
3f9277473954 Initial revision
claus
parents:
diff changeset
   126
    ((width * depth \\ 8) ~~ 0) ifTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   127
        bytesPerRow := bytesPerRow + 1
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   128
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   129
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   130
    data := ByteArray uninitializedNew:(bytesPerRow * height).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   131
    dstIndex := data size.
3f9277473954 Initial revision
claus
parents:
diff changeset
   132
3f9277473954 Initial revision
claus
parents:
diff changeset
   133
    [line notNil] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   134
        1 to:(line size) by:2 do:[:cI |
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   135
            hi := (line at:cI) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   136
            lo := (line at:(cI + 1)) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   137
            val := (hi bitShift:4) bitOr:lo.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   138
            data at:dstIndex put:val.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   139
            dstIndex := dstIndex - 1
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   140
        ].
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   141
        line := aStream nextLine
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   142
    ].
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   143
    photometric := #blackIs0.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   144
    samplesPerPixel := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   145
    bitsPerSample := #(8)
3f9277473954 Initial revision
claus
parents:
diff changeset
   146
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   147
    "
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   148
     FaceReader fromFile:'../goodies/faces/next.com/steve.face'
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   149
    "
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   150
    "this is NOT steve jobs :-)"
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   151
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   152
    "Modified: 23.4.1996 / 12:23:38 / cg"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   153
! !
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   154
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   155
!FaceReader class methodsFor:'documentation'!
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   156
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   157
version
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   158
    ^ '$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.23 1997-02-01 14:05:43 cg Exp $'
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   159
! !
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   160
FaceReader initialize!