PBMReader.st
author Claus Gittinger <cg@exept.de>
Thu, 01 Oct 1998 12:50:21 +0200
changeset 1078 fc33e172bbbc
parent 1064 27f923c3b93d
child 1082 9b629fdac9ec
permissions -rw-r--r--
raise informationLostSignal before attemting to write the file (avoid clobbering the file in case of an abort from an ex-handler)
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
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
    99
    |inStream pnmType|
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.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   104
    inStream next ~~ $P ifTrue:[^ false].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   105
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   106
    pnmType := inStream next.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   107
    (#( $1 $3 $4 $5 $6 $7) includes:pnmType) ifFalse:[^ false].
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   108
    ^ true
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   109
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   110
    "Created: / 3.2.1998 / 17:29:07 / cg"
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   111
    "Modified: / 7.9.1998 / 15:40:47 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   112
! !
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
!PBMReader methodsFor:'private'!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   115
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   116
skipPBMJunkOn:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   117
    "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
   118
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   119
    | char foundNL|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   120
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
        char := aStream peek.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   123
        [char == $#] whileTrue:[
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   124
            "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
   125
"/            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
   126
            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
   127
            foundNL ifFalse: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   128
                "Must be EOF"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   129
                ^self
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   130
            ].
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   131
            char := aStream peek
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   132
        ].
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   133
        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
   134
    ] whileTrue: [aStream next]
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   135
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   136
    "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
   137
    "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
   138
!
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
skipXPMJunkOn:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   141
    "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
   142
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   143
    | char |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   144
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
        char := aStream peek. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   147
        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
   148
    ] whileTrue: [aStream next].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   149
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   150
    [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
   151
        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
   152
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   153
    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
   154
    (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
   155
    (char == $") ifTrue: [ 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   156
        aStream next. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   157
        char := aStream peek. 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   158
        (char isLetterOrDigit 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   159
         or: [(char == $#) 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   160
         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
   161
            ^ self skipXPMJunkOn: aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   162
        ] ifTrue: [^char]
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   163
    ].
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
    ^self skipXPMJunkOn: aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   167
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   168
    "Created: / 3.2.1998 / 17:20:54 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
   169
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
   170
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   171
!PBMReader methodsFor:'reading from file'!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   172
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   173
fromStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   174
    "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
   175
     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
   176
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   177
    | pnmType |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   178
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   179
    inStream := aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   180
    inStream text.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   181
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   182
    inStream next == $P ifFalse:[
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   183
        ^ 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
   184
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   185
    pnmType := inStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   186
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   187
    (pnmType == $1) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   188
        ^ self readDepth1AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   189
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   190
    (pnmType == $3) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   191
        ^ self readDepth24AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   192
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   193
    (pnmType == $4) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   194
        ^ self readDepth1PBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   195
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   196
    (pnmType == $5) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   197
        ^ self readDepth8PGMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   198
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   199
    (pnmType == $6) ifTrue: [
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   200
        ^ self readDepth24PPMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   201
    ].
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   202
    (pnmType == $7) ifTrue: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   203
        ^ self readDepth8PPMStream:aStream
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   204
    ].
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   205
    ^ 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
   206
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
     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
   209
     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
   210
     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
   211
    "
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
    "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
   214
    "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
   215
!
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
readDepth1AsciiPBMStream:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   218
    "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
   219
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   220
    |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
   221
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   222
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   223
    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
   224
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   225
        ^ 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
   226
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   229
    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
   230
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   231
        ^ 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
   232
    ].
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
    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
   235
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   236
    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
   237
    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
   238
    rowIdx := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   239
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   240
    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
   241
        dstIdx := rowIdx.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   242
        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
   243
        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
   244
            char := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   245
            [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
   246
                char := aStream next
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   247
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   248
            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
   249
            char == $1 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   250
                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
   251
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   252
            n := n + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   253
            n == 8 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   254
                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
   255
                dstIdx := dstIdx + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   256
                bits := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   257
                n := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   258
            ].
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
        n ~~ 0 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   261
            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
   262
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   263
        rowIdx := rowIdx + bytesPerRow
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   264
    ].
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
    photometric := #whiteIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   267
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   268
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   269
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   270
    "Created: / 3.2.1998 / 17:21:22 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   271
    "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
   272
!
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
readDepth1PBMStream:aStream 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   275
    "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
   276
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   277
    |bytesPerRow|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   278
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   279
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   280
    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
   281
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   282
        ^ 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
   283
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   286
    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
   287
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   288
        ^ 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
   289
    ].
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
    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
   292
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   293
    bytesPerRow := width // 8.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   294
    ((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
   295
        bytesPerRow := bytesPerRow + 1
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   296
    ].
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
    "/ 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
   299
    aStream binary.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   300
    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
   301
    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
   302
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   303
    photometric := #blackIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   304
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   305
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   306
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   307
    "Created: / 3.2.1998 / 17:21:37 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   308
    "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
   309
!
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
readDepth24AsciiPBMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   312
    "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
   313
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   314
    |maxval 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   315
     nBytes "{Class: SmallInteger }" 
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   316
     v      "{Class: SmallInteger }"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   317
     c|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   318
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   319
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   320
    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
   321
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   322
        ^ 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
   323
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   326
    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
   327
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   328
        ^ 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
   329
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   332
    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
   333
    maxval >= 256 ifTrue: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   334
        ^ 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
   335
    ].
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
    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
   338
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   339
    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
   340
    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
   341
    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
   342
        aStream skipSeparators.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   343
        v := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   344
        c := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   345
        [c isDigit] whileTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   346
            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
   347
            c := aStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   348
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   349
        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
   350
    ].
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
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   353
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   354
    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
   355
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   356
    "Created: / 3.2.1998 / 17:21:55 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   357
    "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
   358
!
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
readDepth24PPMStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   361
    "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
   362
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   363
    | maxval |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   364
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   365
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   366
    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
   367
    width > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   368
        ^ 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
   369
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   372
    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
   373
    height > 0 ifFalse: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   374
        ^ 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
   375
    ].
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
    self skipPBMJunkOn:aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   378
    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
   379
    maxval >= 256 ifTrue: [
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   380
        ^ 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
   381
    ].
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
    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
   384
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   385
    "/ 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
   386
    aStream binary.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   387
    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
   388
    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
   389
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   390
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   391
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   392
    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
   393
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   394
    "Created: / 3.2.1998 / 17:22:18 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   395
    "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
   396
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   397
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   398
readDepth8PGMStream:aStream 
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   399
    "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
   400
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   401
    |maxval|
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   402
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   403
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   404
    width := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   405
    width > 0 ifFalse:[ 
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   406
        ^ self fileFormatError:'Invalid width'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   407
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   408
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   409
    height := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   410
    height > 0 ifFalse:[ 
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   411
        ^ self fileFormatError:'Invalid height'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   412
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   413
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   414
    maxval := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   415
    maxval >= 256 ifTrue:[
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   416
        ^ self fileFormatError:'Invalid format'.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   417
    ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   418
    aStream nextLine "skipThrough: Character cr".
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   419
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   420
    "/ the rest is the binary image data ...
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   421
    aStream binary.
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   422
    data := ByteArray uninitializedNew:(width*height).
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   423
    aStream nextBytes:(data size) into:data.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   424
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   425
    photometric := #blackIs0.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   426
    samplesPerPixel := 1.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   427
    bitsPerSample := #(8).
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   428
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   429
    "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
   430
!
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
readDepth8PPMStream:aStream
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   433
    "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
   434
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   435
    | maxval bitsRed bitsGreen bitsBlue|
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   436
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   437
    aStream skipSeparators.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   438
    bitsRed := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   439
    bitsGreen := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   440
    bitsBlue := aStream next - $0.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   441
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   442
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   443
    width := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   444
    width > 0 ifFalse: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   445
        ^ self fileFormatError:'Invalid width'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   446
    ].
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
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   449
    height := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   450
    height > 0 ifFalse: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   451
        ^ self fileFormatError:'Invalid height'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   452
    ].
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
    self skipPBMJunkOn:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   455
    maxval := Integer readFrom:aStream.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   456
    maxval >= 256 ifTrue: [
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   457
        ^ self fileFormatError:'Invalid format'.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   458
    ].
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
    aStream skipThrough: Character cr.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   461
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   462
    "/ the rest is the binary image data ...
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   463
    aStream binary.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   464
    data := ByteArray uninitializedNew:(width*height*1).
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   465
    aStream nextBytes:(data size) into:data.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   466
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   467
    photometric := #rgb.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   468
    samplesPerPixel := 3.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   469
    bitsPerSample := (Array with:bitsRed with:bitsGreen with:bitsBlue).
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   470
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   471
    "Created: / 7.9.1998 / 15:44:05 / cg"
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   472
    "Modified: / 7.9.1998 / 15:50:36 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   473
! !
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   474
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   475
!PBMReader methodsFor:'writing to file'!
842b6a603cdc Initial revision
claus
parents:
diff changeset
   476
842b6a603cdc Initial revision
claus
parents:
diff changeset
   477
save:image onFile:aFileName
842b6a603cdc Initial revision
claus
parents:
diff changeset
   478
    "save image as PBM/PGM/PNM file on aFileName"
842b6a603cdc Initial revision
claus
parents:
diff changeset
   479
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   480
    |bitsPerPixel|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   481
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   482
    image mask notNil ifTrue:[
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   483
        Image informationLostQuerySignal
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   484
            raiseWith:image
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   485
            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
   486
    ].
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   487
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   488
    outStream := FileStream newFileNamed:aFileName.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   489
    outStream isNil ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   490
        '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
   491
        ^ Image fileCreationErrorSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   492
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   493
            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
   494
    ].
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   495
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   496
    width := image width.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   497
    height := image height.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   498
    photometric := image photometric.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   499
    samplesPerPixel := image samplesPerPixel.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   500
    bitsPerSample := image bitsPerSample.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   501
    colorMap := image colorMap.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   502
    data := image bits.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   503
    bitsPerPixel := image bitsPerPixel.
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   504
842b6a603cdc Initial revision
claus
parents:
diff changeset
   505
    photometric == #rgb ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   506
        ^ self writePNMFileOn:outStream
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   507
    ].
842b6a603cdc Initial revision
claus
parents:
diff changeset
   508
    samplesPerPixel == 1 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   509
        (bitsPerPixel == 1) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   510
            ^ self writePBMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   511
        ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   512
        (bitsPerPixel == 8) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   513
            ^ self writePGMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   514
        ].
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   515
    ].
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   516
    ^ Image cannotRepresentImageSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   517
        raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   518
        errorString:('PBMReader cannot represent this image').
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   519
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   520
    "
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   521
     |img|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   522
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   523
     img := Image fromFile:'bitmaps/SBrowser.xbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   524
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   525
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   526
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   527
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   528
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   529
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   530
     |img mono|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   531
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   532
     img := Image fromFile:'bitmaps/garfield.gif'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   533
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   534
     mono := img asMonochromeFormOn:Display.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   535
     img := mono asImage.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   536
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   537
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   538
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   539
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   540
    "
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   541
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   542
    "Modified: / 30.9.1998 / 23:30:43 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   543
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   544
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   545
writeCommonHeader:format on:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   546
    "common header for P4, P5 and P5 formats"
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   547
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   548
    aStream nextPutAll:format; cr.
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   549
    aStream nextPutAll:'# From Smalltalk/X on '.
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   550
    aStream nextPutAll:(Date today printString).
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   551
    aStream nextPutAll:' at '; nextPutAll:(Time now printString).
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   552
    aStream cr.
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   553
    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
   554
884
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   555
    "Created: / 14.10.1997 / 20:01:05 / cg"
ce3134740a0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   556
    "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
   557
!
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
writePBMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   560
    "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
   561
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   562
    self writeCommonHeader:'P4' on:aStream.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   563
    aStream cr.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   564
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   565
    aStream binary.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   566
    photometric == #blackIs0 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   567
        aStream nextPutAll:data.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   568
    ] ifFalse:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   569
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   570
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   571
        data invert.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   572
    ].
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   573
    aStream close.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   574
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
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   577
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   578
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   579
     PBMReader save:i onFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   580
     i2 := Image fromFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   581
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   582
    "
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
    "Modified: 14.10.1997 / 20:06:49 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   585
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   586
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   587
writePGMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   588
    "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
   589
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   590
    self writeCommonHeader:'P5' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   591
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   592
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   593
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   594
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   595
    data size ~~ (width * height) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   596
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   597
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   598
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   599
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   600
    photometric == #blackIs0 ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   601
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   602
    ] ifFalse:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   603
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   604
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   605
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   606
    ].
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   607
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   608
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
     |i gI i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   611
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   612
     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
   613
     gI := i asFloydSteinbergDitheredGrayImageDepth:8.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   614
     PBMReader save:gI onFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   615
     i2 := Image fromFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   616
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   617
    "
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
    "Modified: 14.10.1997 / 20:06:58 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   620
!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   621
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   622
writePNMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   623
    "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
   624
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   625
    self writeCommonHeader:'P6' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   626
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   627
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   628
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   629
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   630
    data size ~~ (width * height * 3) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   631
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   632
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   633
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   634
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   635
    aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   636
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   637
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
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   640
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   641
     i := Image fromFile:'bitmaps/granite.tiff'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   642
     PBMReader save:i onFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   643
     i2 := Image fromFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   644
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   645
    "
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
    "Modified: 14.10.1997 / 20:07:08 / cg"
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   648
! !
842b6a603cdc Initial revision
claus
parents:
diff changeset
   649
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   650
!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
   651
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   652
version
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   653
    ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.36 1998-10-01 10:50:21 cg Exp $'
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   654
! !
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   655
PBMReader initialize!