Image.st
changeset 2205 9209bc474af9
parent 2199 ac56b54c59a5
child 2206 8bf0549762b8
--- a/Image.st	Wed Jul 29 13:18:53 1998 +0200
+++ b/Image.st	Wed Jul 29 13:20:34 1998 +0200
@@ -2385,6 +2385,19 @@
     ^ mask pixelAtX:x y:y
 !
 
+pixelAt:aPoint
+    "retrieve a pixel at x/y; return a pixel value.
+     Pixels start at 0@0 for upper left pixel, end at
+     (width-1)@(height-1) for lower right pixel.
+     You should not use this method for image-processing, its
+     very slow ...
+     (it is meant to access individual pixels - for example, in a bitmap editor)"
+
+    ^ self pixelAtX:(aPoint x) y:(aPoint y)
+
+    "Created: / 29.7.1998 / 02:48:52 / cg"
+!
+
 pixelAtX:x y:y
     "retrieve the pixelValue at aPoint; return an integer number.
      Pixels start at 0/0 for upper left pixel, and end at
@@ -2811,6 +2824,58 @@
     "Modified: 23.4.1996 / 09:30:50 / cg"
 ! !
 
+!Image methodsFor:'conversion helpers'!
+
+rgbColormapFor:aDevice
+    "helper for conversion to rgb format"
+
+    |nColors    "{ Class: SmallInteger }"
+     scaleRed scaleGreen scaleBlue
+     redShift   "{ Class: SmallInteger }"
+     greenShift "{ Class: SmallInteger }"
+     blueShift  "{ Class: SmallInteger }"
+     colorValues|
+
+    "/ gather r/g/b values for all colors in the map ...
+
+    nColors := 1 bitShift:(self depth).
+
+    "/ precompute scales to map from 0..100 into devices range
+    "/ (this may be different for the individual components)
+
+    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
+    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
+    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
+    redShift := aDevice shiftRed.
+    greenShift := aDevice shiftGreen.
+    blueShift := aDevice shiftBlue.
+
+    colorValues := Array uninitializedNew:nColors.
+
+    0 to:nColors-1 do:[:pixel |
+        |clr rv gv bv v "{ Class: SmallInteger }" |
+
+        clr := self colorFromValue:pixel.
+
+        rv := (clr red * scaleRed) rounded.
+        gv := (clr green * scaleGreen) rounded.
+        bv := (clr blue * scaleBlue) rounded.
+
+        v := rv bitShift:redShift.
+        v := v bitOr:(gv bitShift:greenShift).
+        v := v bitOr:(bv bitShift:blueShift).
+
+        colorValues at:(pixel+1) put:v.
+"/ clr print. ' ' print.
+"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
+"/ ' -> ' print. v printNL.
+    ].
+
+    ^ colorValues
+
+    "Modified: / 29.7.1998 / 00:34:56 / cg"
+! !
+
 !Image methodsFor:'converting'!
 
 asBurkesDitheredMonochromeImage
@@ -7925,20 +7990,29 @@
     "fill a area with aColor like a flood up to surrounded pixels having different colors.
      By using #atImageAndMask:put: it also works on images with mono masks."
 
-    |getSurroundingPixelsBlock detectedColor detectedPixels allDetectedPixels anotherPixels seemsToBeAll|
+    |getSurroundingPixelsBlock detectedPixel detectedPixelCoordinates 
+     allDetectedPixelCoordinates morePixels seemsToBeAll
+     sizeBefore
+     w h|
+
+    w := self width.
+    h := self height.
 
     getSurroundingPixelsBlock := 
     [:aPoint|
-        |surroundingPixels|
+        |surroundingPixels pX pY|
+
         surroundingPixels := OrderedCollection new.
-        (0 <= aPoint y) & (self height - 1 > aPoint y)
-            ifTrue: [surroundingPixels add: (aPoint x@(aPoint y + 1))].
-        (0 < aPoint y) & (self height - 1 >= aPoint y)
-            ifTrue: [surroundingPixels add: (aPoint x@(aPoint y - 1))].
-        (0 <= aPoint x) & (self width - 1 > aPoint x)
-            ifTrue: [surroundingPixels add: (aPoint x + 1@(aPoint y))].
-        (0 < aPoint x) & (self width - 1 >= aPoint x)
-            ifTrue: [surroundingPixels add: (aPoint x - 1@(aPoint y))].
+        pX := aPoint x.
+        pY := aPoint y.
+        ((0 <= pY) and:[h - 1 > pY])
+            ifTrue: [surroundingPixels add: (pX @ (pY + 1))].
+        ((0 < pY) and:[h - 1 >= pY])
+            ifTrue: [surroundingPixels add: (pX @ (pY - 1))].
+        ((0 <= pX) and:[w - 1 > pX])
+            ifTrue: [surroundingPixels add: (pX + 1 @ pY)].
+        ((0 < pX) and:[w - 1 >= pX])
+            ifTrue: [surroundingPixels add: (pX - 1 @ pY)].
         surroundingPixels
     ].
 
@@ -7947,27 +8021,28 @@
     [
         ^(mask floodFillAt: aPoint withColor: Color white) do: [:p| self atImageAndMask: p put: aColor].
     ].
-    detectedColor := self colorAt: aPoint.
-    detectedPixels := Set with: aPoint.
-    allDetectedPixels := OrderedCollection with: aPoint.
+    detectedPixel := self pixelAt: aPoint.
+    detectedPixelCoordinates := Set with: aPoint.
+    allDetectedPixelCoordinates := Set with: aPoint.
     seemsToBeAll := false.
-    [seemsToBeAll] whileFalse:
-    [
-        |sizeBefore|
-        sizeBefore := allDetectedPixels size.
-        anotherPixels := OrderedCollection new.
-        detectedPixels do:
-        [:p|
-            (getSurroundingPixelsBlock value: p) select: [:sp| 
-                (detectedColor = (self colorAt: sp) and: [mask isNil or: [(mask colorAt: sp) = Color white]])
-                ifTrue: [anotherPixels add: sp]]
+    [seemsToBeAll] whileFalse:[
+
+        sizeBefore := allDetectedPixelCoordinates size.
+        morePixels := OrderedCollection new.
+        detectedPixelCoordinates do:[:p|
+            (getSurroundingPixelsBlock value: p) do: [:sp| 
+                (detectedPixel == (self pixelAt: sp) and: [mask isNil or: [(mask colorAt: sp) = Color white]])
+                ifTrue: [morePixels add: sp]
+            ]
         ].
-        detectedPixels := (anotherPixels asSet reject: [:p| allDetectedPixels includes: p]).
-        allDetectedPixels addAll: detectedPixels.
-        seemsToBeAll := sizeBefore = allDetectedPixels size.
+        detectedPixelCoordinates := (morePixels asSet reject: [:p| allDetectedPixelCoordinates includes: p]).
+        allDetectedPixelCoordinates addAll: detectedPixelCoordinates.
+        seemsToBeAll := sizeBefore = allDetectedPixelCoordinates size.
     ]. 
-    allDetectedPixels do: [:p| self atImageAndMask: p put: aColor].
-    ^allDetectedPixels
+    allDetectedPixelCoordinates do: [:p| self atImageAndMask: p put: aColor].
+    ^allDetectedPixelCoordinates
+
+    "Modified: / 29.7.1998 / 03:09:16 / cg"
 !
 
 rectangle: aRectangle withColor:aColor
@@ -11354,6 +11429,6 @@
 !Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.249 1998-07-28 19:55:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.250 1998-07-29 11:20:34 cg Exp $'
 ! !
 Image initialize!