--- a/XBMReader.st Tue Sep 09 13:30:24 2003 +0200
+++ b/XBMReader.st Fri Sep 12 12:38:06 2003 +0200
@@ -52,6 +52,42 @@
[author:]
Claus Gittinger
"
+!
+
+examples
+"
+ Reading from a file:
+ [exBegin]
+ |image|
+
+ image := Image fromFile:('../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm').
+ image inspect
+ [exEnd]
+
+
+ Saving to a file:
+ [exBegin]
+ |image|
+
+ image := Image fromScreen:(0@0 corner:30@30).
+ image := image asThresholdMonochromeImage.
+ XBMReader save:image onFile:'/tmp/test.xbm'.
+ '/tmp/test.xbm' asFilename contents asString inspect.
+ (Image fromFile:('/tmp/test.xbm')) inspect.
+ [exEnd]
+
+
+ Or directly into a stream:
+ [exBegin]
+ |image stream|
+
+ image := Image fromScreen:(0@0 corner:30@30).
+ image := image asThresholdMonochromeImage.
+ stream := WriteStream on:(String new).
+ XPMReader save:image onStream:stream.
+ stream contents inspect.
+ [exEnd]
+"
! !
!XBMReader class methodsFor:'initialization'!
@@ -284,6 +320,48 @@
"save image as XBM file on aFileName.
Only depth1 b&w images can be represented in this format."
+ |stream|
+
+ "sigh - must check before creating file"
+ (self class canRepresent:image) ifFalse:[
+ ^ Image cannotRepresentImageSignal
+ raiseWith:image
+ errorString:('XBM format only supports monochrome images').
+ ].
+
+ image mask notNil ifTrue:[
+ Image informationLostQuerySignal
+ raiseWith:image
+ errorString:('XBM format does not support an imageMask').
+ ].
+
+ [
+ stream := aFileName asFilename newReadWriteStream.
+ ] on:FileStream openErrorSignal do:[:ex|
+ ^ Image fileCreationErrorSignal
+ raiseWith:image
+ errorString:('file creation error: ' , aFileName asString).
+ ].
+
+ self save:image onStream:stream.
+ stream close
+
+ "
+ XBMReader save:(Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm') onFile:'/tmp/test.xbm'
+ "
+ "
+ convert sun icon to XBM format:
+
+ XBMReader save:(Image fromFile:'bitmaps/hello_world.icon') onFile:'test.xbm'
+ "
+
+ "Modified: 27.2.1997 / 12:46:49 / cg"
+!
+
+save:image onStream:aStream
+ "save image as XBM cdata on aStream.
+ Only depth1 b&w images can be represented in this format."
+
|reverseBits bits byte
h "{ Class: SmallInteger }"
srcIndex "{ Class: SmallInteger }"
@@ -301,13 +379,7 @@
errorString:('XBM format does not support an imageMask').
].
- [
- outStream := aFileName asFilename newReadWriteStream.
- ] on:FileStream openErrorSignal do:[:ex|
- ^ Image fileCreationErrorSignal
- raiseWith:image
- errorString:('file creation error: ' , aFileName asString).
- ].
+ outStream := aStream.
width := image width.
height := image height.
@@ -348,24 +420,16 @@
outStream cr
].
outStream nextPutAll: '};'; cr.
- outStream close
"
- XBMReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.xbm'
- "
+ XBMReader save:(Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm') onStream:Transcript
"
- convert sun icon to XBM format:
-
- XBMReader save:(Image fromFile:'bitmaps/hello_world.icon') onFile:'test.xbm'
- "
-
- "Modified: 27.2.1997 / 12:46:49 / cg"
! !
!XBMReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.48 2003-09-01 14:47:52 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.49 2003-09-12 10:38:06 cg Exp $'
! !
XBMReader initialize!