FaceReader.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 18:32:07 +0200
changeset 221 ea942fe5dc04
parent 218 96e8e87e5dc8
child 234 b6352d13e792
permissions -rw-r--r--
documentation
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:''
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
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:]
197
50812e81d86f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 196
diff changeset
    66
        BlitImageReader GIFReader JPEGReader PBMReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    67
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
    68
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    69
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    70
! !
5
claus
parents: 1
diff changeset
    71
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    72
!FaceReader class methodsFor:'initialization'!
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    73
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    74
initialize
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    75
    "install myself in the Image classes fileFormat table
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    76
     for the `.face' extension."
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    77
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    78
    Image fileFormats at:'.face'  put:self.
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    79
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    80
    "Modified: 23.4.1996 / 12:27:35 / cg"
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    81
! !
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    82
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    83
!FaceReader methodsFor:'reading from file'!
3f9277473954 Initial revision
claus
parents:
diff changeset
    84
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    85
fromStream:aStream
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    86
    "read an image in my format from aStream"
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    87
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    88
    |line 
3f9277473954 Initial revision
claus
parents:
diff changeset
    89
     dstIndex "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    90
     bytesPerRow
3f9277473954 Initial revision
claus
parents:
diff changeset
    91
     lo       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    92
     hi       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    93
     val      "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    94
     inHeader s depth|
3f9277473954 Initial revision
claus
parents:
diff changeset
    95
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    96
    inStream := aStream.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    97
43
e85c7d392833 *** empty log message ***
claus
parents: 32
diff changeset
    98
    line := aStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    99
    line isNil ifTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   100
        ^ nil
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   101
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   102
3f9277473954 Initial revision
claus
parents:
diff changeset
   103
    inHeader := true.
3f9277473954 Initial revision
claus
parents:
diff changeset
   104
    [inHeader] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   105
        (line startsWith:'Image:') ifTrue:[
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   106
            s := ReadStream on:line.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   107
            s position:7.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   108
            width := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   109
            height := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   110
            depth := Number readFrom:s.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   111
            inHeader := false.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   112
        ].
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   113
        line := aStream nextLine
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   114
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   115
3f9277473954 Initial revision
claus
parents:
diff changeset
   116
    depth == 8 ifFalse:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   117
        self error:'only depth 8 supported'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   118
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   119
3f9277473954 Initial revision
claus
parents:
diff changeset
   120
    [line isEmpty] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   121
        line := aStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   122
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   123
3f9277473954 Initial revision
claus
parents:
diff changeset
   124
    bytesPerRow := width * depth // 8.
3f9277473954 Initial revision
claus
parents:
diff changeset
   125
    ((width * depth \\ 8) ~~ 0) ifTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   126
        bytesPerRow := bytesPerRow + 1
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   127
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   128
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   129
    data := ByteArray uninitializedNew:(bytesPerRow * height).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   130
    dstIndex := data size.
3f9277473954 Initial revision
claus
parents:
diff changeset
   131
3f9277473954 Initial revision
claus
parents:
diff changeset
   132
    [line notNil] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   133
        1 to:(line size) by:2 do:[:cI |
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   134
            hi := (line at:cI) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   135
            lo := (line at:(cI + 1)) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   136
            val := (hi bitShift:4) bitOr:lo.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   137
            data at:dstIndex put:val.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   138
            dstIndex := dstIndex - 1
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   139
        ].
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   140
        line := aStream nextLine
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   141
    ].
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   142
    photometric := #blackIs0.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   143
    samplesPerPixel := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   144
    bitsPerSample := #(8)
3f9277473954 Initial revision
claus
parents:
diff changeset
   145
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   146
    "
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   147
     FaceReader fromFile:'../goodies/faces/next.com/steve.face'
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   148
    "
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   149
    "this is NOT steve jobs :-)"
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   150
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   151
    "Modified: 23.4.1996 / 12:23:38 / cg"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   152
! !
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   153
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   154
!FaceReader class methodsFor:'documentation'!
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   155
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   156
version
218
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
   157
    ^ '$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.20 1996-04-25 16:09:57 stefan Exp $'
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   158
! !
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   159
FaceReader initialize!