ImageEditor.st
changeset 1852 c40abf408dc4
parent 1847 d7e8ec4f3696
child 1859 254fc0e37550
equal deleted inserted replaced
1851:d036350188f5 1852:c40abf408dc4
  1600           )
  1600           )
  1601          (MenuItem
  1601          (MenuItem
  1602             enabled: hasColormap
  1602             enabled: hasColormap
  1603             label: 'Pick and Add Color'
  1603             label: 'Pick and Add Color'
  1604             itemValue: pickAndAddColorToColormap
  1604             itemValue: pickAndAddColorToColormap
       
  1605             translateLabel: true
       
  1606           )
       
  1607          (MenuItem
       
  1608             label: '-'
       
  1609           )
       
  1610          (MenuItem
       
  1611             enabled: hasColormap
       
  1612             label: 'Cut Color'
       
  1613             itemValue: cutColorFromColormap
       
  1614             translateLabel: true
       
  1615             isVisible: false
       
  1616           )
       
  1617          (MenuItem
       
  1618             enabled: hasColormap
       
  1619             label: 'Copy Color'
       
  1620             itemValue: copyColorFromColormap
       
  1621             translateLabel: true
       
  1622           )
       
  1623          (MenuItem
       
  1624             enabled: hasColormap
       
  1625             label: 'Pick Color'
       
  1626             itemValue: pickColor
       
  1627             translateLabel: true
       
  1628           )
       
  1629          (MenuItem
       
  1630             enabled: hasColormap
       
  1631             label: 'Paste Color'
       
  1632             itemValue: pasteColorIntoColormap
  1605             translateLabel: true
  1633             translateLabel: true
  1606           )
  1634           )
  1607          (MenuItem
  1635          (MenuItem
  1608             label: '-'
  1636             label: '-'
  1609           )
  1637           )
  3931 
  3959 
  3932     "Created: / 28.7.1998 / 20:03:11 / cg"
  3960     "Created: / 28.7.1998 / 20:03:11 / cg"
  3933     "Modified: / 15.9.1998 / 17:53:32 / cg"
  3961     "Modified: / 15.9.1998 / 17:53:32 / cg"
  3934 !
  3962 !
  3935 
  3963 
       
  3964 copyColorFromColormap
       
  3965     imageEditView setSelection:(self selectedColorOrNil)
       
  3966 !
       
  3967 
  3936 copyMask
  3968 copyMask
  3937     |mask|
  3969     |mask|
  3938 
  3970 
  3939     mask := self image mask.
  3971     mask := self image mask.
  3940     MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
  3972     MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
  4030     self processSelectedColorWith:[:clr | clr lightened]
  4062     self processSelectedColorWith:[:clr | clr lightened]
  4031 !
  4063 !
  4032 
  4064 
  4033 makeSelectedColorDarker
  4065 makeSelectedColorDarker
  4034     self processSelectedColorWith:[:clr | clr darkened]
  4066     self processSelectedColorWith:[:clr | clr darkened]
       
  4067 !
       
  4068 
       
  4069 pasteColorIntoColormap
       
  4070     |copyBufferColor|
       
  4071 
       
  4072     copyBufferColor := imageEditView getSelection.
       
  4073     copyBufferColor isColor ifFalse:[
       
  4074         device beep.
       
  4075         ^ self
       
  4076     ].
       
  4077 
       
  4078     self processSelectedColorWith:[:clr |
       
  4079         copyBufferColor
       
  4080     ]
  4035 !
  4081 !
  4036 
  4082 
  4037 pasteMask
  4083 pasteMask
  4038     |img mask|
  4084     |img mask|
  4039 
  4085 
  4056 
  4102 
  4057 pickAndAddColorToColormap
  4103 pickAndAddColorToColormap
  4058     self addColorToColormap:(Color fromUser)
  4104     self addColorToColormap:(Color fromUser)
  4059 !
  4105 !
  4060 
  4106 
       
  4107 pickColor
       
  4108     imageEditView setSelection:(Color fromUser)
       
  4109 !
       
  4110 
  4061 processSelectedColorWith:aBlock
  4111 processSelectedColorWith:aBlock
  4062     |img cMap modifiedColormap clr newImage selectedColorIndex oldSelection|
  4112     "undoable color processing: the selected color will be replaced by the
       
  4113      value of aBlock"
       
  4114 
       
  4115     |img cMap modifiedColormap oldColor newImage selectedColorIndex oldSelection newColor|
  4063 
  4116 
  4064     selectedColorIndex := self selectedColorIndexOrNil.
  4117     selectedColorIndex := self selectedColorIndexOrNil.
  4065     selectedColorIndex isNil ifTrue:[^ self].
  4118     selectedColorIndex isNil ifTrue:[^ self].
  4066 
  4119 
  4067     img := self image.
  4120     img := self image.
  4068     cMap := img colorMap.
  4121     cMap := img colorMap.
  4069     cMap isNil ifTrue:[
  4122     cMap isNil ifTrue:[
  4070         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
  4123         self warn:('Image has no colormap.\Please change the colorMap mode first.' withCRs).
  4071         ^ self
  4124         ^ self
  4072     ].
  4125     ].
       
  4126 
       
  4127     oldColor := cMap at:selectedColorIndex.
  4073     imageEditView makeUndo.
  4128     imageEditView makeUndo.
  4074 
  4129 
  4075     modifiedColormap := cMap asArray copy.
  4130     modifiedColormap := cMap asArray copy.
  4076     clr := modifiedColormap at:selectedColorIndex.
  4131 
  4077     modifiedColormap at:selectedColorIndex put:(aBlock value:clr).
  4132     newColor := aBlock value:oldColor.
       
  4133     modifiedColormap at:selectedColorIndex put:(aBlock value:oldColor).
  4078 
  4134 
  4079     newImage := img species new
  4135     newImage := img species new
  4080                     width:img width
  4136                     width:img width
  4081                     height:img height
  4137                     height:img height
  4082                     depth:img depth
  4138                     depth:img depth
  4088 
  4144 
  4089     oldSelection := self selectionOfColor value.
  4145     oldSelection := self selectionOfColor value.
  4090 
  4146 
  4091     (imageEditView image:newImage) notNil ifTrue:[
  4147     (imageEditView image:newImage) notNil ifTrue:[
  4092         self fetchImageData.
  4148         self fetchImageData.
  4093 "/        self listOfColors contents: newImage colorMap.
       
  4094 "/        self findColorMapMode.
       
  4095 "/        self updateLabelsAndHistory.
       
  4096     ].
  4149     ].
  4097     self selectionOfColor value:oldSelection.
  4150     self selectionOfColor value:oldSelection.
  4098 
  4151 
  4099     "Created: / 12.3.1999 / 00:20:28 / cg"
  4152     "Created: / 12.3.1999 / 00:20:28 / cg"
  4100     "Modified: / 16.3.1999 / 21:57:26 / cg"
  4153     "Modified: / 16.3.1999 / 21:57:26 / cg"
  4145     img mask notNil ifTrue: [ 
  4198     img mask notNil ifTrue: [ 
  4146         clrIndex == 1 ifTrue:[^ nil].
  4199         clrIndex == 1 ifTrue:[^ nil].
  4147         clrIndex := clrIndex - 1 
  4200         clrIndex := clrIndex - 1 
  4148     ].
  4201     ].
  4149     ^ clrIndex
  4202     ^ clrIndex
       
  4203 !
       
  4204 
       
  4205 selectedColorOrNil
       
  4206     |img cMap|
       
  4207 
       
  4208     selectedColorIndex := self selectedColorIndexOrNil.
       
  4209     selectedColorIndex isNil ifTrue:[^ self].
       
  4210 
       
  4211     img := self image.
       
  4212     cMap := img colorMap.
       
  4213     cMap isNil ifTrue:[
       
  4214         self warn:('Image has no colormap.\Please change the colorMap mode first.' withCRs).
       
  4215         ^ self
       
  4216     ].
       
  4217 
       
  4218     ^ cMap at:selectedColorIndex.
  4150 !
  4219 !
  4151 
  4220 
  4152 sortColorMap
  4221 sortColorMap
  4153     "calculates a new color map for the image, sorting colors"
  4222     "calculates a new color map for the image, sorting colors"
  4154 
  4223