ImageEditor.st
changeset 1934 294d0e102881
parent 1933 2fe701f721ac
child 1935 27b19cd0274b
equal deleted inserted replaced
1933:2fe701f721ac 1934:294d0e102881
  2001                   translateLabel: true
  2001                   translateLabel: true
  2002                   submenu: 
  2002                   submenu: 
  2003                  (Menu
  2003                  (Menu
  2004                     (
  2004                     (
  2005                      (MenuItem
  2005                      (MenuItem
       
  2006                         activeHelpKey: colorMap24
       
  2007                         label: '24-Plane'
       
  2008                         itemValue: colorMapMode:
       
  2009                         translateLabel: true
       
  2010                         argument: depth24
       
  2011                         choice: colorMapMode
       
  2012                         choiceValue: depth24
       
  2013                       )
       
  2014                      (MenuItem
       
  2015                         activeHelpKey: colorMap16
       
  2016                         label: '16-Plane'
       
  2017                         itemValue: colorMapMode:
       
  2018                         translateLabel: true
       
  2019                         argument: depth16
       
  2020                         choice: colorMapMode
       
  2021                         choiceValue: depth16
       
  2022                       )
       
  2023                      (MenuItem
  2006                         activeHelpKey: colorMap8
  2024                         activeHelpKey: colorMap8
  2007                         label: '8-Plane'
  2025                         label: '8-Plane'
  2008                         itemValue: colorMapMode:
  2026                         itemValue: colorMapMode:
  2009                         translateLabel: true
  2027                         translateLabel: true
  2010                         argument: depth8
  2028                         argument: depth8
  2038                         choice: colorMapMode
  2056                         choice: colorMapMode
  2039                         choiceValue: depth1
  2057                         choiceValue: depth1
  2040                       )
  2058                       )
  2041                      (MenuItem
  2059                      (MenuItem
  2042                         label: '-'
  2060                         label: '-'
       
  2061                       )
       
  2062                      (MenuItem
       
  2063                         activeHelpKey: colorMap24M
       
  2064                         label: '24-Plane + Mask'
       
  2065                         itemValue: colorMapMode:
       
  2066                         translateLabel: true
       
  2067                         argument: masked24
       
  2068                         choice: colorMapMode
       
  2069                         choiceValue: masked24
       
  2070                       )
       
  2071                      (MenuItem
       
  2072                         activeHelpKey: colorMap16M
       
  2073                         label: '16-Plane + Mask'
       
  2074                         itemValue: colorMapMode:
       
  2075                         translateLabel: true
       
  2076                         argument: masked16
       
  2077                         choice: colorMapMode
       
  2078                         choiceValue: masked16
  2043                       )
  2079                       )
  2044                      (MenuItem
  2080                      (MenuItem
  2045                         activeHelpKey: colorMap8M
  2081                         activeHelpKey: colorMap8M
  2046                         label: '8-Plane + Mask'
  2082                         label: '8-Plane + Mask'
  2047                         itemValue: colorMapMode:
  2083                         itemValue: colorMapMode:
  2100                         label: 'Sort Colormap'
  2136                         label: 'Sort Colormap'
  2101                         itemValue: sortColorMap
  2137                         itemValue: sortColorMap
  2102                         translateLabel: true
  2138                         translateLabel: true
  2103                       )
  2139                       )
  2104                      (MenuItem
  2140                      (MenuItem
  2105                         label: 'Reduce Number of Colors...'
  2141                         label: 'Reduce Number of Colors by Rounding...'
       
  2142                         itemValue: reduceNumberOfColors2
       
  2143                         translateLabel: true
       
  2144                       )
       
  2145                      (MenuItem
       
  2146                         label: 'Reduce Number of Colors by Masking Bits...'
  2106                         itemValue: reduceNumberOfColors
  2147                         itemValue: reduceNumberOfColors
  2107                         translateLabel: true
  2148                         translateLabel: true
  2108                       )
  2149                       )
  2109                      )
  2150                      )
  2110                     nil
  2151                     nil
  4269 reduceNumberOfColors
  4310 reduceNumberOfColors
  4270     |s n anyChange img usedColors|
  4311     |s n anyChange img usedColors|
  4271 
  4312 
  4272     s := Dialog request:'Number of color bits to strip (1-7) ?'.
  4313     s := Dialog request:'Number of color bits to strip (1-7) ?'.
  4273     s size == 0 ifTrue:[^ self].
  4314     s size == 0 ifTrue:[^ self].
       
  4315 
  4274     n := Integer readFrom:s onError:0.
  4316     n := Integer readFrom:s onError:0.
  4275     (n between:1 and:7) ifFalse:[
  4317     (n between:1 and:7) ifFalse:[
  4276         Dialog warn:'Image unchanged'.
  4318         Dialog warn:'Image unchanged'.
  4277         ^ self
  4319         ^ self
  4278     ].
  4320     ].
  4295         ]
  4337         ]
  4296     ].
  4338     ].
  4297 !
  4339 !
  4298 
  4340 
  4299 reduceNumberOfColors2
  4341 reduceNumberOfColors2
  4300     |s n anyChange img usedColors|
  4342     |s rnd usedColors image newImage|
  4301 
  4343 
  4302     s := Dialog request:'Similarity Delta (1..) ?' initialAnswer:2.
  4344     s := Dialog request:'Rounding Interval (2..) ?' initialAnswer:2.
  4303     s size == 0 ifTrue:[
  4345     s size == 0 ifTrue:[^ self].
  4304         self reduceNumberOfColors2.
  4346 
  4305         ^ self
  4347     rnd := Integer readFrom:s onError:0.
  4306     ].
  4348     (rnd > 1) ifFalse:[
  4307     n := Integer readFrom:s onError:0.
       
  4308     (n >= 1) ifFalse:[
       
  4309         Dialog warn:'Image unchanged'.
  4349         Dialog warn:'Image unchanged'.
  4310         ^ self
  4350         ^ self
  4311     ].
  4351     ].
  4312 
  4352 
  4313     self withExecuteCursorDo:[
  4353     self withExecuteCursorDo:[
  4314 "/        anyChange := imageEditView reduceColorResolutionBy:n.
  4354         image := self image.
  4315 "/        anyChange ifFalse:[
  4355         usedColors := image usedColors.
  4316 "/            Dialog warn:'Image unchanged'.
  4356         imageEditView makeUndo.
  4317 "/        ] ifTrue:[
  4357 
  4318 "/            img := imageEditView image.
  4358         newImage := image copy.
  4319 "/            imageEditView image:img.
  4359         image
  4320 "/
  4360             colorsFromX:0 y:0 toX:(image width-1) y:(image height-1) 
  4321 "/            self fetchImageData.
  4361             do:[:x :y :clr |
  4322 "/            usedColors := img usedColorsMax:10000.
  4362                 |r g b nr ng nb newClr|
  4323 "/            usedColors size == 10000 ifTrue:[
  4363 
  4324 "/                Dialog information:('>= ' , usedColors size printString , ' colors used.')
  4364                 r := clr redByte.
  4325 "/            ] ifFalse:[
  4365                 g := clr greenByte.
  4326 "/                Dialog information:(usedColors size printString , ' colors used.')
  4366                 b := clr blueByte. 
  4327 "/            ]
  4367                 nr := (r roundTo:rnd) min:255.
  4328 "/        ]
  4368                 ng := (g roundTo:rnd) min:255.
       
  4369                 nb := (b roundTo:rnd) min:255. 
       
  4370 
       
  4371                 newClr := Color redByte:nr greenByte:ng blueByte:nb.
       
  4372                 newImage colorAtX:x y:y put:newClr
       
  4373             ].
       
  4374 
       
  4375         imageEditView image:newImage.
       
  4376         imageEditView setModified.
       
  4377         self updateImage.
       
  4378         self updateImagePreView.
       
  4379 
       
  4380         self fetchImageData.
       
  4381         usedColors := newImage usedColorsMax:10000.
       
  4382         usedColors size == 10000 ifTrue:[
       
  4383             Dialog information:('>= ' , usedColors size printString , ' colors used.')
       
  4384         ] ifFalse:[
       
  4385             Dialog information:(usedColors size printString , ' colors used.')
       
  4386         ]
  4329     ].
  4387     ].
  4330 !
  4388 !
  4331 
  4389 
  4332 selectedColorIndexOrNil
  4390 selectedColorIndexOrNil
  4333     | img clrIndex|
  4391     | img clrIndex|