PBMReader.st
author Claus Gittinger <cg@exept.de>
Fri, 04 Apr 2003 19:07:54 +0200
changeset 1737 a1ed08195ee7
parent 1082 9b629fdac9ec
child 1745 4fa0fad2a463
permissions -rw-r--r--
refactorings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     1
"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     3
              All Rights Reserved
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     4
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     5
 This software is furnished under a license and may be used
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     6
 only in accordance with the terms of that license and with the
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     8
 be provided or otherwise made available to, or used by, any
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
     9
 other person.  No title to or ownership of the software is
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    10
 hereby transferred.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    11
"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    12
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    13
842b6a603cdc Initial revision
claus
parents:
diff changeset
    14
ImageReader subclass:#PBMReader
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    15
	instanceVariableNames:''
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    16
	classVariableNames:''
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    17
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
    18
	category:'Graphics-Images-Support'
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    19
!
842b6a603cdc Initial revision
claus
parents:
diff changeset
    20
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    21
!PBMReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    22
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    23
copyright
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    24
"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    25
 COPYRIGHT (c) 1992 by Claus Gittinger
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    26
              All Rights Reserved
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    27
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    28
 This software is furnished under a license and may be used
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    29
 only in accordance with the terms of that license and with the
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    31
 be provided or otherwise made available to, or used by, any
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    32
 other person.  No title to or ownership of the software is
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    33
 hereby transferred.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    34
"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    35
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    36
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    37
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    38
documentation
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    39
"
32
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    40
    this class provides methods for loading and saving Portable BitMap-file 
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    41
    images (Jef Poskanzers portable bitmap package).
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    42
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    43
    Reading is supported for 1bit (pbm), greyscale (pgm) and 24bit (ppm) formats.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    44
    (i.e. P1, P3, P4, P5, P6 and P7 formats)
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    45
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    46
    Writing is (currently) only supported for the binary formats;
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    47
    i.e. 1-bit images as (pbm P4), 8-bit gray as (pgm P5) and 24-bit images as (pnm P6).
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    48
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    49
    Q: should we broil this one to perfection and base all others on
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    50
       pipe-readers to the various pbmplus converters ?
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    51
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    52
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    53
        Image Form Icon
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    54
        BlitImageReader FaceReader GIFReader JPEGReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    55
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
    56
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    57
"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    58
! !
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    59
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    60
!PBMReader class methodsFor:'initialization'!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    61
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    62
initialize
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    63
    "install myself in the Image classes fileFormat table
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    64
     for the `.pbm', '.pgm' and '.pnm' extensions."
806
fc45835a5967 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
    65
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    66
    MIMETypes defineImageType:'image/x-portable-bitmap'  suffix:'pbm' reader:self.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    67
    MIMETypes defineImageType:'image/x-portable-graymap' suffix:'pgm' reader:self.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    68
    MIMETypes defineImageType:'image/x-portable-anymap'  suffix:'pnm' reader:self.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    69
    MIMETypes defineImageType:'image/x-portable-pixmap'  suffix:'ppm' reader:self.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    70
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    71
    "Modified: / 1.2.1997 / 15:02:14 / cg"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    72
    "Created: / 3.2.1998 / 17:19:59 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    73
! !
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    74
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    75
!PBMReader class methodsFor:'testing'!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    76
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    77
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    78
    "return true, if anImage can be represented in my file format.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    79
     Currently, only 1bit B&W, 8bit-grey and 24bit RGB images are supported."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    80
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    81
    |depth photometric|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    82
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    83
    anImage photometric == #rgb ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    84
        ^ depth==24
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    85
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    86
    (depth := anImage depth) == 1 ifTrue:[^ true].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    87
    depth == 8 ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    88
        photometric := anImage photometric.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    89
        ^ (photometric == #blackIs0) or:[photometric == #whiteIs0]
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    90
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    91
    ^ false
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    92
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    93
    "Modified: 17.10.1997 / 20:20:52 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    94
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    95
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    96
isValidImageFile:aFileName
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    97
    "return true, if aFileName contains a PBM image (which I can read)"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    98
1082
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
    99
    |inStream pnmType ok|
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   100
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   101
    inStream := self streamReadingFile:aFileName.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   102
    inStream isNil ifTrue:[^ false].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   103
    inStream text.
1082
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   104
    ok := inStream next == $P.
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   105
    ok ifTrue:[
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   106
        pnmType := inStream next.
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   107
        ok := #( $1 $3 $4 $5 $6 $7) includes:pnmType.
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   108
    ].
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   109
    inStream close. 
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   110
    ^ ok
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   111
1082
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   112
    "Modified: / 7.12.1998 / 14:27:11 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   113
! !
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   114
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   115
!PBMReader methodsFor:'private'!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   116
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   117
skipPBMJunkOn:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   118
    "this method removes any superfluous characters from the input stream."
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   119
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   120
    | char foundNL|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   121
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   122
    [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   123
        char := aStream peek.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   124
        [char == $#] whileTrue:[
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   125
            "Start of a comment. Skip to end-of-line."
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   126
"/            foundNL := (aStream skipUpTo: Character cr) notNil.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   127
            foundNL := (aStream skipThrough: Character cr) notNil.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   128
            foundNL ifFalse: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   129
                "Must be EOF"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   130
                ^self
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   131
            ].
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   132
            char := aStream peek
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   133
        ].
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   134
        aStream atEnd not and: [char isSeparator]
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   135
    ] whileTrue: [aStream next]
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   136
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   137
    "Created: / 3.2.1998 / 17:20:37 / cg"
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   138
    "Modified: / 7.9.1998 / 15:49:07 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   139
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   140
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   141
skipXPMJunkOn:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   142
    "this method removes any superfluous characters from the input stream."
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   143
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   144
    | char |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   145
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   146
    [       
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   147
        char := aStream peek. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   148
        aStream atEnd not and: [char isSeparator not]
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   149
    ] whileTrue: [aStream next].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   150
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   151
    [aStream atEnd not and: [char isSeparator]] whileTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   152
        aStream next. char := aStream peek
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   153
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   154
    aStream atEnd ifTrue: [^char].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   155
    (char isDigit) ifTrue: [ ^char ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   156
    (char == $") ifTrue: [ 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   157
        aStream next. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   158
        char := aStream peek. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   159
        (char isLetterOrDigit 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   160
         or: [(char == $#) 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   161
         or: [char == Character space]]) ifFalse:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   162
            ^ self skipXPMJunkOn: aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   163
        ] ifTrue: [^char]
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   164
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   165
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   166
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   167
    ^self skipXPMJunkOn: aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   168
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   169
    "Created: / 3.2.1998 / 17:20:54 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
   170
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
   171
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   172
!PBMReader methodsFor:'reading from file'!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   173
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   174
fromStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   175
    "read a Portable bitmap file format as of Jeff Poskanzers Portable Bitmap Package.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   176
     supported are PBM, PGB and PNM files." 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   177
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   178
    | pnmType |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   179
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   180
    inStream := aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   181
    inStream text.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   182
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   183
    inStream next == $P ifFalse:[
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   184
        ^ self fileFormatError:'not PNM format'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   185
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   186
    pnmType := inStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   187
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   188
    (pnmType == $1) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   189
        ^ self readDepth1AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   190
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   191
    (pnmType == $3) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   192
        ^ self readDepth24AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   193
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   194
    (pnmType == $4) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   195
        ^ self readDepth1PBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   196
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   197
    (pnmType == $5) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   198
        ^ self readDepth8PGMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   199
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   200
    (pnmType == $6) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   201
        ^ self readDepth24PPMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   202
    ].
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   203
    (pnmType == $7) ifTrue: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   204
        ^ self readDepth8PPMStream:aStream
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   205
    ].
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   206
    ^ self fileFormatError:'No recognized PNM file format'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   207
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   208
    "
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   209
     PBMReader fromFile:'bitmaps/testimg.ppm'
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   210
     PBMReader fromFile:'../../fileIn/bitmaps/keyboard.pbm'
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   211
     PBMReader fromFile:'/home2/cg/ppm2fli_b1-92/jeff.001'
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   212
    "
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   213
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   214
    "Created: / 3.2.1998 / 17:25:34 / cg"
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   215
    "Modified: / 7.9.1998 / 15:44:29 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   216
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   217
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   218
readDepth1AsciiPBMStream:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   219
    "import portable bitmap ascii (PBM, P1 format); P1 is already read"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   220
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   221
    |n bits rowIdx dstIdx bytesPerRow char|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   222
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   223
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   224
    width := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   225
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   226
        ^ self fileFormatError:'Invalid width'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   227
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   228
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   229
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   230
    height := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   231
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   232
        ^ self fileFormatError:'Invalid height'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   233
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   234
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   235
    aStream nextLine "skipThrough: Character cr".
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   236
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   237
    bytesPerRow := (width + 7) // 8.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   238
    data := ByteArray new:bytesPerRow * height.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   239
    rowIdx := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   240
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   241
    1 to:height do:[:row |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   242
        dstIdx := rowIdx.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   243
        bits := 0. n := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   244
        1 to:width do:[:col |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   245
            char := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   246
            [char notNil and:[char isSeparator]] whileTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   247
                char := aStream next
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   248
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   249
            bits := bits bitShift:1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   250
            char == $1 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   251
                bits := bits bitOr:1
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   252
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   253
            n := n + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   254
            n == 8 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   255
                data at:dstIdx put:bits.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   256
                dstIdx := dstIdx + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   257
                bits := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   258
                n := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   259
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   260
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   261
        n ~~ 0 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   262
            data at:dstIdx put:bits.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   263
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   264
        rowIdx := rowIdx + bytesPerRow
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   265
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   266
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   267
    photometric := #whiteIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   268
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   269
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   270
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   271
    "Created: / 3.2.1998 / 17:21:22 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   272
    "Modified: / 3.2.1998 / 17:56:32 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   273
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   274
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   275
readDepth1PBMStream:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   276
    "import portable bitmap (PBM, P4 format); P4 is already read"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   277
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   278
    |bytesPerRow|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   279
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   280
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   281
    width := Integer readFrom:aStream onError:0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   282
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   283
        ^ self fileFormatError:'Invalid width'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   284
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   285
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   286
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   287
    height := Integer readFrom:aStream onError:0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   288
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   289
        ^ self fileFormatError:'Invalid height'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   290
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   291
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   292
    aStream nextLine "skipThrough: Character cr".
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   293
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   294
    bytesPerRow := width // 8.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   295
    ((width \\ 8) ~~ 0) ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   296
        bytesPerRow := bytesPerRow + 1
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   297
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   298
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   299
    "/ the rest is the binary image data ...
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   300
    aStream binary.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   301
    data := ByteArray uninitializedNew:(bytesPerRow*height).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   302
    aStream nextBytes:(data size) into:data.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   303
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   304
    photometric := #blackIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   305
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   306
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   307
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   308
    "Created: / 3.2.1998 / 17:21:37 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   309
    "Modified: / 3.2.1998 / 17:56:59 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   310
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   311
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   312
readDepth24AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   313
    "import ascii portable pixmap (PBM, P3 format); P3 is already read"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   314
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   315
    |maxval 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   316
     nBytes "{Class: SmallInteger }" 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   317
     v      "{Class: SmallInteger }"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   318
     c|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   319
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   320
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   321
    width := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   322
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   323
        ^ self fileFormatError:'Invalid width'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   324
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   325
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   326
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   327
    height := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   328
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   329
        ^ self fileFormatError:'Invalid height'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   330
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   331
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   332
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   333
    maxval := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   334
    maxval >= 256 ifTrue: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   335
        ^ self fileFormatError:'Invalid format'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   336
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   337
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   338
    aStream skipThrough: Character cr.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   339
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   340
    nBytes := width*height*3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   341
    data := ByteArray new:nBytes.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   342
    1 to:nBytes do:[:i |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   343
        aStream skipSeparators.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   344
        v := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   345
        c := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   346
        [c isDigit] whileTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   347
            v := v * 10 + (c digitValue).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   348
            c := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   349
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   350
        data at:i put:v
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   351
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   352
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   353
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   354
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   355
    bitsPerSample := #(8 8 8).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   356
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   357
    "Created: / 3.2.1998 / 17:21:55 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   358
    "Modified: / 3.2.1998 / 17:57:30 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   359
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   360
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   361
readDepth24PPMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   362
    "import portable pixmap (PPM, P6 format); P6 is already read"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   363
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   364
    | maxval |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   365
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   366
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   367
    width := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   368
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   369
        ^ self fileFormatError:'Invalid width'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   370
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   371
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   372
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   373
    height := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   374
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   375
        ^ self fileFormatError:'Invalid height'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   376
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   377
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   378
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   379
    maxval := Integer readFrom:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   380
    maxval >= 256 ifTrue: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   381
        ^ self fileFormatError:'Invalid format'.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   382
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   383
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   384
    aStream skipThrough: Character cr.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   385
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   386
    "/ the rest is the binary image data ...
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   387
    aStream binary.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   388
    data := ByteArray uninitializedNew:(width*height*3).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   389
    aStream nextBytes:(data size) into:data.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   390
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   391
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   392
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   393
    bitsPerSample := #(8 8 8).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   394
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   395
    "Created: / 3.2.1998 / 17:22:18 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   396
    "Modified: / 3.2.1998 / 17:57:26 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   397
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   398
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   399
readDepth8PGMStream:aStream 
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   400
    "import portable gray map (PGM, P5 format); P5 is already read"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   401
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   402
    |maxval|
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   403
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   404
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   405
    width := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   406
    width > 0 ifFalse:[ 
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   407
        ^ self fileFormatError:'Invalid width'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   408
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   409
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   410
    height := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   411
    height > 0 ifFalse:[ 
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   412
        ^ self fileFormatError:'Invalid height'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   413
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   414
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   415
    maxval := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   416
    maxval >= 256 ifTrue:[
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   417
        ^ self fileFormatError:'Invalid format'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   418
    ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   419
    aStream nextLine "skipThrough: Character cr".
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   420
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   421
    "/ the rest is the binary image data ...
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   422
    aStream binary.
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   423
    data := ByteArray uninitializedNew:(width*height).
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   424
    aStream nextBytes:(data size) into:data.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   425
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   426
    photometric := #blackIs0.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   427
    samplesPerPixel := 1.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   428
    bitsPerSample := #(8).
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   429
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   430
    "Modified: / 3.2.1998 / 17:57:21 / cg"
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   431
!
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   432
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   433
readDepth8PPMStream:aStream
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   434
    "import portable pixmap (PPM, P7 format); P7 is already read"
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   435
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   436
    | maxval bitsRed bitsGreen bitsBlue|
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   437
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   438
    aStream skipSeparators.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   439
    bitsRed := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   440
    bitsGreen := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   441
    bitsBlue := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   442
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   443
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   444
    width := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   445
    width > 0 ifFalse: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   446
        ^ self fileFormatError:'Invalid width'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   447
    ].
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   448
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   449
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   450
    height := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   451
    height > 0 ifFalse: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   452
        ^ self fileFormatError:'Invalid height'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   453
    ].
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   454
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   455
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   456
    maxval := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   457
    maxval >= 256 ifTrue: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   458
        ^ self fileFormatError:'Invalid format'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   459
    ].
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   460
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   461
    aStream skipThrough: Character cr.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   462
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   463
    "/ the rest is the binary image data ...
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   464
    aStream binary.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   465
    data := ByteArray uninitializedNew:(width*height*1).
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   466
    aStream nextBytes:(data size) into:data.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   467
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   468
    photometric := #rgb.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   469
    samplesPerPixel := 3.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   470
    bitsPerSample := (Array with:bitsRed with:bitsGreen with:bitsBlue).
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   471
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   472
    "Created: / 7.9.1998 / 15:44:05 / cg"
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   473
    "Modified: / 7.9.1998 / 15:50:36 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   474
! !
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   475
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   476
!PBMReader methodsFor:'writing to file'!
842b6a603cdc Initial revision
claus
parents:
diff changeset
   477
842b6a603cdc Initial revision
claus
parents:
diff changeset
   478
save:image onFile:aFileName
842b6a603cdc Initial revision
claus
parents:
diff changeset
   479
    "save image as PBM/PGM/PNM file on aFileName"
842b6a603cdc Initial revision
claus
parents:
diff changeset
   480
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   481
    |bitsPerPixel|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   482
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   483
    image mask notNil ifTrue:[
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   484
        Image informationLostQuerySignal
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   485
            raiseWith:image
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   486
            errorString:('PBM format does not support an imageMask').
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   487
    ].
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   488
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   489
    outStream := FileStream newFileNamed:aFileName.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   490
    outStream isNil ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   491
        'PBMReader [error]: file create error' errorPrintNL. 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   492
        ^ Image fileCreationErrorSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   493
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   494
            errorString:('file creation error: ' , aFileName asString).
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   495
    ].
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   496
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   497
    width := image width.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   498
    height := image height.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   499
    photometric := image photometric.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   500
    samplesPerPixel := image samplesPerPixel.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   501
    bitsPerSample := image bitsPerSample.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   502
    colorMap := image colorMap.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   503
    data := image bits.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   504
    bitsPerPixel := image bitsPerPixel.
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   505
842b6a603cdc Initial revision
claus
parents:
diff changeset
   506
    photometric == #rgb ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   507
        ^ self writePNMFileOn:outStream
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   508
    ].
842b6a603cdc Initial revision
claus
parents:
diff changeset
   509
    samplesPerPixel == 1 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   510
        (bitsPerPixel == 1) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   511
            ^ self writePBMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   512
        ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   513
        (bitsPerPixel == 8) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   514
            ^ self writePGMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   515
        ].
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   516
    ].
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   517
    ^ Image cannotRepresentImageSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   518
        raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   519
        errorString:('PBMReader cannot represent this image').
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   520
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   521
    "
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   522
     |img|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   523
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   524
     img := Image fromFile:'bitmaps/SBrowser.xbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   525
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   526
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   527
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   528
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   529
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   530
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   531
     |img mono|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   532
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   533
     img := Image fromFile:'bitmaps/garfield.gif'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   534
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   535
     mono := img asMonochromeFormOn:Display.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   536
     img := mono asImage.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   537
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   538
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   539
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   540
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   541
    "
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   542
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   543
    "Modified: / 30.9.1998 / 23:30:43 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   544
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   545
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   546
writeCommonHeader:format on:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   547
    "common header for P4, P5 and P5 formats"
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   548
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   549
    aStream nextPutAll:format; cr.
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   550
    aStream nextPutAll:'# From Smalltalk/X on '.
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   551
    aStream nextPutAll:(Date today printString).
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   552
    aStream nextPutAll:' at '; nextPutAll:(Time now printString).
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   553
    aStream cr.
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   554
    aStream nextPutAll:(width printString); space; nextPutAll:(height printString).
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   555
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   556
    "Created: / 14.10.1997 / 20:01:05 / cg"
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   557
    "Modified: / 1.4.1998 / 14:30:47 / cg"
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   558
!
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   559
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   560
writePBMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   561
    "Saves the receivers image on the file fileName in Portable Bitmap format."
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   562
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   563
    self writeCommonHeader:'P4' on:aStream.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   564
    aStream cr.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   565
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   566
    aStream binary.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   567
    photometric == #blackIs0 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   568
        aStream nextPutAll:data.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   569
    ] ifFalse:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   570
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   571
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   572
        data invert.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   573
    ].
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   574
    aStream close.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   575
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   576
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   577
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   578
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   579
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   580
     PBMReader save:i onFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   581
     i2 := Image fromFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   582
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   583
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   584
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   585
    "Modified: 14.10.1997 / 20:06:49 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   586
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   587
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   588
writePGMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   589
    "Saves the receivers image on the file fileName in Portable Greymap format."
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   590
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   591
    self writeCommonHeader:'P5' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   592
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   593
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   594
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   595
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   596
    data size ~~ (width * height) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   597
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   598
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   599
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   600
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   601
    photometric == #blackIs0 ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   602
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   603
    ] ifFalse:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   604
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   605
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   606
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   607
    ].
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   608
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   609
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   610
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   611
     |i gI i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   612
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   613
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   614
     gI := i asFloydSteinbergDitheredGrayImageDepth:8.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   615
     PBMReader save:gI onFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   616
     i2 := Image fromFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   617
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   618
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   619
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   620
    "Modified: 14.10.1997 / 20:06:58 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   621
!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   622
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   623
writePNMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   624
    "Saves the receivers image on the file fileName in Portable Anymap format."
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   625
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   626
    self writeCommonHeader:'P6' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   627
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   628
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   629
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   630
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   631
    data size ~~ (width * height * 3) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   632
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   633
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   634
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   635
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   636
    aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   637
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   638
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   639
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   640
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   641
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   642
     i := Image fromFile:'bitmaps/granite.tiff'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   643
     PBMReader save:i onFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   644
     i2 := Image fromFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   645
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   646
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   647
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   648
    "Modified: 14.10.1997 / 20:07:08 / cg"
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   649
! !
842b6a603cdc Initial revision
claus
parents:
diff changeset
   650
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   651
!PBMReader class methodsFor:'documentation'!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   652
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   653
version
1082
9b629fdac9ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1078
diff changeset
   654
    ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.37 1998-12-08 16:53:27 cg Exp $'
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   655
! !
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   656
PBMReader initialize!