Image.st
changeset 924 d6d5d427b176
parent 916 ddc18f6280ed
child 927 c4bc2a7ff733
--- a/Image.st	Fri Jul 05 15:18:50 1996 +0200
+++ b/Image.st	Fri Jul 05 16:27:30 1996 +0200
@@ -553,14 +553,15 @@
 !
 
 fromForm:aForm
-    "create & return an Image given a form"
+    "create & return an Image given a aForm"
 
     |cls|
 
     cls := self.
     cls == Image ifTrue:[
-	cls := self implementorForDepth:aForm depth
-    ].
+        cls := self implementorForDepth:aForm depth
+    ].
+
     ^ (cls new) fromForm:aForm.
 
     "
@@ -572,6 +573,21 @@
      f inspect.
      (Image fromForm:f) inspect
     "
+
+    "
+     |f|
+
+     f := Form width:16 height:16 depth:(Display depth) on:Display.
+     f clear.
+     f paint:(Color red).
+     f displayLineFromX:0 y:0 toX:15 y:15.
+     f paint:(Color green).
+     f displayLineFromX:15 y:0 toX:0 y:15.
+     f inspect.
+     (Image fromForm:f) inspect
+    "
+
+    "Modified: 5.7.1996 / 16:26:12 / cg"
 !
 
 fromImage:anImage
@@ -3173,9 +3189,18 @@
 
     width := aForm width.
     height := aForm height.
-    bytes := aForm bits.
     bitsPerSample := self bitsPerSample.
     samplesPerPixel := self samplesPerPixel.
+
+    aForm hasBits ifFalse:[
+        "/ must read the data from the device
+        self from:aForm in:(0@0 extent:aForm extent).
+        ^ self
+    ].
+
+    "/ the form has all data available
+
+    bytes := aForm bits.
     map := aForm colorMap.
 
     aForm depth == 1 ifTrue:[
@@ -3209,7 +3234,7 @@
         ]
     ].
 
-    "Modified: 8.6.1996 / 16:02:03 / cg"
+    "Modified: 5.7.1996 / 16:24:31 / cg"
 !
 
 fromImage:anImage
@@ -8053,18 +8078,13 @@
 
 !Image methodsFor:'screen capture'!
 
-fromScreen:aRectangle
-    "read an image from the display screen"
-
-    ^ self fromScreen:aRectangle on:Screen current
-!
-
-fromScreen:aRectangle on:aDevice
-    "read an image from aDevices display screen.
-     Since I have no other displays, only the MonoChrome, StaticGrey 
-     and PseudoColor cases have been tested ... 
-     (especially True- and DirectColor may be wrong).
-     Late note: 24bit rgb now also works."
+from:aDrawable in:aRectangle
+    "read an image from aDrawable.
+     This may be a device Form, a view or the rootView.
+     If its a view or rootView, it must be completely visible (or have
+     the backingStore option turned on). Otherwise, only the clipped contents
+     is returned. This is a common helper for form-to-image conversion,
+     and to read hardcopy images from the screen."
 
     |depth visType 
      x        "{ Class: SmallInteger }"
@@ -8077,7 +8097,7 @@
      dstRow   "{ Class: SmallInteger }"
      inData tmpData usedPixels mapSize 
      map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel
-     info bitsPerPixelIn bytesPerLineIn curs cid rootView
+     info bitsPerPixelIn bytesPerLineIn 
      maskR "{ Class: SmallInteger }"
      maskG "{ Class: SmallInteger }"
      maskB "{ Class: SmallInteger }"
@@ -8090,20 +8110,15 @@
      r "{ Class: SmallInteger }"
      g "{ Class: SmallInteger }"
      b "{ Class: SmallInteger }"
-     word|
-
-    curs := Cursor sourceForm:(Form fromFile:'Camera.xbm')
-                     maskForm:(Form fromFile:'Camera_m.xbm')
-                      hotSpot:16@16.
-    curs notNil ifTrue:[
-        cid := (curs on:aDevice) id
-    ].
+     word device|
+
+    device := aDrawable device.
 
     "
      get some attributes of the display device
     "
-    visType := aDevice visualType.
-    depth := aDevice depth.
+    visType := device visualType.
+    depth := device depth.
 
     "/ kludge for 15bit XFree server
     depth == 15 ifTrue:[
@@ -8111,7 +8126,7 @@
     ].
 
     (visType == #StaticGray) ifTrue:[
-        (aDevice blackpixel == 0) ifTrue:[
+        (device blackpixel == 0) ifTrue:[
             photometric := #blackIs0
         ] ifFalse:[
             photometric := #whiteIs0
@@ -8130,9 +8145,9 @@
                 photometric := #rgb.
                 samplesPerPixel := 3.
 "/                bitsPerPixel := depth.
-"/                bitsPerSample := Array with:aDevice bitsRed
-"/                                       with:aDevice bitsGreen
-"/                                       with:aDevice bitsBlue
+"/                bitsPerSample := Array with:device bitsRed
+"/                                       with:device bitsGreen
+"/                                       with:device bitsBlue
                 bitsPerPixel := 24.
                 bitsPerSample := #(8 8 8).
             ] ifFalse:[
@@ -8170,17 +8185,9 @@
     inData := ByteArray uninitializedNew:(bytesPerLine * height).
 
     "
-     actually have to grabServer ... but thats not yet available
-    "
-    rootView := aDevice rootView.
-    aDevice setActivePointerGrab:rootView.
-    aDevice grabPointerIn:rootView id
-               withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil.
-
-    "
      get the pixels
     "
-    info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. 
+    info := device getBitsFrom:aDrawable id x:x y:y width:w height:h into:inData. 
 
     "
      check if byteorder is what I like (msbFirst)
@@ -8217,15 +8224,15 @@
         bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
             "/ for now, only 32 -> 24 is supported
 
-            maskR := (1 bitShift:aDevice bitsRed) - 1.
-            maskG := (1 bitShift:aDevice bitsGreen) - 1.
-            maskB := (1 bitShift:aDevice bitsBlue) - 1.
-            shR := aDevice shiftRed negated.
-            shG := aDevice shiftGreen negated.
-            shB := aDevice shiftBlue negated.
-            shR2 := (8 - aDevice bitsRed).
-            shG2 := (8 - aDevice bitsGreen).
-            shB2 := (8 - aDevice bitsBlue).
+            maskR := (1 bitShift:device bitsRed) - 1.
+            maskG := (1 bitShift:device bitsGreen) - 1.
+            maskB := (1 bitShift:device bitsBlue) - 1.
+            shR := device shiftRed negated.
+            shG := device shiftGreen negated.
+            shB := device shiftBlue negated.
+            shR2 := (8 - device bitsRed).
+            shG2 := (8 - device bitsGreen).
+            shB2 := (8 - device bitsBlue).
 
             ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
                 "/ 'reformatting 32->24...' printNL.
@@ -8318,13 +8325,56 @@
             |i|
 
             i := colorIndex + 1.
-            aDevice getRGBFrom:colorIndex into:[:r :g :b |
+            device getRGBFrom:colorIndex into:[:r :g :b |
                 map at:i put:(Color red:r green:g blue:b)
             ]
         ].
         colorMap := map.
     ].
 
+    "Modified: 5.7.1996 / 16:14:33 / cg"
+!
+
+fromScreen:aRectangle
+    "read an image from the display screen"
+
+    ^ self fromScreen:aRectangle on:Screen current
+!
+
+fromScreen:aRectangle on:aDevice
+    "read an image from aDevices display screen.
+     Since I have no other displays, only the MonoChrome, StaticGrey 
+     and PseudoColor cases have been tested ... 
+     (especially True- and DirectColor may be wrong).
+     Late note: 24bit rgb now also works."
+
+    |curs cid rootView|
+
+    curs := Cursor sourceForm:(Form fromFile:'Camera.xbm')
+                     maskForm:(Form fromFile:'Camera_m.xbm')
+                      hotSpot:16@16.
+    curs notNil ifTrue:[
+        cid := (curs on:aDevice) id
+    ].
+
+    "
+     actually have to grabServer ... but thats not yet available
+    "
+    rootView := aDevice rootView.
+    aDevice setActivePointerGrab:rootView.
+    aDevice grabPointerIn:rootView id
+               withCursor:cid 
+               pointerMode:#async 
+               keyboardMode:#sync 
+               confineTo:nil.
+
+
+    "
+     get the pixels
+    "
+    self from:rootView in:aRectangle.
+
+
     aDevice ungrabPointer.
 
     "
@@ -8332,12 +8382,12 @@
      (Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
     "
 
-    "Modified: 7.3.1996 / 19:17:33 / cg"
+    "Modified: 5.7.1996 / 16:16:51 / cg"
 ! !
 
 !Image  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.116 1996-07-05 12:39:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.117 1996-07-05 14:27:30 cg Exp $'
 ! !
 Image initialize!