ImageEditor.st
changeset 3281 15b8e734190a
parent 3253 32b2ae3350b9
child 3317 88b892a4012d
equal deleted inserted replaced
3280:6ee34f6dee2f 3281:15b8e734190a
  5978 processSelectedColorsWith:aBlock
  5978 processSelectedColorsWith:aBlock
  5979     "undoable color processing: 
  5979     "undoable color processing: 
  5980      the selected colors will be replaced by the value of aBlock 
  5980      the selected colors will be replaced by the value of aBlock 
  5981      (which gets a color vector and must return a color vector)"
  5981      (which gets a color vector and must return a color vector)"
  5982 
  5982 
  5983     |img cMap modifiedColormap oldColors newImage selectedColorIndices newColors|
  5983     |img cMap modifiedColormap oldColors newImage selectedColorIndices newColors maskOffset|
  5984 
  5984 
  5985     selectedColorIndices := self selectedColors value.
  5985     selectedColorIndices := self selectedColors value.
  5986     selectedColorIndices isEmptyOrNil ifTrue:[^ self].
  5986     selectedColorIndices isEmptyOrNil ifTrue:[^ self].
  5987 
  5987 
  5988     img := self image.
  5988     img := self image.
  5990     cMap isNil ifTrue:[
  5990     cMap isNil ifTrue:[
  5991         self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
  5991         self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
  5992         ^ self
  5992         ^ self
  5993     ].
  5993     ].
  5994     self hasMask ifTrue:[
  5994     self hasMask ifTrue:[
  5995         oldColors := selectedColorIndices collect:[:idx | cMap at:idx-1].
  5995         maskOffset := 1.
  5996     ] ifFalse:[
  5996     ] ifFalse:[
  5997         oldColors := selectedColorIndices collect:[:idx | cMap at:idx].
  5997         maskOffset := 0.
  5998     ].
  5998     ].
       
  5999     oldColors := selectedColorIndices collect:[:idx | cMap at:idx-maskOffset].
  5999     imageEditView makeUndo.
  6000     imageEditView makeUndo.
  6000 
  6001 
  6001     modifiedColormap := cMap asNewArray.
  6002     modifiedColormap := cMap asNewArray.
  6002 
  6003 
  6003     newColors := oldColors collect:aBlock.
  6004     newColors := oldColors collect:aBlock.
  6004     selectedColorIndices with:newColors do:[:idx :newColor | 
  6005     selectedColorIndices with:newColors do:[:idx :newColor | 
  6005         modifiedColormap at:idx put:newColor
  6006         modifiedColormap at:idx-maskOffset put:newColor
  6006     ].
  6007     ].
  6007 
  6008 
  6008     newImage := img species new
  6009     newImage := img species new
  6009                     width:img width
  6010                     width:img width
  6010                     height:img height
  6011                     height:img height