#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Tue, 31 Jan 2017 13:44:38 +0100
changeset 7814 aa4d64730bca
parent 7813 f9a9a63d6263
child 7815 2e9d68bbeeb6
#REFACTORING by stefan class: Image comment/format in: #asDitheredTrueColor8FormOn: #floodFillAt:withValue: #fromImage:photometric: #fromSubImage:in: changed:22 methods SmallLint refactoring
Image.st
--- a/Image.st	Tue Jan 31 13:37:31 2017 +0100
+++ b/Image.st	Tue Jan 31 13:44:38 2017 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
               All Rights Reserved
@@ -1273,7 +1275,7 @@
     |cls|
 
     self == Image ifTrue:[
-        cls := (self implementorForDepth:anImage depth).
+        cls := self implementorForDepth:anImage depth.
     ] ifFalse:[
         cls := self.
     ].
@@ -1309,8 +1311,9 @@
      i24 inspect
     "
 
-    "Created: 20.9.1995 / 01:05:43 / claus"
-    "Modified: 24.4.1997 / 23:13:02 / cg"
+    "Created: / 20-09-1995 / 01:05:43 / claus"
+    "Modified: / 24-04-1997 / 23:13:02 / cg"
+    "Modified (format): / 30-01-2017 / 19:45:54 / stefan"
 !
 
 new
@@ -1734,8 +1737,8 @@
             inStream := fn readStream.
             zipStream := ZipStream readOpenOn:inStream suppressHeaderAndChecksum:true.
             zipStream notNil ifTrue:[
-                [
-                    image := readerClass fromStream:zipStream.
+                image := [
+                    readerClass fromStream:zipStream.
                 ] ensure:[
                     zipStream close.
                     inStream close.
@@ -1822,6 +1825,7 @@
     "
 
     "Modified: / 19-11-2007 / 15:50:52 / cg"
+    "Modified: / 30-01-2017 / 19:48:06 / stefan"
 !
 
 fromFile:aFileName inPackage:aPackage
@@ -2307,12 +2311,11 @@
                                                 with:aRectangle top
                                                 with:aRectangle width
                                                 with:aRectangle height).
-            [
-                img := Image fromFile:tmpFile.
+            ^ [
+                Image fromFile:tmpFile.
             ] ensure:[
                 tmpFile remove.
             ].
-            ^ img.
         ].
     ].
 
@@ -2333,7 +2336,8 @@
     img := self newForDepth:depth.
     ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
 
-    "Modified: / 26.1.1998 / 22:23:08 / cg"
+    "Modified: / 26-01-1998 / 22:23:08 / cg"
+    "Modified: / 30-01-2017 / 19:49:01 / stefan"
 !
 
 fromScreenArea
@@ -2930,11 +2934,13 @@
 !
 
 setColorMap:aColorMap
-    (aColorMap isNil or:[aColorMap isKindOf:Colormap]) ifFalse:[
-        colorMap := MappedPalette withColors:aColorMap
-    ] ifTrue:[
-        colorMap := aColorMap
-    ]
+    colorMap isColormap ifTrue:[
+        colorMap := aColorMap.
+    ] ifFalse:[
+        colorMap := MappedPalette withColors:aColorMap.
+    ].
+
+    "Modified: / 30-01-2017 / 19:15:34 / stefan"
 !
 
 width
@@ -3650,15 +3656,15 @@
     "/ bitsPerPixel := d.
     d == 24 ifTrue:[
         samplesPerPixel := 3.
-        bitsPerSample := #(8 8 8)
+        bitsPerSample := #[8 8 8]
     ] ifFalse:[
         d == 32 ifTrue:[
             samplesPerPixel := 4.
-            bitsPerSample := #(8 8 8 8)
+            bitsPerSample := #[8 8 8 8]
         ] ifFalse:[
             d == 16 ifTrue:[
                 samplesPerPixel := 3.
-                bitsPerSample := #(5 5 5).
+                bitsPerSample := #[5 5 5].
                 "/ bitsPerPixel := 15.
             ] ifFalse:[
                 samplesPerPixel := 1.
@@ -3668,6 +3674,7 @@
     ]
 
     "Modified: / 27-05-2007 / 16:59:47 / cg"
+    "Modified: / 30-01-2017 / 19:36:00 / stefan"
 !
 
 extent:anExtent
@@ -3999,8 +4006,9 @@
     newBits isNil ifTrue:[
         self error:'dithering failed'
     ].
-    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
-
+    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits; yourself
+
+    "Modified: / 30-01-2017 / 19:40:19 / stefan"
 !
 
 asErrorDitheredMonochromeImage
@@ -4638,24 +4646,27 @@
     "Modified: 14.6.1996 / 15:17:28 / cg"
 !
 
-asGrayImageDepth:depth
+asGrayImageDepth:depthArg
     "get a gray image from the receiver"
 
-    ((self colorMap notNil and:[depth <= 8 and:[depth >= self depth]])
-    or:[ self depth >= 8 "do need for dither" ]) ifTrue:[
+    ((self colorMap notNil and:[depthArg between:self depth and:8])
+     or:[self depth >= 8 "do need for dither" ]) ifTrue:[
         ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
     ].
-    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
-
-    "
-     |i|
-
-     i := Image fromFile:'goodies/bitmaps/claus.gif'.
-     (i asGrayFormOn:Display) inspect.
-    "
-
-    "Modified: 10.6.1996 / 17:39:30 / cg"
-    "Created: 10.6.1996 / 19:07:08 / cg"
+    ^ self asGrayImageDepth:depthArg dither:DitherAlgorithm.
+
+    "
+     |i|
+
+     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
+     (i asGrayImageDepth:16).
+     (i asGrayImageDepth:4).
+    "
+
+    "Modified: / 10-06-1996 / 17:39:30 / cg"
+    "Created: / 10-06-1996 / 19:07:08 / cg"
+    "Modified: / 30-01-2017 / 20:13:06 / stefan"
+    "Modified (comment): / 31-01-2017 / 13:25:29 / stefan"
 !
 
 asGrayImageDepth:depth dither:aDitherAlgorithm
@@ -4919,7 +4930,9 @@
     newBits isNil ifTrue:[
         self error:'conversion failed'
     ].
-    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
+    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits; yourself
+
+    "Modified: / 30-01-2017 / 19:40:28 / stefan"
 !
 
 asOrderedDitheredGrayFormOn:aDevice
@@ -5761,9 +5774,7 @@
 
     |map clr mappedRowPixels samePhotometric
      h "{ Class: SmallInteger }"
-     w "{ Class: SmallInteger }"
-     a r g b rgbPixel
-     myDepth otherDepth|
+     w "{ Class: SmallInteger }" myDepth otherDepth|
 
     width := anImage width.
     height := anImage height.
@@ -5786,7 +5797,7 @@
     ].
     self mask:anImage mask.
 
-    samePhotometric := (photometric == anImage photometric).
+    samePhotometric := photometric == anImage photometric.
     myDepth := self depth.
     otherDepth := anImage depth.
 
@@ -5888,6 +5899,7 @@
     "
 
     "Modified: / 22-11-2016 / 03:34:08 / cg"
+    "Modified (format): / 30-01-2017 / 20:46:22 / stefan"
 !
 
 fromSubImage:anImage in:aRectangle
@@ -6114,7 +6126,7 @@
 
     pictureDepth := bitsPerSample at:1.
 
-    (#(2 4 8) includes:pictureDepth) ifFalse:[
+    (#[2 4 8] includes:pictureDepth) ifFalse:[
         self error:'currently only depth-2, 4 or 8 supported'.
         ^ nil
     ].
@@ -6225,7 +6237,8 @@
         with:(f initGC).
     ^ f
 
-    "Modified: 19.10.1997 / 05:19:44 / cg"
+    "Modified: / 19-10-1997 / 05:19:44 / cg"
+    "Modified: / 30-01-2017 / 19:37:01 / stefan"
 !
 
 greyImageAsTrueColorFormOn:aDevice
@@ -6352,7 +6365,8 @@
         ^ self asMonochromeFormOn:aDevice
     ].
 
-    ((type := aDevice visualType) == #StaticGray) ifTrue:[
+    type := aDevice visualType.
+    (type == #StaticGray) ifTrue:[
         ddepth == 8 ifTrue:[
             ^ self paletteImageAsGray8FormOn:aDevice
         ].
@@ -6377,7 +6391,8 @@
 
     ^ self paletteImageAsPseudoFormOn:aDevice
 
-    "Modified: 14.6.1996 / 19:31:01 / cg"
+    "Modified: / 14-06-1996 / 19:31:01 / cg"
+    "Modified: / 30-01-2017 / 20:55:32 / stefan"
 !
 
 paletteImageAsPseudoFormOn:aDevice
@@ -6386,7 +6401,7 @@
     |tempImage d temp8|
 
     d := self depth.
-    (#(1 2 4 8) includes:d) ifTrue:[
+    (#[1 2 4 8] includes:d) ifTrue:[
         "
          fallback code for some depth's:
          create a temporary Depth8Image and use its conversion method
@@ -6404,6 +6419,8 @@
         ^ tempImage paletteImageAsPseudoFormOn:aDevice
     ].
     ^ self subclassResponsibility
+
+    "Modified: / 30-01-2017 / 19:37:57 / stefan"
 !
 
 paletteImageAsTrueColorFormOn:aDevice
@@ -6557,9 +6574,9 @@
     shiftGreen := aDevice shiftGreen.
     shiftBlue := aDevice shiftBlue.
 
-    nRed := (1 bitShift:aDevice bitsRed).
-    nGreen := (1 bitShift:aDevice bitsGreen).
-    nBlue := (1 bitShift:aDevice bitsBlue).
+    nRed := 1 bitShift:aDevice bitsRed.
+    nGreen := 1 bitShift:aDevice bitsGreen.
+    nBlue := 1 bitShift:aDevice bitsBlue.
 
     fixColors := Array new:(nRed * nGreen * nBlue).
 
@@ -6570,7 +6587,7 @@
                 pixel := (sR bitShift:shiftRed)
                          + (sG bitShift:shiftGreen)
                          + (sB bitShift:shiftBlue).
-                fixColors at:dstIdx put:(Color colorId:(pixel)).
+                fixColors at:dstIdx put:(Color colorId:pixel).
                 dstIdx := dstIdx + 1
             ]
         ]
@@ -6581,8 +6598,9 @@
         colors:fixColors
         nRed:nRed nGreen:nGreen nBlue:nBlue
 
-    "Created: 14.6.1996 / 17:23:52 / cg"
-    "Modified: 23.6.1997 / 15:22:36 / cg"
+    "Created: / 14-06-1996 / 17:23:52 / cg"
+    "Modified: / 23-06-1997 / 15:22:36 / cg"
+    "Modified (format): / 30-01-2017 / 19:06:08 / stefan"
 !
 
 compressColorMap
@@ -6816,16 +6834,17 @@
      and clear out any device handles in the copy."
 
     bytes := bytes copy.
-    (colorMap isNil or:[colorMap isKindOf:Colormap]) ifFalse:[
+    colorMap isColormap ifTrue:[
+        colorMap := colorMap copy.
+    ] ifFalse:[
         colorMap := MappedPalette withColors:colorMap.
-    ] ifTrue:[
-        colorMap := colorMap copy.
     ].
     device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
     mask := mask copy.
     maskedPixelsAre0 := false.
 
-    "Modified: / 22.8.1998 / 11:27:09 / cg"
+    "Modified: / 22-08-1998 / 11:27:09 / cg"
+    "Modified: / 30-01-2017 / 19:16:02 / stefan"
 !
 
 skipInstvarIndexInDeepCopy:index
@@ -7073,9 +7092,9 @@
      w       "{Class: SmallInteger }"
      h       "{Class: SmallInteger }"
      index   "{Class: SmallInteger }"
+     lookupPos "{Class: SmallInteger }"
      ditherIds failed lastColor qScramble
-     clrLookup lookupPos
-     error clr|
+     clrLookup error clr|
 
     self depth ~~ 24 ifTrue:[^ nil].
 
@@ -7154,10 +7173,10 @@
         i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
         lookupPos := i.
 
-        [index < lookupPos] whileTrue:[
-            clrLookup at:(index+1) put:(clrPosition-1-1).
-            index := index + 1
-        ]
+        index+1 to:lookupPos do:[:idx|
+            clrLookup at:idx put:(clrPosition-1-1).
+        ].
+        index := lookupPos.
     ].
     clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
 
@@ -7527,6 +7546,8 @@
     ].
 
     ^ pseudoBits
+
+    "Modified: / 30-01-2017 / 19:58:45 / stefan"
 !
 
 floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
@@ -9965,7 +9986,7 @@
 
     processPixelToFill :=
         [:spX :spY |
-            |samePixel sp idx|
+            |samePixel idx|
 
             mask isNil ifTrue:[
                 samePixel := (self pixelAtX:spX y:spY) == detectedPixel
@@ -10033,7 +10054,8 @@
     self release. "/ device-image is no longer valid
     ^ allDetectedPixelCoordinates
 
-    "Modified: / 29.7.1998 / 03:09:16 / cg"
+    "Modified: / 29-07-1998 / 03:09:16 / cg"
+    "Modified (format): / 30-01-2017 / 20:57:36 / stefan"
 !
 
 rectangle: aRectangle withColor:aColor
@@ -12035,7 +12057,7 @@
         ].
 
 
-    photometric == #palette ifFalse:[
+    photometric ~~ #palette ifTrue:[
         "/ direct manipulation of the pixels
         0 to:yMax do:[:y |
             0 to:xMax do:[:x |
@@ -12050,7 +12072,7 @@
         anyChange ifFalse:[
             ^ nil
         ].
-    ] ifTrue:[
+    ] ifFalse:[
         "/ manipulate the colormap
         0 to:yMax do:[:y |
             0 to:xMax do:[:x |
@@ -12089,6 +12111,8 @@
     ].
 
     ^ newImage
+
+    "Modified: / 30-01-2017 / 20:15:02 / stefan"
 !
 
 withPixelFunctionApplied:pixelFunctionBlock
@@ -12428,6 +12452,21 @@
     self photometric:(self class defaultPhotometric)
 ! !
 
+!Image methodsFor:'inspecting'!
+
+inspector2TabImage
+    "an extra tab showing the image;
+     Q: is this needed? (the displayObject tab already shows this)"
+    
+    ^ self newInspector2Tab
+        label: 'Image';
+        priority: 50;
+        view: ((HVScrollableView for:ImageView) image: self; yourself);
+        yourself
+
+    "Created: / 11-10-2011 / 17:12:01 / cg"
+    "Modified: / 30-01-2017 / 19:40:57 / stefan"
+! !
 
 !Image methodsFor:'instance release'!
 
@@ -13372,13 +13411,14 @@
     samplesPerPixel == 4 ifTrue:[
         "/ assume that the cyan bits are the leftMost bits (cmyk)
 
-        bitsPerSample = #(8 8 8 8) ifTrue:[
+        (#[8 8 8 8] isSameSequenceAs:bitsPerSample) ifTrue:[
             ^ 100.0 / 255 * (pixel bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified (format): / 31-01-2017 / 13:15:23 / stefan"
 !
 
 blueBitsOf:pixel
@@ -13595,14 +13635,14 @@
 
     samplesPerPixel == 3 ifTrue:[
         "/ assume that the cyan bits are the leftMost bits (cmy)
-
-        bitsPerSample = #(8 8 8) ifTrue:[
+        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified (format): / 31-01-2017 / 13:15:56 / stefan"
 !
 
 cyanComponentOfCMYK:pixel
@@ -13611,14 +13651,14 @@
 
     samplesPerPixel == 4 ifTrue:[
         "/ assume that the cyan bits are the leftMost bits (cmyk)
-
-        bitsPerSample = #(8 8 8 8) ifTrue:[
+        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * ((pixel bitShift:-24) bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified: / 31-01-2017 / 13:16:14 / stefan"
 !
 
 greenBitsOf:pixel
@@ -13746,15 +13786,14 @@
      return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
 
     samplesPerPixel == 3 ifTrue:[
-        "/ assume that the cyan bits are the leftMost bits (cmy)
-
-        bitsPerSample = #(8 8 8) ifTrue:[
+        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified (format): / 31-01-2017 / 13:19:06 / stefan"
 !
 
 magentaComponentOfCMYK:pixel
@@ -13762,15 +13801,14 @@
      return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
 
     samplesPerPixel == 4 ifTrue:[
-        "/ assume that the cyan bits are the leftMost bits (cmyk)
-
-        bitsPerSample = #(8 8 8 8) ifTrue:[
+        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified (format): / 31-01-2017 / 13:19:11 / stefan"
 !
 
 nColorsUsed
@@ -14291,9 +14329,7 @@
      return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
 
     samplesPerPixel == 3 ifTrue:[
-        "/ assume that the cyan bits are the leftMost bits (cmy)
-
-        bitsPerSample = #(8 8 8) ifTrue:[
+        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * (pixel bitAnd:16rFF)
         ]
     ].
@@ -14301,6 +14337,7 @@
 
     self subclassResponsibility
 
+    "Modified (format): / 31-01-2017 / 13:18:47 / stefan"
 !
 
 yellowComponentOfCMYK:pixel
@@ -14308,15 +14345,14 @@
      return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
 
     samplesPerPixel == 4 ifTrue:[
-        "/ assume that the cyan bits are the leftMost bits (cmyk)
-
-        bitsPerSample = #(8 8 8 8) ifTrue:[
+        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
             ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
         ]
     ].
 
     self subclassResponsibility
 
+    "Modified: / 31-01-2017 / 13:19:00 / stefan"
 ! !
 
 !Image methodsFor:'saving on file'!
@@ -14572,7 +14608,7 @@
     "/                                       with:device bitsGreen
     "/                                       with:device bitsBlue
                     bpp := "bitsPerPixel :=" 24.
-                    bitsPerSample := #(8 8 8).
+                    bitsPerSample := #[8 8 8].
                 ] ifFalse:[
                     self error:'screen visual not supported'.
                     ^ nil
@@ -14793,8 +14829,8 @@
         self setColorMap:map.
     ].
 
-    "Modified: / 9.1.1998 / 21:32:36 / stefan"
-    "Modified: / 7.2.1998 / 18:23:07 / cg"
+    "Modified: / 07-02-1998 / 18:23:07 / cg"
+    "Modified: / 30-01-2017 / 19:36:36 / stefan"
 !
 
 fromScreen:aRectangle