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