ImageEditor.st
changeset 1057 36f9d47e1249
parent 1054 ef98bc11d1fd
child 1075 74795d3e647d
equal deleted inserted replaced
1056:bd9a9fc7a7fc 1057:36f9d47e1249
    82     "opens a Image Editor on aClass and aSelector"
    82     "opens a Image Editor on aClass and aSelector"
    83     "
    83     "
    84      self openOnClass: self andSelector: #leftMouseKeyIcon
    84      self openOnClass: self andSelector: #leftMouseKeyIcon
    85     "
    85     "
    86 
    86 
    87     ^self open loadFromMessage: aClass name, ' ', aSelector
    87     |editor|
       
    88 
       
    89     editor := self new.
       
    90     editor allButOpen.
       
    91     editor loadFromMessage: aClass name, ' ', aSelector.
       
    92     editor openWindow
       
    93 
       
    94     "Modified: / 16.3.1999 / 21:33:49 / cg"
    88 !
    95 !
    89 
    96 
    90 openOnFile: aFileName
    97 openOnFile: aFileName
    91     "opens a Image Editor on aFileName"
    98     "opens a Image Editor on aFileName"
    92     "
    99     "
    93      self openOnFile: 'bitmaps/SmalltalkX.xbm'
   100      self openOnFile: 'bitmaps/SmalltalkX.xbm'
    94     "
   101     "
    95 
   102 
    96     ^self open loadFromFile: aFileName
   103     |editor|
       
   104 
       
   105     editor := self new.
       
   106     editor allButOpen.
       
   107     editor loadFromFile: aFileName.
       
   108     editor openWindow
       
   109 
       
   110     "Modified: / 16.3.1999 / 21:33:25 / cg"
    97 !
   111 !
    98 
   112 
    99 openOnImage: anImage
   113 openOnImage: anImage
   100     "opens a Image Editor on anImage"
   114     "opens a Image Editor on anImage"
   101     "
   115     "
  1738                 ] ifFalse:[
  1752                 ] ifFalse:[
  1739                     self listOfColors removeAll.
  1753                     self listOfColors removeAll.
  1740                 ].
  1754                 ].
  1741                 self findColorMapMode.     
  1755                 self findColorMapMode.     
  1742                 self updateLabelsAndHistory.
  1756                 self updateLabelsAndHistory.
       
  1757                 imageEditView image:img.
  1743             ] ifFalse:[
  1758             ] ifFalse:[
  1744                 self updateForNoImage
  1759                 self updateForNoImage
  1745             ]
  1760             ].
       
  1761             self imagePreView image:img.
  1746         ]
  1762         ]
  1747     ]
  1763     ]
  1748 
  1764 
  1749     "Modified: / 18.8.1998 / 17:03:54 / cg"
  1765     "Modified: / 16.3.1999 / 21:44:26 / cg"
  1750 !
  1766 !
  1751 
  1767 
  1752 loadFromImage:anImage
  1768 loadFromImage:anImage
  1753     "loads an image from anImage and sets up color map list and other info labels"
  1769     "loads an image from anImage and sets up color map list and other info labels"
  1754 
  1770 
  1755     |img|
       
  1756 
       
  1757     imageEditView image:anImage.
  1771     imageEditView image:anImage.
  1758     (img := self image) notNil ifTrue:[    
  1772     self imagePreView image: anImage.
  1759         img colorMap notNil ifTrue:[
  1773     anImage notNil ifTrue:[    
  1760             self listOfColors contents:(img usedColors asSet asOrderedCollection).
  1774         anImage colorMap notNil ifTrue:[
       
  1775             self listOfColors contents:(anImage usedColors asSet asOrderedCollection).
  1761         ] ifFalse:[
  1776         ] ifFalse:[
  1762             self listOfColors removeAll.
  1777             self listOfColors removeAll.
  1763         ].
  1778         ].
  1764         self findColorMapMode.
  1779         self findColorMapMode.
  1765         self updateLabelsAndHistory.
  1780         self updateLabelsAndHistory.
  1766     ] ifFalse:[
  1781     ] ifFalse:[
  1767         self updateForNoImage
  1782         self updateForNoImage
  1768     ]
  1783     ]
  1769 
  1784 
  1770     "Modified: / 18.8.1998 / 17:04:46 / cg"
  1785     "Modified: / 16.3.1999 / 21:43:56 / cg"
  1771 !
  1786 !
  1772 
  1787 
  1773 loadFromMessage: aMessage
  1788 loadFromMessage: aMessage
  1774     "loads an image by evaluating aMessage and sets up color map list and other info labels"
  1789     "loads an image by evaluating aMessage and sets up color map list and other info labels"
  1775 
  1790 
  1778     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  1793     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  1779         (img := self image) notNil ifTrue:[
  1794         (img := self image) notNil ifTrue:[
  1780             self listOfColors contents:(img usedColors asSet asOrderedCollection).
  1795             self listOfColors contents:(img usedColors asSet asOrderedCollection).
  1781             self findColorMapMode.
  1796             self findColorMapMode.
  1782             self updateLabelsAndHistory.
  1797             self updateLabelsAndHistory.
       
  1798             imageEditView image:img.
       
  1799             self imagePreView image:img.
  1783         ] ifFalse:[
  1800         ] ifFalse:[
  1784             self updateForNoImage
  1801             self updateForNoImage
  1785         ]
  1802         ]
  1786     ]
  1803     ]
  1787 
  1804 
  1788     "Modified: / 18.8.1998 / 17:03:01 / cg"
  1805     "Modified: / 16.3.1999 / 21:44:41 / cg"
  1789 !
  1806 !
  1790 
  1807 
  1791 loadFromOrPrepareForMessage: aMessage
  1808 loadFromOrPrepareForMessage: aMessage
  1792     "loads an image by evaluating aMessage;
  1809     "loads an image by evaluating aMessage;
  1793      if no image could extract from aMessage; do set the class and the selector from 
  1810      if no image could extract from aMessage; do set the class and the selector from 
  1802     ifFalse:
  1819     ifFalse:
  1803     [
  1820     [
  1804         imageEditView resourceMessage: aMessage.
  1821         imageEditView resourceMessage: aMessage.
  1805     ].
  1822     ].
  1806     self updateLabelsAndHistory.
  1823     self updateLabelsAndHistory.
       
  1824     self imagePreView image:(self image).
       
  1825 
       
  1826     "Modified: / 16.3.1999 / 21:45:07 / cg"
  1807 ! !
  1827 ! !
  1808 
  1828 
  1809 !ImageEditor methodsFor:'menu modes'!
  1829 !ImageEditor methodsFor:'menu modes'!
  1810 
  1830 
  1811 colorMapMode
  1831 colorMapMode
  1938 ! !
  1958 ! !
  1939 
  1959 
  1940 !ImageEditor methodsFor:'user actions - colormap'!
  1960 !ImageEditor methodsFor:'user actions - colormap'!
  1941 
  1961 
  1942 addColorToColormap
  1962 addColorToColormap
  1943     |depth img cMap newColorMap newImage oldCListSize|
  1963     |depth img cMap newColorMap newImage oldCListSize newMode|
  1944 
  1964 
  1945     img := self image.
  1965     img := self image.
  1946     depth := img depth.
  1966     depth := img depth.
  1947     cMap := img colorMap.
  1967     cMap := img colorMap.
  1948     cMap isNil ifTrue:[
  1968     cMap isNil ifTrue:[
  1957             ^ self
  1977             ^ self
  1958         ].
  1978         ].
  1959         (self confirm:'No space for more colors in colormap.\Change depth first.' withCRs)
  1979         (self confirm:'No space for more colors in colormap.\Change depth first.' withCRs)
  1960         ifFalse:[
  1980         ifFalse:[
  1961             ^ self
  1981             ^ self
  1962         ]
  1982         ].
       
  1983 
       
  1984         imageEditView makeUndo.
       
  1985         newMode := (depth*2) printString , (colorMapMode value copyFrom:2).
       
  1986         self colorMapMode:newMode.
       
  1987     ] ifFalse:[
       
  1988         imageEditView makeUndo.
  1963     ].
  1989     ].
  1964 
  1990 
  1965     imageEditView makeUndo.
  1991 self halt.
  1966 
       
  1967     cMap := cMap asArray.
  1992     cMap := cMap asArray.
  1968     oldCListSize := self listOfColors size.
  1993     oldCListSize := self listOfColors size.
  1969 
  1994 
  1970 "/    (colorMapMode value asString endsWith:'mask') ifTrue:[
  1995 "/    (colorMapMode value asString endsWith:'mask') ifTrue:[
  1971 "/        cMap last = Color noColor ifTrue:[
  1996 "/        cMap last = Color noColor ifTrue:[
  2000         self selectionOfColor value:(self listOfColors size).
  2025         self selectionOfColor value:(self listOfColors size).
  2001         self updateLabelsAndHistory.
  2026         self updateLabelsAndHistory.
  2002     ]
  2027     ]
  2003 
  2028 
  2004     "Created: / 12.3.1999 / 00:20:28 / cg"
  2029     "Created: / 12.3.1999 / 00:20:28 / cg"
  2005     "Modified: / 12.3.1999 / 02:09:01 / cg"
  2030     "Modified: / 16.3.1999 / 21:57:26 / cg"
  2006 !
  2031 !
  2007 
  2032 
  2008 colorMapChanged
  2033 colorMapChanged
  2009     |img|
  2034     |img|
  2010 
  2035 
  2050             ] ifFalse:[
  2075             ] ifFalse:[
  2051                 quest := 'Keep colormap (or use standard)'
  2076                 quest := 'Keep colormap (or use standard)'
  2052             ]
  2077             ]
  2053         ].
  2078         ].
  2054         ((prevMode = aMode)
  2079         ((prevMode = aMode)
  2055         or:[self confirm:(resources string:quest)]) ifTrue:[
  2080         or:[depth > oldImage depth
       
  2081         or:[self confirm:(resources string:quest)]]) ifTrue:[
  2056 
  2082 
  2057             "/ keep the colormap
  2083             "/ keep the colormap
  2058             newColorMap atAllPut:Color black.
  2084             newColorMap atAllPut:Color black.
  2059             depth > oldImage depth ifTrue:[
  2085             depth > oldImage depth ifTrue:[
  2060                 "/ easy - simply copy the part
  2086                 "/ easy - simply copy the part
  2200             self findColorMapMode.
  2226             self findColorMapMode.
  2201             self updateLabelsAndHistory.
  2227             self updateLabelsAndHistory.
  2202         ]
  2228         ]
  2203     ]
  2229     ]
  2204 
  2230 
  2205     "Modified: / 11.3.1999 / 16:20:09 / cg"
  2231     "Modified: / 16.3.1999 / 21:55:39 / cg"
  2206 !
  2232 !
  2207 
  2233 
  2208 compressColorMap
  2234 compressColorMap
  2209     "calculates a new color map for the image, using only used colors"
  2235     "calculates a new color map for the image, using only used colors"
  2210 
  2236