PBMReader.st
author Stefan Vogel <sv@exept.de>
Mon, 13 Mar 2017 09:54:33 +0100
changeset 3941 dd9237d3a727
parent 1848 864ca2cd4e71
child 3855 1db7742d33ad
permissions -rw-r--r--
#BUGFIX by stefan class: MIMETypes application/xml -> #isXmlType
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
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
    17
	instanceVariableNames:'maxVal'
200
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
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   117
!PBMReader methodsFor:'private-reading'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   118
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   119
readMaxVal
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   120
    self skipPBMJunk.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   121
    maxVal := Integer readFrom:inStream onError:nil.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   122
    (maxVal isNil or:[maxVal >= 256]) ifTrue: [
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   123
        self fileFormatError:'Invalid format'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   124
        ^ false.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   125
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   126
    ^ true
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   127
!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   128
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   129
readWidthAndHeight
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   130
    self skipPBMJunk.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   131
    width := Integer readFrom:inStream onError:0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   132
    width > 0 ifFalse: [
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   133
        self fileFormatError:'Invalid width'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   134
        ^ false
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   135
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   136
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   137
    self skipPBMJunk.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   138
    height := Integer readFrom:inStream onError:0.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   139
    height > 0 ifFalse: [
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   140
        self fileFormatError:'Invalid height'.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   141
        ^ false
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   142
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   143
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   144
    self reportDimension.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   145
    ^ true
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   146
!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   147
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   148
readWidthAndHeightAndMaxVal
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   149
    (self readWidthAndHeight) ifFalse:[ ^ false ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   150
    ^ self readMaxVal
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   151
!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   152
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   153
skipPBMJunk
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   154
    "this method removes any superfluous characters from the input stream."
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   155
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   156
    | char foundNL|
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   157
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   158
    [
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   159
        char := inStream peek.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   160
        [char == $#] whileTrue:[
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   161
            "Start of a comment. Skip to end-of-line."
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   162
"/            foundNL := (aStream skipUpTo: Character cr) notNil.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   163
            foundNL := (inStream skipThrough: Character cr) notNil.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   164
            foundNL ifFalse: [
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   165
                "Must be EOF"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   166
                ^self
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   167
            ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   168
            char := inStream peek
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   169
        ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   170
        inStream atEnd not and: [char isSeparator]
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   171
    ] whileTrue: [inStream next]
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   172
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   173
    "Created: / 3.2.1998 / 17:20:37 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   174
    "Modified: / 7.9.1998 / 15:49:07 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   175
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   176
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   177
!PBMReader methodsFor:'private-writing'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   178
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   179
writeCommonHeader:format on:aStream
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   180
    "common header for P4, P5 and P5 formats"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   181
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   182
    aStream nextPutAll:format; cr.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   183
    aStream nextPutAll:'# From Smalltalk/X on '.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   184
    aStream nextPutAll:(Date today printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   185
    aStream nextPutAll:' at '; nextPutAll:(Time now printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   186
    aStream cr.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   187
    aStream nextPutAll:(width printString); space; nextPutAll:(height printString).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   188
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   189
    "Created: / 14.10.1997 / 20:01:05 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   190
    "Modified: / 1.4.1998 / 14:30:47 / cg"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   191
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   192
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   193
!PBMReader methodsFor:'reading'!
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   194
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   195
fromStream:aStream
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   196
    "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
   197
     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
   198
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   199
    | pnmType |
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   200
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   201
    inStream := aStream.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   202
    inStream text.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   203
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   204
    inStream next == $P ifFalse:[
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   205
        ^ 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
   206
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   207
    pnmType := inStream next.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   208
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   209
    (pnmType == $1) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   210
        ^ self readDepth1AsciiPBMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   211
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   212
    (pnmType == $3) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   213
        ^ self readDepth24AsciiPBMStream
807
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
    (pnmType == $4) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   216
        ^ self readDepth1PBMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   217
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   218
    (pnmType == $5) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   219
        ^ self readDepth8PGMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   220
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   221
    (pnmType == $6) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   222
        ^ self readDepth24PPMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   223
    ].
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   224
    (pnmType == $7) ifTrue: [
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   225
        ^ self readDepth8PPMStream
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   226
    ].
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   227
    ^ 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
   228
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
     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
   231
     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
   232
     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
   233
    "
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   234
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   235
    "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
   236
    "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
   237
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   238
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   239
readDepth1AsciiPBMStream 
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   240
    "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
   241
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   242
    |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
   243
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   244
    (self readWidthAndHeight) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   245
    inStream nextLine "skipThrough: Character cr".
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   246
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   247
    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
   248
    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
   249
    rowIdx := 1.
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
    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
   252
        dstIdx := rowIdx.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   253
        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
   254
        1 to:width do:[:col |
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   255
            char := inStream next.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   256
            [char notNil and:[char isSeparator]] whileTrue:[
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   257
                char := inStream next
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   258
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   259
            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
   260
            char == $1 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   261
                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
   262
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   263
            n := n + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   264
            n == 8 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   265
                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
   266
                dstIdx := dstIdx + 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   267
                bits := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   268
                n := 0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   269
            ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   270
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   271
        n ~~ 0 ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   272
            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
   273
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   274
        rowIdx := rowIdx + bytesPerRow
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
    photometric := #whiteIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   278
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   279
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   280
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   281
    "Created: / 3.2.1998 / 17:21:22 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   282
    "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
   283
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   284
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   285
readDepth1PBMStream 
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   286
    "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
   287
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   288
    |bytesPerRow|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   289
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   290
    (self readWidthAndHeight) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   291
    inStream nextLine "skipThrough: Character cr".
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
    bytesPerRow := width // 8.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   294
    ((width \\ 8) ~~ 0) ifTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   295
        bytesPerRow := bytesPerRow + 1
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   296
    ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   297
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   298
    "/ the rest is the binary image data ...
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   299
    inStream binary.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   300
    data := ByteArray uninitializedNew:(bytesPerRow*height).
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   301
    inStream nextBytes:(data size) into:data.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   302
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   303
    photometric := #blackIs0.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   304
    samplesPerPixel := 1.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   305
    bitsPerSample := #(1).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   306
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   307
    "Created: / 3.2.1998 / 17:21:37 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   308
    "Modified: / 3.2.1998 / 17:56:59 / cg"
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   309
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   310
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   311
readDepth24AsciiPBMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   312
    "import ascii portable pixmap (PBM, P3 format); P3 is already read"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   313
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   314
    |nBytes "{Class: SmallInteger }" 
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   315
     v      "{Class: SmallInteger }"
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   316
     c|
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   317
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   318
    (self readWidthAndHeightAndMaxVal) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   319
    inStream nextLine "skipThrough: Character cr".
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   320
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   321
    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
   322
    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
   323
    1 to:nBytes do:[:i |
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   324
        inStream skipSeparators.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   325
        v := 0.
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   326
        c := inStream next.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   327
        [c isDigit] whileTrue:[
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   328
            v := v * 10 + (c digitValue).
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   329
            c := inStream next.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   330
        ].
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   331
        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
   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
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   335
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   336
    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
   337
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   338
    "Created: / 3.2.1998 / 17:21:55 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   339
    "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
   340
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   341
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   342
readDepth24PPMStream
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   343
    "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
   344
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   345
    (self readWidthAndHeightAndMaxVal) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   346
    inStream nextLine "skipThrough: Character cr".
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   347
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   348
    "/ the rest is the binary image data ...
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   349
    inStream binary.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   350
    data := ByteArray uninitializedNew:(width*height*3).
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   351
    inStream nextBytes:(data size) into:data.
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   352
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   353
    photometric := #rgb.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   354
    samplesPerPixel := 3.
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   355
    bitsPerSample := #(8 8 8).
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   356
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   357
    "Created: / 3.2.1998 / 17:22:18 / cg"
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   358
    "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
   359
!
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   360
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   361
readDepth8PGMStream
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   362
    "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
   363
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   364
    (self readWidthAndHeightAndMaxVal) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   365
    inStream nextLine "skipThrough: Character cr".
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   366
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   367
    "/ the rest is the binary image data ...
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   368
    inStream binary.
523
f26a8b493514 faster data read
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
   369
    data := ByteArray uninitializedNew:(width*height).
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   370
    inStream nextBytes:(data size) into:data.
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   371
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   372
    photometric := #blackIs0.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   373
    samplesPerPixel := 1.
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   374
    bitsPerSample := #(8).
506
e029bc0ede3a support P3 (ascii) encoding
Claus Gittinger <cg@exept.de>
parents: 461
diff changeset
   375
811
86a93acb3be7 use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   376
    "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
   377
!
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   378
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   379
readDepth8PPMStream
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   380
    "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
   381
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   382
    | bitsRed bitsGreen bitsBlue|
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   383
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   384
    inStream skipSeparators.
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   385
    bitsRed := inStream next - $0.
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   386
    bitsGreen := inStream next - $0.
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   387
    bitsBlue := inStream next - $0.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   388
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   389
    (self readWidthAndHeightAndMaxVal) ifFalse:[^ nil].
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   390
    inStream nextLine "skipThrough: Character cr".
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   391
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   392
    "/ the rest is the binary image data ...
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   393
    inStream binary.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   394
    data := ByteArray uninitializedNew:(width*height*1).
1845
9e16152a374f dimensionReport & refactoring
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   395
    inStream nextBytes:(data size) into:data.
1064
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   396
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   397
    photometric := #rgb.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   398
    samplesPerPixel := 3.
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   399
    bitsPerSample := (Array with:bitsRed with:bitsGreen with:bitsBlue).
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   400
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   401
    "Created: / 7.9.1998 / 15:44:05 / cg"
27f923c3b93d added P7 format support (8bit rgb).
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   402
    "Modified: / 7.9.1998 / 15:50:36 / cg"
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
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   405
!PBMReader methodsFor:'writing'!
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   406
1814
2f204c2a957d image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   407
save:image onStream:aStream
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   408
    "save image as PBM/PGM/PNM file on aFileName"
842b6a603cdc Initial revision
claus
parents:
diff changeset
   409
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   410
    |bitsPerPixel|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   411
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   412
    image mask notNil ifTrue:[
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   413
        Image informationLostQuerySignal
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   414
            raiseWith:image
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   415
            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
   416
    ].
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   417
1814
2f204c2a957d image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   418
    outStream := aStream.
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   419
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   420
    width := image width.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   421
    height := image height.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   422
    photometric := image photometric.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   423
    samplesPerPixel := image samplesPerPixel.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   424
    bitsPerSample := image bitsPerSample.
842b6a603cdc Initial revision
claus
parents:
diff changeset
   425
    colorMap := image colorMap.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   426
    data := image bits.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   427
    bitsPerPixel := image bitsPerPixel.
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   428
842b6a603cdc Initial revision
claus
parents:
diff changeset
   429
    photometric == #rgb ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   430
        ^ self writePNMFileOn:outStream
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   431
    ].
842b6a603cdc Initial revision
claus
parents:
diff changeset
   432
    samplesPerPixel == 1 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   433
        (bitsPerPixel == 1) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   434
            ^ self writePBMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   435
        ].
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   436
        (bitsPerPixel == 8) ifTrue:[
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   437
            ^ self writePGMFileOn:outStream
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   438
        ].
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   439
    ].
1814
2f204c2a957d image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   440
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   441
    ^ Image cannotRepresentImageSignal 
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   442
        raiseWith:image
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   443
        errorString:('PBMReader cannot represent this image').
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   444
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   445
    "
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   446
     |img|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   447
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   448
     img := Image fromFile:'bitmaps/SBrowser.xbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   449
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   450
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   451
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   452
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   453
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   454
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   455
     |img mono|
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   456
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   457
     img := Image fromFile:'bitmaps/garfield.gif'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   458
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   459
     mono := img asMonochromeFormOn:Display.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   460
     img := mono asImage.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   461
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   462
     PBMReader save:img onFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   463
     img := Image fromFile:'test.pbm'.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   464
     img inspect.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   465
    "
461
bacef118f54a more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   466
1078
fc33e172bbbc raise informationLostSignal before attemting to write the file
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
   467
    "Modified: / 30.9.1998 / 23:30:43 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   468
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   469
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   470
writePBMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   471
    "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
   472
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   473
    self writeCommonHeader:'P4' on:aStream.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   474
    aStream cr.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   475
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   476
    aStream binary.
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   477
    photometric == #blackIs0 ifTrue:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   478
        aStream nextPutAll:data.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   479
    ] ifFalse:[
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   480
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   481
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   482
        data invert.
46
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   483
    ].
c49b204c2ef0 *** empty log message ***
claus
parents: 32
diff changeset
   484
    aStream close.
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   485
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   486
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   487
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   488
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   489
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   490
     PBMReader save:i onFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   491
     i2 := Image fromFile:'foo.pbm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   492
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   493
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   494
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   495
    "Modified: 14.10.1997 / 20:06:49 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   496
!
66b31c91177f *** empty log message ***
claus
parents: 16
diff changeset
   497
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   498
writePGMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   499
    "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
   500
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   501
    self writeCommonHeader:'P5' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   502
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   503
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   504
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   505
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   506
    data size ~~ (width * height) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   507
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   508
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   509
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   510
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   511
    photometric == #blackIs0 ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   512
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   513
    ] ifFalse:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   514
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   515
        aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   516
        data invert.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   517
    ].
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   518
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   519
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   520
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   521
     |i gI i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   522
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   523
     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
   524
     gI := i asFloydSteinbergDitheredGrayImageDepth:8.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   525
     PBMReader save:gI onFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   526
     i2 := Image fromFile:'foo.pgm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   527
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   528
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   529
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   530
    "Modified: 14.10.1997 / 20:06:58 / cg"
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   531
!
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   532
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   533
writePNMFileOn:aStream
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   534
    "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
   535
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   536
    self writeCommonHeader:'P6' on:aStream.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   537
    aStream space.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   538
    aStream nextPutAll:255 printString.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   539
    aStream cr.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   540
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   541
    data size ~~ (width * height * 3) ifTrue:[
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   542
        "/ self halt:'data size mismatch'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   543
    ].
200
33e4adf6fd59 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   544
709
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   545
    aStream binary.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   546
    aStream nextPutAll:data.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   547
    aStream close.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   548
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   549
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   550
     |i i2|
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   551
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   552
     i := Image fromFile:'bitmaps/granite.tiff'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   553
     PBMReader save:i onFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   554
     i2 := Image fromFile:'foo.pnm'.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   555
     i2 inspect.
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   556
    "
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   557
813553f7bd20 added write for P4, P5 and P6 formats.
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   558
    "Modified: 14.10.1997 / 20:07:08 / cg"
2
842b6a603cdc Initial revision
claus
parents:
diff changeset
   559
! !
842b6a603cdc Initial revision
claus
parents:
diff changeset
   560
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   561
!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
   562
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   563
version
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1845
diff changeset
   564
    ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.42 2003-11-19 15:38:51 cg Exp $'
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   565
! !
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
   566
807
855f41b1ec1a oops - all readers were lost from 1.28 to 1.29
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   567
PBMReader initialize!