XWDReader.st
changeset 204 277d2523d8cb
parent 114 e577a2f332d0
child 205 ddb3c0dfcc0d
--- a/XWDReader.st	Tue Apr 23 12:40:18 1996 +0200
+++ b/XWDReader.st	Tue Apr 23 12:43:27 1996 +0200
@@ -1,56 +1,59 @@
 "
- COPYRIGHT (c) 1995 by Claus Gittinger
-	      All Rights Reserved
+     COPYRIGHT (c) 1995 by Claus Gittinger
+              All Rights Reserved
 
- This software is furnished under a license and may be used
- only in accordance with the terms of that license and with the
- inclusion of the above copyright notice.   This software may not
- be provided or otherwise made available to, or used by, any
- other person.  No title to or ownership of the software is
- hereby transferred.
+     This software is furnished under a license and may be used
+     only in accordance with the terms of that license and with the
+     inclusion of the above copyright notice.   This software may not
+     be provided or otherwise made available to, or used by, any
+     other person.  No title to or ownership of the software is
+     hereby transferred.
 
 
- The above copyright does not apply to:
-	XWDReader>>save:onFile:
- which is in the public domain.
+     The above copyright does not apply to:
+        XWDReader>>save:onFile:
+     which was written by Brad Schoening <brad@boole.com> 
+     who placed it into the public domain.
 "
 
 ImageReader subclass:#XWDReader
-	 instanceVariableNames:''
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Graphics-Images support'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Graphics-Images support'
 !
 
 !XWDReader class methodsFor:'documentation'!
 
 copyright
 "
- COPYRIGHT (c) 1995 by Claus Gittinger
-	      All Rights Reserved
+     COPYRIGHT (c) 1995 by Claus Gittinger
+              All Rights Reserved
 
- This software is furnished under a license and may be used
- only in accordance with the terms of that license and with the
- inclusion of the above copyright notice.   This software may not
- be provided or otherwise made available to, or used by, any
- other person.  No title to or ownership of the software is
- hereby transferred.
+     This software is furnished under a license and may be used
+     only in accordance with the terms of that license and with the
+     inclusion of the above copyright notice.   This software may not
+     be provided or otherwise made available to, or used by, any
+     other person.  No title to or ownership of the software is
+     hereby transferred.
 
 
- The above copyright does not apply to:
-	XWDReader>>save:onFile:
- which is in the public domain.
+     The above copyright does not apply to:
+        XWDReader>>save:onFile:
+     which was written by Brad Schoening <brad@boole.com> 
+     who placed it into the public domain.
 "
 !
 
-version
-    ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.10 1995-11-11 16:05:49 cg Exp $'
-!
-
 documentation
 "
     this class provides methods for loading x-window dump (xwd) images.
-    Image save is not supported.
+    Both reading and writing of images is supported.
+
+    [See also:]
+        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
+        ST80FormReader SunRasterReader TIFFReader WindowsIconReader 
+        XBMReader XPMReader 
 "
 ! !
 
@@ -67,8 +70,8 @@
 
 !XWDReader methodsFor:'image reading'!
 
-fromStream: aStream 
-    "read an image in XWD (X Window Dump) format."
+fromStream:aStream 
+    "read an image in XWD (X Window Dump) format from aStream."
 
     |header nColors pad 
      srcRowByteSize bytesPerRow bitsPerPixel colormapSize depth 
@@ -88,13 +91,13 @@
 
     bitsPerPixel := header at: 12.
     bitsPerPixel == 24 ifTrue:[
-	bitsPerSample := #(8 8 8).
-	samplesPerPixel := 3.
-	photometric := #rgb
+        bitsPerSample := #(8 8 8).
+        samplesPerPixel := 3.
+        photometric := #rgb
     ] ifFalse:[
-	bitsPerSample := Array with:bitsPerPixel.
-	samplesPerPixel := 1.
-	photometric := #palette
+        bitsPerSample := Array with:bitsPerPixel.
+        samplesPerPixel := 1.
+        photometric := #palette
     ].
 "/  depth ~~ bitsPerPixel ifTrue:[self halt].
 
@@ -104,37 +107,37 @@
     colorMap := Array new:colormapSize.
 
     1 to:nColors do:[:i |
-	|clr r g b|
+        |clr r g b|
 
-	aStream nextLong.
-	r := aStream nextUnsignedShortMSB:true.
-	g := aStream nextUnsignedShortMSB:true.
-	b := aStream nextUnsignedShortMSB:true.
-	clr := ColorValue scaledRed: (r bitShift: -3)
-			scaledGreen: (g bitShift: -3)
-			 scaledBlue: (b bitShift: -3).
-	colorMap at:i put:clr.
-	aStream nextWord.
+        aStream nextLong.
+        r := aStream nextUnsignedShortMSB:true.
+        g := aStream nextUnsignedShortMSB:true.
+        b := aStream nextUnsignedShortMSB:true.
+        clr := ColorValue scaledRed: (r bitShift: -3)
+                        scaledGreen: (g bitShift: -3)
+                         scaledBlue: (b bitShift: -3).
+        colorMap at:i put:clr.
+        aStream nextWord.
     ].
 
     nColors+1 to:colormapSize do: [:i | colorMap at:i put:Color black].
 
     bytesPerRow := width * bitsPerPixel // 8.
     ((width * bitsPerPixel \\ 8) ~~ 0) ifTrue:[
-	bytesPerRow := bytesPerRow + 1
+        bytesPerRow := bytesPerRow + 1
     ].
     srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8).
 
     data := ByteArray uninitializedNew: srcRowByteSize * height.
     srcRowByteSize == bytesPerRow ifTrue:[
-	aStream nextBytes:srcRowByteSize * height into:data.
+        aStream nextBytes:srcRowByteSize * height into:data.
     ] ifFalse:[
-	dstIndex := 1.
-	1 to:height do:[:y |
-	    aStream nextBytes:bytesPerRow into:data startingAt:dstIndex.
-	    aStream next:(srcRowByteSize - bytesPerRow).
-	    dstIndex := dstIndex + bytesPerRow.
-	].
+        dstIndex := 1.
+        1 to:height do:[:y |
+            aStream nextBytes:bytesPerRow into:data startingAt:dstIndex.
+            aStream next:(srcRowByteSize - bytesPerRow).
+            dstIndex := dstIndex + bytesPerRow.
+        ].
     ]
     "
      XWDReader fromFile:'testfile.xwd'
@@ -150,31 +153,31 @@
 save:image onFile:fileName
     "Save as a version 7 color X11 window dump file (xwd) to the file fileName.
      This produces a mapped color table with 16 bit color.  The xwd file can be 
-     viewed by the xwud program and printed with xpr.  There is no compression 
-     encoding performed on the scanlines.
+     viewed by the xwud program and printed with xpr.  
+     No compression is performed.
 
      See the file ...include/X11/XWDFile.h for a definition of the format.
 
      Notice:
-	this method was adapted from a goody in the uiuc archive 
-	(Prime time freeware).
-	The original files header is:
-	    NAME            imageToXWD
-	    AUTHOR          Brad Schoening <brad@boole.com>
-	    FUNCTION        Writes a Smalltalk image to an X11 xwd file
-	    ST-VERSION      PPST 4.0 or 4.1
-	    DISTRIBUTION    world
-	    VERSION         1.0
-	    DATE            July 1993
+        this method was adapted from a goody in the uiuc archive 
+        (Prime time freeware).
+        The original files header is:
+            NAME            imageToXWD
+            AUTHOR          Brad Schoening <brad@boole.com>
+            FUNCTION        Writes a Smalltalk image to an X11 xwd file
+            ST-VERSION      PPST 4.0 or 4.1
+            DISTRIBUTION    world
+            VERSION         1.0
+            DATE            July 1993
 
-	thanks to Brad for giving us the base for this mehtod.
+        thanks to Brad for giving us the base for this mehtod.
     "
 
     |aStream rgbColor paletteColors ncolors dumpName headerSize|
 
     (self class canRepresent:image) ifFalse:[
-	self error:'XWD format only supports 8bit palette images'.
-	^ nil
+        self error:'XWD format only supports 8bit palette images'.
+        ^ nil
     ].
 
     dumpName := 'stdin'.
@@ -219,28 +222,28 @@
 "/    [(aStream position rem: 4) == 0] whileFalse: [ aStream nextPut: 0 ].
 
     "Write out the color table.  Each color table entry is 12 bytes long composed of:
-		    an index                (4 bytes)
-		    red color value         (2 bytes)
-		    green color value       (2 bytes)
-		    blue color value        (2 bytes)
-		    flag values             (1 byte)
-		    pad                     (1 byte)
+                    an index                (4 bytes)
+                    red color value         (2 bytes)
+                    green color value       (2 bytes)
+                    blue color value        (2 bytes)
+                    flag values             (1 byte)
+                    pad                     (1 byte)
     "
     0 to: ncolors-1 do: [ :index |
-	|r g b|
+        |r g b|
 
-	aStream nextLongPut: index.
-	rgbColor := paletteColors at: (1+index).
-	(rgbColor isNil) ifTrue: [ rgbColor := ColorValue white ].
-	r := (rgbColor red / 100.0 * 65535) rounded.
-	g := (rgbColor green / 100.0 * 65535) rounded.
-	b := (rgbColor blue / 100.0 * 65535) rounded.
+        aStream nextLongPut: index.
+        rgbColor := paletteColors at: (1+index).
+        (rgbColor isNil) ifTrue: [ rgbColor := ColorValue white ].
+        r := (rgbColor red / 100.0 * 65535) rounded.
+        g := (rgbColor green / 100.0 * 65535) rounded.
+        b := (rgbColor blue / 100.0 * 65535) rounded.
 
-	aStream nextWordPut:r.
-	aStream nextWordPut:g.
-	aStream nextWordPut:b.
-	aStream nextPut: 7.                     "flags"
-	aStream nextPut: 0.                     "pad"
+        aStream nextWordPut:r.
+        aStream nextWordPut:g.
+        aStream nextWordPut:b.
+        aStream nextPut: 7.                     "flags"
+        aStream nextPut: 0.                     "pad"
     ].
 
     "Write out the pixels as index color values"
@@ -261,3 +264,9 @@
      (Image fromFile: '/tmp/st.xwd') inspect 
     "
 ! !
+
+!XWDReader class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.11 1996-04-23 10:43:27 cg Exp $'
+! !