ImageEditor.st
changeset 3635 74101a749a34
parent 3625 b05e45a69b82
child 3644 61d49e748c1f
equal deleted inserted replaced
3634:b97f51aaa9ac 3635:74101a749a34
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1997-1998 by eXept Software AG
     2  COPYRIGHT (c) 1997-1998 by eXept Software AG
     5               All Rights Reserved
     3               All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
  5834     resourceClass notNil ifTrue:[
  5832     resourceClass notNil ifTrue:[
  5835         resourceSelector := imageEditView resourceSelector.
  5833         resourceSelector := imageEditView resourceSelector.
  5836         resourceSelector notNil ifTrue:[
  5834         resourceSelector notNil ifTrue:[
  5837             ^ resources 
  5835             ^ resources 
  5838                     string:(self modified 
  5836                     string:(self modified 
  5839                             ifTrue:['ImageEditor (modified): %1 » %2']
  5837                             ifTrue:['ImageEditor (modified): %1 » %2']
  5840                             ifFalse:['ImageEditor: %1 » %2'])
  5838                             ifFalse:['ImageEditor: %1 » %2'])
  5841                     with:resourceClass name
  5839                     with:resourceClass name
  5842                     with:resourceSelector
  5840                     with:resourceSelector
  5843         ].
  5841         ].
  5844     ].
  5842     ].
  5845     
  5843     
  5868     resourceClass notNil ifTrue:[
  5866     resourceClass notNil ifTrue:[
  5869         resourceSelector := imageEditView resourceSelector.
  5867         resourceSelector := imageEditView resourceSelector.
  5870         resourceSelector notNil ifTrue:[
  5868         resourceSelector notNil ifTrue:[
  5871             ^ resources 
  5869             ^ resources 
  5872                     string:(self modified 
  5870                     string:(self modified 
  5873                             ifTrue:['Image (modified) from: %1 » %2']
  5871                             ifTrue:['Image (modified) from: %1 » %2']
  5874                             ifFalse:['Image from: %1 » %2'])
  5872                             ifFalse:['Image from: %1 » %2'])
  5875                     with:resourceClass name
  5873                     with:resourceClass name
  5876                     with:resourceSelector
  5874                     with:resourceSelector
  5877         ].
  5875         ].
  5878     ].
  5876     ].
  5879     
  5877     
  6801         |image red green blue|
  6799         |image red green blue|
  6802 
  6800 
  6803         image := imageEditView image.
  6801         image := imageEditView image.
  6804         originalColormap := image colorMap copy.
  6802         originalColormap := image colorMap copy.
  6805         originalPixels := image bits.
  6803         originalPixels := image bits.
  6806         red := (colorsToShift collect:[:clr | clr red]) average.
  6804         colorsToShift size > 0 ifTrue:[
  6807         green := (colorsToShift collect:[:clr | clr green]) average.
  6805             red := (colorsToShift collect:[:clr | clr red]) average.
  6808         blue := (colorsToShift collect:[:clr | clr blue]) average.
  6806             green := (colorsToShift collect:[:clr | clr green]) average.
  6809         avgColor := Color red:red green:green blue:blue.
  6807             blue := (colorsToShift collect:[:clr | clr blue]) average.
       
  6808             avgColor := Color red:red green:green blue:blue.
       
  6809         ].    
  6810         avgColorHolder value:avgColor.
  6810         avgColorHolder value:avgColor.
  6811 
  6811 
  6812         previewImage := self image magnifiedPreservingRatioTo:100@100.
  6812         previewImage := self image magnifiedPreservingRatioTo:100@100.
  6813         previewImageHolder value: previewImage.
  6813         previewImageHolder value: previewImage.
  6814         originalPreviewColormap := previewImage colorMap copy.
  6814         originalPreviewColormap := previewImage colorMap copy.
  6889 
  6889 
  6890     bindings := IdentityDictionary new.
  6890     bindings := IdentityDictionary new.
  6891     bindings at:#hueShiftAmount put:(hueShift := 0 asValue).
  6891     bindings at:#hueShiftAmount put:(hueShift := 0 asValue).
  6892     hueShift onChangeEvaluate:shiftAction.
  6892     hueShift onChangeEvaluate:shiftAction.
  6893 
  6893 
  6894     bindings at:#lightAmount put:(lightValue := 100 asValue).
  6894     bindings at:#lightAmount put:(lightValue := 1.0 asValue).
  6895     lightValue onChangeEvaluate:shiftAction.
  6895     lightValue onChangeEvaluate:shiftAction.
  6896 
  6896 
  6897     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
  6897     bindings at:#saturationAmount put:(saturationValue := 1.0 asValue).
  6898     saturationValue onChangeEvaluate:shiftAction.
  6898     saturationValue onChangeEvaluate:shiftAction.
  6899 
  6899 
  6900     bindings at:#acceptChannel put:acceptChannel.
  6900     bindings at:#acceptChannel put:acceptChannel.
  6901     bindings at:#hlsColor put:avgColorHolder.
  6901     bindings at:#hlsColor put:avgColorHolder.
  6902     bindings at:#previewImageHolder put:previewImageHolder.
  6902     bindings at:#previewImageHolder put:previewImageHolder.
       
  6903 
       
  6904     bindings at:#resetHueShift put:[ hueShift value: 0 ].
       
  6905     bindings at:#resetLightFactor put:[ lightValue value: 1.0 ].
       
  6906     bindings at:#resetSaturationFactor put:[ saturationValue value: 1.0 ].
  6903 
  6907 
  6904     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
  6908     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
  6905     ifFalse:[ 
  6909     ifFalse:[ 
  6906         anyChange ifTrue:[
  6910         anyChange ifTrue:[
  6907             imageEditView undo
  6911             imageEditView undo
  6916         self updateImage.
  6920         self updateImage.
  6917         self updateImagePreView.
  6921         self updateImagePreView.
  6918     ].
  6922     ].
  6919 
  6923 
  6920     "Modified (comment): / 28-08-2017 / 13:04:44 / cg"
  6924     "Modified (comment): / 28-08-2017 / 13:04:44 / cg"
       
  6925     "Modified: / 14-01-2019 / 14:52:50 / Claus Gittinger"
  6921 !
  6926 !
  6922 
  6927 
  6923 clearColormapEntry0AndMaskedPixels
  6928 clearColormapEntry0AndMaskedPixels
  6924     "ensure that there is a colorMap entry with 0/0/0 at position
  6929     "ensure that there is a colorMap entry with 0/0/0 at position
  6925      0 and then clear all masked pixels (to pixelValue 0).
  6930      0 and then clear all masked pixels (to pixelValue 0).
  7459 
  7464 
  7460     cMap := self image colorMap.
  7465     cMap := self image colorMap.
  7461     
  7466     
  7462     "/ if there is a mask, it is at position 1 in the table
  7467     "/ if there is a mask, it is at position 1 in the table
  7463     cmapOffset := self hasTransparentColorInColorList ifTrue:[1] ifFalse:[0].
  7468     cmapOffset := self hasTransparentColorInColorList ifTrue:[1] ifFalse:[0].
  7464     colors := self selectedColors value collect:[:idx | cMap at:idx-cmapOffset].
  7469     colors := self selectedColors value 
       
  7470                 select:[:idx | idx > cmapOffset]
       
  7471                 thenCollect:[:idx | cMap at:idx-cmapOffset].
  7465     self changeHLSOfColors:colors.
  7472     self changeHLSOfColors:colors.
  7466 
  7473 
  7467     "Modified: / 05-09-2017 / 09:03:47 / cg"
  7474     "Modified: / 05-09-2017 / 09:03:47 / cg"
       
  7475     "Modified: / 14-01-2019 / 14:46:51 / Claus Gittinger"
  7468 !
  7476 !
  7469 
  7477 
  7470 makeSelectedColorSlightlyBrighter
  7478 makeSelectedColorSlightlyBrighter
  7471     self processSelectedColorsWith:[:clr | clr slightlyLightened]
  7479     self processSelectedColorsWith:[:clr | clr slightlyLightened]
  7472 !
  7480 !
  7660     ] ifFalse:[
  7668     ] ifFalse:[
  7661         ("cMap isMappedPalette or:["cMap isFixedPalette"]") ifTrue:[
  7669         ("cMap isMappedPalette or:["cMap isFixedPalette"]") ifTrue:[
  7662             oldColors := cMap asArray.
  7670             oldColors := cMap asArray.
  7663             processingSubset := false.
  7671             processingSubset := false.
  7664         ] ifFalse:[
  7672         ] ifFalse:[
       
  7673             selectedColorIndices := selectedColorIndices select:[:idx | idx > maskOffset].
       
  7674             selectedColorIndices isEmpty ifTrue:[
       
  7675                 Dialog warn:'Please select any non-mask color'.
       
  7676                 ^ self.
       
  7677             ].        
  7665             oldColors := selectedColorIndices collect:[:idx | cMap at:idx-maskOffset].
  7678             oldColors := selectedColorIndices collect:[:idx | cMap at:idx-maskOffset].
  7666             processingSubset := true.
  7679             processingSubset := true.
  7667         ].
  7680         ].
  7668     ].
  7681     ].
  7669     imageEditView makeUndo.
  7682     imageEditView makeUndo.
  7670 
  7683 
  7671     modifiedColormap := cMap asNewArray.
  7684     modifiedColormap := cMap asNewArray.
  7672     (selectedColorIndices max - maskOffset)  > modifiedColormap size ifTrue:[
  7685     (selectedColorIndices max - maskOffset) > modifiedColormap size ifTrue:[
  7673         |t|
  7686         |t|
  7674         t := Array new:(selectedColorIndices max - maskOffset).
  7687         t := Array new:(selectedColorIndices max - maskOffset).
  7675         t replaceFrom:1 with:modifiedColormap.
  7688         t replaceFrom:1 with:modifiedColormap.
  7676         modifiedColormap := t.
  7689         modifiedColormap := t.
  7677     ].
  7690     ].
  7706         self fetchImageData.
  7719         self fetchImageData.
  7707     ].
  7720     ].
  7708     self selectedColors value:selectedColorIndices.
  7721     self selectedColors value:selectedColorIndices.
  7709 
  7722 
  7710     "Modified: / 08-10-2017 / 09:20:13 / cg"
  7723     "Modified: / 08-10-2017 / 09:20:13 / cg"
  7711     "Modified: / 27-05-2018 / 10:34:25 / Claus Gittinger"
  7724     "Modified: / 14-01-2019 / 14:56:49 / Claus Gittinger"
  7712 !
  7725 !
  7713 
  7726 
  7714 reduceNumberOfColors
  7727 reduceNumberOfColors
  7715     "reduce by masking off r/g/b bits"
  7728     "reduce by masking off r/g/b bits"
  7716 
  7729