ImageEditor.st
changeset 1651 577ddbd9fb26
parent 1650 cb63d6bf76c1
child 1652 d6d40619e21a
equal deleted inserted replaced
1650:cb63d6bf76c1 1651:577ddbd9fb26
   664     ^ 
   664     ^ 
   665      #(#FullSpec
   665      #(#FullSpec
   666         #name: #changeHLSDialogSpec
   666         #name: #changeHLSDialogSpec
   667         #window: 
   667         #window: 
   668        #(#WindowSpec
   668        #(#WindowSpec
   669           #label: 'Shift Hue'
   669           #label: 'HLS Edit Dialog'
   670           #name: 'Shift Hue'
   670           #name: 'HLS Edit Dialog'
   671           #min: #(#Point 10 10)
   671           #min: #(#Point 10 10)
   672           #max: #(#Point 800 478)
   672           #max: #(#Point 800 478)
   673           #bounds: #(#Rectangle 16 46 328 229)
   673           #bounds: #(#Rectangle 16 46 328 229)
   674         )
   674         )
   675         #component: 
   675         #component: 
   676        #(#SpecCollection
   676        #(#SpecCollection
   677           #collection: #(
   677           #collection: #(
   678            #(#LabelSpec
   678            #(#LabelSpec
   679               #label: 'Hue-Shift:'
   679               #label: 'Hue-Shift:'
   680               #name: 'HueLabel'
   680               #name: 'HueLabel'
   681               #layout: #(#LayoutFrame 14 0 21 0 90 0 43 0)
   681               #layout: #(#LayoutFrame 20 0 21 0 120 0 43 0)
   682               #translateLabel: true
   682               #translateLabel: true
   683               #adjust: #right
   683               #adjust: #right
   684             )
   684             )
   685            #(#InputFieldSpec
   685            #(#InputFieldSpec
   686               #name: 'HueShiftEntryField'
   686               #name: 'HueShiftEntryField'
   687               #layout: #(#LayoutFrame 95 0 21 0 138 0 43 0)
   687               #layout: #(#LayoutFrame 123 0 21 0 166 0 43 0)
   688               #tabable: true
   688               #tabable: true
   689               #model: #hueShiftAmount
   689               #model: #hueShiftAmount
   690               #type: #numberInRange
   690               #type: #numberInRange
   691               #minValue: 0
   691               #minValue: 0
   692               #maxValue: 360
   692               #maxValue: 360
   693               #acceptChannel: #acceptChannel
   693               #acceptChannel: #acceptChannel
   694               #acceptOnPointerLeave: false
   694               #acceptOnPointerLeave: false
   695             )
   695             )
   696            #(#ThumbWheelSpec
   696            #(#ThumbWheelSpec
   697               #name: 'HueWheel'
   697               #name: 'HueWheel'
   698               #layout: #(#LayoutFrame 152 0 22 0 269 0 42 0)
   698               #layout: #(#LayoutFrame 180 0 22 0 297 0 42 0)
   699               #model: #hueShiftAmount
   699               #model: #hueShiftAmount
   700               #orientation: #horizontal
   700               #orientation: #horizontal
   701               #step: 1
   701               #step: 1
   702               #endlessRotation: true
   702               #endlessRotation: true
   703             )
   703             )
   704            #(#LabelSpec
   704            #(#LabelSpec
   705               #label: 'Light:'
   705               #label: 'Light Factor:'
   706               #name: 'LightLabel'
   706               #name: 'LightLabel'
   707               #layout: #(#LayoutFrame 14 0 50 0 90 0 72 0)
   707               #layout: #(#LayoutFrame 18 0 50 0 120 0 72 0)
   708               #translateLabel: true
   708               #translateLabel: true
   709               #adjust: #right
   709               #adjust: #right
   710             )
   710             )
   711            #(#InputFieldSpec
   711            #(#InputFieldSpec
   712               #name: 'LightEntryField'
   712               #name: 'LightEntryField'
   713               #layout: #(#LayoutFrame 95 0 50 0 138 0 72 0)
   713               #layout: #(#LayoutFrame 123 0 50 0 166 0 72 0)
   714               #tabable: true
   714               #tabable: true
   715               #model: #lightAmount
   715               #model: #lightAmount
   716               #type: #numberInRange
   716               #type: #numberInRange
   717               #minValue: 0
   717               #minValue: 0
   718               #maxValue: 1000
   718               #maxValue: 1000
   719               #acceptChannel: #acceptChannel
   719               #acceptChannel: #acceptChannel
   720               #acceptOnPointerLeave: false
   720               #acceptOnPointerLeave: false
   721             )
   721             )
   722            #(#ThumbWheelSpec
   722            #(#ThumbWheelSpec
   723               #name: 'LightWheel'
   723               #name: 'LightWheel'
   724               #layout: #(#LayoutFrame 152 0 51 0 269 0 71 0)
   724               #layout: #(#LayoutFrame 180 0 51 0 297 0 71 0)
   725               #model: #lightAmount
   725               #model: #lightAmount
   726               #orientation: #horizontal
   726               #orientation: #horizontal
   727               #stop: 1000
   727               #stop: 1000
   728               #step: 1
   728               #step: 1
   729             )
   729             )
   730            #(#LabelSpec
   730            #(#LabelSpec
   731               #label: 'Saturation:'
   731               #label: 'Saturation Factor:'
   732               #name: 'SaturationLabel'
   732               #name: 'SaturationLabel'
   733               #layout: #(#LayoutFrame 14 0 79 0 90 0 101 0)
   733               #layout: #(#LayoutFrame 9 0 79 0 120 0 101 0)
   734               #translateLabel: true
   734               #translateLabel: true
   735               #adjust: #right
   735               #adjust: #right
   736             )
   736             )
   737            #(#InputFieldSpec
   737            #(#InputFieldSpec
   738               #name: 'SaturationEntryField'
   738               #name: 'SaturationEntryField'
   739               #layout: #(#LayoutFrame 95 0 79 0 138 0 101 0)
   739               #layout: #(#LayoutFrame 123 0 79 0 166 0 101 0)
   740               #tabable: true
   740               #tabable: true
   741               #model: #saturationAmount
   741               #model: #saturationAmount
   742               #type: #numberInRange
   742               #type: #numberInRange
   743               #minValue: 0
   743               #minValue: 0
   744               #maxValue: 1000
   744               #maxValue: 1000
   745               #acceptChannel: #acceptChannel
   745               #acceptChannel: #acceptChannel
   746               #acceptOnPointerLeave: false
   746               #acceptOnPointerLeave: false
   747             )
   747             )
   748            #(#ThumbWheelSpec
   748            #(#ThumbWheelSpec
   749               #name: 'SaturationWheel'
   749               #name: 'SaturationWheel'
   750               #layout: #(#LayoutFrame 152 0 80 0 269 0 100 0)
   750               #layout: #(#LayoutFrame 180 0 80 0 297 0 100 0)
   751               #model: #saturationAmount
   751               #model: #saturationAmount
   752               #orientation: #horizontal
   752               #orientation: #horizontal
   753               #stop: 1000
   753               #stop: 1000
   754               #step: 1
   754               #step: 1
   755             )
   755             )
   756            #(#LabelSpec
   756            #(#LabelSpec
   757               #name: 'HueColorLabel'
   757               #name: 'HueColorLabel'
   758               #layout: #(#LayoutFrame 10 0.0 109 0 -10 1.0 148 0)
   758               #layout: #(#LayoutFrame 10 0.0 109 0 -10 1.0 148 0)
   759               #translateLabel: true
   759               #translateLabel: true
   760               #backgroundChannel: #hueColor
   760               #backgroundChannel: #hlsColor
   761             )
   761             )
   762            #(#HorizontalPanelViewSpec
   762            #(#HorizontalPanelViewSpec
   763               #name: 'HorizontalPanel1'
   763               #name: 'HorizontalPanel1'
   764               #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
   764               #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
   765               #horizontalLayout: #fitSpace
   765               #horizontalLayout: #fitSpace
  3267 
  3267 
  3268 changeHLS
  3268 changeHLS
  3269     "interactive Hue/Light/Saturation editing"
  3269     "interactive Hue/Light/Saturation editing"
  3270 
  3270 
  3271     |bindings hueShift lightValue saturationValue originalColormap firstChange acceptChannel 
  3271     |bindings hueShift lightValue saturationValue originalColormap firstChange acceptChannel 
  3272      shiftAction colorHolder|
  3272      shiftAction colorHolder avgColor shiftedColor|
  3273 
  3273 
  3274     originalColormap := imageEditView image colorMap copy.
  3274     originalColormap := imageEditView image colorMap copy.
       
  3275     avgColor := imageEditView image averageColor.
  3275 
  3276 
  3276     acceptChannel := TriggerValue new.
  3277     acceptChannel := TriggerValue new.
  3277 
  3278 
  3278     firstChange := true.
  3279     firstChange := true.
  3279 
  3280 
       
  3281     shiftedColor := [:clr :hShift :lFactor :sFactor |
       
  3282                         Color 
       
  3283                                 hue:((clr hue) ? 0 + hShift) 
       
  3284                                 light:((clr light * lFactor / 100) min:100)
       
  3285                                 saturation:((clr saturation * sFactor / 100) min:100)].
  3280     shiftAction := 
  3286     shiftAction := 
  3281         [
  3287         [
  3282             |hShift lFactor sFactor|
  3288             |hShift lFactor sFactor|
  3283 
  3289 
  3284             acceptChannel value:true.
  3290             acceptChannel value:true.
  3290 
  3296 
  3291             hShift := hueShift value.
  3297             hShift := hueShift value.
  3292             lFactor := lightValue value.
  3298             lFactor := lightValue value.
  3293             sFactor := saturationValue value.
  3299             sFactor := saturationValue value.
  3294 
  3300 
  3295             colorHolder value:(Color hue:hShift light:(lFactor min:100) saturation:(sFactor min:100)).
  3301             colorHolder value:(shiftedColor value:avgColor value:hShift value:lFactor value:sFactor).
  3296             imageEditView image colorMap:originalColormap copy.
  3302             imageEditView image colorMap:originalColormap copy.
  3297             imageEditView image colorMapProcessing:[:clr | Color 
  3303             imageEditView image colorMapProcessing:[:clr | shiftedColor value:clr value:hShift value:lFactor value:sFactor].
  3298                                                                 hue:((clr hue) ? 0 + hShift) 
       
  3299                                                                 light:((clr light * lFactor / 100) min:100)
       
  3300                                                                 saturation:((clr saturation * sFactor / 100) min:100)].
       
  3301             self updateImage.
  3304             self updateImage.
  3302             self updateInfoLabel.
  3305             self updateInfoLabel.
  3303         ].
  3306         ].
  3304 
  3307 
  3305     bindings := IdentityDictionary new.
  3308     bindings := IdentityDictionary new.
  3311 
  3314 
  3312     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
  3315     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
  3313     (bindings at:#saturationAmount) onChangeEvaluate:shiftAction.
  3316     (bindings at:#saturationAmount) onChangeEvaluate:shiftAction.
  3314 
  3317 
  3315     bindings at:#acceptChannel put:acceptChannel.
  3318     bindings at:#acceptChannel put:acceptChannel.
  3316     bindings at:#hueColor put:(colorHolder := Color white asValue).
  3319     bindings at:#hlsColor put:(colorHolder := avgColor asValue).
  3317 
  3320 
  3318     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
  3321     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
  3319     ifFalse:[ 
  3322     ifFalse:[ 
  3320         firstChange ~~ true ifTrue:[
  3323         firstChange ~~ true ifTrue:[
  3321             imageEditView undo
  3324             imageEditView undo