PBMReader.st
changeset 461 bacef118f54a
parent 398 aef700d15416
child 506 e029bc0ede3a
equal deleted inserted replaced
460:2c2215c50c28 461:bacef118f54a
   349 save:image onFile:aFileName
   349 save:image onFile:aFileName
   350     "save image as PBM/PGM/PNM file on aFileName"
   350     "save image as PBM/PGM/PNM file on aFileName"
   351 
   351 
   352     outStream := FileStream newFileNamed:aFileName.
   352     outStream := FileStream newFileNamed:aFileName.
   353     outStream isNil ifTrue:[
   353     outStream isNil ifTrue:[
   354 	'PBMREADER: create error' errorPrintNL. 
   354         'PBMReader [error]: file create error' errorPrintNL. 
   355 	^ nil
   355         ^ Image fileCreationErrorSignal 
       
   356             raiseWith:image
       
   357             errorString:('file creation error: ' , aFileName asString).
       
   358     ].
       
   359 
       
   360     image mask notNil ifTrue:[
       
   361         Image informationLostQuerySignal
       
   362             raiseWith:image
       
   363             errorString:('PBM format does not support an imageMask').
   356     ].
   364     ].
   357 
   365 
   358     width := image width.
   366     width := image width.
   359     height := image height.
   367     height := image height.
   360     photometric := image photometric.
   368     photometric := image photometric.
   362     bitsPerSample := image bitsPerSample.
   370     bitsPerSample := image bitsPerSample.
   363     colorMap := image colorMap.
   371     colorMap := image colorMap.
   364     data := image bits.
   372     data := image bits.
   365 
   373 
   366     photometric == #rgb ifTrue:[
   374     photometric == #rgb ifTrue:[
   367 	^ self writePNMFileOn:outStream
   375         ^ self writePNMFileOn:outStream
   368     ].
   376     ].
   369     samplesPerPixel == 1 ifTrue:[
   377     samplesPerPixel == 1 ifTrue:[
   370 	((bitsPerSample at:1) == 1) ifTrue:[
   378         ((bitsPerSample at:1) == 1) ifTrue:[
   371 	    ^ self writePBMFileOn:outStream
   379             ^ self writePBMFileOn:outStream
   372 	].
   380         ].
   373 	((bitsPerSample at:1) == 8) ifTrue:[
   381         ((bitsPerSample at:1) == 8) ifTrue:[
   374 	    ^ self writePGMFileOn:outStream
   382             ^ self writePGMFileOn:outStream
   375 	].
   383         ].
   376     ].
   384     ].
   377     self error:'format not supported'.
   385     ^ Image cannotRepresentImageSignal 
       
   386         raiseWith:image
       
   387         errorString:('PBMReader cannot represent this image').
   378 
   388 
   379     "
   389     "
   380      |img|
   390      |img|
   381 
   391 
   382      img := Image fromFile:'bitmaps/SBrowser.xbm'.
   392      img := Image fromFile:'bitmaps/SBrowser.xbm'.
   395      img inspect.
   405      img inspect.
   396      PBMReader save:img onFile:'test.pbm'.
   406      PBMReader save:img onFile:'test.pbm'.
   397      img := Image fromFile:'test.pbm'.
   407      img := Image fromFile:'test.pbm'.
   398      img inspect.
   408      img inspect.
   399     "
   409     "
       
   410 
       
   411     "Modified: 27.2.1997 / 12:45:42 / cg"
   400 !
   412 !
   401 
   413 
   402 writePBMFileOn:aStream
   414 writePBMFileOn:aStream
   403     "Saves the receivers image on the file fileName in Portable Bitmap format.
   415     "Saves the receivers image on the file fileName in Portable Bitmap format.
   404      See the class method pbmSyntax for details of the format."
   416      See the class method pbmSyntax for details of the format."
   437 ! !
   449 ! !
   438 
   450 
   439 !PBMReader class methodsFor:'documentation'!
   451 !PBMReader class methodsFor:'documentation'!
   440 
   452 
   441 version
   453 version
   442     ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.21 1997-02-01 14:05:30 cg Exp $'
   454     ^ '$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.22 1997-02-27 11:49:40 cg Exp $'
   443 ! !
   455 ! !
   444 PBMReader initialize!
   456 PBMReader initialize!