ImageEditor.st
changeset 2192 398c9aba6588
parent 2190 5bb9504b58bd
child 2196 7e4e066ca7f5
equal deleted inserted replaced
2191:88d55c87942d 2192:398c9aba6588
  2181                      (MenuItem
  2181                      (MenuItem
  2182                         label: 'Change HLS...'
  2182                         label: 'Change HLS...'
  2183                         itemValue: changeHLS
  2183                         itemValue: changeHLS
  2184                         translateLabel: true
  2184                         translateLabel: true
  2185                       )
  2185                       )
       
  2186                      (MenuItem
       
  2187                         label: 'Colorize...'
       
  2188                         itemValue: colorize
       
  2189                         translateLabel: true
       
  2190                       )
  2186                      )
  2191                      )
  2187                     nil
  2192                     nil
  2188                     nil
  2193                     nil
  2189                   )
  2194                   )
  2190                 )
  2195                 )
  2234                   activeHelpKey: settingsGridMagnification
  2239                   activeHelpKey: settingsGridMagnification
  2235                   label: 'Grid Magnification Limit...'
  2240                   label: 'Grid Magnification Limit...'
  2236                   itemValue: doChangeGridMagnification
  2241                   itemValue: doChangeGridMagnification
  2237                   translateLabel: true
  2242                   translateLabel: true
  2238                 )
  2243                 )
       
  2244                (MenuItem
       
  2245                   label: 'Pen'
       
  2246                   translateLabel: true
       
  2247                   submenu: 
       
  2248                  (Menu
       
  2249                     (
       
  2250                      (MenuItem
       
  2251                         label: '1'
       
  2252                         itemValue: penWidth:
       
  2253                         translateLabel: true
       
  2254                         argument: 1
       
  2255                       )
       
  2256                      (MenuItem
       
  2257                         label: '5'
       
  2258                         itemValue: penWidth:
       
  2259                         translateLabel: true
       
  2260                         argument: 5
       
  2261                       )
       
  2262                      (MenuItem
       
  2263                         label: '10'
       
  2264                         itemValue: penWidth:
       
  2265                         translateLabel: true
       
  2266                         argument: 10
       
  2267                       )
       
  2268                      )
       
  2269                     nil
       
  2270                     nil
       
  2271                   )
       
  2272                 )
  2239                )
  2273                )
  2240               nil
  2274               nil
  2241               nil
  2275               nil
  2242             )
  2276             )
  2243           )
  2277           )
  2255           )
  2289           )
  2256          )
  2290          )
  2257         nil
  2291         nil
  2258         nil
  2292         nil
  2259       )
  2293       )
  2260 
       
  2261     "Modified: / 23-10-2006 / 23:16:47 / cg"
       
  2262 !
  2294 !
  2263 
  2295 
  2264 menuMouseButtonColors
  2296 menuMouseButtonColors
  2265     "This resource specification was automatically generated
  2297     "This resource specification was automatically generated
  2266      by the MenuEditor of ST/X."
  2298      by the MenuEditor of ST/X."
  4112     ]
  4144     ]
  4113 
  4145 
  4114     "Modified: / 20-07-2007 / 09:18:59 / cg"
  4146     "Modified: / 20-07-2007 / 09:18:59 / cg"
  4115 !
  4147 !
  4116 
  4148 
       
  4149 colorize
       
  4150     "interactive Hue editing"
       
  4151 
       
  4152     |bindings hueShift lightValue saturationValue originalColormap firstChange acceptChannel 
       
  4153      shiftAction avgColorHolder avgColor shiftedColor shiftProcess readySema
       
  4154      originalPixels p|
       
  4155 
       
  4156     "/ compute the averageColor in the background (while asking user)
       
  4157     readySema := Semaphore new.
       
  4158     [
       
  4159         |image|
       
  4160 
       
  4161         image := imageEditView image.
       
  4162         originalColormap := image colorMap copy.
       
  4163         avgColor := image averageColor.
       
  4164         originalPixels := image bits.
       
  4165         readySema signal.
       
  4166     ] forkAt:7.
       
  4167 
       
  4168     acceptChannel := TriggerValue new.
       
  4169     avgColorHolder := avgColor asValue.
       
  4170 
       
  4171     firstChange := true.
       
  4172 
       
  4173     shiftedColor := [:clr :hShift :lFactor :sFactor |
       
  4174                         Color 
       
  4175                                 hue:((clr hue) ? 0 + hShift) 
       
  4176                                 light:((clr light * lFactor / 100) "min:100")
       
  4177                                 saturation:(((clr saturation max:20) * sFactor / 100) "min:100")].
       
  4178 
       
  4179 
       
  4180     shiftAction := 
       
  4181         [
       
  4182             |hShift lFactor sFactor|
       
  4183 
       
  4184             acceptChannel value:true.
       
  4185 
       
  4186             firstChange ifTrue:[
       
  4187                 imageEditView makeUndo.
       
  4188                 firstChange := false.
       
  4189             ].
       
  4190             readySema notNil ifTrue:[readySema wait. readySema := nil].
       
  4191 
       
  4192             hShift := hueShift value.
       
  4193             lFactor := lightValue value.
       
  4194             sFactor := saturationValue value.
       
  4195 
       
  4196             avgColorHolder value:(shiftedColor value:avgColor value:hShift value:lFactor value:sFactor).
       
  4197 
       
  4198             shiftProcess notNil ifTrue:[
       
  4199                 shiftProcess terminate.
       
  4200                 shiftProcess waitUntilTerminated.
       
  4201                 shiftProcess := nil.
       
  4202             ].
       
  4203             shiftProcess := 
       
  4204                 [
       
  4205                     [
       
  4206                         imageEditView image 
       
  4207                             colorMap:originalColormap copy;
       
  4208                             bits:originalPixels copy;
       
  4209                             release;
       
  4210                             colorMapProcessing:[:clr | shiftedColor value:clr value:hShift value:lFactor value:sFactor].
       
  4211                         self updateImage.
       
  4212                         self updateInfoLabel.
       
  4213                         self updateImagePreView.
       
  4214                     ] ensure:[ shiftProcess := nil ].    
       
  4215                 ] forkAt:7.
       
  4216         ].
       
  4217 
       
  4218     bindings := IdentityDictionary new.
       
  4219     bindings at:#hueShiftAmount put:(hueShift := 0 asValue).
       
  4220     hueShift onChangeEvaluate:shiftAction.
       
  4221 
       
  4222     bindings at:#lightAmount put:(lightValue := 100 asValue).
       
  4223     lightValue onChangeEvaluate:shiftAction.
       
  4224 
       
  4225     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
       
  4226     saturationValue onChangeEvaluate:shiftAction.
       
  4227 
       
  4228     bindings at:#acceptChannel put:acceptChannel.
       
  4229     bindings at:#hlsColor put:avgColorHolder.
       
  4230 
       
  4231     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
       
  4232     ifFalse:[ 
       
  4233         firstChange ~~ true ifTrue:[
       
  4234             imageEditView undo
       
  4235         ]
       
  4236     ].
       
  4237 
       
  4238     (p := shiftProcess) notNil ifTrue:[
       
  4239         p waitUntilTerminated.
       
  4240     ].
       
  4241     self updateImage.
       
  4242     self updateImagePreView.
       
  4243 
       
  4244     "Created: / 01-11-2007 / 23:27:37 / cg"
       
  4245 !
       
  4246 
  4117 compressColorMap
  4247 compressColorMap
  4118     "calculates a new color map for the image, using only used colors"
  4248     "calculates a new color map for the image, using only used colors"
  4119 
  4249 
  4120     |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| 
  4250     |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| 
  4121 
  4251 
  5371         newGridLimit := (99 min: (2 max:newGridLimit)) asPoint.
  5501         newGridLimit := (99 min: (2 max:newGridLimit)) asPoint.
  5372         imageEditView class gridMagnificationLimit:newGridLimit.
  5502         imageEditView class gridMagnificationLimit:newGridLimit.
  5373         imageEditView invalidate
  5503         imageEditView invalidate
  5374     ]
  5504     ]
  5375 
  5505 
       
  5506 !
       
  5507 
       
  5508 penWidth:n
       
  5509     imageEditView penWidth:n
       
  5510 
       
  5511     "Created: / 01-11-2007 / 23:47:48 / cg"
  5376 ! !
  5512 ! !
  5377 
  5513 
  5378 !ImageEditor class methodsFor:'documentation'!
  5514 !ImageEditor class methodsFor:'documentation'!
  5379 
  5515 
  5380 version
  5516 version