--- a/ImageEditView.st Thu Sep 05 19:20:07 2002 +0200
+++ b/ImageEditView.st Fri Sep 06 17:16:35 2002 +0200
@@ -1211,10 +1211,10 @@
].
anyColorMissing ifTrue:[
answer := Dialog
- confirmWithCancel:'Some color(s) cannot be represented (colorMap full). Use nearest or compute colorMap ?'
- labels:#('use nearest' 'new ColorMap' 'cancel')
- values:#(nearest new nil)
- default:1.
+ confirmWithCancel:'Some color(s) cannot be represented (colorMap full).\Use nearest or compute colorMap ?' withCRs
+ labels:#( 'Cancel' 'New ColorMap' 'Use Nearest' )
+ values:#( nil new nearest)
+ default:3.
answer isNil ifTrue:[^ self].
@@ -1385,18 +1385,22 @@
!
performSpecialOperationOn:imageBox withColor:clr
- |operation x0 y0 x1 y1 grey|
+ |operation x0 y0 x1 y1 grey pixelAction requiredColors missingColors answer|
operation := Dialog
choose:'Which Operation:'
fromList:#(
-"/ 'brighten'
-"/ 'darken'
-"/ '-'
-"/ 'greying'
+ 'slightly brightened'
+ 'slightly darkened'
+ 'brightened'
+ 'darkened'
+ '-'
+ 'greyed'
'grey pattern'
+ '-'
+ 'reversed'
)
- values:#("brighten darken nil greying "greyPattern)
+ values:#(slightlyBrighter slightlyDarker brighter darker nil grey greyPattern nil reversed)
lines:6
cancel:nil.
@@ -1410,36 +1414,68 @@
x1 := imageBox right - 1.
y1 := imageBox bottom -1 .
+ operation == #slightlyBrighter ifTrue:[
+ pixelAction := [:x :y :clr | clr slightlyLightened].
+ ].
+ operation == #slightlyDarker ifTrue:[
+ pixelAction := [:x :y :clr | clr slightlyDarkened].
+ ].
operation == #brighten ifTrue:[
- self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr |
- self image colorAtX:x y:y put:(clr lightened).
- ].
- ^ true.
+ pixelAction := [:x :y :clr | clr lightened].
].
operation == #darken ifTrue:[
- self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr |
- self image colorAtX:x y:y put:(clr darkened).
- ].
- ^ true.
+ pixelAction := [:x :y :clr | clr darkened].
+ ].
+ operation == #reversed ifTrue:[
+ pixelAction := [:x :y :clr | Color red:(100-clr red) green:(100-clr green) blue:(100-clr blue) ].
].
operation == #greying ifTrue:[
- self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr |
- self image colorAtX:x y:y put:(clr blendWith:Color grey).
- ].
- ^ true.
+ pixelAction := [:x :y :clr | clr blendWith:Color grey].
].
operation == #greyPattern ifTrue:[
- grey := Color grey nearestIn:(self image colorMap).
- self image colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :clr |
- (x + y )odd ifTrue:[
- self image colorAtX:x y:y put:grey.
- ]
- ].
- ^ true.
+ pixelAction := [:x :y :clr | Color grey].
+ ].
+ pixelAction isNil ifTrue:[self halt. ^ false].
+
+ "/ compute required colors ...
+ requiredColors := Set new.
+ self image
+ colorsFromX:x0 y:y0 toX:x1 y:y1
+ do:[:x :y :clr |
+ requiredColors add:(pixelAction value:x value:y value:clr)
+ ].
+
+ missingColors := requiredColors select:[:clr | (image colorMap includes:clr) not].
+
+ missingColors notEmpty ifTrue:[
+ answer := Dialog
+ confirmWithCancel:'Some color(s) cannot be represented in the images colorMap.\Use nearest or compute colorMap ?' withCRs
+ labels:#( 'Cancel' 'Add to ColorMap' 'Use Nearest')
+ values:#( nil add nearest)
+ default:3.
+ answer isNil ifTrue:[^ self].
+ answer == #add ifTrue:[
+ self halt:'this finction is not yet implemented'.
+ missingColors do:[:eachColor |
+ ].
+ ^ false.
+ ].
].
- self halt.
- ^ false.
+ "/ now, do it
+ self image
+ colorsFromX:x0 y:y0 toX:x1 y:y1
+ do:[:x :y :clr |
+ |newClr|
+
+ newClr := pixelAction value:x value:y value:clr.
+ answer == #nearest ifTrue:[
+ newClr := newClr nearestIn:image colorMap
+ ].
+ self image colorAtX:x y:y put:newClr
+ ].
+
+ ^ true.
!
pointAt:aPoint
@@ -2152,6 +2188,6 @@
!ImageEditView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.165 2002-09-05 12:22:23 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.166 2002-09-06 15:16:35 cg Exp $'
! !
ImageEditView initialize!