# HG changeset patch # User Claus Gittinger # Date 1253019254 -7200 # Node ID 9e8d63aadb11e6f4918deeb26526854cba940a40 # Parent 43e98f6d71d27da65d56e7be488d383a73c4088b more grey values used when dithering diff -r 43e98f6d71d2 -r 9e8d63aadb11 ImageEditor.st --- a/ImageEditor.st Fri Sep 11 16:42:36 2009 +0200 +++ b/ImageEditor.st Tue Sep 15 14:54:14 2009 +0200 @@ -4639,31 +4639,52 @@ ! ditherToDepth:depth - |ditherColors newImage| - - depth = 1 ifTrue:[ - ditherColors := Array with:(Color black) with:(Color white). - ] ifFalse:[ depth = 2 ifTrue:[ - ditherColors := Array - with:(Color black) - with:(Color darkGrey) - with:(Color lightGrey) - with:(Color white). - ] ifFalse:[ depth = 3 ifTrue:[ - ditherColors := Color colorCubeWithRed:2 green:2 blue:2. - ] ifFalse:[ depth = 4 ifTrue:[ - ditherColors := Color vgaColors. - ] ifFalse:[ depth = 5 ifTrue:[ - ditherColors := Color colorCubeWithRed:4 green:4 blue:2. - ] ifFalse:[ depth = 5 ifTrue:[ - ditherColors := Color colorCubeWithRed:4 green:4 blue:3. - ] ifFalse:[ depth <= 8 ifTrue:[ - ditherColors := Color colorCubeWithRed:6 green:6 blue:5. - ] ifFalse:[ - self error:'unsupported depth'. - ]]]]]]]. + |ditherColors newImage useStandardColors nGrey greyColorsAlready additionalGreyColors moreColors d| + + useStandardColors := true. +"/ useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'. +"/ useStandardColors isNil ifTrue:[^ self]. + + useStandardColors ifTrue:[ + depth = 1 ifTrue:[ + ditherColors := Array with:(Color black) with:(Color white). + ] ifFalse:[ depth = 2 ifTrue:[ + ditherColors := Array + with:(Color black) + with:(Color darkGrey) + with:(Color lightGrey) + with:(Color white). + ] ifFalse:[ depth = 3 ifTrue:[ + ditherColors := Color colorCubeWithRed:2 green:2 blue:2. + ] ifFalse:[ depth = 4 ifTrue:[ + ditherColors := Color vgaColors. + ] ifFalse:[ depth = 5 ifTrue:[ + ditherColors := Color colorCubeWithRed:4 green:4 blue:2. + ] ifFalse:[ depth = 6 ifTrue:[ + ditherColors := Color colorCubeWithRed:4 green:4 blue:3. + ] ifFalse:[ depth <= 8 ifTrue:[ + ditherColors := Color colorCubeWithRed:6 green:6 blue:5. + ] ifFalse:[ + self error:'unsupported depth'. + ]]]]]]]. + + nGrey := (2 raisedTo:depth) - ditherColors size. + nGrey > 0 ifTrue:[ + nGrey := nGrey min:128. + greyColorsAlready := ditherColors select:[:clr | clr isGreyColor]. + d := 1 / nGrey. + moreColors := (1 to:nGrey-1) + collect:[:i | Color brightness:(d * i)] + thenReject:[:clr | greyColorsAlready includes:clr ]. + + ditherColors := ditherColors , moreColors. + ]. + ] ifFalse:[ +self halt. + ]. self withExecuteCursorDo:[ + "/ newImage := self image asDitheredImageUsing:ditherColors depth:depth. newImage := self image asDitheredImageUsing:ditherColors depth:8. imageEditView makeUndo.