#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Tue, 31 Jan 2017 16:17:37 +0100
changeset 7824 1ecfb677d8d7
parent 7823 5a255f3fbbd6
child 7825 07ea44507793
#REFACTORING by stefan class: Image comment/format in: #extent:depth:palette: #skipInstvarIndexInDeepCopy: changed: #colorMap: #computeBitsFromPixelFunction #extent:depth:antiAliasedPalette:bgColor:mixedArray: #from:in: #fromFile: #fromFile:resolution:on: #fromSubForm:in: #greyImageAsTrueColorFormOn: #negative #paletteImageAsTrueColorFormOn: #pixelArraySpecies #threeDProjected:and: #valueFromRGB: #valuesFromX:y:toX:y:do: SmallLint
Image.st
--- a/Image.st	Tue Jan 31 13:48:23 2017 +0100
+++ b/Image.st	Tue Jan 31 16:17:37 2017 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
               All Rights Reserved
@@ -988,9 +986,8 @@
 !
 
 extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
-    |colors colorMap colorIndex colorDictionary tmpDic newImage emptyBits|
-
-    colors := OrderedCollection new.
+    |colorMap colorIndex colorDictionary tmpDic newImage|
+
     colorMap := OrderedCollection new.
     colorIndex := 0.
     colorDictionary := Dictionary new.
@@ -1046,13 +1043,15 @@
             from:0
             angle:360
             withColor:Color blue
-            antiAliasedPalette:aaImgArray first
-            startWith:aaImgArray second.
+            colorDictionary:aaImgArray first
+            blendStart:aaImgArray second.
 
         aaImgArray last inspect.
     "
 
     "Modified: / 02-11-2010 / 20:57:41 / cg"
+    "Modified: / 31-01-2017 / 14:30:22 / stefan"
+    "Modified (comment): / 31-01-2017 / 15:47:39 / stefan"
 !
 
 extent:ext depth:d bits:bits
@@ -1084,7 +1083,7 @@
     "create & return a blank image of the given size.
      ST-80 compatibility"
 
-    |newImage emptyBits|
+    |newImage|
 
     newImage := (self implementorForDepth:d) new.
     newImage width:ext x height:ext y depth:d palette:aColormap.
@@ -1101,6 +1100,7 @@
 
     "Created: / 06-03-1997 / 15:24:01 / cg"
     "Modified: / 02-11-2010 / 20:56:53 / cg"
+    "Modified (format): / 31-01-2017 / 14:51:03 / stefan"
 !
 
 extent:ext depth:d palette:aColormap bits:bits
@@ -1216,7 +1216,7 @@
     depth := aForm depth.
     formsDevice := aForm device.
 
-    photometric := (depth > 8) ifTrue:#rgb ifFalse:#palette.
+    photometric := (depth > 8) ifTrue:[#rgb] ifFalse:[#palette].
 
     (formsDevice notNil and:[depth == formsDevice depth]) ifTrue:[
         "/
@@ -1263,6 +1263,8 @@
      (Image fromForm:f) inspect.
      (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
     "
+
+    "Modified: / 31-01-2017 / 15:03:17 / stefan"
 !
 
 fromSubImage:anImage in:aRectangle
@@ -1746,8 +1748,11 @@
             ]
         ] ifFalse:[
             BadImageFormatQuerySignal handle:[:ex |
-                BadImageFormatQuerySignal isHandled ifTrue:[ ex reject ].
-                Transcript showCR:(readersErrorMsg := ex description).
+                BadImageFormatQuerySignal isHandled ifTrue:[
+                    ex reject
+                ].
+                readersErrorMsg := ex description.
+                Logger warning:readersErrorMsg.
                 image := nil.
                 ex return.
             ] do:[
@@ -1825,7 +1830,7 @@
     "
 
     "Modified: / 19-11-2007 / 15:50:52 / cg"
-    "Modified: / 30-01-2017 / 19:48:06 / stefan"
+    "Modified: / 31-01-2017 / 15:56:14 / stefan"
 !
 
 fromFile:aFileName inPackage:aPackage
@@ -1901,7 +1906,9 @@
     ] ifFalse:[
         dpiH := 90
     ].
-    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
+    (dpi between:(dpiH * 0.75) and:(dpiH * 1.5)) ifTrue:[
+        ^ img
+    ].
     mag := (dpiH / dpi) rounded.
     mag = 0 ifTrue:[^ img].
     mag = 1 ifTrue:[^ img].
@@ -1912,7 +1919,8 @@
     ].
     ^ img
 
-    "Modified: 1.2.1997 / 14:48:20 / cg"
+    "Modified: / 01-02-1997 / 14:48:20 / cg"
+    "Modified (format): / 31-01-2017 / 15:06:23 / stefan"
 !
 
 fromStream:aStream
@@ -2681,8 +2689,7 @@
 colorMap:aColorMap
     "set the colorMap; this also sets the photometric to a useful default."
 
-    |newSize "{ Class: SmallInteger }"
-     oldSize "{ Class: SmallInteger }"
+    |oldSize "{ Class: SmallInteger }"
      sameColors|
 
     (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
@@ -2691,7 +2698,8 @@
 
     photometric == #palette ifTrue:[
         "/ any change at all ?
-        (newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
+        oldSize := colorMap size.
+        aColorMap size >= oldSize ifTrue:[
             sameColors := true.
 
             1 to:oldSize do:[:idx |
@@ -2718,8 +2726,9 @@
         self release
     ]
 
-    "Modified: / 31.8.1995 / 03:05:59 / claus"
-    "Modified: / 22.8.1998 / 12:29:58 / cg"
+    "Modified: / 31-08-1995 / 03:05:59 / claus"
+    "Modified: / 22-08-1998 / 12:29:58 / cg"
+    "Modified: / 31-01-2017 / 14:48:56 / stefan"
 !
 
 colorMapFromArray: anArray
@@ -6245,8 +6254,7 @@
     "return a true-color device-form for the grey-image receiver.
      TODO: the pixel loops ought to be implemented as inline primitive code ..."
 
-    |depth
-     myDepth    "{ Class: SmallInteger }"
+    |myDepth    "{ Class: SmallInteger }"
      nColors    "{ Class: SmallInteger }"
      colorValues
      scaleDown
@@ -6265,7 +6273,6 @@
     "/ this is a slow fallback method; this ought to be
     "/ redefined in DepthxImage for more performance.
 
-    depth := aDevice depth.
     myDepth := self depth.
     myDepth > 16 ifTrue:[
         self error:'unsupported depth' mayProceed:true.
@@ -6350,6 +6357,7 @@
 
     "Created: / 20-10-1995 / 22:05:10 / cg"
     "Modified: / 05-02-2011 / 10:40:13 / cg"
+    "Modified (format): / 31-01-2017 / 14:42:05 / stefan"
 ! !
 
 !Image methodsFor:'converting palette images'!
@@ -6426,8 +6434,7 @@
 paletteImageAsTrueColorFormOn:aDevice
     "return a true-color device-form for the palette-image receiver."
 
-    |depth
-     nColors "{ Class: SmallInteger }"
+    |nColors "{ Class: SmallInteger }"
      h       "{ Class: SmallInteger }"
      pixel   "{ Class: SmallInteger }"
      colorValues
@@ -6439,8 +6446,6 @@
     "/ this is a slow fallback method; this ought to be
     "/ redefined in DepthxImage for more performance.
 
-    depth := aDevice depth.
-
     bestFormat := self bestSupportedImageFormatFor:aDevice.
     usedDeviceDepth := bestFormat at:#depth.
     usedDeviceDepth == 1 ifTrue:[
@@ -6507,7 +6512,7 @@
             self rowAt:y into:pixelArray.
             1 to:width do:[:x |
                 pixel := pixelArray at:x.
-                newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:0).
+                newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:[0]).
             ].
             i rowAt:y putAll:newPixelArray.
         ].
@@ -6551,7 +6556,8 @@
 
     ^ form
 
-    "Modified: / 24.7.1998 / 00:56:14 / cg"
+    "Modified: / 24-07-1998 / 00:56:14 / cg"
+    "Modified: / 31-01-2017 / 15:01:05 / stefan"
 ! !
 
 !Image methodsFor:'converting rgb images'!
@@ -6853,6 +6859,9 @@
 
     "
         self allInstanceVariableNames indexOf:#device
+        self allInstanceVariableNames indexOf:#deviceForm
+        self allInstanceVariableNames indexOf:#monoDeviceForm
+        self allInstanceVariableNames indexOf:#fullColorDeviceForm
     "
 
     index == 13 ifTrue:[
@@ -6868,6 +6877,8 @@
         ^ true "/ skip fullColorDeviceForm
     ].
     ^ false
+
+    "Modified (comment): / 31-01-2017 / 15:41:40 / stefan"
 ! !
 
 !Image methodsFor:'displaying'!
@@ -10197,18 +10208,19 @@
      should be redefined in concrete subclasses, to avoid some processing
      when going from pixel to pixel (i.e. the byte-index and mask computations)."
 
-    |xS "{Class: SmallInteger }"
-     xE "{Class: SmallInteger }"|
-
-    xS := xStart.
-    xE := xEnd.
-    yStart to:yEnd do:[:yRun |
+    |yS "{Class: SmallInteger }"
+     yE "{Class: SmallInteger }"|
+
+    yS := yStart.
+    yE := yEnd.
+    yS to:yE do:[:yRun |
         self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
             aBlock value:xRun value:yRun value:pixel
         ]
     ]
 
-    "Modified: 7.6.1996 / 19:09:29 / cg"
+    "Modified: / 07-06-1996 / 19:09:29 / cg"
+    "Modified: / 31-01-2017 / 14:46:26 / stefan"
 ! !
 
 !Image methodsFor:'finalization'!
@@ -11764,21 +11776,19 @@
 
      ^ self
         copyWithColorMapProcessing:[:clr |
-                |newColor|
-
-                newColor := Color
-                                redByte:(255 - clr redByte)
-                                greenByte:(255 - clr greenByte)
-                                blueByte:(255 - clr blueByte)
-        ]
+                Color
+                    redByte:(255 - clr redByte)
+                    greenByte:(255 - clr greenByte)
+                    blueByte:(255 - clr blueByte)
+            ]
 
     "
      (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
      (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
     "
 
-    "Created: 20.6.1997 / 13:13:41 / cg"
-    "Modified: 20.6.1997 / 13:17:50 / cg"
+    "Created: / 20-06-1997 / 13:13:41 / cg"
+    "Modified: / 31-01-2017 / 14:43:19 / stefan"
 !
 
 rotated:degrees
@@ -11895,13 +11905,12 @@
 threeDProjected:fraction1 and:fraction2
     "return a 3D-projected version"
 
-    |dx1 dx2 newImage newBytesPerRow newBits
-     blackPixel halfW halfH m myDepth maskBits pix fr fl ml mr dm fractX my fy dstY o1 o2 df|
+    |dx1 dx2 newImage newBits
+     blackPixel halfH m myDepth maskBits pix fr fl ml mr dm fractX my fy dstY o1 df|
 
     newImage := self species new.
     newImage width:width.
     newImage height:height.
-    newBytesPerRow := newImage bytesPerRow.
     newImage createPixelStore.
     newBits := newImage bits.
     newImage photometric:photometric.
@@ -11947,7 +11956,6 @@
     "/ now, walk over destination pixels,
     "/ fetching from source.
 
-    halfW := (width - 1) / 2.0.
     halfH := (height - 1) / 2.0.
 
     "/  --------------------------------------------------------------
@@ -11984,7 +11992,6 @@
         my := ml + (dm * fractX).
         fy := fl + (df * fractX).
         o1 := dx1 * fractX.
-        o2 := dx2 * fractX.
 
         0 to:height-1 do:[:srcY |
             srcY < halfH ifTrue:[
@@ -12010,6 +12017,8 @@
      (i threeDProjected:0.1 and:0.3) inspect
      (i threeDProjected:0.1 and:0.1) inspect
     "
+
+    "Modified: / 31-01-2017 / 15:04:22 / stefan"
 !
 
 withColorResolutionReducedBy:numBits
@@ -12452,21 +12461,6 @@
     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'!
 
@@ -12736,16 +12730,17 @@
 computeBitsFromPixelFunction
     "compute the bits from the pixelfunction"
 
-    |bpr idx|
+    |bpr|
 
     bpr := self bytesPerRow.
     bytes := ByteArray new:(bpr * height).
-    idx := 1.
     0 to:height-1 do:[:y |
         0 to:width-1 do:[:x |
             self pixelAtX:x y:y put:(pixelFunction value:x value:y).
         ]
     ].
+
+    "Modified: / 31-01-2017 / 14:39:26 / stefan"
 !
 
 pixelFunction
@@ -13818,12 +13813,13 @@
 pixelArraySpecies
     "return the kind of pixel-value container in rowAt:/rowAt:put: methods"
 
-    |d|
-
-    (d := self depth) <= 8 ifTrue:[^ ByteArray].
+    self depth <= 8 ifTrue:[^ ByteArray].
+    "/ (d := self depth) <= 8 ifTrue:[^ ByteArray].
     "/ d <= 16 ifTrue:[^ WordArray].
     "/ ^ IntegerArray
     ^ Array
+
+    "Modified: / 31-01-2017 / 14:52:42 / stefan"
 !
 
 realColorMap
@@ -14228,7 +14224,7 @@
     "given a color, return the corresponding pixel value.
      Non-representable colors return nil."
 
-    |pixel redBits greenBits blueBits alphaBits r g b a|
+    |pixel redBits greenBits blueBits r g b a|
 
     r := rgb bitAnd:16rFF.
     g := (rgb bitShift:-8) bitAnd:16rFF.
@@ -14279,7 +14275,7 @@
             redBits := bitsPerSample at:1.
             greenBits := bitsPerSample at:2.
             blueBits := bitsPerSample at:3.
-            alphaBits := bitsPerSample at:4.
+"/            alphaBits := bitsPerSample at:4.
             pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
             ^ pixel
         ]
@@ -14288,6 +14284,7 @@
     ^ nil
 
     "Created: / 15-01-2008 / 15:55:08 / cg"
+    "Modified: / 31-01-2017 / 14:45:00 / stefan"
 !
 
 valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
@@ -14574,8 +14571,8 @@
             ddepth := aDrawable depth.
         ]. 
         photometric := aDrawable photometric.
-        samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
-        bitsPerSample := ddepth == 24 ifTrue:#[8 8 8] ifFalse:[ByteArray with:bpp].
+        samplesPerPixel := ddepth == 24 ifTrue:[3] ifFalse:[1].
+        bitsPerSample := ddepth == 24 ifTrue:[#[8 8 8]] ifFalse:[ByteArray with:bpp].
     ] ifFalse:[
         "get some attributes of the display device"
         visType := device visualType.
@@ -14692,9 +14689,9 @@
     bytesPerLineIn := (info at:#bytesPerLine).           "what I got"
     bytesPerLine := (w * bpp + 7) // 8.                  "what I want"
 
-    maskR := info at:#redMask ifAbsent:0.
-    maskG := info at:#greenMask ifAbsent:0.
-    maskB := info at:#blueMask ifAbsent:0.
+    maskR := info at:#redMask ifAbsent:[0].
+    maskG := info at:#greenMask ifAbsent:[0].
+    maskB := info at:#blueMask ifAbsent:[0].
 
     ((bytesPerLine ~~ bytesPerLineIn)
      or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
@@ -14830,7 +14827,7 @@
     ].
 
     "Modified: / 07-02-1998 / 18:23:07 / cg"
-    "Modified: / 30-01-2017 / 19:36:36 / stefan"
+    "Modified: / 31-01-2017 / 15:02:52 / stefan"
 !
 
 fromScreen:aRectangle