PBMReader.st
author ca
Thu, 23 Oct 1997 15:36:34 +0200
changeset 716 a23d48401446
parent 713 548898fdd1dc
child 806 fc45835a5967
permissions -rw-r--r--
actionFor:aKey withValue:aValue allow argument for an action
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
     1
'From Smalltalk/X, Version:3.2.1 on 17-oct-1997 at 9:13:03 pm'                  !
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
     2
842b6a603cdc Initial revision
claus
parents:
diff changeset
     3
ImageReader subclass:#PBMReader
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
     4
	instanceVariableNames:''
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
     5
	classVariableNames:''
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
     6
	poolDictionaries:''
259
62b1bbafd9ba category change
Claus Gittinger <cg@exept.de>
parents: 234
diff changeset
     7
	category:'Graphics-Images-Support'
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
     8
!
842b6a603cdc Initial revision
claus
parents:
diff changeset
     9
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    10
!PBMReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    11
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    12
documentation
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    13
"
32
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    14
    this class provides methods for loading and saving Portable BitMap-file 
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    15
    images (Jef Poskanzers portable bitmap package).
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    16
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    17
    Reading is supported for 1bit (pbm), greyscale (pgm) and 24bit (ppm) formats.
507
d62283703efb documentation
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
    18
    (i.e. P1, P3, P4, P5 and P6 formats)
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    19
    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
    20
    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
    21
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    22
    Q: should we bring this one to perfection and base all others on
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
    23
       pipe-readers to the various pbmplus converters ?
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    24
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    25
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 210
diff changeset
    26
        Image Form Icon
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    27
        BlitImageReader FaceReader GIFReader JPEGReader PCXReader 
210
5405de794686 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
    28
        ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader 
209
840ddcf12904 commentary
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
    29
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    30
"
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
    31
! !
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    32
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    33
!PBMReader class methodsFor:'testing'!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    34
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    35
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    36
    "return true, if anImage can be represented in my file format.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    37
     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
    38
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    39
    |depth photometric|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    40
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    41
    anImage photometric == #rgb ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    42
        ^ depth==24
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    43
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    44
    (depth := anImage depth) == 1 ifTrue:[^ true].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    45
    depth == 8 ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    46
        photometric := anImage photometric.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    47
        ^ (photometric == #blackIs0) or:[photometric == #whiteIs0]
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    48
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    49
    ^ false
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    50
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    51
    "Modified: 17.10.1997 / 20:20:52 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    52
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 709
diff changeset
    53
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    54
!PBMReader methodsFor:'reading from file'!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    55
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    56
readDepth8PGMStream:aStream 
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    57
    "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
    58
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    59
    |maxval|
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    60
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    61
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    62
    width := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    63
    width > 0 ifFalse:[ 
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    64
        'PBMREADER: Invalid width' errorPrintNL.
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    65
        ^ nil
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    66
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    67
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    68
    height := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    69
    height > 0 ifFalse:[ 
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    70
        'PBMREADER: Invalid height' errorPrintNL.
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    71
        ^ nil
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    72
    ].
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    73
    self skipPBMJunkOn:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    74
    maxval := Integer readFrom:aStream.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    75
    maxval >= 256 ifTrue:[
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    76
        'PBMREADER: Invalid format' errorPrintNL.
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    77
        ^ nil
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    78
    ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    79
    aStream nextLine "skipThrough: Character cr".
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
    80
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
    81
    "/ the rest is the binary image data ...
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    82
    aStream binary.
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
    83
    data := ByteArray uninitializedNew:(width*height).
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
    84
    aStream nextBytes:(data size) into:data.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    85
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    86
    photometric := #blackIs0.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    87
    samplesPerPixel := 1.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    88
    bitsPerSample := #(8).
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
    89
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    90
    "Modified: 14.10.1997 / 19:44:05 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    91
! !
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    92
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
    93
!PBMReader methodsFor:'writing to file'!
842b6a603cdc Initial revision
claus
parents:
diff changeset
    94
842b6a603cdc Initial revision
claus
parents:
diff changeset
    95
save:image onFile:aFileName
842b6a603cdc Initial revision
claus
parents:
diff changeset
    96
    "save image as PBM/PGM/PNM file on aFileName"
842b6a603cdc Initial revision
claus
parents:
diff changeset
    97
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    98
    |bitsPerPixel|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
    99
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   100
    outStream := FileStream newFileNamed:aFileName.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   101
    outStream isNil ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   102
        'PBMReader [error]: file create error' errorPrintNL. 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   103
        ^ Image fileCreationErrorSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   104
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   105
            errorString:('file creation error: ' , aFileName asString).
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   106
    ].
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   107
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   108
    image mask notNil ifTrue:[
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   109
        Image informationLostQuerySignal
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   110
            raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   111
            errorString:('PBM format does not support an imageMask').
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   112
    ].
842b6a603cdc Initial revision
claus
parents:
diff changeset
   113
842b6a603cdc Initial revision
claus
parents:
diff changeset
   114
    width := image width.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   115
    height := image height.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   116
    photometric := image photometric.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   117
    samplesPerPixel := image samplesPerPixel.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   118
    bitsPerSample := image bitsPerSample.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   119
    colorMap := image colorMap.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   120
    data := image bits.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   121
    bitsPerPixel := image bitsPerPixel.
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   122
842b6a603cdc Initial revision
claus
parents:
diff changeset
   123
    photometric == #rgb ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   124
        ^ self writePNMFileOn:outStream
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   125
    ].
842b6a603cdc Initial revision
claus
parents:
diff changeset
   126
    samplesPerPixel == 1 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   127
        (bitsPerPixel == 1) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   128
            ^ self writePBMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   129
        ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   130
        (bitsPerPixel == 8) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   131
            ^ self writePGMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   132
        ].
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   133
    ].
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   134
    ^ Image cannotRepresentImageSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   135
        raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   136
        errorString:('PBMReader cannot represent this image').
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   137
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   138
    "
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   139
     |img|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   140
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   141
     img := Image fromFile:'bitmaps/SBrowser.xbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   142
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   143
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   144
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   145
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   146
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   147
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   148
     |img mono|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   149
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   150
     img := Image fromFile:'bitmaps/garfield.gif'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   151
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   152
     mono := img asMonochromeFormOn:Display.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   153
     img := mono asImage.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   154
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   155
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   156
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   157
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   158
    "
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   159
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   160
    "Modified: 14.10.1997 / 19:41:59 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   161
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   162
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   163
writeCommonHeader:format on:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   164
    "common header for P4, P5 and P5 formats"
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   165
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   166
    aStream nextPutAll:format; cr.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   167
    aStream nextPutAll:'#  Converted from Smalltalk Form on '.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   168
    aStream nextPutAll:Date today printString.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   169
    aStream nextPutAll:' at '; nextPutAll:Time now printString.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   170
    aStream cr.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   171
    aStream nextPutAll:width printString.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   172
    aStream space.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   173
    aStream nextPutAll:height printString.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   174
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   175
    "Created: 14.10.1997 / 20:01:05 / cg"
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   176
!
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   177
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   178
writePBMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   179
    "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
   180
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   181
    self writeCommonHeader:'P4' on:aStream.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   182
    aStream cr.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   183
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   184
    aStream binary.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   185
    photometric == #blackIs0 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   186
        aStream nextPutAll:data.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   187
    ] ifFalse:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   188
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   189
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   190
        data invert.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   191
    ].
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   192
    aStream close.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   193
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   194
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   195
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   196
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   197
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   198
     PBMReader save:i onFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   199
     i2 := Image fromFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   200
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   201
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   202
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   203
    "Modified: 14.10.1997 / 20:06:49 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   204
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   205
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   206
writePGMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   207
    "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
   208
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   209
    self writeCommonHeader:'P5' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   210
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   211
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   212
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   213
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   214
    data size ~~ (width * height) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   215
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   216
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   217
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   218
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   219
    photometric == #blackIs0 ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   220
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   221
    ] ifFalse:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   222
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   223
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   224
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   225
    ].
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   226
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   227
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   228
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   229
     |i gI i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   230
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   231
     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
   232
     gI := i asFloydSteinbergDitheredGrayImageDepth:8.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   233
     PBMReader save:gI onFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   234
     i2 := Image fromFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   235
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   236
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   237
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   238
    "Modified: 14.10.1997 / 20:06:58 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   239
!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   240
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   241
writePNMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   242
    "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
   243
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   244
    self writeCommonHeader:'P6' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   245
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   246
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   247
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   248
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   249
    data size ~~ (width * height * 3) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   250
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   251
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   252
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   253
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   254
    aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   255
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   256
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   257
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   258
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   259
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   260
     i := Image fromFile:'bitmaps/granite.tiff'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   261
     PBMReader save:i onFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   262
     i2 := Image fromFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   263
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   264
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   265
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   266
    "Modified: 14.10.1997 / 20:07:08 / cg"
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   267
! !
842b6a603cdc Initial revision
claus
parents:
diff changeset
   268