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