FaceReader.st
author Claus Gittinger <cg@exept.de>
Sun, 29 Jan 2017 02:26:51 +0100
changeset 3853 5a78ffcf69de
parent 1846 d29322944b05
child 3855 1db7742d33ad
child 3898 bf47b82c9c30
permissions -rw-r--r--
#FEATURE by cg class: TypeConverter changed: #timeOfClass:withFormat:orDefault:language:
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
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
    13
"{ Package: 'stx:libview2' }"
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
    14
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    15
ImageReader subclass:#FaceReader
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    16
	instanceVariableNames:''
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    17
	classVariableNames:''
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    18
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
    19
	category:'Graphics-Images-Readers'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    20
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    21
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    22
!FaceReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    23
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    24
copyright
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    25
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    27
	      All Rights Reserved
5
claus
parents: 1
diff changeset
    28
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    29
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    30
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    32
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    33
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    34
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    35
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    36
!
5
claus
parents: 1
diff changeset
    37
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    38
documentation
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    39
"
218
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
    40
    This class knows how to read face files.
96e8e87e5dc8 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 210
diff changeset
    41
    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
    42
     ftp-servers, to improve mail- and/or newsreaders :-).
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    43
    Other than above, that format is not used often.
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    44
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    45
    The file format is (ascii):
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    46
        ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    47
        FirstName: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    48
        LastName: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    49
        E-mail: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    50
        PicData: ...
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    51
        Image: <width> <height> <depth>
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    52
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    53
        bits; encoded in uppercase hex ascii; 2 chars/pixel
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    54
        pixel values are greyscale-value; 0..255
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    55
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    56
    Only 8-bit greyscale is supported 
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    57
    - I have never encountered any other face-file-format.
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    58
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    59
    Only file reading is supported.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    60
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    61
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    62
    Notice: 
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    63
        Face files come in two formats: the first is the one implemented here,
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    64
        the other is the blitImage file format, which only supports 48x48x1 images.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    65
        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
    66
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    67
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 218
diff changeset
    68
        Image Form Icon
197
50812e81d86f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 196
diff changeset
    69
        BlitImageReader GIFReader JPEGReader PBMReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    70
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 198
diff changeset
    71
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    72
"
66b31c91177f *** empty log message ***
claus
parents: 15
diff changeset
    73
! !
5
claus
parents: 1
diff changeset
    74
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    75
!FaceReader class methodsFor:'initialization'!
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    76
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    77
initialize
198
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    78
    "install myself in the Image classes fileFormat table
6d76856aaa80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 197
diff changeset
    79
     for the `.face' extension."
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    80
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
    81
    MIMETypes defineImageType:nil suffix:'face' reader:self
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    82
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
    83
    "Modified: 1.2.1997 / 15:01:25 / cg"
26
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    84
! !
2fe6294ca833 *** empty log message ***
claus
parents: 23
diff changeset
    85
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1753
diff changeset
    86
!FaceReader methodsFor:'reading'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    87
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
    88
readImage
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
    89
    "read an image in my format from my inStream"
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
    90
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    91
    |line 
3f9277473954 Initial revision
claus
parents:
diff changeset
    92
     dstIndex "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    93
     bytesPerRow
3f9277473954 Initial revision
claus
parents:
diff changeset
    94
     lo       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    95
     hi       "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    96
     val      "{ Class: SmallInteger }"
3f9277473954 Initial revision
claus
parents:
diff changeset
    97
     inHeader s depth|
3f9277473954 Initial revision
claus
parents:
diff changeset
    98
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
    99
    line := inStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   100
    line isNil ifTrue:[
808
495535230e80 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   101
        ^ self fileFormatError:'short read'.
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.
1753
aa246112438a avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   108
            s skip:6.
196
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
        ].
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   114
        line := inStream 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:[
808
495535230e80 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   118
        ^ self fileFormatError:'only depth 8 supported'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   119
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   120
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   121
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   122
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   123
    [line isEmpty] whileTrue:[
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   124
        line := inStream nextLine.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   125
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   126
3f9277473954 Initial revision
claus
parents:
diff changeset
   127
    bytesPerRow := width * depth // 8.
3f9277473954 Initial revision
claus
parents:
diff changeset
   128
    ((width * depth \\ 8) ~~ 0) ifTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   129
        bytesPerRow := bytesPerRow + 1
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   130
    ].
3f9277473954 Initial revision
claus
parents:
diff changeset
   131
1
6fe019b6ea79 *** empty log message ***
claus
parents: 0
diff changeset
   132
    data := ByteArray uninitializedNew:(bytesPerRow * height).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   133
    dstIndex := data size.
3f9277473954 Initial revision
claus
parents:
diff changeset
   134
3f9277473954 Initial revision
claus
parents:
diff changeset
   135
    [line notNil] whileTrue:[
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   136
        1 to:(line size) by:2 do:[:cI |
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   137
            hi := (line at:cI) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   138
            lo := (line at:(cI + 1)) digitValue.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   139
            val := (hi bitShift:4) bitOr:lo.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   140
            data at:dstIndex put:val.
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   141
            dstIndex := dstIndex - 1
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   142
        ].
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   143
        line := inStream nextLine
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   144
    ].
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   145
    photometric := #blackIs0.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   146
    samplesPerPixel := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   147
    bitsPerSample := #(8)
3f9277473954 Initial revision
claus
parents:
diff changeset
   148
120
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   149
    "
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   150
     FaceReader fromFile:'../goodies/faces/next.com/steve.face'
719d6c8c3b39 blackIs0 <-> whiteIs0
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   151
    "
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   152
    "this is NOT steve jobs :-)"
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   153
808
495535230e80 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
   154
    "Modified: / 3.2.1998 / 17:50:52 / cg"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   155
! !
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   156
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   157
!FaceReader class methodsFor:'documentation'!
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   158
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   159
version
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   160
    ^ '$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.30 2003-11-19 15:28:06 cg Exp $'
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   161
! !
1739
971f1a3970a3 refactorings
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   162
196
a3153c2b1d27 commentary
Claus Gittinger <cg@exept.de>
parents: 120
diff changeset
   163
FaceReader initialize!