ImageEditor.st
changeset 3496 83bb01ebff3b
parent 3494 50e94e3563fa
child 3497 632e25674f39
equal deleted inserted replaced
3495:3f1eab73f7fa 3496:83bb01ebff3b
  2717             itemValue: addColorToColormap
  2717             itemValue: addColorToColormap
  2718             translateLabel: true
  2718             translateLabel: true
  2719           )
  2719           )
  2720          (MenuItem
  2720          (MenuItem
  2721             enabled: canAddColorToColormapHolder
  2721             enabled: canAddColorToColormapHolder
       
  2722             label: 'Add & Paste Color'
       
  2723             itemValue: addPastedColorToColormap
       
  2724             translateLabel: true
       
  2725           )
       
  2726          (MenuItem
       
  2727             enabled: canAddColorToColormapHolder
  2722             label: 'Pick and Add Color...'
  2728             label: 'Pick and Add Color...'
  2723             itemValue: pickAndAddColorToColormap
  2729             itemValue: pickAndAddColorToColormap
  2724             translateLabel: true
  2730             translateLabel: true
  2725           )
  2731           )
  2726          (MenuItem
  2732          (MenuItem
  2804          )
  2810          )
  2805         nil
  2811         nil
  2806         nil
  2812         nil
  2807       )
  2813       )
  2808 
  2814 
  2809     "Modified: / 31-08-2017 / 18:46:33 / cg"
  2815     "Modified: / 08-10-2017 / 15:02:33 / cg"
  2810 !
  2816 !
  2811 
  2817 
  2812 menu
  2818 menu
  2813     "This resource specification was automatically generated
  2819     "This resource specification was automatically generated
  2814      by the MenuEditor of ST/X."
  2820      by the MenuEditor of ST/X."
  4680     ^ [ self selectedColors value size == 1 "self selectedColorIndexOrNil notNil" ]
  4686     ^ [ self selectedColors value size == 1 "self selectedColorIndexOrNil notNil" ]
  4681 
  4687 
  4682     "Created: / 04-07-2010 / 10:12:22 / cg"
  4688     "Created: / 04-07-2010 / 10:12:22 / cg"
  4683 !
  4689 !
  4684 
  4690 
       
  4691 hasWritableColorSelectedHolder
       
  4692     ^ [ self hasSingleColorSelectedHolder value and:[self canChangeColorInColormap ]]
       
  4693 
       
  4694     "Created: / 08-10-2017 / 14:45:11 / cg"
       
  4695 !
       
  4696 
  4685 imageHasColormap
  4697 imageHasColormap
  4686     "true if a colormap is shown (might be a drwing map, not the real map)"
  4698     "true if a colormap is shown (might be a drwing map, not the real map)"
  4687     
  4699     
  4688     |img|
  4700     |img|
  4689     
  4701     
  6200         ^ self
  6212         ^ self
  6201     ].
  6213     ].
  6202 
  6214 
  6203     depth := img depth.
  6215     depth := img depth.
  6204     cMap := img colorMap.
  6216     cMap := img colorMap.
  6205     (cMap isNil or:[cMap isMappedPalette or:[cMap isFixedPalette]]) ifTrue:[
  6217 
  6206         drawingColormap isNil ifTrue:[
  6218     (cMap notNil and:[cMap isMappedPalette or:[cMap isArray]]) ifTrue:[
  6207             self information:(resources stringWithCRs:'Image has no colormap.\The shown colorMap is for drawing only.').
  6219     ] ifFalse:[
  6208             drawingColormap := OrderedCollection new.
  6220         (cMap isNil or:[cMap isFixedPalette]) ifTrue:[
       
  6221             drawingColormap isNil ifTrue:[
       
  6222                 self information:(resources stringWithCRs:'Image has no colormap.\The shown colorMap is for drawing only.').
       
  6223                 drawingColormap := OrderedCollection new.
       
  6224             ].
       
  6225             drawingColormap add:newColor.
       
  6226             self listOfColors contents:drawingColormap.
       
  6227             self selectedColors value:{drawingColormap size}.
       
  6228             "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
       
  6229             ^ self
  6209         ].
  6230         ].
  6210         drawingColormap add:newColor.
  6231     ].
  6211         self listOfColors contents:drawingColormap.
  6232     
  6212         self selectedColors value:{drawingColormap size}.
       
  6213         "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
       
  6214         ^ self
       
  6215     ].
       
  6216 
       
  6217     (cMap size == (1 bitShift:depth)) ifTrue:[
  6233     (cMap size == (1 bitShift:depth)) ifTrue:[
  6218         depth >= 8 ifTrue:[
  6234         depth >= 8 ifTrue:[
  6219             self warn:'No space for more colors in colormap.'.
  6235             self warn:'No space for more colors in colormap.'.
  6220             ^ self
  6236             ^ self
  6221         ].
  6237         ].
  6259         self selectedColors value:{listOfColors size}.
  6275         self selectedColors value:{listOfColors size}.
  6260         self updateLabelsAndHistory.
  6276         self updateLabelsAndHistory.
  6261     ]
  6277     ]
  6262 
  6278 
  6263     "Created: / 31-08-2017 / 14:30:01 / cg"
  6279     "Created: / 31-08-2017 / 14:30:01 / cg"
       
  6280     "Modified: / 08-10-2017 / 09:15:10 / cg"
       
  6281 !
       
  6282 
       
  6283 addPastedColorToColormap
       
  6284     "undoable: add the color in the clipboard to the map"
       
  6285 
       
  6286     |clipBoardColor|
       
  6287 
       
  6288     (clipBoardColor := self clipBoardColor) isNil ifTrue:[                
       
  6289         ^ self
       
  6290     ].
       
  6291     self addColorToColormap:clipBoardColor undoable:true
       
  6292 
       
  6293     "Created: / 08-10-2017 / 09:04:23 / cg"
  6264 !
  6294 !
  6265 
  6295 
  6266 changeHLS
  6296 changeHLS
  6267     "interactive Hue/Light/Saturation editing with thumbWheels"
  6297     "interactive Hue/Light/Saturation editing with thumbWheels"
  6268 
  6298 
  6564     ].
  6594     ].
  6565 
  6595 
  6566     (imageEditView image:newImage) notNil ifTrue:[
  6596     (imageEditView image:newImage) notNil ifTrue:[
  6567         self fetchImageData.
  6597         self fetchImageData.
  6568     ]
  6598     ]
       
  6599 !
       
  6600 
       
  6601 clipBoardColor
       
  6602     "return the color in the clipboard, or nil, if there is none.
       
  6603      If there is none, beep (if user's settings allow it)"
       
  6604      
       
  6605     |clr|
       
  6606 
       
  6607     clr := imageEditView getClipboardObject.
       
  6608     clr isColor ifFalse:[
       
  6609         UserPreferences current beepInEditor ifTrue:[                
       
  6610             self window beep.
       
  6611         ].
       
  6612         ^ nil
       
  6613     ].
       
  6614     ^ clr
       
  6615 
       
  6616     "Created: / 08-10-2017 / 09:02:14 / cg"
  6569 !
  6617 !
  6570 
  6618 
  6571 colorMapChanged
  6619 colorMapChanged
  6572     |img|
  6620     |img|
  6573 
  6621 
  7169     "Created: / 30-09-1998 / 23:51:23 / cg"
  7217     "Created: / 30-09-1998 / 23:51:23 / cg"
  7170     "Modified: / 31-08-2017 / 14:20:14 / cg"
  7218     "Modified: / 31-08-2017 / 14:20:14 / cg"
  7171 !
  7219 !
  7172 
  7220 
  7173 pasteColorIntoColormap
  7221 pasteColorIntoColormap
  7174     |copyBufferColor cmap|
  7222     |clipBoardColor cmap|
  7175 
  7223 
  7176     copyBufferColor := imageEditView getClipboardObject.
  7224     (clipBoardColor := self clipBoardColor) isNil ifTrue:[                
  7177     copyBufferColor isColor ifFalse:[
       
  7178         UserPreferences current beepInEditor ifTrue:[                
       
  7179             self window beep.
       
  7180         ].
       
  7181         ^ self
  7225         ^ self
  7182     ].
  7226     ].
  7183 
  7227 
  7184     cmap := self image colorMap.
  7228     cmap := self image colorMap.
  7185     (cmap isNil or:[cmap isMappedPalette or:[cmap isFixedPalette]]) ifTrue:[
  7229     (cmap isNil or:[cmap isMappedPalette or:[cmap isFixedPalette]]) ifTrue:[
  7186         drawingColormap isNil ifTrue:[
  7230         drawingColormap isNil ifTrue:[
  7187             drawingColormap := #()
  7231             drawingColormap := #()
  7188         ].
  7232         ].
  7189         drawingColormap := drawingColormap copyWith:copyBufferColor.
  7233         drawingColormap := drawingColormap copyWith:clipBoardColor.
  7190         self selectedColors value:drawingColormap size.
  7234         self selectedColors value:drawingColormap size.
  7191         ^ self.
  7235         ^ self.
  7192     ].
  7236     ].
  7193     
  7237     
  7194     self processSelectedColorWith:[:clr |
  7238     self processSelectedColorWith:[:clr | clipBoardColor]
  7195         copyBufferColor
  7239 
  7196     ]
  7240     "Modified (format): / 08-10-2017 / 09:03:59 / cg"
  7197 
       
  7198     "Modified: / 03-02-2017 / 21:45:45 / cg"
       
  7199 !
  7241 !
  7200 
  7242 
  7201 pickAndAddColorToColormap
  7243 pickAndAddColorToColormap
  7202     self addColorToColormap:(Color fromUser) undoable:true
  7244     self addColorToColormap:(Color fromUser) undoable:true
  7203 
  7245 
  7247         ].
  7289         ].
  7248     ].
  7290     ].
  7249     imageEditView makeUndo.
  7291     imageEditView makeUndo.
  7250 
  7292 
  7251     modifiedColormap := cMap asNewArray.
  7293     modifiedColormap := cMap asNewArray.
  7252 
  7294     selectedColorIndices max > modifiedColormap size ifTrue:[
       
  7295         |t|
       
  7296         t := Array new:selectedColorIndices max.
       
  7297         t replaceFrom:1 with:modifiedColormap.
       
  7298         modifiedColormap := t.
       
  7299     ].
       
  7300     
  7253     newColors := oldColors collect:aBlock.
  7301     newColors := oldColors collect:aBlock.
  7254     selectedColorIndices do:[:idx |
  7302     selectedColorIndices do:[:idx |
  7255         modifiedColormap at:idx-maskOffset put:(newColors at:idx)
  7303         modifiedColormap at:idx-maskOffset put:(newColors at:idx-maskOffset ifAbsent:[Color black])
  7256     ].
  7304     ].
  7257 
  7305 
  7258     newImage := img species new
  7306     newImage := img species new
  7259                     width:img width
  7307                     width:img width
  7260                     height:img height
  7308                     height:img height
  7273     (imageEditView image:newImage) notNil ifTrue:[
  7321     (imageEditView image:newImage) notNil ifTrue:[
  7274         self fetchImageData.
  7322         self fetchImageData.
  7275     ].
  7323     ].
  7276     self selectedColors value:selectedColorIndices.
  7324     self selectedColors value:selectedColorIndices.
  7277 
  7325 
  7278     "Modified: / 05-09-2017 / 09:03:52 / cg"
  7326     "Modified: / 08-10-2017 / 09:20:13 / cg"
  7279 !
  7327 !
  7280 
  7328 
  7281 reduceNumberOfColors
  7329 reduceNumberOfColors
  7282     "reduce by masking off r/g/b bits"
  7330     "reduce by masking off r/g/b bits"
  7283 
  7331 
  8788 doNewImageFromClipboard
  8836 doNewImageFromClipboard
  8789     |image|
  8837     |image|
  8790 
  8838 
  8791     self checkModified ifFalse:[ ^ self ].
  8839     self checkModified ifFalse:[ ^ self ].
  8792 
  8840 
  8793     image := imageEditView clipBoard.
  8841     image := imageEditView clipBoardImage.
  8794     image isImageOrForm ifFalse:[
  8842     image isImageOrForm ifFalse:[
  8795         image := Image readFrom:(image asString) onError:nil.
  8843         image := Image readFrom:(image asString) onError:nil.
  8796         image isNil ifTrue:[
  8844         image isNil ifTrue:[
  8797             Dialog warn:'Clipboard does not contain an image I can use/understand'.
  8845             Dialog warn:'Clipboard does not contain an image I can use/understand'.
  8798             ^ self.
  8846             ^ self.
  8799         ].
  8847         ].
  8800     ].
  8848     ].
       
  8849     
  8801     imageEditView image:image.
  8850     imageEditView image:image.
  8802 
  8851 
  8803     image notNil ifTrue:[
  8852     image notNil ifTrue:[
  8804         self updateColorsFromImage:image.
  8853         self updateColorsFromImage:image.
  8805         self findColorMapMode.
  8854         self findColorMapMode.
  8806         self updateLabelsAndHistory.
  8855         self updateLabelsAndHistory.
  8807     ]
  8856     ]
       
  8857 
       
  8858     "Modified (format): / 08-10-2017 / 08:58:03 / cg"
  8808 !
  8859 !
  8809 
  8860 
  8810 doNewMaskFromClipboard
  8861 doNewMaskFromClipboard
  8811     |mask image newImage|
  8862     |mask image newImage|
  8812 
  8863 
  8813     self checkModified ifFalse:[ ^ self ].
  8864     self checkModified ifFalse:[ ^ self ].
  8814 
  8865 
  8815     mask := imageEditView clipBoard.
  8866     mask := imageEditView clipBoardImage.
  8816     mask isImageOrForm ifFalse:[
  8867     mask isImageOrForm ifFalse:[
  8817         mask := Image readFrom:(mask asString) onError:nil.
  8868         mask := Image readFrom:(mask asString) onError:nil.
  8818         mask isNil ifTrue:[
  8869         mask isNil ifTrue:[
  8819             Dialog warn:'Clipboard does not contain an image I can use/understand'.
  8870             Dialog warn:'Clipboard does not contain an image I can use/understand'.
  8820             ^ self.
  8871             ^ self.
  8821         ].
  8872         ].
  8822     ].
  8873     ].
       
  8874     
  8823     (image:= imageEditView image) isNil ifTrue:[
  8875     (image:= imageEditView image) isNil ifTrue:[
  8824         image := mask.
  8876         image := mask.
  8825     ].
  8877     ].
  8826     mask extent ~= image extent ifTrue:[
  8878     mask extent ~= image extent ifTrue:[
  8827         mask := imageEditView resizedImage:mask to:image extent.
  8879         mask := imageEditView resizedImage:mask to:image extent.
  8829     newImage := image copy.
  8881     newImage := image copy.
  8830     newImage mask:mask.
  8882     newImage mask:mask.
  8831     imageEditView newImageWithUndo:newImage.
  8883     imageEditView newImageWithUndo:newImage.
  8832     self updateAfterImageChange.
  8884     self updateAfterImageChange.
  8833 
  8885 
  8834     "Modified (comment): / 16-02-2017 / 10:22:19 / cg"
  8886     "Modified (format): / 08-10-2017 / 08:57:58 / cg"
  8835 !
  8887 !
  8836 
  8888 
  8837 grabFullScreenImage
  8889 grabFullScreenImage
  8838     "grab all for editing"
  8890     "grab all for editing"
  8839 
  8891