ImageEditor.st
changeset 1682 f1b2491c9dc2
parent 1656 f5c0716efd78
child 1687 f4543a556b89
equal deleted inserted replaced
1681:7a8e5df3f07d 1682:f1b2491c9dc2
  1561                 #label: 'Add Color'
  1561                 #label: 'Add Color'
  1562                 #translateLabel: true
  1562                 #translateLabel: true
  1563                 #value: #addColorToColormap
  1563                 #value: #addColorToColormap
  1564             )
  1564             )
  1565              #(#MenuItem
  1565              #(#MenuItem
       
  1566                 #label: 'Pick and Add Color'
       
  1567                 #translateLabel: true
       
  1568                 #value: #pickAndAddColorToColormap
       
  1569             )
       
  1570              #(#MenuItem
       
  1571                 #label: '-'
       
  1572             )
       
  1573              #(#MenuItem
       
  1574                 #label: 'Darker'
       
  1575                 #translateLabel: true
       
  1576                 #value: #makeSelectedColorDarker
       
  1577             )
       
  1578              #(#MenuItem
       
  1579                 #label: 'Brighter'
       
  1580                 #translateLabel: true
       
  1581                 #value: #makeSelectedColorBrighter
       
  1582             )
       
  1583              #(#MenuItem
  1566                 #label: '-'
  1584                 #label: '-'
  1567             )
  1585             )
  1568              #(#MenuItem
  1586              #(#MenuItem
  1569                 #label: 'Inspect Color'
  1587                 #label: 'Inspect Color'
  1570                 #translateLabel: true
  1588                 #translateLabel: true
  1613               #(
  1631               #(
  1614                #(#MenuItem
  1632                #(#MenuItem
  1615                   #activeHelpKey: #fileNewImage
  1633                   #activeHelpKey: #fileNewImage
  1616                   #label: 'New...'
  1634                   #label: 'New...'
  1617                   #itemValue: #doNewImage
  1635                   #itemValue: #doNewImage
       
  1636                   #translateLabel: true
       
  1637                 )
       
  1638                #(#MenuItem
       
  1639                   #activeHelpKey: #fileNewImage
       
  1640                   #label: 'New from ClipBoard'
       
  1641                   #itemValue: #doNewImageFromClipboard
  1618                   #translateLabel: true
  1642                   #translateLabel: true
  1619                 )
  1643                 )
  1620                #(#MenuItem
  1644                #(#MenuItem
  1621                   #label: '-'
  1645                   #label: '-'
  1622                 )
  1646                 )
  2594     ].
  2618     ].
  2595     ^ holder
  2619     ^ holder
  2596 !
  2620 !
  2597 
  2621 
  2598 selectionOfColor
  2622 selectionOfColor
  2599     "returns current selection of the edit color as an AspectAdaptor"
  2623     "returns a valueHolder for the current selection of the edit color.
       
  2624      Here, an AspectAdaptor which accesses selectedColorIndex is returned."
  2600 
  2625 
  2601     |holder|
  2626     |holder|
       
  2627 
  2602     (holder := builder bindingAt:#selectionOfColor) isNil ifTrue:[
  2628     (holder := builder bindingAt:#selectionOfColor) isNil ifTrue:[
  2603         builder aspectAt:#selectionOfColor put:(
  2629         builder aspectAt:#selectionOfColor put:(
  2604         holder := AspectAdaptor new subject:self; forAspect:#selectedColorIndex).
  2630         holder := AspectAdaptor new subject:self; forAspect:#selectedColorIndex ).
  2605     ].
  2631     ].
  2606     ^ holder
  2632     ^ holder
  2607 !
  2633 !
  2608 
  2634 
  2609 tileModeHolder
  2635 tileModeHolder
  3177 ! !
  3203 ! !
  3178 
  3204 
  3179 !ImageEditor methodsFor:'user actions - colormap'!
  3205 !ImageEditor methodsFor:'user actions - colormap'!
  3180 
  3206 
  3181 addColorToColormap
  3207 addColorToColormap
       
  3208     self addColorToColormap:(Color black)
       
  3209 !
       
  3210 
       
  3211 addColorToColormap:newColor
  3182     |depth img cMap newColorMap newImage oldCListSize newMode listOfColors|
  3212     |depth img cMap newColorMap newImage oldCListSize newMode listOfColors|
  3183 
  3213 
  3184     img := self image.
  3214     img := self image.
  3185     img isNil ifTrue:[
  3215     img isNil ifTrue:[
  3186         self warn:'No Image.'.
  3216         self warn:'No Image.'.
  3192     cMap isNil ifTrue:[
  3222     cMap isNil ifTrue:[
  3193         drawingColormap isNil ifTrue:[
  3223         drawingColormap isNil ifTrue:[
  3194             self information:'Image has no colormap.\The shown colorMap is for drawing only.' withCRs.
  3224             self information:'Image has no colormap.\The shown colorMap is for drawing only.' withCRs.
  3195             drawingColormap := OrderedCollection new.
  3225             drawingColormap := OrderedCollection new.
  3196         ].
  3226         ].
  3197         drawingColormap add:(Color black).
  3227         drawingColormap add:newColor.
  3198         self listOfColors contents:drawingColormap.
  3228         self listOfColors contents:drawingColormap.
  3199         self selectionOfColor value:(drawingColormap size).
  3229         self selectionOfColor value:(drawingColormap size).
  3200 
  3230 
  3201         "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
  3231         "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
  3202         ^ self
  3232         ^ self
  3233 "/            ]
  3263 "/            ]
  3234 "/        ].
  3264 "/        ].
  3235 "/    ].
  3265 "/    ].
  3236 "/
  3266 "/
  3237 
  3267 
  3238     newColorMap := cMap copyWith:(Color black).
  3268     newColorMap := cMap copyWith:newColor.
  3239 
  3269 
  3240     newImage := img species new
  3270     newImage := img species new
  3241                     width:img width
  3271                     width:img width
  3242                     height:img height
  3272                     height:img height
  3243                     depth:depth
  3273                     depth:depth
  3703         self updateLabelsAndHistory.
  3733         self updateLabelsAndHistory.
  3704     ]
  3734     ]
  3705 !
  3735 !
  3706 
  3736 
  3707 inspectColor
  3737 inspectColor
  3708     | img clrIndex|
  3738     |clrIndex|
  3709 
  3739 
  3710     img := self image.
  3740     clrIndex := self selectedColorIndexOrNil.
  3711     img isNil ifTrue:[
  3741     clrIndex isNil ifTrue:[
  3712         self warn:'No Image.'.
       
  3713         ^ self
  3742         ^ self
  3714     ].
  3743     ].
  3715     clrIndex := self selectionOfColor value.
  3744     (self image colorFromValue:clrIndex-1) inspect
  3716     img mask notNil ifTrue: [ clrIndex := clrIndex - 1 ].
       
  3717     (img colorFromValue:clrIndex-1) inspect
       
  3718 !
  3745 !
  3719 
  3746 
  3720 makeBrighter
  3747 makeBrighter
  3721     | anyChange|
  3748     | anyChange|
  3722 
  3749 
  3768         ]
  3795         ]
  3769     ].
  3796     ].
  3770 !
  3797 !
  3771 
  3798 
  3772 makeSelectedColorBrighter
  3799 makeSelectedColorBrighter
  3773     |img cMap newImage clr|
  3800     self processSelectedColorWith:[:clr | clr lightened]
  3774 
       
  3775     img := self image.
       
  3776     cMap := img colorMap.
       
  3777     cMap isNil ifTrue:[
       
  3778         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
       
  3779         ^ self
       
  3780     ].
       
  3781 
       
  3782     imageEditView makeUndo.
       
  3783 
       
  3784     cMap := cMap asArray.
       
  3785     clr := cMap at:imageEditView selectedColorIndex.
       
  3786     cMap at:imageEditView selectedColorIndex put:clr lightened.
       
  3787 
       
  3788     newImage := img species new
       
  3789                     width:img width
       
  3790                     height:img height
       
  3791                     depth:nil
       
  3792                     fromArray:img bits.
       
  3793 
       
  3794     newImage colorMap:cMap.  
       
  3795     newImage fileName:img fileName.
       
  3796     newImage mask:(img mask copy).
       
  3797 
       
  3798     (imageEditView image:newImage) notNil ifTrue:[
       
  3799         self fetchImageData.
       
  3800 "/        self listOfColors contents: newImage colorMap.
       
  3801 "/        self findColorMapMode.
       
  3802 "/        self updateLabelsAndHistory.
       
  3803     ]
       
  3804 
       
  3805     "Created: / 12.3.1999 / 00:20:28 / cg"
       
  3806     "Modified: / 16.3.1999 / 21:57:26 / cg"
       
  3807 !
  3801 !
  3808 
  3802 
  3809 makeSelectedColorDarker
  3803 makeSelectedColorDarker
  3810     |img cMap clr newImage|
  3804     self processSelectedColorWith:[:clr | clr darkened]
  3811 
       
  3812     img := self image.
       
  3813     cMap := img colorMap.
       
  3814     cMap isNil ifTrue:[
       
  3815         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
       
  3816         ^ self
       
  3817     ].
       
  3818     imageEditView makeUndo.
       
  3819 
       
  3820     cMap := cMap asArray.
       
  3821     clr := cMap at:imageEditView selectedColorIndex.
       
  3822     cMap at:imageEditView selectedColorIndex put:clr darkened.
       
  3823 
       
  3824     newImage := img species new
       
  3825                     width:img width
       
  3826                     height:img height
       
  3827                     depth:nil
       
  3828                     fromArray:img bits.
       
  3829 
       
  3830     newImage colorMap:cMap.  
       
  3831     newImage fileName:img fileName.
       
  3832     newImage mask:(img mask copy).
       
  3833 
       
  3834     (imageEditView image:newImage) notNil ifTrue:[
       
  3835         self fetchImageData.
       
  3836 "/        self listOfColors contents: newImage colorMap.
       
  3837 "/        self findColorMapMode.
       
  3838 "/        self updateLabelsAndHistory.
       
  3839     ]
       
  3840 
       
  3841     "Created: / 12.3.1999 / 00:20:28 / cg"
       
  3842     "Modified: / 16.3.1999 / 21:57:26 / cg"
       
  3843 !
  3805 !
  3844 
  3806 
  3845 pasteMask
  3807 pasteMask
  3846     |img mask|
  3808     |img mask|
  3847 
  3809 
  3860     (imageEditView image:img copy) notNil ifTrue:[
  3822     (imageEditView image:img copy) notNil ifTrue:[
  3861         self fetchImageData.
  3823         self fetchImageData.
  3862     ]
  3824     ]
  3863 !
  3825 !
  3864 
  3826 
       
  3827 pickAndAddColorToColormap
       
  3828     self addColorToColormap:(Color fromUser)
       
  3829 !
       
  3830 
       
  3831 processSelectedColorWith:aBlock
       
  3832     |img cMap clr newImage selectedColorIndex oldSelection|
       
  3833 
       
  3834     selectedColorIndex := self selectedColorIndexOrNil.
       
  3835     selectedColorIndex isNil ifTrue:[^ self].
       
  3836 
       
  3837     img := self image.
       
  3838     cMap := img colorMap.
       
  3839     cMap isNil ifTrue:[
       
  3840         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
       
  3841         ^ self
       
  3842     ].
       
  3843     imageEditView makeUndo.
       
  3844 
       
  3845     cMap := cMap asArray.
       
  3846     clr := cMap at:selectedColorIndex.
       
  3847     cMap at:selectedColorIndex put:(aBlock value:clr).
       
  3848 
       
  3849     newImage := img species new
       
  3850                     width:img width
       
  3851                     height:img height
       
  3852                     depth:nil
       
  3853                     fromArray:img bits.
       
  3854 
       
  3855     newImage colorMap:cMap.  
       
  3856     newImage fileName:img fileName.
       
  3857     newImage mask:(img mask copy).
       
  3858 
       
  3859     oldSelection := self selectionOfColor value.
       
  3860 
       
  3861     (imageEditView image:newImage) notNil ifTrue:[
       
  3862         self fetchImageData.
       
  3863 "/        self listOfColors contents: newImage colorMap.
       
  3864 "/        self findColorMapMode.
       
  3865 "/        self updateLabelsAndHistory.
       
  3866     ].
       
  3867     self selectionOfColor value:oldSelection.
       
  3868 
       
  3869     "Created: / 12.3.1999 / 00:20:28 / cg"
       
  3870     "Modified: / 16.3.1999 / 21:57:26 / cg"
       
  3871 !
       
  3872 
  3865 reduceNumberOfColors
  3873 reduceNumberOfColors
  3866     |s n anyChange img|
  3874     |s n anyChange img|
  3867 
  3875 
  3868     s := Dialog request:'Number of color bits to strip (1-7) ?'.
  3876     s := Dialog request:'Number of color bits to strip (1-7) ?'.
  3869     s size == 0 ifTrue:[^ self].
  3877     s size == 0 ifTrue:[^ self].
  3886 "/            self findColorMapMode.
  3894 "/            self findColorMapMode.
  3887 "/            self updateLabelsAndHistory.
  3895 "/            self updateLabelsAndHistory.
  3888             Dialog information:(img usedColors size printString , ' colors used.')
  3896             Dialog information:(img usedColors size printString , ' colors used.')
  3889         ]
  3897         ]
  3890     ].
  3898     ].
       
  3899 !
       
  3900 
       
  3901 selectedColorIndexOrNil
       
  3902     | img clrIndex|
       
  3903 
       
  3904     img := self image.
       
  3905     img isNil ifTrue:[
       
  3906         self warn:'No Image.'.
       
  3907         ^ nil
       
  3908     ].
       
  3909     clrIndex := self selectionOfColor value.
       
  3910     img mask notNil ifTrue: [ clrIndex := clrIndex - 1 ].
       
  3911     ^ clrIndex
  3891 !
  3912 !
  3892 
  3913 
  3893 sortColorMap
  3914 sortColorMap
  3894     "calculates a new color map for the image, sorting colors"
  3915     "calculates a new color map for the image, sorting colors"
  3895 
  3916 
  4426             self updateLabelsAndHistory.
  4447             self updateLabelsAndHistory.
  4427         ]
  4448         ]
  4428     ]
  4449     ]
  4429 !
  4450 !
  4430 
  4451 
       
  4452 doNewImageFromClipboard
       
  4453     |image|
       
  4454 
       
  4455     image := imageEditView clipBoard.
       
  4456 
       
  4457     (imageEditView image:image) notNil
       
  4458     ifTrue:[
       
  4459         self listOfColors contents:(image colorMap).
       
  4460         self findColorMapMode.
       
  4461         self updateLabelsAndHistory.
       
  4462     ]
       
  4463 !
       
  4464 
  4431 grabScreenImage
  4465 grabScreenImage
  4432     "let user choose an area and grab that are for editing"
  4466     "let user choose an area and grab that are for editing"
  4433 
  4467 
  4434     Processor 
  4468     Processor 
  4435         addTimedBlock:[
  4469         addTimedBlock:[