ImageEditor.st
changeset 3195 32e373ae50fa
parent 3191 ae97e9478128
child 3196 830d70ff1d54
equal deleted inserted replaced
3194:86cf12ddc8fd 3195:32e373ae50fa
  1841     "
  1841     "
  1842 
  1842 
  1843     <resource: #canvas>
  1843     <resource: #canvas>
  1844 
  1844 
  1845     ^ 
  1845     ^ 
  1846      #(FullSpec
  1846     #(FullSpec
  1847         name: windowSpec
  1847        name: windowSpec
  1848         window: 
  1848        window: 
  1849        (WindowSpec
  1849       (WindowSpec
  1850           label: 'Image Editor'
  1850          label: 'Image Editor'
  1851           name: 'Image Editor'
  1851          name: 'Image Editor'
  1852           min: (Point 400 320)
  1852          min: (Point 400 320)
  1853           bounds: (Rectangle 0 0 450 350)
  1853          bounds: (Rectangle 0 0 450 350)
  1854           menu: menu
  1854          menu: menu
  1855           icon: defaultIcon
  1855          icon: defaultIcon
  1856         )
  1856        )
  1857         component: 
  1857        component: 
  1858        (SpecCollection
  1858       (SpecCollection
  1859           collection: (
  1859          collection: (
  1860            (MenuPanelSpec
  1860           (MenuPanelSpec
  1861               name: 'menuToolbarView'
  1861              name: 'menuToolbarView'
  1862               layout: (LayoutFrame 0 0.0 0 0 0 1.0 32 0)
  1862              layout: (LayoutFrame 0 0.0 0 0 0 1.0 32 0)
  1863               style: (FontDescription helvetica medium roman 10)
  1863              style: (FontDescription helvetica medium roman 10)
  1864               menu: menuToolbar
  1864              menu: menuToolbar
  1865               showSeparatingLines: true
  1865              showSeparatingLines: true
  1866             )
  1866            )
  1867            (VariableHorizontalPanelSpec
  1867           (VariableHorizontalPanelSpec
  1868               name: 'mainPanel'
  1868              name: 'mainPanel'
  1869               layout: (LayoutFrame 0 0.0 34 0.0 0 1.0 -26 1.0)
  1869              layout: (LayoutFrame 0 0.0 34 0.0 0 1.0 -26 1.0)
  1870               snapMode: both
  1870              snapMode: both
  1871               barLevel: 0
  1871              barLevel: 0
  1872               component: 
  1872              component: 
  1873              (SpecCollection
  1873             (SpecCollection
  1874                 collection: (
  1874                collection: (
  1875                  (ViewSpec
  1875                 (ViewSpec
  1876                     name: 'leftView'
  1876                    name: 'leftView'
  1877                     level: 1
  1877                    level: 1
  1878                     component: 
  1878                    component: 
  1879                    (SpecCollection
  1879                   (SpecCollection
  1880                       collection: (
  1880                      collection: (
  1881                        (VariableVerticalPanelSpec
  1881                       (VariableVerticalPanelSpec
  1882                           name: 'verticalPanel'
  1882                          name: 'verticalPanel'
  1883                           layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
  1883                          layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
  1884                           level: 0
  1884                          level: 0
  1885                           snapMode: both
  1885                          snapMode: both
  1886                           component: 
  1886                          component: 
  1887                          (SpecCollection
  1887                         (SpecCollection
  1888                             collection: (
  1888                            collection: (
  1889                              (ViewSpec
  1889                             (ViewSpec
  1890                                 name: 'View1'
  1890                                name: 'View1'
  1891                                 component: 
  1891                                component: 
  1892                                (SpecCollection
  1892                               (SpecCollection
  1893                                   collection: (
  1893                                  collection: (
  1894                                    (MenuPanelSpec
  1894                                   (MenuPanelSpec
  1895                                       name: 'MouseButtonColorToolBar'
  1895                                      name: 'MouseButtonColorToolBar'
  1896                                       layout: (LayoutFrame 0 0.0 0 0 0 1.0 24 0)
  1896                                      layout: (LayoutFrame 0 0.0 0 0 0 1.0 24 0)
  1897                                       level: 0
  1897                                      level: 0
  1898                                       menu: menuMouseButtonColors
  1898                                      menu: menuMouseButtonColors
  1899                                     )
       
  1900                                    (DataSetSpec
       
  1901                                       name: 'colorDataSetView'
       
  1902                                       layout: (LayoutFrame 0 0.0 26 0.0 0 1.0 0 1.0)
       
  1903                                       activeHelpKey: colorMapTable
       
  1904                                       style: (FontDescription helvetica medium roman 10)
       
  1905                                       model: selectionOfColor
       
  1906                                       menu: colorMapMenu
       
  1907                                       hasHorizontalScrollBar: true
       
  1908                                       hasVerticalScrollBar: true
       
  1909                                       miniScrollerHorizontal: true
       
  1910                                       miniScrollerVertical: true
       
  1911                                       dataList: listOfColors
       
  1912                                       has3Dseparators: true
       
  1913                                       doubleClickSelector: doubleClickOnColor:
       
  1914                                       columnHolder: colorTableColumns
       
  1915                                       verticalSpacing: 1
       
  1916                                       columnAdaptor: colorColumnAdaptor
       
  1917                                     )
       
  1918                                    )
  1899                                    )
  1919                                  
  1900                                   (DataSetSpec
  1920                                 )
  1901                                      name: 'colorDataSetView'
  1921                               )
  1902                                      layout: (LayoutFrame 0 0.0 26 0.0 0 1.0 0 1.0)
  1922                              (ArbitraryComponentSpec
  1903                                      activeHelpKey: colorMapTable
  1923                                 name: 'imagePreView'
  1904                                      style: (FontDescription helvetica medium roman 10)
  1924                                 activeHelpKey: previewView
  1905                                      model: selectedColors
  1925                                 menu: previewMenu
  1906                                      menu: colorMapMenu
  1926                                 hasHorizontalScrollBar: true
  1907                                      hasHorizontalScrollBar: true
  1927                                 hasVerticalScrollBar: true
  1908                                      hasVerticalScrollBar: true
  1928                                 miniScrollerHorizontal: false
  1909                                      miniScrollerHorizontal: true
  1929                                 miniScrollerVertical: false
  1910                                      miniScrollerVertical: true
  1930                                 hasBorder: false
  1911                                      dataList: listOfColors
  1931                                 component: ImageView
  1912                                      has3Dseparators: true
  1932                               )
  1913                                      doubleClickSelector: doubleClickOnColor:
       
  1914                                      columnHolder: colorTableColumns
       
  1915                                      multipleSelectOk: true
       
  1916                                      verticalSpacing: 1
       
  1917                                      columnAdaptor: colorColumnAdaptor
       
  1918                                    )
       
  1919                                   )
       
  1920                                 
       
  1921                                )
  1933                              )
  1922                              )
  1934                            
  1923                             (ArbitraryComponentSpec
  1935                           )
  1924                                name: 'imagePreView'
  1936                           handles: (Any 0.5 1.0)
  1925                                activeHelpKey: previewView
  1937                         )
  1926                                menu: previewMenu
       
  1927                                hasHorizontalScrollBar: true
       
  1928                                hasVerticalScrollBar: true
       
  1929                                miniScrollerHorizontal: false
       
  1930                                miniScrollerVertical: false
       
  1931                                hasBorder: false
       
  1932                                component: ImageView
       
  1933                              )
       
  1934                             )
       
  1935                           
       
  1936                          )
       
  1937                          handles: (Any 0.5 1.0)
  1938                        )
  1938                        )
  1939                      
  1939                       )
  1940                     )
  1940                     
  1941                   )
  1941                    )
  1942                  (ViewSpec
  1942                  )
  1943                     name: 'rightView'
  1943                 (ViewSpec
  1944                     component: 
  1944                    name: 'rightView'
  1945                    (SpecCollection
  1945                    component: 
  1946                       collection: (
  1946                   (SpecCollection
  1947                        (MenuPanelSpec
  1947                      collection: (
  1948                           name: 'ToolBar1'
  1948                       (MenuPanelSpec
  1949                           layout: (LayoutFrame 0 0 0 0.0 28 0 0 1.0)
  1949                          name: 'ToolBar1'
  1950                           level: 1
  1950                          layout: (LayoutFrame 0 0 0 0.0 28 0 0 1.0)
  1951                           menu: toolsMenuToolbar
  1951                          level: 1
  1952                           verticalLayout: true
  1952                          menu: toolsMenuToolbar
  1953                           centerItems: true
  1953                          verticalLayout: true
  1954                           textDefault: true
  1954                          centerItems: true
  1955                         )
  1955                          textDefault: true
  1956                        (ViewSpec
  1956                        )
  1957                           name: 'editingView'
  1957                       (ViewSpec
  1958                           layout: (LayoutFrame 28 0.0 0 0.0 0 1.0 0 1.0)
  1958                          name: 'editingView'
  1959                           level: 1
  1959                          layout: (LayoutFrame 28 0.0 0 0.0 0 1.0 0 1.0)
  1960                           component: 
  1960                          level: 1
  1961                          (SpecCollection
  1961                          component: 
  1962                             collection: (
  1962                         (SpecCollection
  1963                              (ArbitraryComponentSpec
  1963                            collection: (
  1964                                 name: 'imageEditView'
  1964                             (ArbitraryComponentSpec
  1965                                 layout: (LayoutFrame 2 0.0 2 0.0 -2 1.0 -24 1.0)
  1965                                name: 'imageEditView'
  1966                                 hasHorizontalScrollBar: true
  1966                                layout: (LayoutFrame 2 0.0 2 0.0 -2 1.0 -24 1.0)
  1967                                 hasVerticalScrollBar: true
  1967                                hasHorizontalScrollBar: true
  1968                                 hasBorder: false
  1968                                hasVerticalScrollBar: true
  1969                                 component: ImageEditView
  1969                                hasBorder: false
  1970                               )
  1970                                component: ImageEditView
  1971                              (LabelSpec
       
  1972                                 name: 'coordLabel'
       
  1973                                 layout: (LayoutFrame 2 0.0 -22 1 -83 1.0 0 1.0)
       
  1974                                 level: -1
       
  1975                                 labelChannel: imageInfoHolder
       
  1976                                 resizeForLabel: false
       
  1977                                 adjust: left
       
  1978                               )
       
  1979                              (ArrowButtonSpec
       
  1980                                 name: 'magnifyDownButton'
       
  1981                                 layout: (LayoutFrame -80 1 -22 1 -58 1 0 1)
       
  1982                                 activeHelpKey: magnifyImageDown
       
  1983                                 model: doMagnifyDown
       
  1984                                 enableChannel: imageIsLoadedHolder
       
  1985                                 isTriggerOnDown: true
       
  1986                                 direction: left
       
  1987                               )
       
  1988                              (ArrowButtonSpec
       
  1989                                 name: 'magnifyUpButton'
       
  1990                                 layout: (LayoutFrame -24 1 -22 1 -2 1 0 1)
       
  1991                                 activeHelpKey: magnifyImageUp
       
  1992                                 model: doMagnifyUp
       
  1993                                 enableChannel: imageIsLoadedHolder
       
  1994                                 isTriggerOnDown: true
       
  1995                                 direction: right
       
  1996                               )
       
  1997                              (InputFieldSpec
       
  1998                                 name: 'magnificationInputField'
       
  1999                                 layout: (LayoutFrame -57 1 -22 1 -26 1 0 1)
       
  2000                                 activeHelpKey: magnificationNumber
       
  2001                                 enableChannel: imageIsLoadedHolder
       
  2002                                 model: magnificationHolder
       
  2003                                 type: numberInRange
       
  2004                                 acceptOnReturn: true
       
  2005                                 acceptOnTab: true
       
  2006                                 numChars: 2
       
  2007                                 minValue: 1
       
  2008                                 maxValue: 99
       
  2009                                 acceptOnPointerLeave: true
       
  2010                               )
       
  2011                              )
  1971                              )
  2012                            
  1972                             (LabelSpec
  2013                           )
  1973                                name: 'coordLabel'
  2014                         )
  1974                                layout: (LayoutFrame 2 0.0 -22 1 -83 1.0 0 1.0)
       
  1975                                level: -1
       
  1976                                translateLabel: true
       
  1977                                labelChannel: imageInfoHolder
       
  1978                                resizeForLabel: false
       
  1979                                adjust: left
       
  1980                              )
       
  1981                             (ArrowButtonSpec
       
  1982                                name: 'magnifyDownButton'
       
  1983                                layout: (LayoutFrame -80 1 -22 1 -58 1 0 1)
       
  1984                                activeHelpKey: magnifyImageDown
       
  1985                                translateLabel: true
       
  1986                                model: doMagnifyDown
       
  1987                                enableChannel: imageIsLoadedHolder
       
  1988                                isTriggerOnDown: true
       
  1989                                direction: left
       
  1990                              )
       
  1991                             (ArrowButtonSpec
       
  1992                                name: 'magnifyUpButton'
       
  1993                                layout: (LayoutFrame -24 1 -22 1 -2 1 0 1)
       
  1994                                activeHelpKey: magnifyImageUp
       
  1995                                translateLabel: true
       
  1996                                model: doMagnifyUp
       
  1997                                enableChannel: imageIsLoadedHolder
       
  1998                                isTriggerOnDown: true
       
  1999                                direction: right
       
  2000                              )
       
  2001                             (InputFieldSpec
       
  2002                                name: 'magnificationInputField'
       
  2003                                layout: (LayoutFrame -57 1 -22 1 -26 1 0 1)
       
  2004                                activeHelpKey: magnificationNumber
       
  2005                                enableChannel: imageIsLoadedHolder
       
  2006                                model: magnificationHolder
       
  2007                                type: numberInRange
       
  2008                                acceptOnReturn: true
       
  2009                                acceptOnTab: true
       
  2010                                numChars: 2
       
  2011                                minValue: 1
       
  2012                                maxValue: 99
       
  2013                                acceptOnPointerLeave: true
       
  2014                              )
       
  2015                             )
       
  2016                           
       
  2017                          )
  2015                        )
  2018                        )
  2016                      
  2019                       )
  2017                     )
  2020                     
  2018                   )
  2021                    )
  2019                  )
  2022                  )
  2020                
  2023                 )
  2021               )
  2024               
  2022               handles: (Any 0.288889 1.0)
  2025              )
  2023             )
  2026              handles: (Any 0.28888900000000006 1.0)
  2024            (UISubSpecification
       
  2025               name: 'infoBarSubSpec'
       
  2026               layout: (LayoutFrame 0 0.0 -24 1 0 1.0 0 1.0)
       
  2027               majorKey: ToolApplicationModel
       
  2028               minorKey: windowSpecForInfoBar
       
  2029             )
       
  2030            )
  2027            )
  2031          
  2028           (UISubSpecification
  2032         )
  2029              name: 'infoBarSubSpec'
  2033       )
  2030              layout: (LayoutFrame 0 0.0 -24 1 0 1.0 0 1.0)
  2034 
  2031              majorKey: ToolApplicationModel
  2035     "Modified: / 04-07-2010 / 10:18:33 / cg"
  2032              minorKey: windowSpecForInfoBar
       
  2033            )
       
  2034           )
       
  2035         
       
  2036        )
       
  2037      )
  2036 ! !
  2038 ! !
  2037 
  2039 
  2038 !ImageEditor class methodsFor:'menu specs'!
  2040 !ImageEditor class methodsFor:'menu specs'!
  2039 
  2041 
  2040 colorMapMenu
  2042 colorMapMenu
  2068           )
  2070           )
  2069          (MenuItem
  2071          (MenuItem
  2070             label: '-'
  2072             label: '-'
  2071           )
  2073           )
  2072          (MenuItem
  2074          (MenuItem
  2073             enabled: hasColormapAndColorSelected
  2075             enabled: hasColormapAndSingleColorSelected
  2074             label: 'Cut Color'
  2076             label: 'Cut Color'
  2075             itemValue: cutColorFromColormap
  2077             itemValue: cutColorFromColormap
  2076             translateLabel: true
  2078             translateLabel: true
  2077             isVisible: false
  2079             isVisible: false
  2078           )
  2080           )
  2079          (MenuItem
  2081          (MenuItem
  2080             enabled: hasColorSelectedHolder
  2082             enabled: hasSingleColorSelectedHolder
  2081             label: 'Copy Color'
  2083             label: 'Copy Color'
  2082             itemValue: copyColorFromColormap
  2084             itemValue: copyColorFromColormap
  2083             translateLabel: true
  2085             translateLabel: true
  2084             shortcutKey: Copy
  2086             shortcutKey: Copy
  2085           )
  2087           )
  2086          (MenuItem
  2088          (MenuItem
  2087             enabled: hasColormapAndColorSelected
  2089             enabled: hasColormapAndSingleColorSelected
  2088             label: 'Pick and Paste Color...'
  2090             label: 'Pick and Paste Color...'
  2089             itemValue: pickAndPasteColor
  2091             itemValue: pickAndPasteColor
  2090             translateLabel: true
  2092             translateLabel: true
  2091           )
  2093           )
  2092          (MenuItem
  2094          (MenuItem
  2097           )
  2099           )
  2098          (MenuItem
  2100          (MenuItem
  2099             label: '-'
  2101             label: '-'
  2100           )
  2102           )
  2101          (MenuItem
  2103          (MenuItem
  2102             enabled: hasColormapAndColorSelected
  2104             enabled: hasColormapAndSingleColorSelected
  2103             label: 'Edit Color...'
  2105             label: 'Edit Color...'
  2104             itemValue: editSelectedColor
  2106             itemValue: editSelectedColor
  2105             translateLabel: true
  2107             translateLabel: true
  2106           )
  2108           )
  2107          (MenuItem
  2109          (MenuItem
  2121             label: 'Make Gray'
  2123             label: 'Make Gray'
  2122             itemValue: makeSelectedColorGray
  2124             itemValue: makeSelectedColorGray
  2123             translateLabel: true
  2125             translateLabel: true
  2124           )
  2126           )
  2125          (MenuItem
  2127          (MenuItem
       
  2128             enabled: hasColormapAndColorSelected
       
  2129             label: 'Color Shift'
       
  2130             itemValue: makeSelectedColorShifted
       
  2131             translateLabel: true
       
  2132           )
       
  2133          (MenuItem
  2126             label: '-'
  2134             label: '-'
  2127           )
  2135           )
  2128          (MenuItem
  2136          (MenuItem
  2129             enabled: hasColorSelectedHolder
  2137             enabled: hasSingleColorSelectedHolder
  2130             label: 'Inspect Color'
  2138             label: 'Inspect Color'
  2131             itemValue: inspectColor
  2139             itemValue: inspectColor
  2132             translateLabel: true
  2140             translateLabel: true
  2133           )
  2141           )
  2134          (MenuItem
  2142          (MenuItem
  3724 
  3732 
  3725     "Created: / 04-07-2010 / 10:11:47 / cg"
  3733     "Created: / 04-07-2010 / 10:11:47 / cg"
  3726 !
  3734 !
  3727 
  3735 
  3728 hasColorSelectedHolder
  3736 hasColorSelectedHolder
  3729     ^ [ self selectedColorIndexOrNil notNil ]
  3737     ^ [ self selectedColors value notEmptyOrNil "self selectedColorIndexOrNil notNil" ]
  3730 
  3738 
  3731     "Created: / 04-07-2010 / 10:12:22 / cg"
  3739     "Created: / 04-07-2010 / 10:12:22 / cg"
  3732 !
  3740 !
  3733 
  3741 
  3734 hasColormap
  3742 hasColormap
  3742     ^ [ self hasColormapHolder value and:[self hasColorSelectedHolder value]]
  3750     ^ [ self hasColormapHolder value and:[self hasColorSelectedHolder value]]
  3743 
  3751 
  3744     "Modified: / 04-07-2010 / 10:13:13 / cg"
  3752     "Modified: / 04-07-2010 / 10:13:13 / cg"
  3745 !
  3753 !
  3746 
  3754 
       
  3755 hasColormapAndSingleColorSelected
       
  3756     ^ [ self hasColormapHolder value and:[self hasSingleColorSelectedHolder value]]
       
  3757 
       
  3758     "Modified: / 04-07-2010 / 10:13:13 / cg"
       
  3759 !
       
  3760 
  3747 hasColormapHolder
  3761 hasColormapHolder
  3748     ^ [self hasColormap]
  3762     ^ [self hasColormap]
  3749 
  3763 
  3750     "Created: / 04-07-2010 / 10:13:05 / cg"
  3764     "Created: / 04-07-2010 / 10:13:05 / cg"
       
  3765 !
       
  3766 
       
  3767 hasSingleColorSelectedHolder
       
  3768     ^ [ self selectedColors value size == 1 "self selectedColorIndexOrNil notNil" ]
       
  3769 
       
  3770     "Created: / 04-07-2010 / 10:12:22 / cg"
  3751 !
  3771 !
  3752 
  3772 
  3753 imageHasImageSequence
  3773 imageHasImageSequence
  3754     |img|
  3774     |img|
  3755 
  3775 
  3894         holder addDependent:self.
  3914         holder addDependent:self.
  3895     ].
  3915     ].
  3896     ^ holder
  3916     ^ holder
  3897 
  3917 
  3898     "Created: / 04-07-2010 / 10:19:34 / cg"
  3918     "Created: / 04-07-2010 / 10:19:34 / cg"
       
  3919 !
       
  3920 
       
  3921 selectedColors
       
  3922     "returns a valueHolder for the current set of selected colors."
       
  3923 
       
  3924     |holder|
       
  3925 
       
  3926     (holder := builder bindingAt:#selectedColors) isNil ifTrue:[
       
  3927         builder aspectAt:#selectedColors put:(holder := nil asValue).
       
  3928         holder onChangeSend:#selectedColorsChanged to:self.
       
  3929     ].
       
  3930     ^ holder
  3899 !
  3931 !
  3900 
  3932 
  3901 selectionOfColor
  3933 selectionOfColor
  3902     "returns a valueHolder for the current selection of the edit color.
  3934     "returns a valueHolder for the current selection of the edit color.
  3903      Here, an AspectAdaptor which accesses selectedColorIndex is returned."
  3935      Here, an AspectAdaptor which accesses selectedColorIndex is returned."
  4002     self listOfColors asOrderedCollection ~= newListOfColors ifTrue:[
  4034     self listOfColors asOrderedCollection ~= newListOfColors ifTrue:[
  4003         self listOfColors contents:newListOfColors.
  4035         self listOfColors contents:newListOfColors.
  4004     ].
  4036     ].
  4005 
  4037 
  4006     "Modified: / 18-01-2012 / 13:58:38 / cg"
  4038     "Modified: / 18-01-2012 / 13:58:38 / cg"
       
  4039 !
       
  4040 
       
  4041 selectedColorsChanged
       
  4042     |colorIndices|
       
  4043 
       
  4044     (colorIndices := self selectedColors value) isEmptyOrNil ifTrue:[
       
  4045         self selectionOfColor value:nil
       
  4046     ] ifFalse:[
       
  4047         colorIndices size == 1 ifTrue:[
       
  4048             "/ as single color selected
       
  4049             self selectionOfColor value:colorIndices first
       
  4050         ] ifFalse:[
       
  4051             "/ multipl selected
       
  4052             self selectionOfColor value:nil
       
  4053         ].
       
  4054     ].
  4007 !
  4055 !
  4008 
  4056 
  4009 update:something with:aParameter from:changedObject
  4057 update:something with:aParameter from:changedObject
  4010     |clrIndex img imagePreView clr changedColor|
  4058     |clrIndex img imagePreView clr changedColor|
  4011 
  4059 
  4088                 "/ self halt.
  4136                 "/ self halt.
  4089                 clrIndex := self hasMask ifTrue:[1] ifFalse:[0].
  4137                 clrIndex := self hasMask ifTrue:[1] ifFalse:[0].
  4090             ] ifFalse:[
  4138             ] ifFalse:[
  4091                 clrIndex := self listOfColors indexOf:aParameter.
  4139                 clrIndex := self listOfColors indexOf:aParameter.
  4092             ].
  4140             ].
  4093             self selectionOfColor value:clrIndex.
  4141             self selectedColors value:{clrIndex}. "/ selectionOfColor value:clrIndex.
  4094             ^ self.
  4142             ^ self.
  4095         ].
  4143         ].
  4096         ^ self.
  4144         ^ self.
  4097     ].
  4145     ].
  4098 
  4146 
  4264             imageEditView image:newImage.
  4312             imageEditView image:newImage.
  4265             imageEditView setModified.
  4313             imageEditView setModified.
  4266             self updateImage.
  4314             self updateImage.
  4267             self updateImagePreView.
  4315             self updateImagePreView.
  4268 
  4316 
  4269             self selectionOfColor value:oldSel.
  4317             self selectedColors value:{oldSel}.
  4270             imageEditView selectedColorIndex:oldSel.
  4318             imageEditView selectedColorIndex:oldSel.
  4271             imageEditView selectedColor:(self listOfColors at:oldSel).
  4319             imageEditView selectedColor:(self listOfColors at:oldSel).
  4272         ]
  4320         ]
  4273     ].
  4321     ].
  4274 !
  4322 !
  4567 
  4615 
  4568     mouseKeyColorMode isNil ifTrue:[
  4616     mouseKeyColorMode isNil ifTrue:[
  4569         mouseKeyColorMode := 1 asValue.
  4617         mouseKeyColorMode := 1 asValue.
  4570         mouseKeyColorMode onChangeEvaluate: [
  4618         mouseKeyColorMode onChangeEvaluate: [
  4571             imageEditView mouseKeyColorMode:mouseKeyColorMode value. 
  4619             imageEditView mouseKeyColorMode:mouseKeyColorMode value. 
  4572             self selectionOfColor value: (self listOfColors indexOf:imageEditView selectedColor).
  4620             self selectedColors value:{ self listOfColors indexOf:imageEditView selectedColor }.
  4573         ]
  4621         ]
  4574     ].
  4622     ].
  4575 
  4623 
  4576     ^mouseKeyColorMode
  4624     ^mouseKeyColorMode
  4577 
  4625 
  4612     ].
  4660     ].
  4613     ^ nil
  4661     ^ nil
  4614 !
  4662 !
  4615 
  4663 
  4616 sortBlockForColors
  4664 sortBlockForColors
       
  4665     ^ self sortBlockForColorsByHLS.
       
  4666 "/    ^ self sortBlockForColorsByRGB
       
  4667 !
       
  4668 
       
  4669 sortBlockForColorsByHLS
       
  4670     ^ [:a :b |
       
  4671         |h1 h2 s1 s2 l1 l2|
       
  4672 
       
  4673         h1 := a hue ? 0.
       
  4674         h2 := b hue ? 0.
       
  4675         (h1 between: h2-30 and:h2+30) ifTrue:[
       
  4676             l1 := a light.
       
  4677             l2 := b light.
       
  4678             l1 = l2 ifTrue:[
       
  4679                 a saturation < b saturation
       
  4680             ] ifFalse:[
       
  4681                 l1 < l2
       
  4682             ].
       
  4683 "/            s1 := a saturation.
       
  4684 "/            s2 := b saturation.
       
  4685 "/            s1 = s2 ifTrue:[
       
  4686 "/                a light < b light
       
  4687 "/            ] ifFalse:[
       
  4688 "/                s1 < s2 
       
  4689 "/            ]
       
  4690         ] ifFalse:[
       
  4691             h1 < h2 
       
  4692         ]
       
  4693       ]
       
  4694 !
       
  4695 
       
  4696 sortBlockForColorsByRGB
  4617     ^ [:a :b |
  4697     ^ [:a :b |
  4618             a redByte == b redByte ifTrue:[
  4698             a redByte == b redByte ifTrue:[
  4619                 a greenByte == b greenByte ifTrue:[
  4699                 a greenByte == b greenByte ifTrue:[
  4620                     a blueByte < b blueByte
  4700                     a blueByte < b blueByte
  4621                 ] ifFalse:[
  4701                 ] ifFalse:[
  4806             self information:(resources stringWithCRs:'Image has no colormap.\The shown colorMap is for drawing only.').
  4886             self information:(resources stringWithCRs:'Image has no colormap.\The shown colorMap is for drawing only.').
  4807             drawingColormap := OrderedCollection new.
  4887             drawingColormap := OrderedCollection new.
  4808         ].
  4888         ].
  4809         drawingColormap add:newColor.
  4889         drawingColormap add:newColor.
  4810         self listOfColors contents:drawingColormap.
  4890         self listOfColors contents:drawingColormap.
  4811         self selectionOfColor value:(drawingColormap size).
  4891         self selectedColors value:{drawingColormap size}.
  4812 
       
  4813         "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
  4892         "/ self warn:'Image has no colormap.\Change colorMap mode first.' withCRs.
  4814         ^ self
  4893         ^ self
  4815     ].
  4894     ].
  4816 
  4895 
  4817     ("(depth == 1)" false
  4896     ("(depth == 1)" false
  4857         self findColorMapMode.
  4936         self findColorMapMode.
  4858         "/ mhmh - somehow, we get two colors added ... (sigh findColorMapMode adds another one ...)
  4937         "/ mhmh - somehow, we get two colors added ... (sigh findColorMapMode adds another one ...)
  4859         listOfColors size > (oldCListSize + 1) ifTrue:[
  4938         listOfColors size > (oldCListSize + 1) ifTrue:[
  4860             listOfColors removeLast
  4939             listOfColors removeLast
  4861         ].
  4940         ].
  4862         self selectionOfColor value:(listOfColors size).
  4941         self selectedColors value:{listOfColors size}.
  4863         self updateLabelsAndHistory.
  4942         self updateLabelsAndHistory.
  4864     ]
  4943     ]
  4865 
  4944 
  4866     "Created: / 12.3.1999 / 00:20:28 / cg"
  4945     "Created: / 12.3.1999 / 00:20:28 / cg"
  4867     "Modified: / 16.3.1999 / 21:57:26 / cg"
  4946     "Modified: / 16.3.1999 / 21:57:26 / cg"
  4945                         imageEditView image 
  5024                         imageEditView image 
  4946                             colorMap:originalColormap copy;
  5025                             colorMap:originalColormap copy;
  4947                             bits:originalPixels copy;
  5026                             bits:originalPixels copy;
  4948                             release;
  5027                             release;
  4949                             colorMapProcessing:[:clr | shiftedColor value:clr value:hShift value:lFactor value:sFactor].
  5028                             colorMapProcessing:[:clr | shiftedColor value:clr value:hShift value:lFactor value:sFactor].
       
  5029                         self updateImage.
       
  5030                         self updateInfoLabel.
       
  5031                         self updateImagePreView.
       
  5032                     ] ensure:[ shiftProcess := nil ].    
       
  5033                 ] forkAt:7.
       
  5034         ].
       
  5035 
       
  5036     bindings := IdentityDictionary new.
       
  5037     bindings at:#hueShiftAmount put:(hueShift := 0 asValue).
       
  5038     hueShift onChangeEvaluate:shiftAction.
       
  5039 
       
  5040     bindings at:#lightAmount put:(lightValue := 100 asValue).
       
  5041     lightValue onChangeEvaluate:shiftAction.
       
  5042 
       
  5043     bindings at:#saturationAmount put:(saturationValue := 100 asValue).
       
  5044     saturationValue onChangeEvaluate:shiftAction.
       
  5045 
       
  5046     bindings at:#acceptChannel put:acceptChannel.
       
  5047     bindings at:#hlsColor put:avgColorHolder.
       
  5048     bindings at:#previewImageHolder put:previewImageHolder.
       
  5049 
       
  5050     (self openDialogInterface:#changeHLSDialogSpec withBindings:bindings) 
       
  5051     ifFalse:[ 
       
  5052         anyChange ifTrue:[
       
  5053             imageEditView undo
       
  5054         ]
       
  5055     ].
       
  5056 
       
  5057     (p := shiftProcess) notNil ifTrue:[
       
  5058         p waitUntilTerminated.
       
  5059     ].
       
  5060 
       
  5061     anyChange ifTrue:[
       
  5062         self updateImage.
       
  5063         self updateImagePreView.
       
  5064     ].
       
  5065 !
       
  5066 
       
  5067 changeHLSOfColors:colorsToShift
       
  5068     "interactive Hue/Light/Saturation editing"
       
  5069 
       
  5070     |bindings hueShift lightValue saturationValue originalColormap firstChange acceptChannel 
       
  5071      shiftAction avgColorHolder avgColor shiftedColor shiftProcess readySema
       
  5072      originalPixels p previewImage previewImageHolder originalPreviewColormap originalPreviewPixels
       
  5073      anyChange |
       
  5074 
       
  5075     "/ compute the averageColor in the background (while asking user)
       
  5076     avgColorHolder := nil asValue.
       
  5077     previewImageHolder := nil asValue.
       
  5078 
       
  5079     readySema := Semaphore new.
       
  5080     [
       
  5081         |image red green blue|
       
  5082 
       
  5083         image := imageEditView image.
       
  5084         originalColormap := image colorMap copy.
       
  5085         originalPixels := image bits.
       
  5086         red := (colorsToShift collect:[:clr | clr red]) average.
       
  5087         green := (colorsToShift collect:[:clr | clr green]) average.
       
  5088         blue := (colorsToShift collect:[:clr | clr blue]) average.
       
  5089         avgColor := Color red:red green:green blue:blue.
       
  5090         avgColorHolder value:avgColor.
       
  5091 
       
  5092         previewImage := self image magnifiedPreservingRatioTo:100@100.
       
  5093         previewImageHolder value: previewImage.
       
  5094         originalPreviewColormap := previewImage colorMap copy.
       
  5095         originalPreviewPixels := previewImage bits.
       
  5096 
       
  5097         readySema signal.
       
  5098     ] forkAt:7.
       
  5099 
       
  5100     acceptChannel := TriggerValue new.
       
  5101 
       
  5102     firstChange := true.
       
  5103     anyChange := false.
       
  5104 
       
  5105     shiftedColor := [:clr :hShift :lFactor :sFactor |
       
  5106                         Color 
       
  5107                                 hue:((clr hue) ? 0 + hShift) 
       
  5108                                 light:((clr light * lFactor / 100) min:100)
       
  5109                                 saturation:((clr saturation * sFactor / 100) min:100)].
       
  5110 
       
  5111     shiftAction := 
       
  5112         [
       
  5113             |hShift lFactor sFactor|
       
  5114 
       
  5115             acceptChannel value:true.
       
  5116 
       
  5117             firstChange ifTrue:[
       
  5118                 imageEditView makeUndo.
       
  5119                 firstChange := false.
       
  5120                 anyChange := true.
       
  5121             ].
       
  5122             readySema notNil ifTrue:[readySema wait. readySema := nil].
       
  5123 
       
  5124             hShift := hueShift value.
       
  5125             lFactor := lightValue value.
       
  5126             sFactor := saturationValue value.
       
  5127 
       
  5128             avgColorHolder value:(shiftedColor value:avgColor value:hShift value:lFactor value:sFactor).
       
  5129 
       
  5130             previewImage
       
  5131                 colorMap:originalPreviewColormap copy;
       
  5132                 bits:originalPreviewPixels copy;
       
  5133                 release;
       
  5134                 colorMapProcessing:[:clr | 
       
  5135                     (colorsToShift includes:clr) ifTrue:[
       
  5136                         shiftedColor value:clr value:hShift value:lFactor value:sFactor.
       
  5137                     ] ifFalse:[
       
  5138                         clr
       
  5139                     ]
       
  5140                 ].
       
  5141             previewImageHolder value:nil; value:previewImage.
       
  5142 
       
  5143             shiftProcess notNil ifTrue:[
       
  5144                 shiftProcess terminate.
       
  5145                 shiftProcess waitUntilTerminated.
       
  5146                 shiftProcess := nil.
       
  5147             ].
       
  5148 
       
  5149             shiftProcess := 
       
  5150                 [
       
  5151                     [
       
  5152                         imageEditView image 
       
  5153                             colorMap:originalColormap copy;
       
  5154                             bits:originalPixels copy;
       
  5155                             release;
       
  5156                             colorMapProcessing:[:clr | 
       
  5157                                 (colorsToShift includes:clr) ifTrue:[
       
  5158                                     shiftedColor value:clr value:hShift value:lFactor value:sFactor.
       
  5159                                 ] ifFalse:[
       
  5160                                     clr
       
  5161                                 ]
       
  5162                             ].
  4950                         self updateImage.
  5163                         self updateImage.
  4951                         self updateInfoLabel.
  5164                         self updateInfoLabel.
  4952                         self updateImagePreView.
  5165                         self updateImagePreView.
  4953                     ] ensure:[ shiftProcess := nil ].    
  5166                     ] ensure:[ shiftProcess := nil ].    
  4954                 ] forkAt:7.
  5167                 ] forkAt:7.
  5541         ]
  5754         ]
  5542     ].
  5755     ].
  5543 !
  5756 !
  5544 
  5757 
  5545 makeSelectedColorBrighter
  5758 makeSelectedColorBrighter
  5546     self processSelectedColorWith:[:clr | clr lightened]
  5759     self processSelectedColorsWith:[:clr | clr lightened]
  5547 !
  5760 !
  5548 
  5761 
  5549 makeSelectedColorDarker
  5762 makeSelectedColorDarker
  5550     self processSelectedColorWith:[:clr | clr darkened]
  5763     self processSelectedColorsWith:[:clr | clr darkened]
  5551 !
  5764 !
  5552 
  5765 
  5553 makeSelectedColorGray
  5766 makeSelectedColorGray
  5554     self processSelectedColorWith:[:clr | Color brightness:(clr brightness)]
  5767     self processSelectedColorsWith:[:clr | Color brightness:(clr brightness)]
       
  5768 !
       
  5769 
       
  5770 makeSelectedColorShifted
       
  5771     |cMap colors|
       
  5772 
       
  5773     cMap := self image colorMap.
       
  5774     self hasMask ifTrue:[
       
  5775         colors := self selectedColors value collect:[:idx | cMap at:idx-1].
       
  5776     ] ifFalse:[
       
  5777         colors := self selectedColors value collect:[:idx | cMap at:idx].
       
  5778     ].
       
  5779     self changeHLSOfColors:colors.
  5555 !
  5780 !
  5556 
  5781 
  5557 makeSlightlyBrighter
  5782 makeSlightlyBrighter
  5558     | anyChange|
  5783     | anyChange|
  5559 
  5784 
  5709 pickColor
  5934 pickColor
  5710     imageEditView setClipboardObject:(Color fromUser)
  5935     imageEditView setClipboardObject:(Color fromUser)
  5711 !
  5936 !
  5712 
  5937 
  5713 processSelectedColorWith:aBlock
  5938 processSelectedColorWith:aBlock
  5714     "undoable color processing: the selected color will be replaced by the
  5939     "undoable color processing: 
  5715      value of aBlock"
  5940      the selected color will be replaced by the value of aBlock"
  5716 
  5941 
  5717     |img cMap modifiedColormap oldColor newImage selectedColorIndex oldSelection newColor|
  5942     self processSelectedColorsWith:aBlock.
  5718 
  5943 !
  5719     selectedColorIndex := self selectedColorIndexOrNil.
  5944 
  5720     selectedColorIndex isNil ifTrue:[^ self].
  5945 processSelectedColorsWith:aBlock
       
  5946     "undoable color processing: 
       
  5947      the selected colors will be replaced by the value of aBlock 
       
  5948      (which gets a color vector and must return a color vector)"
       
  5949 
       
  5950     |img cMap modifiedColormap oldColors newImage selectedColorIndices newColors|
       
  5951 
       
  5952     selectedColorIndices := self selectedColors value.
       
  5953     selectedColorIndices isEmptyOrNil ifTrue:[^ self].
  5721 
  5954 
  5722     img := self image.
  5955     img := self image.
  5723     cMap := img colorMap.
  5956     cMap := img colorMap.
  5724     cMap isNil ifTrue:[
  5957     cMap isNil ifTrue:[
  5725         self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
  5958         self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
  5726         ^ self
  5959         ^ self
  5727     ].
  5960     ].
  5728 
  5961     self hasMask ifTrue:[
  5729     oldColor := cMap at:selectedColorIndex.
  5962         oldColors := selectedColorIndices collect:[:idx | cMap at:idx-1].
       
  5963     ] ifFalse:[
       
  5964         oldColors := selectedColorIndices collect:[:idx | cMap at:idx].
       
  5965     ].
  5730     imageEditView makeUndo.
  5966     imageEditView makeUndo.
  5731 
  5967 
  5732     modifiedColormap := cMap asNewArray.
  5968     modifiedColormap := cMap asNewArray.
  5733 
  5969 
  5734     newColor := aBlock value:oldColor.
  5970     newColors := oldColors collect:aBlock.
  5735     modifiedColormap at:selectedColorIndex put:newColor.
  5971     selectedColorIndices with:newColors do:[:idx :newColor | 
       
  5972         modifiedColormap at:idx put:newColor
       
  5973     ].
  5736 
  5974 
  5737     newImage := img species new
  5975     newImage := img species new
  5738                     width:img width
  5976                     width:img width
  5739                     height:img height
  5977                     height:img height
  5740                     depth:img depth
  5978                     depth:img depth
  5742 
  5980 
  5743     newImage colorMap:modifiedColormap.  
  5981     newImage colorMap:modifiedColormap.  
  5744     newImage fileName:img fileName.
  5982     newImage fileName:img fileName.
  5745     newImage mask:(img mask copy).
  5983     newImage mask:(img mask copy).
  5746 
  5984 
  5747     oldSelection := self selectionOfColor value.
       
  5748 
       
  5749     (imageEditView image:newImage) notNil ifTrue:[
  5985     (imageEditView image:newImage) notNil ifTrue:[
  5750         self fetchImageData.
  5986         self fetchImageData.
  5751     ].
  5987     ].
  5752     self selectionOfColor value:oldSelection.
  5988     self selectedColors value:selectedColorIndices.
  5753 
       
  5754     "Created: / 12.3.1999 / 00:20:28 / cg"
       
  5755     "Modified: / 16.3.1999 / 21:57:26 / cg"
       
  5756 !
  5989 !
  5757 
  5990 
  5758 reduceNumberOfColors
  5991 reduceNumberOfColors
  5759     |s n anyChange img usedColors|
  5992     |s n anyChange img usedColors|
  5760 
  5993 
  5807         Dialog warn:'Image unchanged'.
  6040         Dialog warn:'Image unchanged'.
  5808         ^ self
  6041         ^ self
  5809     ].
  6042     ].
  5810 
  6043 
  5811     self withExecuteCursorDo:[
  6044     self withExecuteCursorDo:[
  5812         image := self image.
  6045         |reduceColor|
  5813         "/ usedColors := image usedColorsMax:4096.
  6046 
  5814         imageEditView makeUndo.
  6047         reduceColor :=
  5815 
  6048             [:clr |
  5816         newImage := image copy.
  6049                 |r g b nr ng nb|
  5817         newImage photometric == #palette ifTrue:[
       
  5818             newImage colorMap:(OrderedCollection new).
       
  5819         ].
       
  5820 
       
  5821         image
       
  5822             colorsFromX:0 y:0 toX:(image width-1) y:(image height-1) 
       
  5823             do:[:x :y :clr |
       
  5824                 |r g b nr ng nb newClr|
       
  5825 
  6050 
  5826                 r := clr redByte.
  6051                 r := clr redByte.
  5827                 g := clr greenByte.
  6052                 g := clr greenByte.
  5828                 b := clr blueByte. 
  6053                 b := clr blueByte. 
  5829                 nr := (r roundTo:rndR) min:255.
  6054                 nr := (r roundTo:rndR) min:255.
  5830                 ng := (g roundTo:rndG) min:255.
  6055                 ng := (g roundTo:rndG) min:255.
  5831                 nb := (b roundTo:rndB) min:255. 
  6056                 nb := (b roundTo:rndB) min:255. 
  5832 
  6057 
  5833                 newClr := Color redByte:nr greenByte:ng blueByte:nb.
  6058                 Color redByte:nr greenByte:ng blueByte:nb.
  5834                 newImage photometric == #palette ifTrue:[
  6059             ].
  5835                     (newImage colorMap includes:newClr) ifFalse:[
  6060 
  5836                         newImage colorMap add:newClr
  6061         image := self image.
  5837                     ].
  6062         "/ usedColors := image usedColorsMax:4096.
       
  6063         imageEditView makeUndo.
       
  6064 
       
  6065         newImage := image copy.
       
  6066         newImage photometric == #palette ifTrue:[
       
  6067             newImage colorMap:(image colorMap collect:reduceColor).
       
  6068         ] ifFalse:[
       
  6069             image
       
  6070                 colorsFromX:0 y:0 toX:(image width-1) y:(image height-1) 
       
  6071                 do:[:x :y :clr |
       
  6072                     newImage colorAtX:x y:y put:(reduceColor value:clr)
  5838                 ].
  6073                 ].
  5839                 newImage colorAtX:x y:y put:newClr
  6074         ].
  5840             ].
       
  5841 
       
  5842         imageEditView image:newImage.
  6075         imageEditView image:newImage.
  5843         imageEditView setModified.
  6076         imageEditView setModified.
  5844         self updateImage.
  6077         self updateImage.
  5845         self updateImagePreView.
  6078         self updateImagePreView.
  5846 
  6079 
  5884                     ].
  6117                     ].
  5885                 ].
  6118                 ].
  5886             ].
  6119             ].
  5887         ].
  6120         ].
  5888     ].
  6121     ].
  5889     self selectionOfColor value:idx.
  6122     self selectedColors value:{idx}.
  5890 
  6123 
  5891     "Modified: / 02-07-2010 / 12:06:07 / cg"
  6124     "Modified: / 02-07-2010 / 12:06:07 / cg"
  5892 !
  6125 !
  5893 
  6126 
  5894 selectedColorIndexOrNil
  6127 selectedColorIndexOrNil
  5930 !
  6163 !
  5931 
  6164 
  5932 sortColorMap
  6165 sortColorMap
  5933     "calculates a new color map for the image, sorting colors"
  6166     "calculates a new color map for the image, sorting colors"
  5934 
  6167 
  5935     self sortColorMapWith:self sortBlockForColors
  6168     self sortColorMapWith:self sortBlockForColorsByRGB
  5936 !
  6169 !
  5937 
  6170 
  5938 sortColorMapWith:sortBlock
  6171 sortColorMapWith:sortBlock
  5939     "calculates a new color map for the image, sorting colors"
  6172     "calculates a new color map for the image, sorting colors"
  5940 
  6173