ImageEditor.st
changeset 3470 da26c2e9a037
parent 3469 52837773925b
child 3471 95c973cafdc1
equal deleted inserted replaced
3469:52837773925b 3470:da26c2e9a037
  7535     "Created: / 07-07-2006 / 13:22:10 / cg"
  7535     "Created: / 07-07-2006 / 13:22:10 / cg"
  7536     "Modified: / 24-08-2017 / 17:06:00 / cg"
  7536     "Modified: / 24-08-2017 / 17:06:00 / cg"
  7537 !
  7537 !
  7538 
  7538 
  7539 ditherToDepth:depth 
  7539 ditherToDepth:depth 
  7540     |ditherColors computeNewColormap nGrey greyColorsAlready moreColors d|
  7540     |answer labels values ditherColors nGrey greyColorsAlready moreColors d|
  7541 
  7541 
  7542     computeNewColormap := Dialog 
  7542     (depth >= 8) ifTrue:[
  7543                             confirmWithCancel:'Compute a new (optimized) colormap?\\(or else use a standard colormap)\\Warning: this may take some time...' withCRs
  7543         labels := #('Cancel' 'Use Browser Palette' 'Use Standard' 'Compute' ).
  7544                             default:false.
  7544         values := #(nil UseBrowserPalette UseStandard Compute).
  7545     computeNewColormap isNil ifTrue:[^ self].
  7545     ] ifFalse:[
  7546 
  7546         labels := #('Cancel' 'Use Standard' 'Compute' ).
  7547     computeNewColormap ifFalse:[
  7547         values := #(nil UseStandard Compute). 
  7548         depth = 1 ifTrue:[
  7548     ].
  7549             ditherColors := Array with:(Color black) with:(Color white).
  7549 
  7550         ] ifFalse:[ depth = 2 ifTrue:[
  7550     answer := OptionBox
  7551             ditherColors := Array 
  7551               request:'Compute a new (optimized) colormap\(Warning: this may take some time)\\or else use a standard colormap?' withCRs
  7552                                 with:(Color black) 
  7552               label:(resources string:'Dither how')
  7553                                 with:(Color darkGray)
  7553               image:(YesNoBox iconBitmap)
  7554                                 with:(Color lightGray)
  7554               buttonLabels:(resources array:labels)
  7555                                 with:(Color white).
  7555               values:values
  7556         ] ifFalse:[ depth = 3 ifTrue:[
  7556               default:#UseStandard
  7557             ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
  7557               onCancel:nil.
  7558         ] ifFalse:[ depth = 4 ifTrue:[
  7558     answer isNil ifTrue:[^ self].
  7559             ditherColors := Color vgaColors. 
  7559     
  7560         ] ifFalse:[ depth = 5 ifTrue:[
  7560     (answer == #Compute) ifTrue:[
  7561             ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
       
  7562         ] ifFalse:[ depth = 6 ifTrue:[
       
  7563             ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
       
  7564         ] ifFalse:[ depth = 7 ifTrue:[
       
  7565             ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
       
  7566         ] ifFalse:[ depth == 8 ifTrue:[
       
  7567             ditherColors := Color standardDitherColorsForDepth8. 
       
  7568         ] ifFalse:[ 
       
  7569             self error:'unsupported depth'.
       
  7570         ]]]]]]]].
       
  7571 
       
  7572         "/ add as many gray colors as possible.
       
  7573         nGrey := (2 raisedTo:depth) - ditherColors size.  
       
  7574         nGrey > 0 ifTrue:[
       
  7575             nGrey := nGrey min:128.
       
  7576             greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
       
  7577             d := 1 / nGrey.
       
  7578             moreColors := (1 to:nGrey-1) 
       
  7579                             collect:[:i | Color brightness:(d * i)] 
       
  7580                             thenReject:[:clr | greyColorsAlready includes:clr ].
       
  7581 
       
  7582             ditherColors := ditherColors , moreColors.
       
  7583         ].
       
  7584     ] ifTrue:[
       
  7585         ditherColors :=
  7561         ditherColors :=
  7586             Color
  7562             Color
  7587                 best:(1 bitShift:depth) 
  7563                 best:(1 bitShift:depth) 
  7588                 ditherColorsForImage:self image
  7564                 ditherColorsForImage:self image
       
  7565     ] ifFalse:[
       
  7566         (answer == #UseBrowserPalette) ifTrue:[
       
  7567             ditherColors := Color colorCubeWithRed:6 green:6 blue:6. 
       
  7568         ] ifFalse:[
       
  7569             depth = 1 ifTrue:[
       
  7570                 ditherColors := Array with:(Color black) with:(Color white).
       
  7571             ] ifFalse:[ depth = 2 ifTrue:[
       
  7572                 ditherColors := Array 
       
  7573                                     with:(Color black) 
       
  7574                                     with:(Color darkGray)
       
  7575                                     with:(Color lightGray)
       
  7576                                     with:(Color white).
       
  7577             ] ifFalse:[ depth = 3 ifTrue:[
       
  7578                 ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
       
  7579             ] ifFalse:[ depth = 4 ifTrue:[
       
  7580                 ditherColors := Color vgaColors. 
       
  7581             ] ifFalse:[ depth = 5 ifTrue:[
       
  7582                 ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
       
  7583             ] ifFalse:[ depth = 6 ifTrue:[
       
  7584                 ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
       
  7585             ] ifFalse:[ depth = 7 ifTrue:[
       
  7586                 ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
       
  7587             ] ifFalse:[ depth == 8 ifTrue:[
       
  7588                 ditherColors := Color standardDitherColorsForDepth8. 
       
  7589             ] ifFalse:[ 
       
  7590                 self error:'unsupported depth'.
       
  7591             ]]]]]]]].
       
  7592 
       
  7593         
       
  7594             "/ add as many gray colors as possible.
       
  7595             nGrey := (2 raisedTo:depth) - ditherColors size.  
       
  7596             nGrey > 0 ifTrue:[
       
  7597                 nGrey := nGrey min:128.
       
  7598                 greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
       
  7599                 d := 1 / nGrey.
       
  7600                 moreColors := (1 to:nGrey-1) 
       
  7601                                 collect:[:i | Color brightness:(d * i)] 
       
  7602                                 thenReject:[:clr | greyColorsAlready includes:clr ].
       
  7603 
       
  7604                 ditherColors := ditherColors , moreColors.
       
  7605             ].
       
  7606         ].
  7589     ].
  7607     ].
  7590 
  7608 
  7591     self withExecuteCursorDo:[
  7609     self withExecuteCursorDo:[
  7592         |newImage|
  7610         |newImage|
  7593         
  7611         
  7594         newImage := self image asDitheredImageUsing:ditherColors depth:depth.
  7612         newImage := self image asDitheredImageUsing:ditherColors depth:depth.
  7595         imageEditView newImageWithUndo:newImage.
  7613         imageEditView newImageWithUndo:newImage.
  7596     ].
  7614     ].
  7597 
  7615 
  7598     "Created: / 07-07-2006 / 13:20:56 / cg"
  7616     "Created: / 07-07-2006 / 13:20:56 / cg"
  7599     "Modified: / 29-08-2017 / 17:37:51 / cg"
  7617     "Modified: / 29-08-2017 / 21:08:34 / cg"
  7600 !
  7618 !
  7601 
  7619 
  7602 do3DProjection
  7620 do3DProjection
  7603     |box dx1 dx2 image|
  7621     |box dx1 dx2 image|
  7604 
  7622