Image.st
branchjv
changeset 7715 925b859e1758
parent 7600 8b42a8f0f649
parent 7659 01fe20eef85d
child 7716 3dba89415c91
--- a/Image.st	Fri Nov 18 20:50:35 2016 +0000
+++ b/Image.st	Fri Nov 18 21:26:33 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
               All Rights Reserved
@@ -153,7 +151,7 @@
                                             monoDeviceForm and lowResDeviceForm are
 
         deviceForm          <Form>          the device form which gives the best
-                                            possible aproximation of the image on
+                                            possible approximation of the image on
                                             device using standard colors.
 
         monoDeviceForm      <Form>          the device form which gives a monochrome
@@ -1142,6 +1140,17 @@
     ^ self width:ext x height:ext y fromArray:bits
 !
 
+fromDeviceForm:aForm maskForm:aMaskFormOrNil
+    "create & return an image form aForm that is already on a device"
+
+    |img|
+
+    img := self newForDepth:aForm depth.
+    img fromDeviceForm:aForm maskForm:aMaskFormOrNil.
+
+    ^ img 
+!
+
 fromForm:aForm
     "create & return an Image given a aForm"
 
@@ -2851,6 +2860,14 @@
     ^ device
 !
 
+drawableId
+    "return the id of the image on the device.
+     Return nil, if the image is unassigned."
+
+    deviceForm isNil ifTrue:[^ nil].
+    ^ deviceForm drawableId
+!
+
 extent
     "return the images extent"
 
@@ -2894,11 +2911,7 @@
 !
 
 id
-    "return the id of the image on the device.
-     Return nil, if the image is unassigned."
-
-    deviceForm isNil ifTrue:[^ nil].
-    ^ deviceForm id
+    ^ self drawableId  
 !
 
 imageSequence
@@ -8824,7 +8837,7 @@
                  * colors in subCubeColors.
                  *
                  * since the error is at most 1/16 (i.e. roughly 6%),
-                 * dont care for searching the best - simply take the
+                 * don't care for searching the best - simply take the
                  * first color found there.
                  * (statistic reduces the error to even a smaller value).
                  * There is no real problem due to that error, since
@@ -12974,7 +12987,7 @@
         "/ for now, ignore all depth's which are neither 1 nor the
         "/ devices depth.
         "/ (actually, many devices can handle other pixMap formats,
-        "/ but I dont know (yet) how to pass the correct color info
+        "/ but I don't know (yet) how to pass the correct color info
 
         ((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
 
@@ -13091,6 +13104,19 @@
     "Modified: 10.1.1997 / 17:52:21 / cg"
 !
 
+fromDeviceForm:aForm maskForm:aMaskFormOrNil
+    device := aForm device.
+    self assert:device notNil.
+    photometric := aForm photometric.
+    deviceForm := aForm.
+    width := aForm width.
+    height := aForm height.
+
+    aMaskFormOrNil notNil ifTrue:[
+        mask := Image fromDeviceForm:aMaskFormOrNil maskForm:nil.
+    ].
+!
+
 greyByteMapForRange:range
     "return a collection to map from pixelValues to greyLevels
      in the range 0..range.
@@ -14615,33 +14641,26 @@
 
     device := aDrawable graphicsDevice.
 
-    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
-        "/ a monochrome bitmap ?
-        visType := #StaticGray.
-        ddepth := 1.
-    ] ifFalse:[
-        (aDrawable isForm) ifFalse:[
-            "
-             get some attributes of the display device
-            "
-            visType := device visualType.
-            ddepth := device depth.
-        ] ifTrue:[
+    aDrawable isForm ifTrue:[
+        aDrawable depth == 1 ifTrue:[
+            "/ a monochrome bitmap ?
+            visType := #StaticGray.
+            ddepth := 1.
+        ] ifFalse:[
             visType := aDrawable photometric.
             ddepth := aDrawable depth.
-        ].
-    ].
-
-    "/ kludge for 15bit XFree server
-    ddepth == 15 ifTrue:[
-        ddepth := 16
-    ].
-
-    aDrawable isForm ifTrue:[
+        ]. 
         photometric := aDrawable photometric.
         samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
-        bitsPerSample := ddepth == 24 ifTrue:#[8 8 8 ] ifFalse:[ByteArray with:bpp].
+        bitsPerSample := ddepth == 24 ifTrue:#[8 8 8] ifFalse:[ByteArray with:bpp].
     ] ifFalse:[
+        "get some attributes of the display device"
+        visType := device visualType.
+        ddepth := device depth.
+        "/ kludge for 15bit XFree server
+        ddepth == 15 ifTrue:[
+            ddepth := 16
+        ].
         (visType == #StaticGray) ifTrue:[
             (device blackpixel == 0) ifTrue:[
                 photometric := #blackIs0
@@ -14700,8 +14719,6 @@
     ].
 
     bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
-    "/ inData := ByteArray uninitializedNew:(bytesPerLine * height).
-    inData := ByteArray new:(bytesPerLine * height).
 
     "
      get the pixels
@@ -14716,15 +14733,17 @@
                         yourself.
             inData := aDrawable bits.
         ] ifFalse:[
+            inData := ByteArray new:(bytesPerLine * height).
             info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData.
         ]
     ] ifFalse:[
+        inData := ByteArray new:(bytesPerLine * height).
         info := device getBitsFromViewId:aDrawable id x:x y:y width:w height:h into:inData.
     ].
 
     bitsPerPixelIn := info at:#bitsPerPixel.
 
-    isMSB := ((info at:#byteOrder) == #msbFirst).
+    isMSB := (info at:#byteOrder) == #msbFirst.
 
     "/
     "/ check if bitorder is what I like (msbFirst)
@@ -14755,7 +14774,7 @@
     maskB := info at:#blueMask ifAbsent:0.
 
     ((bytesPerLine ~~ bytesPerLineIn)
-    or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
+     or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
         tmpData := inData.
         inData := ByteArray uninitializedNew:(bytesPerLine * height).
 
@@ -15070,10 +15089,10 @@
     isLeft := leftOrRight sameAs:#left.
     isLeft ifTrue:[
         workPoint := (xRun - 1)@yRun.
-        [(
-            (tempForm pixelAtX:workPoint x y:workPoint y) == 0 and:[
-            (tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1]) and:[
-            (tempForm pixelAtX:workPoint x - 1 y:workPoint y + additionalY) == 1]
+        [
+            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
+            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
+            and:[ ((tempForm pixelAtX:workPoint x - 1 y:workPoint y + additionalY) == 1) ]]
         ] whileTrue:[
             startX := workPoint x.
             endX isNil ifTrue:[endX := workPoint x].
@@ -15081,10 +15100,10 @@
         ].
     ] ifFalse:[
         workPoint := (xRun + 1)@yRun.
-        [(
-            (tempForm pixelAtX:workPoint x y:workPoint y) == 0 and:[
-            (tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1]) and:[
-            (tempForm pixelAtX:workPoint x + 1 y:workPoint y + additionalY) == 1]
+        [
+            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
+            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
+            and:[ ((tempForm pixelAtX:workPoint x + 1 y:workPoint y + additionalY) == 1) ]]
         ] whileTrue:[
             endX := workPoint x.
             startX isNil ifTrue:[startX := workPoint x].
@@ -15141,10 +15160,10 @@
     isBottom := bottomOrTop sameAs:#bottom.
     isBottom ifTrue:[
         workPoint := xRun@(yRun + 1).
-        [(
-            (tempForm pixelAtX:workPoint x y:workPoint y) == 0 and:[
-            (tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1]) and:[
-            (tempForm pixelAtX:workPoint x + additionalX y:workPoint y + 1) == 1]
+        [
+            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
+            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
+            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y + 1) == 1) ]]
         ] whileTrue:[
             endY := workPoint y.
             startY isNil ifTrue:[startY := workPoint y].
@@ -15152,10 +15171,10 @@
         ].
     ] ifFalse:[
         workPoint := xRun@(yRun - 1).
-        [(
-            (tempForm pixelAtX:workPoint x y:workPoint y) == 0 and:[
-            (tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1]) and:[
-            (tempForm pixelAtX:workPoint x + additionalX y:workPoint y - 1) == 1]
+        [
+            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
+            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
+            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y - 1) == 1) ]]
         ] whileTrue:[
             startY := workPoint y.
             endY isNil ifTrue:[endY := workPoint y].