ImageEditor.st
changeset 3460 5d1d7e85222c
parent 3459 f264db47ed05
child 3461 bd826e508822
equal deleted inserted replaced
3459:f264db47ed05 3460:5d1d7e85222c
  3080                   label: 'Make GrayScale'
  3080                   label: 'Make GrayScale'
  3081                   itemValue: makeGrayScaleImage
  3081                   itemValue: makeGrayScaleImage
  3082                   translateLabel: true
  3082                   translateLabel: true
  3083                 )
  3083                 )
  3084                (MenuItem
  3084                (MenuItem
  3085                   label: 'Make Monochrome'
  3085                   label: 'Make Monochrome...'
  3086                   itemValue: makeMonochromeImage
  3086                   itemValue: makeMonochromeImage
  3087                   translateLabel: true
  3087                   translateLabel: true
  3088                 )
  3088                 )
  3089                (MenuItem
  3089                (MenuItem
  3090                   label: 'Make Inverse'
  3090                   label: 'Make Inverse'
  3105                   label: 'Dither to Depth...'
  3105                   label: 'Dither to Depth...'
  3106                   itemValue: ditherToDepth
  3106                   itemValue: ditherToDepth
  3107                   translateLabel: true
  3107                   translateLabel: true
  3108                 )
  3108                 )
  3109                (MenuItem
  3109                (MenuItem
  3110                   label: 'Threshold to Depth...'
  3110                   label: 'Make GrayScale with Depth (Dither)...'
  3111                   itemValue: thresholdToDepth
  3111                   itemValue: ditherGrayToDepth
       
  3112                   translateLabel: true
       
  3113                 )
       
  3114                (MenuItem
       
  3115                   label: 'Make GrayScale with Depth (Threshold)...'
       
  3116                   itemValue: thresholdGrayToDepth
  3112                   translateLabel: true
  3117                   translateLabel: true
  3113                 )
  3118                 )
  3114                (MenuItem
  3119                (MenuItem
  3115                   label: '-'
  3120                   label: '-'
  3116                 )
  3121                 )
  3196          )
  3201          )
  3197         nil
  3202         nil
  3198         nil
  3203         nil
  3199       )
  3204       )
  3200 
  3205 
  3201     "Modified: / 24-08-2017 / 15:25:00 / cg"
  3206     "Modified: / 24-08-2017 / 17:49:04 / cg"
  3202 !
  3207 !
  3203 
  3208 
  3204 menuEdit
  3209 menuEdit
  3205     "This resource specification was automatically generated
  3210     "This resource specification was automatically generated
  3206      by the MenuEditor of ST/X."
  3211      by the MenuEditor of ST/X."
  5107             imagePreView image:image scroll:false.
  5112             imagePreView image:image scroll:false.
  5108             self updateListOfColorsAndColormapMode.
  5113             self updateListOfColorsAndColormapMode.
  5109             self tileModeHolder value ifTrue:[
  5114             self tileModeHolder value ifTrue:[
  5110                 imagePreView tileMode:true tileOffset:(image extent).
  5115                 imagePreView tileMode:true tileOffset:(image extent).
  5111             ].
  5116             ].
       
  5117             self updateInfoLabel.
  5112             ^ self.
  5118             ^ self.
  5113         ].
  5119         ].
  5114         something == #subImageIn ifTrue:[
  5120         something == #subImageIn ifTrue:[
  5115             imagePreView image ~~ image ifTrue:[
  5121             imagePreView image ~~ image ifTrue:[
  5116                 self error:'internal error' mayProceed:true.
  5122                 self error:'internal error' mayProceed:true.
  5147         ^ self.
  5153         ^ self.
  5148     ].
  5154     ].
  5149 
  5155 
  5150     super update:something with:aParameter from:changedObject
  5156     super update:something with:aParameter from:changedObject
  5151 
  5157 
  5152     "Modified: / 20-03-2017 / 16:05:55 / cg"
  5158     "Modified: / 24-08-2017 / 17:12:59 / cg"
  5153 !
  5159 !
  5154 
  5160 
  5155 updateAfterImageChange
  5161 updateAfterImageChange
  5156     |img|
  5162     |img|
  5157 
  5163 
  5730 
  5736 
  5731     "Modified: / 10.2.2000 / 23:16:42 / cg"
  5737     "Modified: / 10.2.2000 / 23:16:42 / cg"
  5732 ! !
  5738 ! !
  5733 
  5739 
  5734 !ImageEditor methodsFor:'private'!
  5740 !ImageEditor methodsFor:'private'!
       
  5741 
       
  5742 askForDepthThenDo:aBlock
       
  5743     |oldDepth suggestion depth|
       
  5744 
       
  5745     oldDepth := self image depth.
       
  5746     suggestion := oldDepth > 8 ifTrue:[8] ifFalse:[(oldDepth // 2 - 1) nextPowerOf2].
       
  5747 
       
  5748     depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
       
  5749     depth isEmptyOrNil ifTrue:[^ self].
       
  5750 
       
  5751     depth := Number readFrom:depth onError:nil.
       
  5752     depth isNil ifTrue:[^ self].
       
  5753 
       
  5754     aBlock value:depth
       
  5755 
       
  5756     "Created: / 24-08-2017 / 17:05:39 / cg"
       
  5757 !
  5735 
  5758 
  5736 checkModified
  5759 checkModified
  5737     imageEditView modified value ifTrue:[
  5760     imageEditView modified value ifTrue:[
  5738         (Dialog
  5761         (Dialog
  5739             confirm:(resources string:'Image was not saved. Proceed anyway ?')
  5762             confirm:(resources string:'Image was not saved. Proceed anyway ?')
  6768 
  6791 
  6769 copyColorFromColormap
  6792 copyColorFromColormap
  6770     imageEditView setClipboardObject:(self selectedColorOrNil)
  6793     imageEditView setClipboardObject:(self selectedColorOrNil)
  6771 !
  6794 !
  6772 
  6795 
  6773 ditherToDepth
       
  6774     |oldDepth suggestion depth|
       
  6775 
       
  6776     oldDepth := self image depth.
       
  6777     suggestion := oldDepth > 8 ifTrue:[8] ifFalse:[(oldDepth // 2 - 1) nextPowerOf2].
       
  6778 
       
  6779     depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
       
  6780     depth isEmptyOrNil ifTrue:[^ self].
       
  6781 
       
  6782     depth := Number readFrom:depth onError:nil.
       
  6783     depth isNil ifTrue:[^ self].
       
  6784 
       
  6785     self ditherToDepth:depth
       
  6786 
       
  6787     "Created: / 07-07-2006 / 13:22:10 / cg"
       
  6788     "Modified: / 06-04-2017 / 13:34:05 / cg"
       
  6789 !
       
  6790 
       
  6791 ditherToDepth:depth
       
  6792     |ditherColors newImage useStandardColors nGrey greyColorsAlready moreColors d|
       
  6793 
       
  6794     useStandardColors := true.
       
  6795 "/    useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'.
       
  6796 "/    useStandardColors isNil ifTrue:[^ self].
       
  6797 
       
  6798     useStandardColors ifTrue:[
       
  6799         depth = 1 ifTrue:[
       
  6800             ditherColors := Array with:(Color black) with:(Color white).
       
  6801         ] ifFalse:[ depth = 2 ifTrue:[
       
  6802             ditherColors := Array 
       
  6803                                 with:(Color black) 
       
  6804                                 with:(Color darkGray)
       
  6805                                 with:(Color lightGray)
       
  6806                                 with:(Color white).
       
  6807         ] ifFalse:[ depth = 3 ifTrue:[
       
  6808             ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
       
  6809         ] ifFalse:[ depth = 4 ifTrue:[
       
  6810             ditherColors := Color vgaColors. 
       
  6811         ] ifFalse:[ depth = 5 ifTrue:[
       
  6812             ditherColors := Color colorCubeWithRed:4 green:4 blue:2. 
       
  6813         ] ifFalse:[ depth = 6 ifTrue:[
       
  6814             ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
       
  6815         ] ifFalse:[ depth <= 8 ifTrue:[
       
  6816             ditherColors := Color colorCubeWithRed:6 green:6 blue:5. 
       
  6817         ] ifFalse:[ 
       
  6818             self error:'unsupported depth'.
       
  6819         ]]]]]]].
       
  6820 
       
  6821         nGrey := (2 raisedTo:depth) - ditherColors size.  
       
  6822         nGrey > 0 ifTrue:[
       
  6823             nGrey := nGrey min:128.
       
  6824             greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
       
  6825             d := 1 / nGrey.
       
  6826             moreColors := (1 to:nGrey-1) 
       
  6827                             collect:[:i | Color brightness:(d * i)] 
       
  6828                             thenReject:[:clr | greyColorsAlready includes:clr ].
       
  6829 
       
  6830             ditherColors := ditherColors , moreColors.
       
  6831         ].
       
  6832     ] ifFalse:[
       
  6833         self halt:'unhandled dither color setup'.
       
  6834     ].
       
  6835 
       
  6836     self withExecuteCursorDo:[
       
  6837         "/ newImage := self image asDitheredImageUsing:ditherColors depth:depth.
       
  6838         newImage := self image asDitheredImageUsing:ditherColors depth:8.
       
  6839 
       
  6840         imageEditView makeUndo.
       
  6841         imageEditView image:newImage.
       
  6842         imageEditView setModified.
       
  6843         self updateImage.
       
  6844         self updateImagePreView.
       
  6845 
       
  6846         self fetchImageData.
       
  6847     ].
       
  6848 
       
  6849     "Created: / 07-07-2006 / 13:20:56 / cg"
       
  6850     "Modified: / 05-09-2006 / 16:13:25 / cg"
       
  6851 !
       
  6852 
       
  6853 doubleClickOnColor:aColorIndex
  6796 doubleClickOnColor:aColorIndex
  6854     self editSelectedColor.
  6797     self editSelectedColor.
  6855 
  6798 
  6856     "Created: / 22-07-2007 / 13:14:37 / cg"
  6799     "Created: / 22-07-2007 / 13:14:37 / cg"
  6857 !
  6800 !
  7507     self updateInfoLabel
  7450     self updateInfoLabel
  7508 
  7451 
  7509     "Created: / 20-02-2017 / 18:06:03 / cg"
  7452     "Created: / 20-02-2017 / 18:06:03 / cg"
  7510 !
  7453 !
  7511 
  7454 
       
  7455 ditherGrayToDepth
       
  7456     self askForDepthThenDo:[:depth |
       
  7457         self ditherGrayToDepth:depth
       
  7458     ].
       
  7459 
       
  7460     "Created: / 24-08-2017 / 17:49:42 / cg"
       
  7461 !
       
  7462 
       
  7463 ditherGrayToDepth:depth
       
  7464     self withExecuteCursorDo:[
       
  7465         |newImage|
       
  7466         
       
  7467         newImage := self image asGrayImageDepth:depth dither:true.
       
  7468         imageEditView newImageWithUndo:newImage.
       
  7469     ].
       
  7470 
       
  7471     "Created: / 24-08-2017 / 17:51:07 / cg"
       
  7472 !
       
  7473 
       
  7474 ditherToDepth
       
  7475     self askForDepthThenDo:[:depth |
       
  7476         self ditherToDepth:depth
       
  7477     ].
       
  7478 
       
  7479     "Created: / 07-07-2006 / 13:22:10 / cg"
       
  7480     "Modified: / 24-08-2017 / 17:06:00 / cg"
       
  7481 !
       
  7482 
       
  7483 ditherToDepth:depth 
       
  7484     |ditherColors useStandardColors nGrey greyColorsAlready moreColors d|
       
  7485 
       
  7486     useStandardColors := true.
       
  7487 "/    useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'.
       
  7488 "/    useStandardColors isNil ifTrue:[^ self].
       
  7489 
       
  7490     useStandardColors ifTrue:[
       
  7491         depth = 1 ifTrue:[
       
  7492             ditherColors := Array with:(Color black) with:(Color white).
       
  7493         ] ifFalse:[ depth = 2 ifTrue:[
       
  7494             ditherColors := Array 
       
  7495                                 with:(Color black) 
       
  7496                                 with:(Color darkGray)
       
  7497                                 with:(Color lightGray)
       
  7498                                 with:(Color white).
       
  7499         ] ifFalse:[ depth = 3 ifTrue:[
       
  7500             ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
       
  7501         ] ifFalse:[ depth = 4 ifTrue:[
       
  7502             ditherColors := Color vgaColors. 
       
  7503         ] ifFalse:[ depth = 5 ifTrue:[
       
  7504             ditherColors := Color colorCubeWithRed:4 green:4 blue:2. 
       
  7505         ] ifFalse:[ depth = 6 ifTrue:[
       
  7506             ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
       
  7507         ] ifFalse:[ depth <= 8 ifTrue:[
       
  7508             ditherColors := Color colorCubeWithRed:6 green:6 blue:5. 
       
  7509         ] ifFalse:[ 
       
  7510             self error:'unsupported depth'.
       
  7511         ]]]]]]].
       
  7512 
       
  7513         nGrey := (2 raisedTo:depth) - ditherColors size.  
       
  7514         nGrey > 0 ifTrue:[
       
  7515             nGrey := nGrey min:128.
       
  7516             greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
       
  7517             d := 1 / nGrey.
       
  7518             moreColors := (1 to:nGrey-1) 
       
  7519                             collect:[:i | Color brightness:(d * i)] 
       
  7520                             thenReject:[:clr | greyColorsAlready includes:clr ].
       
  7521 
       
  7522             ditherColors := ditherColors , moreColors.
       
  7523         ].
       
  7524     ] ifFalse:[
       
  7525         self halt:'unhandled dither color setup'.
       
  7526     ].
       
  7527 
       
  7528     self withExecuteCursorDo:[
       
  7529         |newImage|
       
  7530         
       
  7531         newImage := self image asDitheredImageUsing:ditherColors depth:depth.
       
  7532         imageEditView newImageWithUndo:newImage.
       
  7533     ].
       
  7534 
       
  7535     "Created: / 07-07-2006 / 13:20:56 / cg"
       
  7536     "Modified (format): / 24-08-2017 / 17:53:46 / cg"
       
  7537 !
       
  7538 
  7512 do3DProjection
  7539 do3DProjection
  7513     |box dx1 dx2 image|
  7540     |box dx1 dx2 image|
  7514 
  7541 
  7515     image := imageEditView image.
  7542     image := imageEditView image.
  7516 
  7543 
  7961     Dialog modifyingBoxWith:[:box |
  7988     Dialog modifyingBoxWith:[:box |
  7962         |preview slider update thresholdValue|
  7989         |preview slider update thresholdValue|
  7963 
  7990 
  7964         thresholdValue := 0.5 asValue.
  7991         thresholdValue := 0.5 asValue.
  7965 
  7992 
  7966         box enterField converter:(PrintConverter new initForNumber).
  7993         box enterField 
  7967         box enterField model:thresholdValue.
  7994             converter:(PrintConverter new initForNumber);
       
  7995             model:thresholdValue.
       
  7996             
  7968         box verticalPanel extent:1.0 @ 300.
  7997         box verticalPanel extent:1.0 @ 300.
  7969         
  7998         
  7970         box verticalPanel add:(slider := HorizontalSlider new start:0 stop:1 step:0.05).
  7999         box verticalPanel add:(slider := HorizontalSlider new start:0 stop:1 step:0.05).
  7971         slider model:thresholdValue.
  8000         slider model:thresholdValue.
  7972         slider width:1.0; leftInset:4; rightInset:4.
  8001         slider width:1.0; leftInset:4; rightInset:4.
  7998 
  8027 
  7999     thresholdBrighness := thresholdBrighness clampBetween:0 and:1.
  8028     thresholdBrighness := thresholdBrighness clampBetween:0 and:1.
  8000     imageEditView newImageWithUndo:(image asThresholdMonochromeImage:thresholdBrighness)
  8029     imageEditView newImageWithUndo:(image asThresholdMonochromeImage:thresholdBrighness)
  8001 
  8030 
  8002     "Created: / 24-08-2017 / 15:26:44 / cg"
  8031     "Created: / 24-08-2017 / 15:26:44 / cg"
  8003     "Modified (comment): / 24-08-2017 / 16:53:49 / cg"
  8032     "Modified: / 24-08-2017 / 17:54:21 / cg"
       
  8033 !
       
  8034 
       
  8035 thresholdGrayToDepth
       
  8036     self askForDepthThenDo:[:depth |
       
  8037         self thresholdGrayToDepth:depth
       
  8038     ].
       
  8039 
       
  8040     "Created: / 24-08-2017 / 17:49:23 / cg"
       
  8041 !
       
  8042 
       
  8043 thresholdGrayToDepth:depth
       
  8044     self withExecuteCursorDo:[
       
  8045         |newImage|
       
  8046 
       
  8047         newImage := self image asThresholdGrayImageDepth:depth.
       
  8048         imageEditView newImageWithUndo:newImage.
       
  8049     ].
       
  8050 
       
  8051     "Created: / 24-08-2017 / 17:49:30 / cg"
  8004 ! !
  8052 ! !
  8005 
  8053 
  8006 !ImageEditor methodsFor:'user actions-image sequences'!
  8054 !ImageEditor methodsFor:'user actions-image sequences'!
  8007 
  8055 
  8008 editEachImageFromSequence
  8056 editEachImageFromSequence