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