#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Fri, 01 Sep 2017 11:41:23 +0200
changeset 5591 1d2029c136ec
parent 5590 b4a62912f9f1
child 5592 bdb957272782
#UI_ENHANCEMENT by cg class: ImageEditView changed: #redrawImageX:y:width:height:unmaskedOnly:processColorsWith:
ImageEditView.st
--- a/ImageEditView.st	Fri Sep 01 10:28:03 2017 +0200
+++ b/ImageEditView.st	Fri Sep 01 11:41:23 2017 +0200
@@ -619,13 +619,19 @@
 redrawImageX:x y:y width:w height:h unmaskedOnly:unmaskedOnly processColorsWith:aColorBlock
     "redraw the magnified (editing) view of the image"
 
-    |ih iw magX magY minX maxX minY maxY lastColor lastY runW x0 maskColor mask
-     sizeOfMaskPoint useNearestColor origin isRGBA|
+    |ih iw magX magY minX maxX minY maxY lastColor lastY runW x0 
+     isMasked mask photometric
+     lastPixelColor
+     sizeOfMaskPoint offsetOfMaskPoint
+     useNearestColor isRGBA isRGBLike drawPixel 
+     showPixelValue pixelValueFont savedFont ascent|
 
     useNearestColor := device visualType == #PseudoColor.
 
     mask := image mask.
-    isRGBA := image photometric == #rgba.
+    photometric := image photometric.
+    isRGBA := photometric == #rgba.
+    isRGBLike := #(rgb rgba argb) includes:photometric.
     ih := image height.
     iw := image width.
     magX := magnification x.
@@ -640,12 +646,49 @@
     maxY := (y + h) // magY + 1.
     maxY > ih ifTrue:[maxY := ih].
 
+    showPixelValue := "(image depth <= 12) and:["(magX > 32) and:[magY > 32]"]".
+    showPixelValue ifTrue:[
+        pixelValueFont := TextView defaultFont asSize:(magY // 6).
+        pixelValueFont := pixelValueFont onDevice:gc device.
+        savedFont := gc font.
+        gc font:pixelValueFont.
+        ascent := pixelValueFont ascent + 2.
+    ].
+    
+    drawPixel :=
+        [:x :y :clr |
+            |origin pixelColor pixelValue s|
+            
+            origin := (x * magX + margin)@(y * magY + margin).
+            (unmaskedOnly and:[isMasked]) ifFalse:[
+                self fillFramedRectangle: (origin extent: runW@magY).
+                isMasked ifTrue:[
+                    gc xoring:[
+                        gc fillRectangle: (origin + offsetOfMaskPoint extent: sizeOfMaskPoint)
+                    ]
+                ] ifFalse:[
+                    pixelValueFont notNil ifTrue:[
+                        pixelColor := gc paint.
+                        gc paint:(pixelColor contrastingColorFor:pixelColor).
+                        pixelValue := image pixelAtX:x y:y.
+                        isRGBLike ifTrue:[
+                            s := pixelValue hexPrintString.
+                        ] ifFalse:[
+                            s := pixelValue printString.
+                        ].    
+                        gc displayString:s x:(origin x + 1) y:(origin y + ascent).
+                    ].    
+                ].    
+            ]
+        ].
+        
     lastY := -1.
-
     x0 := minX.
     runW := 0.
-    maskColor := false.
-    sizeOfMaskPoint := magnification//3.
+    isMasked := false.
+    sizeOfMaskPoint := (magnification//3) min:8.
+    offsetOfMaskPoint := (magnification - sizeOfMaskPoint) // 2.
+    
     image 
         colorsFromX:minX y:minY toX:maxX-1 y:maxY-1 
         do:[:xx :yy :colorIn|
@@ -657,53 +700,41 @@
 
             yy ~~ lastY ifTrue:[
                 runW ~~ 0 ifTrue:[
-                    origin := (x0 * magX + margin) @ (lastY * magY + margin).
-                    (unmaskedOnly not or:[maskColor not]) ifTrue:[
-                        self fillFramedRectangle: (origin extent: (runW@magY)).                    
-                        maskColor ifTrue:[
-                            gc xoring: [gc fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
-                        ]
-                    ].
+                    drawPixel value:x0 value:lastY value:lastColor.
                     runW := 0.
                 ]. 
                 x0 := xx.
                 lastY := yy.
             ]. 
 
-            color ~= lastColor ifTrue:[
+            (color ~= lastColor or:[showPixelValue]) ifTrue:[
                 runW ~~ 0 ifTrue:[
-                    origin := (x0 * magX + margin)@(yy * magY + margin).
-                    (unmaskedOnly not or:[maskColor not]) ifTrue:[
-                        self fillFramedRectangle: (origin extent: (runW@magY)).
-                        maskColor ifTrue:[
-                            gc xoring: [gc fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
-                        ].
-                    ].
+                    drawPixel value:x0 value:yy value:lastColor.
                     runW := 0.
                 ].
-
-                lastColor := color.
+                
+                lastColor := lastPixelColor := color.
                 useNearestColor ifTrue:[
                     lastColor := lastColor nearestOn:device
                 ].
                 gc paint:lastColor.
                 mask notNil ifTrue:[  
-                    maskColor := false.
+                    isMasked := false.
                     (mask pixelAtX:xx y:yy) == 0 ifTrue:[
                         unmaskedOnly ifFalse:[
                             gc paint: (lastColor := self viewBackground).
                         ].
-                        maskColor := true.
+                        isMasked := true.
                     ].
                     lastColor := nil.
                 ] ifFalse:[
                     isRGBA ifTrue:[
-                        maskColor := false.
+                        isMasked := false.
                         colorIn alphaByte == 0 ifTrue:[
                             unmaskedOnly ifFalse:[
                                 gc paint: (lastColor := self viewBackground).
                             ].
-                            maskColor := true.
+                            isMasked := true.
                         ] ifFalse:[  
                         ].    
                         lastColor := nil.
@@ -716,19 +747,15 @@
         ].
 
     runW ~~ 0 ifTrue:[
-        origin := (x0 * magX + margin)@(lastY * magY + margin).
-        (unmaskedOnly not or:[maskColor not]) ifTrue:[
-            self fillFramedRectangle: (origin extent: runW@magY).
-            maskColor ifTrue:[
-                gc xoring:[
-                    gc fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)
-                ]
-            ].
-        ]
+        drawPixel value:x0 value:lastY value:lastColor.
+    ].
+
+    savedFont notNil ifTrue:[
+        gc font:savedFont.
     ].
 
     "Created: / 18-05-1999 / 20:13:39 / cg"
-    "Modified: / 17-02-2017 / 17:19:59 / cg"
+    "Modified: / 01-09-2017 / 11:39:09 / cg"
 !
 
 redrawX:x y:y width:w height:h