ImageEditor.st
changeset 3471 95c973cafdc1
parent 3470 da26c2e9a037
child 3472 f6c63e715a5b
equal deleted inserted replaced
3470:da26c2e9a037 3471:95c973cafdc1
    17 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    17 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    18 		selectedColorIndex postOpenAction imageSeqNr drawingColormap
    18 		selectedColorIndex postOpenAction imageSeqNr drawingColormap
    19 		lastShiftUsedWrap lastGrabbedScreenArea
    19 		lastShiftUsedWrap lastGrabbedScreenArea
    20 		allowedToChangeImageDimensionAndDepth savedImage savedFile'
    20 		allowedToChangeImageDimensionAndDepth savedImage savedFile'
    21 	classVariableNames:'DefaultRelativeSizes LastColormapMode LastDirectory
    21 	classVariableNames:'DefaultRelativeSizes LastColormapMode LastDirectory
    22 		LastSizeString LastURL MaskClipboard'
    22 		LastSizeString LastURL MaskClipboard LastDepth'
    23 	poolDictionaries:''
    23 	poolDictionaries:''
    24 	category:'Interface-UIPainter'
    24 	category:'Interface-UIPainter'
    25 !
    25 !
    26 
    26 
    27 !ImageEditor class methodsFor:'documentation'!
    27 !ImageEditor class methodsFor:'documentation'!
  3108                   label: 'Dither to Depth...'
  3108                   label: 'Dither to Depth...'
  3109                   itemValue: ditherToDepth
  3109                   itemValue: ditherToDepth
  3110                   translateLabel: true
  3110                   translateLabel: true
  3111                 )
  3111                 )
  3112                (MenuItem
  3112                (MenuItem
       
  3113                   label: 'Threshold to Depth...'
       
  3114                   itemValue: thresholdToDepth
       
  3115                   translateLabel: true
       
  3116                 )
       
  3117                (MenuItem
  3113                   label: 'Make GrayScale with Depth (Dither)...'
  3118                   label: 'Make GrayScale with Depth (Dither)...'
  3114                   itemValue: ditherGrayToDepth
  3119                   itemValue: ditherGrayToDepth
  3115                   translateLabel: true
  3120                   translateLabel: true
  3116                 )
  3121                 )
  3117                (MenuItem
  3122                (MenuItem
  3204          )
  3209          )
  3205         nil
  3210         nil
  3206         nil
  3211         nil
  3207       )
  3212       )
  3208 
  3213 
  3209     "Modified: / 24-08-2017 / 17:49:04 / cg"
  3214     "Modified: / 30-08-2017 / 00:35:31 / cg"
  3210 !
  3215 !
  3211 
  3216 
  3212 menuEdit
  3217 menuEdit
       
  3218     <resource: #menu>
  3213     "This resource specification was automatically generated
  3219     "This resource specification was automatically generated
  3214      by the MenuEditor of ST/X."
  3220      by the MenuEditor of ST/X."
  3215 
       
  3216     "Do not manually edit this!! If it is corrupted,
  3221     "Do not manually edit this!! If it is corrupted,
  3217      the MenuEditor may not be able to read the specification."
  3222      the MenuEditor may not be able to read the specification."
  3218 
       
  3219 
       
  3220     "
  3223     "
  3221      MenuEditor new openOnClass:ImageEditor andSelector:#menuEdit
  3224      MenuEditor new openOnClass:ImageEditor andSelector:#menuEdit
  3222      (Menu new fromLiteralArrayEncoding:(ImageEditor menuEdit)) startUp
  3225      (Menu new fromLiteralArrayEncoding:(ImageEditor menuEdit)) startUp"
  3223     "
  3226     
  3224 
  3227     ^ #( #Menu
  3225     <resource: #menu>
  3228       #((MenuItem activeHelpKey: editUndo enabled: canUndoHolder label: 'Undo' itemValue: doUndo) (MenuItem label: '-') (MenuItem enabled: imageIsLoadedHolder label: 'Copy to Clipboard' itemValue: doCopyImageToClipboard) (MenuItem label: '-') (MenuItem activeHelpKey: editResize enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: 'Resize...' itemValue: doResizeImage) (MenuItem activeHelpKey: editMagnifyImage enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: 'Magnify...' itemValue: doMagnifyImage) (MenuItem activeHelpKey: editMagnifyImage enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: 'Magnify By...' itemValue: doMagnifyImageBy) (MenuItem activeHelpKey: editRotate enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: 'Rotate...' itemValue: doRotateImage) (MenuItem activeHelpKey: edit3DProjection enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: '3D Projection...' itemValue: do3DProjection) (MenuItem enabled: imageIsLoadedAndAllowedToFlipHolder label: 'Flip' submenu: (Menu ((MenuItem activeHelpKey: editFlipVertical enabled: imageIsLoadedAndNotReadonlyHolder label: 'Flip - Vertical' itemValue: doFlipVertical labelImage: (ResourceRetriever ImageEditor flipVerticalIcon 'Flip - Vertical')) (MenuItem activeHelpKey: editFlipHorizontal enabled: imageIsLoadedAndNotReadonlyHolder label: 'Flip - Horizontal' itemValue: doFlipHorizontal labelImage: (ResourceRetriever ImageEditor flipHorizontalIcon 'Flip - Horizontal'))) nil nil)) (MenuItem label: '-') (MenuItem enabled: imageIsLoadedAndAllowedToChangeImageDimension label: 'Crop' submenu: (Menu ((MenuItem activeHelpKey: cropManual label: 'Manual...' itemValue: doCropManual) (MenuItem label: '-' isVisible: false) (MenuItem activeHelpKey: autoCropAll label: 'All' itemValue: autoCropAll) (MenuItem label: '-') (MenuItem activeHelpKey: autoCropLeft label: 'Left' itemValue: autoCropLeft) (MenuItem activeHelpKey: autoCropRight label: 'Right' itemValue: autoCropRight) (MenuItem activeHelpKey: autoCropTop label: 'Top' itemValue: autoCropTop) (MenuItem activeHelpKey: autoCropBottom label: 'Bottom' itemValue: autoCropBottom)) nil nil)) (MenuItem activeHelpKey: uncropManual enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth label: 'Uncrop (Add Border)...' itemValue: doUnCropManual) (MenuItem activeHelpKey: shiftManual enabled: imageIsLoadedAndAllowedToChangeImageDimension label: 'Shift...' itemValue: doShiftManual) (MenuItem label: '-') (MenuItem activeHelpKey: fileEditMask enabled: hasMaskHolder label: 'Edit Mask' itemValue: doEditMask) (MenuItem enabled: imageIsLoadedAndNotReadonlyHolder label: 'Text...' itemValue: doInsertTextFromUser) (MenuItem label: '-') (MenuItem enabled: imageIsLoadedHolder label: 'Animation Sequence' submenu: (Menu ((MenuItem enabled: imageHasNextImageHolder label: 'Next in Sequence' itemValue: nextImageInSequence) (MenuItem enabled: imageHasPreviousImageHolder label: 'Previous in Sequence' itemValue: previousImageInSequence) (MenuItem label: '-') (MenuItem enabled: imageHasImageSequenceHolder label: 'Edit each from Sequence' itemValue: editEachImageFromSequence)) nil nil)))
  3226 
  3229       nil
  3227     ^ 
  3230       nil )
  3228      #(Menu
       
  3229         (
       
  3230          (MenuItem
       
  3231             activeHelpKey: editUndo
       
  3232             enabled: canUndoHolder
       
  3233             label: 'Undo'
       
  3234             itemValue: doUndo
       
  3235           )
       
  3236          (MenuItem
       
  3237             label: '-'
       
  3238           )
       
  3239          (MenuItem
       
  3240             enabled: imageIsLoadedHolder
       
  3241             label: 'Copy to Clipboard'
       
  3242             itemValue: doCopyImageToClipboard
       
  3243           )
       
  3244          (MenuItem
       
  3245             label: '-'
       
  3246           )
       
  3247          (MenuItem
       
  3248             activeHelpKey: editResize
       
  3249             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3250             label: 'Resize...'
       
  3251             itemValue: doResizeImage
       
  3252           )
       
  3253          (MenuItem
       
  3254             activeHelpKey: editMagnifyImage
       
  3255             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3256             label: 'Magnify...'
       
  3257             itemValue: doMagnifyImage
       
  3258           )
       
  3259          (MenuItem
       
  3260             activeHelpKey: editMagnifyImage
       
  3261             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3262             label: 'Magnify By...'
       
  3263             itemValue: doMagnifyImageBy
       
  3264           )
       
  3265          (MenuItem
       
  3266             activeHelpKey: editRotate
       
  3267             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3268             label: 'Rotate...'
       
  3269             itemValue: doRotateImage
       
  3270           )
       
  3271          (MenuItem
       
  3272             activeHelpKey: edit3DProjection
       
  3273             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3274             label: '3D Projection...'
       
  3275             itemValue: do3DProjection
       
  3276           )
       
  3277          (MenuItem
       
  3278             enabled: imageIsLoadedAndAllowedToFlipHolder
       
  3279             label: 'Flip'
       
  3280             submenu: 
       
  3281            (Menu
       
  3282               (
       
  3283                (MenuItem
       
  3284                   activeHelpKey: editFlipVertical
       
  3285                   enabled: imageIsLoadedAndNotReadonlyHolder
       
  3286                   label: 'Flip - Vertical'
       
  3287                   itemValue: doFlipVertical
       
  3288                   labelImage: (ResourceRetriever ImageEditor flipVerticalIcon 'Flip - Vertical')
       
  3289                 )
       
  3290                (MenuItem
       
  3291                   activeHelpKey: editFlipHorizontal
       
  3292                   enabled: imageIsLoadedAndNotReadonlyHolder
       
  3293                   label: 'Flip - Horizontal'
       
  3294                   itemValue: doFlipHorizontal
       
  3295                   labelImage: (ResourceRetriever ImageEditor flipHorizontalIcon 'Flip - Horizontal')
       
  3296                 )
       
  3297                )
       
  3298               nil
       
  3299               nil
       
  3300             )
       
  3301           )
       
  3302          (MenuItem
       
  3303             label: '-'
       
  3304           )
       
  3305          (MenuItem
       
  3306             enabled: imageIsLoadedAndAllowedToChangeImageDimension
       
  3307             label: 'Crop'
       
  3308             submenu: 
       
  3309            (Menu
       
  3310               (
       
  3311                (MenuItem
       
  3312                   activeHelpKey: cropManual
       
  3313                   label: 'Manual...'
       
  3314                   itemValue: doCropManual
       
  3315                 )
       
  3316                (MenuItem
       
  3317                   label: '-'
       
  3318                   isVisible: false
       
  3319                 )
       
  3320                (MenuItem
       
  3321                   activeHelpKey: autoCropAll
       
  3322                   label: 'All'
       
  3323                   itemValue: autoCropAll
       
  3324                 )
       
  3325                (MenuItem
       
  3326                   label: '-'
       
  3327                 )
       
  3328                (MenuItem
       
  3329                   activeHelpKey: autoCropLeft
       
  3330                   label: 'Left'
       
  3331                   itemValue: autoCropLeft
       
  3332                 )
       
  3333                (MenuItem
       
  3334                   activeHelpKey: autoCropRight
       
  3335                   label: 'Right'
       
  3336                   itemValue: autoCropRight
       
  3337                 )
       
  3338                (MenuItem
       
  3339                   activeHelpKey: autoCropTop
       
  3340                   label: 'Top'
       
  3341                   itemValue: autoCropTop
       
  3342                 )
       
  3343                (MenuItem
       
  3344                   activeHelpKey: autoCropBottom
       
  3345                   label: 'Bottom'
       
  3346                   itemValue: autoCropBottom
       
  3347                 )
       
  3348                )
       
  3349               nil
       
  3350               nil
       
  3351             )
       
  3352           )
       
  3353          (MenuItem
       
  3354             activeHelpKey: uncropManual
       
  3355             enabled: imageIsLoadedAndAllowedToChangeImageDimensionAndDepth
       
  3356             label: 'Uncrop (Add Border)...'
       
  3357             itemValue: doUnCropManual
       
  3358           )
       
  3359          (MenuItem
       
  3360             activeHelpKey: shiftManual
       
  3361             enabled: imageIsLoadedAndAllowedToChangeImageDimension
       
  3362             label: 'Shift...'
       
  3363             itemValue: doShiftManual
       
  3364           )
       
  3365          (MenuItem
       
  3366             label: '-'
       
  3367           )
       
  3368          (MenuItem
       
  3369             activeHelpKey: fileEditMask
       
  3370             enabled: hasMaskHolder
       
  3371             label: 'Edit Mask'
       
  3372             itemValue: doEditMask
       
  3373           )
       
  3374          (MenuItem
       
  3375             enabled: imageIsLoadedAndNotReadonlyHolder
       
  3376             label: 'Text...'
       
  3377             itemValue: doInsertTextFromUser
       
  3378           )
       
  3379          (MenuItem
       
  3380             label: '-'
       
  3381           )
       
  3382          (MenuItem
       
  3383             enabled: imageIsLoadedHolder
       
  3384             label: 'Animation Sequence'
       
  3385             submenu: 
       
  3386            (Menu
       
  3387               (
       
  3388                (MenuItem
       
  3389                   enabled: imageHasNextImageHolder
       
  3390                   label: 'Next in Sequence'
       
  3391                   itemValue: nextImageInSequence
       
  3392                 )
       
  3393                (MenuItem
       
  3394                   enabled: imageHasPreviousImageHolder
       
  3395                   label: 'Previous in Sequence'
       
  3396                   itemValue: previousImageInSequence
       
  3397                 )
       
  3398                (MenuItem
       
  3399                   label: '-'
       
  3400                 )
       
  3401                (MenuItem
       
  3402                   enabled: imageHasImageSequenceHolder
       
  3403                   label: 'Edit each from Sequence'
       
  3404                   itemValue: editEachImageFromSequence
       
  3405                 )
       
  3406                )
       
  3407               nil
       
  3408               nil
       
  3409             )
       
  3410           )
       
  3411          )
       
  3412         nil
       
  3413         nil
       
  3414       )
       
  3415 
  3231 
  3416     "Modified: / 12-04-2017 / 09:25:18 / cg"
  3232     "Modified: / 12-04-2017 / 09:25:18 / cg"
       
  3233     "Modified (comment): / 30-08-2017 / 00:30:38 / cg"
  3417 !
  3234 !
  3418 
  3235 
  3419 menuFile
  3236 menuFile
  3420     "This resource specification was automatically generated
  3237     "This resource specification was automatically generated
  3421      by the MenuEditor of ST/X."
  3238      by the MenuEditor of ST/X."
  5771 
  5588 
  5772 askForDepthThenDo:aBlock
  5589 askForDepthThenDo:aBlock
  5773     |oldDepth suggestion depth|
  5590     |oldDepth suggestion depth|
  5774 
  5591 
  5775     oldDepth := self image depth.
  5592     oldDepth := self image depth.
  5776     suggestion := oldDepth > 8 ifTrue:[8] ifFalse:[(oldDepth // 2 - 1) nextPowerOf2].
  5593     
       
  5594     suggestion := LastDepth notNil ifTrue:[
       
  5595                     LastDepth
       
  5596                   ] ifFalse:[
       
  5597                     oldDepth > 8 
       
  5598                         ifTrue:[8] 
       
  5599                         ifFalse:[(oldDepth // 2 - 1) nextPowerOf2]
       
  5600                   ].
  5777 
  5601 
  5778     depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
  5602     depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
  5779     depth isEmptyOrNil ifTrue:[^ self].
  5603     depth isEmptyOrNil ifTrue:[^ self].
  5780 
  5604 
  5781     depth := Number readFrom:depth onError:nil.
  5605     depth := Number readFrom:depth onError:nil.
  5782     depth isNil ifTrue:[^ self].
  5606     depth isNil ifTrue:[^ self].
  5783 
  5607 
       
  5608     LastDepth := depth.    
  5784     aBlock value:depth
  5609     aBlock value:depth
  5785 
  5610 
  5786     "Created: / 24-08-2017 / 17:05:39 / cg"
  5611     "Created: / 24-08-2017 / 17:05:39 / cg"
       
  5612     "Modified: / 30-08-2017 / 01:22:36 / cg"
  5787 !
  5613 !
  5788 
  5614 
  5789 checkModified
  5615 checkModified
  5790     imageEditView modified value ifTrue:[
  5616     imageEditView modified value ifTrue:[
  5791         (Dialog
  5617         (Dialog
  7506     self updateInfoLabel
  7332     self updateInfoLabel
  7507 
  7333 
  7508     "Created: / 20-02-2017 / 18:06:03 / cg"
  7334     "Created: / 20-02-2017 / 18:06:03 / cg"
  7509 !
  7335 !
  7510 
  7336 
  7511 ditherGrayToDepth
  7337 convertToDepth:depth dither:doDither
  7512     self askForDepthThenDo:[:depth |
  7338     |answer labels values 
  7513         self ditherGrayToDepth:depth
  7339      ditherColors fixColors
  7514     ].
  7340      nGrey greyColorsAlready moreColors d|
  7515 
  7341 
  7516     "Created: / 24-08-2017 / 17:49:42 / cg"
  7342     "/ no colormap above 12 bits!!
  7517 !
  7343     depth > 12 ifTrue:[
  7518 
  7344         answer := #TrueColor.
  7519 ditherGrayToDepth:depth
  7345     ] ifFalse:[    
  7520     self withExecuteCursorDo:[
  7346         doDither ifTrue:[
  7521         |newImage|
  7347             (depth >= 8) ifTrue:[
  7522         
  7348                 labels := #('Cancel' 'Use Browser Palette' 'Use Standard' 'Compute' 'TrueColor').
  7523         newImage := self image asGrayImageDepth:depth dither:true.
  7349                 values := #(nil UseBrowserPalette UseStandard Compute TrueColor).
  7524         imageEditView newImageWithUndo:newImage.
  7350             ] ifFalse:[
  7525     ].
  7351                 depth == 1 ifTrue:[
  7526 
  7352                     answer := #UseStandard
  7527     "Created: / 24-08-2017 / 17:51:07 / cg"
  7353                 ] ifFalse:[
  7528 !
  7354                     labels := #('Cancel' 'Use Standard' 'Compute' 'TrueColor').
  7529 
  7355                     values := #(nil UseStandard Compute TrueColor). 
  7530 ditherToDepth
  7356                 ].
  7531     self askForDepthThenDo:[:depth |
  7357             ].
  7532         self ditherToDepth:depth
  7358         ] ifFalse:[
  7533     ].
  7359             (depth >= 8) ifTrue:[
  7534 
  7360                 labels := #('Cancel' 'Use Browser Palette' 'Use Standard' 'TrueColor').
  7535     "Created: / 07-07-2006 / 13:22:10 / cg"
  7361                 values := #(nil UseBrowserPalette UseStandard TrueColor).
  7536     "Modified: / 24-08-2017 / 17:06:00 / cg"
  7362             ] ifFalse:[
  7537 !
  7363                 answer := #UseStandard
  7538 
  7364             ].    
  7539 ditherToDepth:depth 
  7365         ].    
  7540     |answer labels values ditherColors nGrey greyColorsAlready moreColors d|
  7366     ].
  7541 
  7367 
  7542     (depth >= 8) ifTrue:[
  7368     answer isNil ifTrue:[    
  7543         labels := #('Cancel' 'Use Browser Palette' 'Use Standard' 'Compute' ).
  7369         answer := OptionBox
  7544         values := #(nil UseBrowserPalette UseStandard Compute).
  7370                   request:'Compute a new (optimized) colormap\(Warning: this may take some time)\\or else use a standard colormap?' withCRs
  7545     ] ifFalse:[
  7371                   label:(resources string:'Dither how')
  7546         labels := #('Cancel' 'Use Standard' 'Compute' ).
  7372                   image:(YesNoBox iconBitmap)
  7547         values := #(nil UseStandard Compute). 
  7373                   buttonLabels:(resources array:labels)
  7548     ].
  7374                   values:values
  7549 
  7375                   default:#UseStandard
  7550     answer := OptionBox
  7376                   onCancel:nil.
  7551               request:'Compute a new (optimized) colormap\(Warning: this may take some time)\\or else use a standard colormap?' withCRs
  7377         answer isNil ifTrue:[^ self].
  7552               label:(resources string:'Dither how')
  7378     ].
  7553               image:(YesNoBox iconBitmap)
       
  7554               buttonLabels:(resources array:labels)
       
  7555               values:values
       
  7556               default:#UseStandard
       
  7557               onCancel:nil.
       
  7558     answer isNil ifTrue:[^ self].
       
  7559     
  7379     
  7560     (answer == #Compute) ifTrue:[
  7380     (answer == #Compute) ifTrue:[
  7561         ditherColors :=
  7381         ditherColors :=
  7562             Color
  7382             Color
  7563                 best:(1 bitShift:depth) 
  7383                 best:(1 bitShift:depth) 
  7564                 ditherColorsForImage:self image
  7384                 ditherColorsForImage:self image
  7565     ] ifFalse:[
  7385     ] ifFalse:[
  7566         (answer == #UseBrowserPalette) ifTrue:[
  7386         (answer == #UseBrowserPalette) ifTrue:[
  7567             ditherColors := Color colorCubeWithRed:6 green:6 blue:6. 
  7387             ditherColors := Color colorCubeWithRed:6 green:6 blue:6. 
  7568         ] ifFalse:[
  7388         ] ifFalse:[
  7569             depth = 1 ifTrue:[
  7389             answer == #TrueColor ifTrue:[
  7570                 ditherColors := Array with:(Color black) with:(Color white).
  7390                 depth == 6 ifTrue:[
  7571             ] ifFalse:[ depth = 2 ifTrue:[
  7391                     fixColors := FixedPalette 
  7572                 ditherColors := Array 
  7392                                     redShift:4 redMask:3
  7573                                     with:(Color black) 
  7393                                     greenShift:2 greenMask:3
  7574                                     with:(Color darkGray)
  7394                                     blueShift:0 blueMask:3
  7575                                     with:(Color lightGray)
  7395                 ].
  7576                                     with:(Color white).
  7396                 depth == 9 ifTrue:[
  7577             ] ifFalse:[ depth = 3 ifTrue:[
  7397                     fixColors := FixedPalette 
  7578                 ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
  7398                                     redShift:6 redMask:7
  7579             ] ifFalse:[ depth = 4 ifTrue:[
  7399                                     greenShift:3 greenMask:7
  7580                 ditherColors := Color vgaColors. 
  7400                                     blueShift:0 blueMask:7
  7581             ] ifFalse:[ depth = 5 ifTrue:[
  7401                 ].
  7582                 ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
  7402                 depth == 12 ifTrue:[
  7583             ] ifFalse:[ depth = 6 ifTrue:[
  7403                     fixColors := FixedPalette 
  7584                 ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
  7404                                     redShift:8 redMask:16r0F
  7585             ] ifFalse:[ depth = 7 ifTrue:[
  7405                                     greenShift:4 greenMask:16r0F
  7586                 ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
  7406                                     blueShift:0 blueMask:16r0F
  7587             ] ifFalse:[ depth == 8 ifTrue:[
  7407                 ].
  7588                 ditherColors := Color standardDitherColorsForDepth8. 
  7408                 depth == 15 ifTrue:[
  7589             ] ifFalse:[ 
  7409                     fixColors := FixedPalette 
  7590                 self error:'unsupported depth'.
  7410                                     redShift:10 redMask:16r1F
  7591             ]]]]]]]].
  7411                                     greenShift:5 greenMask:16r1F
  7592 
  7412                                     blueShift:0 blueMask:16r1F
  7593         
  7413                 ].
  7594             "/ add as many gray colors as possible.
  7414                 depth == 16 ifTrue:[
  7595             nGrey := (2 raisedTo:depth) - ditherColors size.  
  7415                     fixColors := FixedPalette 
  7596             nGrey > 0 ifTrue:[
  7416                                     redShift:11 redMask:16r1F
  7597                 nGrey := nGrey min:128.
  7417                                     greenShift:5 greenMask:16r3F
  7598                 greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
  7418                                     blueShift:0 blueMask:16r1F
  7599                 d := 1 / nGrey.
  7419                 ].
  7600                 moreColors := (1 to:nGrey-1) 
  7420                 depth == 18 ifTrue:[
  7601                                 collect:[:i | Color brightness:(d * i)] 
  7421                     fixColors := FixedPalette 
  7602                                 thenReject:[:clr | greyColorsAlready includes:clr ].
  7422                                     redShift:12 redMask:16r3F
  7603 
  7423                                     greenShift:6 greenMask:16r3F
  7604                 ditherColors := ditherColors , moreColors.
  7424                                     blueShift:0 blueMask:16r3F
       
  7425                 ].
       
  7426             ] ifFalse:[
       
  7427                 depth == 1 ifTrue:[
       
  7428                     ditherColors := { Color black . Color white }.
       
  7429                 ].
       
  7430                 depth == 2 ifTrue:[
       
  7431                     ditherColors := { Color black . Color darkGray  .Color lightGray . Color white }.
       
  7432                 ].
       
  7433                 depth = 3 ifTrue:[
       
  7434                     ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
       
  7435                 ].
       
  7436                 depth = 4 ifTrue:[
       
  7437                     ditherColors := Color vgaColors. 
       
  7438                 ].
       
  7439                 depth = 5 ifTrue:[
       
  7440                     ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
       
  7441                 ].
       
  7442                 depth = 6 ifTrue:[
       
  7443                     ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
       
  7444                 ].
       
  7445                 depth = 7 ifTrue:[
       
  7446                     ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
       
  7447                 ].
       
  7448                 depth == 8 ifTrue:[
       
  7449                     ditherColors := Color standardDitherColorsForDepth8. 
       
  7450                 ].
       
  7451                 depth == 9 ifTrue:[
       
  7452                     ditherColors := Color colorCubeWithRed:8 green:8 blue:8. 
       
  7453                 ].
       
  7454                 ditherColors isNil ifTrue:[
       
  7455                     self error:'unsupported depth'.
       
  7456                 ].
       
  7457 
       
  7458                 "/ add as many gray colors as possible.
       
  7459                 nGrey := (2 raisedTo:depth) - ditherColors size.  
       
  7460                 nGrey > 0 ifTrue:[
       
  7461                     nGrey := nGrey min:100.
       
  7462                     greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
       
  7463                     d := 1 / nGrey.
       
  7464                     moreColors := (1 to:nGrey-1) 
       
  7465                                     collect:[:i | Color brightness:(d * i)] 
       
  7466                                     thenReject:[:clr | greyColorsAlready includes:clr ].
       
  7467 
       
  7468                     ditherColors := ditherColors , moreColors.
       
  7469                 ].
  7605             ].
  7470             ].
  7606         ].
  7471         ].
  7607     ].
  7472     ].
  7608 
  7473 
  7609     self withExecuteCursorDo:[
  7474     self withExecuteCursorDo:[
  7610         |newImage|
  7475         |newImage|
  7611         
  7476 
  7612         newImage := self image asDitheredImageUsing:ditherColors depth:depth.
  7477         doDither ifTrue:[
       
  7478             depth == 1 ifTrue:[
       
  7479                 newImage := self image asErrorDitheredMonochromeImage
       
  7480             ] ifFalse:[
       
  7481                 answer == #TrueColor ifTrue:[
       
  7482                     newImage := self image asDitheredImageUsing:fixColors depth:depth.
       
  7483                 ] ifFalse:[    
       
  7484                     newImage := self image asDitheredImageUsing:ditherColors depth:depth.
       
  7485                 ]
       
  7486             ]
       
  7487         ] ifFalse:[
       
  7488             answer == #TrueColor ifTrue:[
       
  7489                 self halt.
       
  7490             ] ifFalse:[    
       
  7491                 newImage := self image asNearestPaintImageDepth:depth colors:ditherColors
       
  7492             ].
       
  7493         ].
  7613         imageEditView newImageWithUndo:newImage.
  7494         imageEditView newImageWithUndo:newImage.
  7614     ].
  7495     ].
  7615 
  7496 
  7616     "Created: / 07-07-2006 / 13:20:56 / cg"
  7497     "Created: / 30-08-2017 / 00:33:55 / cg"
  7617     "Modified: / 29-08-2017 / 21:08:34 / cg"
  7498     "Modified: / 30-08-2017 / 02:13:03 / cg"
       
  7499 !
       
  7500 
       
  7501 ditherGrayToDepth
       
  7502     self askForDepthThenDo:[:depth |
       
  7503         self ditherGrayToDepth:depth
       
  7504     ].
       
  7505 
       
  7506     "Created: / 24-08-2017 / 17:49:42 / cg"
       
  7507 !
       
  7508 
       
  7509 ditherGrayToDepth:depth
       
  7510     self withExecuteCursorDo:[
       
  7511         |newImage|
       
  7512 
       
  7513         depth == 1 ifTrue:[
       
  7514             newImage := self image asErrorDitheredMonochromeImage
       
  7515         ] ifFalse:[
       
  7516             newImage := self image asGrayImageDepth:depth dither:#floydSteinberg.
       
  7517         ].
       
  7518         imageEditView newImageWithUndo:newImage.
       
  7519     ].
       
  7520 
       
  7521     "Created: / 24-08-2017 / 17:51:07 / cg"
       
  7522     "Modified: / 30-08-2017 / 01:18:43 / cg"
       
  7523 !
       
  7524 
       
  7525 ditherToDepth
       
  7526     self askForDepthThenDo:[:depth |
       
  7527         self convertToDepth:depth dither:true
       
  7528     ].
       
  7529 
       
  7530     "Created: / 07-07-2006 / 13:22:10 / cg"
       
  7531     "Modified: / 30-08-2017 / 00:34:42 / cg"
  7618 !
  7532 !
  7619 
  7533 
  7620 do3DProjection
  7534 do3DProjection
  7621     |box dx1 dx2 image|
  7535     |box dx1 dx2 image|
  7622 
  7536 
  7854 !
  7768 !
  7855 
  7769 
  7856 doMagnifyImageBy
  7770 doMagnifyImageBy
  7857     "magnifies the current image (by a scale)"
  7771     "magnifies the current image (by a scale)"
  7858 
  7772 
  7859     |oldSize newSize scaleString scale image antiAliased|
  7773     |oldSize newSize scaleString scale image antiAliased smoothing|
  7860 
  7774 
  7861     image := imageEditView image.
  7775     image := imageEditView image.
  7862     oldSize := image extent.
  7776     oldSize := image extent.
  7863 
  7777 
  7864     antiAliased := false asValue.
  7778     antiAliased := false asValue.
  7865 
  7779     smoothing := false asValue.
       
  7780     
  7866     Dialog modifyingBoxWith:[:box |
  7781     Dialog modifyingBoxWith:[:box |
  7867         box addCheckBox:(resources string:'Antialiased') on:antiAliased.
  7782         box verticalPanel add:(CheckBox label:(resources string:'Antialias/Smooth') model:antiAliased).
       
  7783         "/ box verticalPanel add:(CheckBox label:(resources string:'Smoothing') model:smoothing).
  7868     ] do:[
  7784     ] do:[
  7869         scaleString := Dialog 
  7785         scaleString := Dialog 
  7870                    request:(resources string:'Scale factor (<1 to shrink; >1 to magnify):') 
  7786                    request:(resources string:'Scale factor (<1 to shrink; >1 to magnify):') 
  7871                    initialAnswer:'1'
  7787                    initialAnswer:'1'
  7872                    list:#('0.25' '0.5' '2' '4').     
  7788                    list:#('0.1' '0.25' '0.3' '0.5' '1.5' '2' '3' '4').     
  7873     ].
  7789     ].
  7874     scaleString isNil ifTrue:[^ self].
  7790     scaleString isNil ifTrue:[^ self].
  7875 
       
  7876 "/    box := EnterBox new.
       
  7877 "/    box title:(resources string:'Scale factor (<1 to shrink; >1 to magnify):').
       
  7878 "/    box okText:(resources string:'OK').
       
  7879 "/    box abortText:(resources string:'Cancel').
       
  7880 "/    box initialText:1 printString.
       
  7881 "/    box showAtPointer.
       
  7882 "/    box accepted ifTrue:[
       
  7883 "/        scaleString := box contents.
       
  7884 "/    ].
       
  7885 
  7791 
  7886     scale := Object readFromString:scaleString onError:nil.
  7792     scale := Object readFromString:scaleString onError:nil.
  7887 
  7793 
  7888     scale notNil ifTrue:[
  7794     scale notNil ifTrue:[
  7889         scale isNumber ifFalse:[
  7795         scale isNumber ifFalse:[
  7890             self warn:'please enter a scale factor (<1 to shrink; >1 to magnify).'.
  7796             self warn:'please enter a scale factor (<1 to shrink; >1 to magnify).'.
  7891             ^ self.    
  7797             ^ self.    
  7892         ].
  7798         ].
  7893         newSize := oldSize * scale.
  7799         newSize := oldSize * scale.
  7894         antiAliased value ifTrue:[
  7800         antiAliased value ifTrue:[
  7895             imageEditView magnifyAntiAliasedImageTo:newSize.
  7801             scale < 1 ifTrue:[
       
  7802                 imageEditView magnifySmoothingBy:scale.
       
  7803             ] ifFalse:[    
       
  7804                 imageEditView magnifyAntiAliasedImageTo:newSize.
       
  7805             ].
  7896         ] ifFalse:[
  7806         ] ifFalse:[
  7897             imageEditView magnifyImageTo:newSize.
  7807             imageEditView magnifyImageTo:newSize.
  7898         ].
  7808         ].
  7899     ].
  7809     ].
  7900 
  7810 
  7901     self updateInfoLabel
  7811     self updateInfoLabel
       
  7812 
       
  7813     "Modified: / 30-08-2017 / 15:34:56 / cg"
  7902 !
  7814 !
  7903 
  7815 
  7904 doMagnifyUp
  7816 doMagnifyUp
  7905     "magnifies the current image one step up"
  7817     "magnifies the current image one step up"
  7906 
  7818 
  8128         newImage := self image asThresholdGrayImageDepth:depth.
  8040         newImage := self image asThresholdGrayImageDepth:depth.
  8129         imageEditView newImageWithUndo:newImage.
  8041         imageEditView newImageWithUndo:newImage.
  8130     ].
  8042     ].
  8131 
  8043 
  8132     "Created: / 24-08-2017 / 17:49:30 / cg"
  8044     "Created: / 24-08-2017 / 17:49:30 / cg"
       
  8045 !
       
  8046 
       
  8047 thresholdToDepth
       
  8048     self askForDepthThenDo:[:depth |
       
  8049         self convertToDepth:depth dither:false
       
  8050     ].
       
  8051 
       
  8052     "Created: / 30-08-2017 / 00:31:33 / cg"
  8133 ! !
  8053 ! !
  8134 
  8054 
  8135 !ImageEditor methodsFor:'user actions-image sequences'!
  8055 !ImageEditor methodsFor:'user actions-image sequences'!
  8136 
  8056 
  8137 editEachImageFromSequence
  8057 editEachImageFromSequence