ImageEditor.st
changeset 1650 cb63d6bf76c1
parent 1649 80586cf27eb8
child 1651 577ddbd9fb26
equal deleted inserted replaced
1649:80586cf27eb8 1650:cb63d6bf76c1
   644         constantNamed:#'ImageEditor class specialIcon'
   644         constantNamed:#'ImageEditor class specialIcon'
   645         ifAbsentPut:[(Depth1Image new) width: 14; height: 14; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@L@@@@B@@@@@0@@@@@@@@@@@@@@@P@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 255 0 0]; mask:((Depth1Image new) width: 14; height: 14; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@L@@0@G @^@A8@G @L@@0@@@@L@@0@@@@@a') ; yourself); yourself]
   645         ifAbsentPut:[(Depth1Image new) width: 14; height: 14; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@L@@@@B@@@@@0@@@@@@@@@@@@@@@P@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 255 0 0]; mask:((Depth1Image new) width: 14; height: 14; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@L@@0@G @^@A8@G @L@@0@@@@L@@0@@@@@a') ; yourself); yourself]
   646 ! !
   646 ! !
   647 
   647 
   648 !ImageEditor class methodsFor:'interface specs'!
   648 !ImageEditor class methodsFor:'interface specs'!
       
   649 
       
   650 changeHLSDialogSpec
       
   651     "This resource specification was automatically generated
       
   652      by the UIPainter of ST/X."
       
   653 
       
   654     "Do not manually edit this!! If it is corrupted,
       
   655      the UIPainter may not be able to read the specification."
       
   656 
       
   657     "
       
   658      UIPainter new openOnClass:ImageEditor andSelector:#changeHLSDialogSpec
       
   659      ImageEditor new openInterface:#changeHLSDialogSpec
       
   660     "
       
   661 
       
   662     <resource: #canvas>
       
   663 
       
   664     ^ 
       
   665      #(#FullSpec
       
   666         #name: #changeHLSDialogSpec
       
   667         #window: 
       
   668        #(#WindowSpec
       
   669           #label: 'Shift Hue'
       
   670           #name: 'Shift Hue'
       
   671           #min: #(#Point 10 10)
       
   672           #max: #(#Point 800 478)
       
   673           #bounds: #(#Rectangle 16 46 328 229)
       
   674         )
       
   675         #component: 
       
   676        #(#SpecCollection
       
   677           #collection: #(
       
   678            #(#LabelSpec
       
   679               #label: 'Hue-Shift:'
       
   680               #name: 'HueLabel'
       
   681               #layout: #(#LayoutFrame 14 0 21 0 90 0 43 0)
       
   682               #translateLabel: true
       
   683               #adjust: #right
       
   684             )
       
   685            #(#InputFieldSpec
       
   686               #name: 'HueShiftEntryField'
       
   687               #layout: #(#LayoutFrame 95 0 21 0 138 0 43 0)
       
   688               #tabable: true
       
   689               #model: #hueShiftAmount
       
   690               #type: #numberInRange
       
   691               #minValue: 0
       
   692               #maxValue: 360
       
   693               #acceptChannel: #acceptChannel
       
   694               #acceptOnPointerLeave: false
       
   695             )
       
   696            #(#ThumbWheelSpec
       
   697               #name: 'HueWheel'
       
   698               #layout: #(#LayoutFrame 152 0 22 0 269 0 42 0)
       
   699               #model: #hueShiftAmount
       
   700               #orientation: #horizontal
       
   701               #step: 1
       
   702               #endlessRotation: true
       
   703             )
       
   704            #(#LabelSpec
       
   705               #label: 'Light:'
       
   706               #name: 'LightLabel'
       
   707               #layout: #(#LayoutFrame 14 0 50 0 90 0 72 0)
       
   708               #translateLabel: true
       
   709               #adjust: #right
       
   710             )
       
   711            #(#InputFieldSpec
       
   712               #name: 'LightEntryField'
       
   713               #layout: #(#LayoutFrame 95 0 50 0 138 0 72 0)
       
   714               #tabable: true
       
   715               #model: #lightAmount
       
   716               #type: #numberInRange
       
   717               #minValue: 0
       
   718               #maxValue: 1000
       
   719               #acceptChannel: #acceptChannel
       
   720               #acceptOnPointerLeave: false
       
   721             )
       
   722            #(#ThumbWheelSpec
       
   723               #name: 'LightWheel'
       
   724               #layout: #(#LayoutFrame 152 0 51 0 269 0 71 0)
       
   725               #model: #lightAmount
       
   726               #orientation: #horizontal
       
   727               #stop: 1000
       
   728               #step: 1
       
   729             )
       
   730            #(#LabelSpec
       
   731               #label: 'Saturation:'
       
   732               #name: 'SaturationLabel'
       
   733               #layout: #(#LayoutFrame 14 0 79 0 90 0 101 0)
       
   734               #translateLabel: true
       
   735               #adjust: #right
       
   736             )
       
   737            #(#InputFieldSpec
       
   738               #name: 'SaturationEntryField'
       
   739               #layout: #(#LayoutFrame 95 0 79 0 138 0 101 0)
       
   740               #tabable: true
       
   741               #model: #saturationAmount
       
   742               #type: #numberInRange
       
   743               #minValue: 0
       
   744               #maxValue: 1000
       
   745               #acceptChannel: #acceptChannel
       
   746               #acceptOnPointerLeave: false
       
   747             )
       
   748            #(#ThumbWheelSpec
       
   749               #name: 'SaturationWheel'
       
   750               #layout: #(#LayoutFrame 152 0 80 0 269 0 100 0)
       
   751               #model: #saturationAmount
       
   752               #orientation: #horizontal
       
   753               #stop: 1000
       
   754               #step: 1
       
   755             )
       
   756            #(#LabelSpec
       
   757               #name: 'HueColorLabel'
       
   758               #layout: #(#LayoutFrame 10 0.0 109 0 -10 1.0 148 0)
       
   759               #translateLabel: true
       
   760               #backgroundChannel: #hueColor
       
   761             )
       
   762            #(#HorizontalPanelViewSpec
       
   763               #name: 'HorizontalPanel1'
       
   764               #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
       
   765               #horizontalLayout: #fitSpace
       
   766               #verticalLayout: #center
       
   767               #horizontalSpace: 3
       
   768               #verticalSpace: 3
       
   769               #reverseOrderIfOKAtLeft: true
       
   770               #component: 
       
   771              #(#SpecCollection
       
   772                 #collection: #(
       
   773                  #(#ActionButtonSpec
       
   774                     #label: 'Cancel'
       
   775                     #name: 'Button1'
       
   776                     #translateLabel: true
       
   777                     #tabable: true
       
   778                     #model: #cancel
       
   779                     #extent: #(#Point 151 22)
       
   780                   )
       
   781                  #(#ActionButtonSpec
       
   782                     #label: 'OK'
       
   783                     #name: 'Button2'
       
   784                     #translateLabel: true
       
   785                     #tabable: true
       
   786                     #model: #accept
       
   787                     #extent: #(#Point 152 22)
       
   788                   )
       
   789                  )
       
   790                
       
   791               )
       
   792             )
       
   793            )
       
   794          
       
   795         )
       
   796       )
       
   797 !
   649 
   798 
   650 dialogSpecForNewImage
   799 dialogSpecForNewImage
   651     "This resource specification was automatically generated
   800     "This resource specification was automatically generated
   652      by the UIPainter of ST/X."
   801      by the UIPainter of ST/X."
   653 
   802 
   899                     #extent: #(#Point 78 22)
  1048                     #extent: #(#Point 78 22)
   900                   )
  1049                   )
   901                  )
  1050                  )
   902                
  1051                
   903               )
  1052               )
   904             )
       
   905            )
       
   906          
       
   907         )
       
   908       )
       
   909 !
       
   910 
       
   911 hueShiftDialogSpec
       
   912     "This resource specification was automatically generated
       
   913      by the UIPainter of ST/X."
       
   914 
       
   915     "Do not manually edit this!! If it is corrupted,
       
   916      the UIPainter may not be able to read the specification."
       
   917 
       
   918     "
       
   919      UIPainter new openOnClass:ImageEditor andSelector:#hueShiftDialogSpec
       
   920      ImageEditor new openInterface:#hueShiftDialogSpec
       
   921     "
       
   922 
       
   923     <resource: #canvas>
       
   924 
       
   925     ^ 
       
   926      #(#FullSpec
       
   927         #name: #hueShiftDialogSpec
       
   928         #window: 
       
   929        #(#WindowSpec
       
   930           #label: 'Shift Hue'
       
   931           #name: 'Shift Hue'
       
   932           #min: #(#Point 10 10)
       
   933           #max: #(#Point 800 478)
       
   934           #bounds: #(#Rectangle 16 46 261 229)
       
   935         )
       
   936         #component: 
       
   937        #(#SpecCollection
       
   938           #collection: #(
       
   939            #(#LabelSpec
       
   940               #label: 'Hue-Shift:'
       
   941               #name: 'HueLabel'
       
   942               #layout: #(#LayoutFrame 14 0 21 0 90 0 43 0)
       
   943               #translateLabel: true
       
   944               #adjust: #right
       
   945             )
       
   946            #(#InputFieldSpec
       
   947               #name: 'HueShiftEntryField'
       
   948               #layout: #(#LayoutFrame 95 0 21 0 138 0 43 0)
       
   949               #tabable: true
       
   950               #model: #hueShiftAmount
       
   951               #type: #number
       
   952               #acceptChannel: #acceptChannel
       
   953               #acceptOnPointerLeave: false
       
   954             )
       
   955            #(#HorizontalPanelViewSpec
       
   956               #name: 'HorizontalPanel1'
       
   957               #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
       
   958               #horizontalLayout: #fitSpace
       
   959               #verticalLayout: #center
       
   960               #horizontalSpace: 3
       
   961               #verticalSpace: 3
       
   962               #reverseOrderIfOKAtLeft: true
       
   963               #component: 
       
   964              #(#SpecCollection
       
   965                 #collection: #(
       
   966                  #(#ActionButtonSpec
       
   967                     #label: 'Cancel'
       
   968                     #name: 'Button1'
       
   969                     #translateLabel: true
       
   970                     #tabable: true
       
   971                     #model: #cancel
       
   972                     #extent: #(#Point 118 22)
       
   973                   )
       
   974                  #(#ActionButtonSpec
       
   975                     #label: 'OK'
       
   976                     #name: 'Button2'
       
   977                     #translateLabel: true
       
   978                     #tabable: true
       
   979                     #model: #accept
       
   980                     #extent: #(#Point 118 22)
       
   981                   )
       
   982                  )
       
   983                
       
   984               )
       
   985             )
       
   986            #(#ThumbWheelSpec
       
   987               #name: 'ThumbWheel1'
       
   988               #layout: #(#LayoutFrame 60 0 83 0 177 0 103 0)
       
   989               #model: #hueShiftAmount
       
   990               #orientation: #horizontal
       
   991               #step: 1
       
   992               #endlessRotation: true
       
   993             )
       
   994            #(#LabelSpec
       
   995               #name: 'HueColorLabel'
       
   996               #layout: #(#LayoutFrame 5 0 109 0 241 0 148 0)
       
   997               #translateLabel: true
       
   998               #backgroundChannel: #hueColor
       
   999             )
  1053             )
  1000            )
  1054            )
  1001          
  1055          
  1002         )
  1056         )
  1003       )
  1057       )
  1977                       )
  2031                       )
  1978                      #(#MenuItem
  2032                      #(#MenuItem
  1979                         #label: '-'
  2033                         #label: '-'
  1980                       )
  2034                       )
  1981                      #(#MenuItem
  2035                      #(#MenuItem
  1982                         #label: 'Change Hue...'
  2036                         #label: 'Change HLS...'
  1983                         #itemValue: #changeHue
  2037                         #itemValue: #changeHLS
  1984                         #translateLabel: true
  2038                         #translateLabel: true
  1985                       )
  2039                       )
  1986                      )
  2040                      )
  1987                     nil
  2041                     nil
  1988                     nil
  2042                     nil
  3209 
  3263 
  3210     "Created: / 12.3.1999 / 00:20:28 / cg"
  3264     "Created: / 12.3.1999 / 00:20:28 / cg"
  3211     "Modified: / 16.3.1999 / 21:57:26 / cg"
  3265     "Modified: / 16.3.1999 / 21:57:26 / cg"
  3212 !
  3266 !
  3213 
  3267 
  3214 changeHue
  3268 changeHLS
  3215     "let user specify amount and shift"
  3269     "interactive Hue/Light/Saturation editing"
  3216 
  3270 
  3217     |bindings shiftAmount originalColormap img firstChange shiftAction acceptChannel hueColorHolder|
  3271     |bindings hueShift lightValue saturationValue originalColormap firstChange acceptChannel 
       
  3272      shiftAction colorHolder|
  3218 
  3273 
  3219     originalColormap := imageEditView image colorMap copy.
  3274     originalColormap := imageEditView image colorMap copy.
  3220 
  3275 
  3221     acceptChannel := TriggerValue new.
  3276     acceptChannel := TriggerValue new.
  3222 
  3277 
  3223     firstChange := true.
  3278     firstChange := true.
  3224 
  3279 
  3225     shiftAction := 
  3280     shiftAction := 
  3226         [
  3281         [
       
  3282             |hShift lFactor sFactor|
       
  3283 
  3227             acceptChannel value:true.
  3284             acceptChannel value:true.
  3228 
  3285 
  3229             firstChange ifTrue:[
  3286             firstChange ifTrue:[
  3230                 imageEditView makeUndo.
  3287                 imageEditView makeUndo.
  3231                 firstChange := false.
  3288                 firstChange := false.
  3232             ].
  3289             ].
  3233             hueColorHolder value:(Color hue:shiftAmount value light:50 saturation:100).
  3290 
       
  3291             hShift := hueShift value.
       
  3292             lFactor := lightValue value.
       
  3293             sFactor := saturationValue value.
       
  3294 
       
  3295             colorHolder value:(Color hue:hShift light:(lFactor min:100) saturation:(sFactor min:100)).
  3234             imageEditView image colorMap:originalColormap copy.
  3296             imageEditView image colorMap:originalColormap copy.
  3235             imageEditView image colorMapProcessing:[:clr | Color hue:((clr hue) ? 0+shiftAmount value) light:clr light saturation:clr saturation].
  3297             imageEditView image colorMapProcessing:[:clr | Color 
       
  3298                                                                 hue:((clr hue) ? 0 + hShift) 
       
  3299                                                                 light:((clr light * lFactor / 100) min:100)
       
  3300                                                                 saturation:((clr saturation * sFactor / 100) min:100)].
  3236             self updateImage.
  3301             self updateImage.
  3237             self updateInfoLabel.
  3302             self updateInfoLabel.
  3238         ].
  3303         ].
  3239 
  3304 
  3240     bindings := IdentityDictionary new.
  3305     bindings := IdentityDictionary new.
  3241     bindings at:#hueShiftAmount put:(shiftAmount := 0 asValue).
  3306     bindings at:#hueShiftAmount put:(hueShift := 0 asValue).
  3242     (bindings at:#hueShiftAmount) onChangeEvaluate:shiftAction.
  3307     (bindings at:#hueShiftAmount) onChangeEvaluate:shiftAction.
       
  3308 
       
  3309     bindings at:#lightAmount put:(lightValue := 100 asValue).
       
  3310     (bindings at:#lightAmount) onChangeEvaluate:shiftAction.
       
  3311 
       
  3312     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
       
  3313     (bindings at:#saturationAmount) onChangeEvaluate:shiftAction.
       
  3314 
  3243     bindings at:#acceptChannel put:acceptChannel.
  3315     bindings at:#acceptChannel put:acceptChannel.
  3244     bindings at:#hueColor put:(hueColorHolder := Color white asValue).
  3316     bindings at:#hueColor put:(colorHolder := Color white asValue).
  3245 
  3317 
  3246     (self openDialogInterface:#hueShiftDialogSpec withBindings:bindings) 
  3318     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
  3247     ifFalse:[ 
  3319     ifFalse:[ 
  3248         firstChange ~~ true ifTrue:[
  3320         firstChange ~~ true ifTrue:[
  3249             imageEditView undo
  3321             imageEditView undo
  3250         ]
  3322         ]
  3251     ].
  3323     ].