1426 |
1426 |
1427 "Created: / 26.7.1998 / 12:17:03 / cg" |
1427 "Created: / 26.7.1998 / 12:17:03 / cg" |
1428 ! |
1428 ! |
1429 |
1429 |
1430 hasClassAndSelectorDefined |
1430 hasClassAndSelectorDefined |
1431 ^ [(Smalltalk at:(imageEditView resourceClass) ifAbsent:nil) notNil |
1431 ^ [ |
1432 and:[imageEditView resourceSelector notNil]] |
1432 |clsName| |
|
1433 |
|
1434 (clsName := imageEditView resourceClass) size > 0 |
|
1435 and:[(Smalltalk at:clsName ifAbsent:nil) notNil |
|
1436 and:[imageEditView resourceSelector notNil]] |
|
1437 ] |
1433 |
1438 |
1434 "Created: / 31.7.1998 / 02:02:54 / cg" |
1439 "Created: / 31.7.1998 / 02:02:54 / cg" |
1435 ! |
1440 ! |
1436 |
1441 |
1437 hasClassDefined |
1442 hasClassDefined |
1438 ^ [(Smalltalk at:(imageEditView resourceClass) ifAbsent:nil) notNil] |
1443 ^ [ |
|
1444 |clsName| |
|
1445 |
|
1446 (clsName := imageEditView resourceClass) > 0 |
|
1447 and:[(Smalltalk at:clsName ifAbsent:nil) notNil] |
|
1448 ] |
1439 |
1449 |
1440 "Created: / 31.7.1998 / 02:02:22 / cg" |
1450 "Created: / 31.7.1998 / 02:02:22 / cg" |
1441 ! |
1451 ! |
1442 |
1452 |
1443 hasColormap |
1453 hasColormap |
1511 !ImageEditor methodsFor:'change & update'! |
1521 !ImageEditor methodsFor:'change & update'! |
1512 |
1522 |
1513 findColorMapMode |
1523 findColorMapMode |
1514 "finds the colorMapMode for a new image" |
1524 "finds the colorMapMode for a new image" |
1515 |
1525 |
1516 self image depth > 8 ifTrue: [colorMapMode value: ''. self listOfColors removeAll. ^nil]. |
1526 |image listOfColors| |
1517 |
1527 |
1518 colorMapMode value: self image depth printString, '-plane'. |
1528 image := self image. |
1519 |
1529 image depth > 8 ifTrue: [ |
1520 self listOfColors isEmpty |
1530 colorMapMode value: ''. |
1521 ifTrue: |
1531 self listOfColors removeAll. |
1522 [ |
1532 ^ nil |
1523 self colorMapMode: colorMapMode value |
1533 ]. |
|
1534 |
|
1535 colorMapMode value:(image depth printString, '-plane'). |
|
1536 |
|
1537 (listOfColors := self listOfColors) isEmpty ifTrue:[ |
|
1538 self colorMapMode: colorMapMode value. |
|
1539 listOfColors := self listOfColors. |
|
1540 image := self image. |
1524 ]. |
1541 ]. |
1525 imageEditView selectColors: (Array with: (self listOfColors at: 1) with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1])). |
1542 imageEditView selectColors: (Array |
1526 |
1543 with: (listOfColors at:1) |
1527 self image mask notNil |
1544 with: (listOfColors at:2 ifAbsent:[listOfColors at:1])). |
1528 ifTrue: |
1545 |
1529 [ |
1546 image mask notNil ifTrue: [ |
1530 colorMapMode value: colorMapMode value, ' + mask'. |
1547 colorMapMode value:(colorMapMode value, ' + mask'). |
1531 |
1548 |
1532 (self listOfColors detect: [:clr| clr = (Color basicNew setColorId:0)] ifNone: nil) isNil |
1549 (listOfColors detect: [:clr| clr = (Color basicNew setColorId:0)] ifNone: nil) isNil |
1533 ifTrue: |
1550 ifTrue:[ |
1534 [ |
1551 listOfColors addFirst: (Color basicNew setColorId:0). |
1535 self listOfColors addFirst: (Color basicNew setColorId:0). |
1552 imageEditView selectColors: (Array |
1536 imageEditView selectColors: (Array with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1]) with: (self listOfColors at: 1)). |
1553 with:(listOfColors at:2 ifAbsent:[listOfColors at: 1]) |
|
1554 with: (listOfColors at: 1)). |
1537 ] |
1555 ] |
1538 ]. |
1556 ]. |
1539 self selectionOfColor value: 0. |
1557 self selectionOfColor |
1540 self selectionOfColor value: (self listOfColors indexOf: imageEditView selectedColor). |
1558 value: 0; |
|
1559 value: (self listOfColors indexOf: imageEditView selectedColor). |
1541 ! |
1560 ! |
1542 |
1561 |
1543 update:something with:aParameter from:changedObject |
1562 update:something with:aParameter from:changedObject |
1544 |clrIndex| |
1563 |clrIndex| |
1545 |
1564 |
1560 super update:something with:aParameter from:changedObject |
1579 super update:something with:aParameter from:changedObject |
1561 |
1580 |
1562 "Modified: / 18.8.1998 / 17:18:42 / cg" |
1581 "Modified: / 18.8.1998 / 17:18:42 / cg" |
1563 ! |
1582 ! |
1564 |
1583 |
1565 updateForNoneImage |
1584 updateForNoImage |
1566 "updates channels and view, if image is loaded" |
1585 "updates channels and view, if image is loaded" |
1567 |
1586 |
1568 self imageIsLoaded value: false. |
1587 self imageIsLoaded value: false. |
1569 self listOfColors removeAll. |
1588 self listOfColors removeAll. |
1570 self imagePreView image: nil |
1589 self imagePreView image: nil |
1760 (img := self image) notNil ifTrue:[ |
1779 (img := self image) notNil ifTrue:[ |
1761 self listOfColors contents:(img usedColors asSet asOrderedCollection). |
1780 self listOfColors contents:(img usedColors asSet asOrderedCollection). |
1762 self findColorMapMode. |
1781 self findColorMapMode. |
1763 self updateLabelsAndHistory. |
1782 self updateLabelsAndHistory. |
1764 ] ifFalse:[ |
1783 ] ifFalse:[ |
1765 self updateForNoneImage |
1784 self updateForNoImage |
1766 ] |
1785 ] |
1767 ] |
1786 ] |
1768 |
1787 |
1769 "Modified: / 18.8.1998 / 17:03:01 / cg" |
1788 "Modified: / 18.8.1998 / 17:03:01 / cg" |
1770 ! |
1789 ! |
1864 ! |
1881 ! |
1865 |
1882 |
1866 selectedColorIndex: anIndex |
1883 selectedColorIndex: anIndex |
1867 "sets the index of the selected color" |
1884 "sets the index of the selected color" |
1868 |
1885 |
1869 selectedColorIndex := anIndex. |
1886 |clr pixel| |
1870 imageEditView selectedColor: (self listOfColors at: anIndex ifAbsent: [^nil]) |
1887 |
|
1888 selectedColorIndex := anIndex. |
|
1889 clr := self listOfColors at:anIndex ifAbsent:nil. |
|
1890 clr isNil ifTrue:[^ self]. |
|
1891 |
|
1892 (self listOfColors at:1) = Color noColor ifTrue:[ |
|
1893 anIndex == 1 ifTrue:[ |
|
1894 pixel := nil. "/ mask |
|
1895 ] ifFalse:[ |
|
1896 pixel := anIndex - 2 |
|
1897 ] |
|
1898 ] ifFalse:[ |
|
1899 pixel := anIndex - 1 |
|
1900 ]. |
|
1901 imageEditView selectedColorIndex:pixel. |
|
1902 imageEditView selectedColor:clr. |
1871 |
1903 |
1872 ! ! |
1904 ! ! |
1873 |
1905 |
1874 !ImageEditor methodsFor:'startup / release'! |
1906 !ImageEditor methodsFor:'startup / release'! |
1875 |
1907 |
1906 ! ! |
1938 ! ! |
1907 |
1939 |
1908 !ImageEditor methodsFor:'user actions - colormap'! |
1940 !ImageEditor methodsFor:'user actions - colormap'! |
1909 |
1941 |
1910 addColorToColormap |
1942 addColorToColormap |
1911 |d img cMap newCMap| |
1943 |depth img cMap newColorMap newImage oldCListSize| |
1912 |
1944 |
1913 img := self image. |
1945 img := self image. |
1914 d := img depth. |
1946 depth := img depth. |
1915 cMap := img colorMap. |
1947 cMap := img colorMap. |
1916 ((d == 1) |
1948 cMap isNil ifTrue:[ |
1917 or:[cMap size == (1 bitShift:d)]) ifTrue:[ |
1949 self warn:'Image has no colormap\change colorMap mode first.' withCRs. |
1918 d >= 8 ifTrue:[ |
1950 ^ self |
|
1951 ]. |
|
1952 |
|
1953 ((depth == 1) |
|
1954 or:[cMap size == (1 bitShift:depth)]) ifTrue:[ |
|
1955 depth >= 8 ifTrue:[ |
1919 self warn:'No space for more colors in colormap.'. |
1956 self warn:'No space for more colors in colormap.'. |
1920 ^ self |
1957 ^ self |
1921 ]. |
1958 ]. |
1922 (self confirm:'No space for more colors in colormap.\Change depth ?' withCRs) |
1959 (self confirm:'No space for more colors in colormap.\Change depth first.' withCRs) |
1923 ifFalse:[ |
1960 ifFalse:[ |
1924 ^ self |
1961 ^ self |
1925 ] |
1962 ] |
1926 ]. |
1963 ]. |
1927 newCMap := cMap asArray copyWith:(Color black). |
1964 |
1928 img colorMap:newCMap. |
1965 imageEditView makeUndo. |
1929 self listOfColors contents: newCMap. |
1966 |
|
1967 cMap := cMap asArray. |
|
1968 oldCListSize := self listOfColors size. |
|
1969 |
|
1970 "/ (colorMapMode value asString endsWith:'mask') ifTrue:[ |
|
1971 "/ cMap last = Color noColor ifTrue:[ |
|
1972 "/ cMap := cMap copyWithoutLast:1 |
|
1973 "/ ] ifFalse:[ |
|
1974 "/ cMap first = Color noColor ifTrue:[ |
|
1975 "/ cMap := cMap copyFrom:2 |
|
1976 "/ ] |
|
1977 "/ ]. |
|
1978 "/ ]. |
|
1979 "/ |
|
1980 |
|
1981 newColorMap := cMap copyWith:(Color black). |
|
1982 |
|
1983 newImage := img species new |
|
1984 width:img width |
|
1985 height:img height |
|
1986 depth:depth |
|
1987 fromArray:img bits. |
|
1988 |
|
1989 newImage colorMap:newColorMap. |
|
1990 newImage fileName:img fileName. |
|
1991 newImage mask:(img mask copy). |
|
1992 |
|
1993 (imageEditView image:newImage) notNil ifTrue:[ |
|
1994 self listOfColors contents: newImage colorMap. |
|
1995 self findColorMapMode. |
|
1996 "/ mhmh - somehow, we get two colors added ... (sigh findColorMapMode adds another one ...) |
|
1997 self listOfColors size > (oldCListSize + 1) ifTrue:[ |
|
1998 self listOfColors removeLast |
|
1999 ]. |
|
2000 self selectionOfColor value:(self listOfColors size). |
|
2001 self updateLabelsAndHistory. |
|
2002 ] |
1930 |
2003 |
1931 "Created: / 12.3.1999 / 00:20:28 / cg" |
2004 "Created: / 12.3.1999 / 00:20:28 / cg" |
1932 "Modified: / 12.3.1999 / 02:09:01 / cg" |
2005 "Modified: / 12.3.1999 / 02:09:01 / cg" |
1933 ! |
2006 ! |
1934 |
2007 |
2107 ]. |
2180 ]. |
2108 ] ifFalse:[ |
2181 ] ifFalse:[ |
2109 image mask: nil. |
2182 image mask: nil. |
2110 ]. |
2183 ]. |
2111 realColorMap := OrderedCollection new. |
2184 realColorMap := OrderedCollection new. |
2112 image realColorMap do: |
2185 image realColorMap do:[:clr| |
2113 [:clr| |
|
2114 (realColorMap includes: clr) ifFalse: [realColorMap add: clr] |
2186 (realColorMap includes: clr) ifFalse: [realColorMap add: clr] |
2115 ]. |
2187 ]. |
2116 newColors := realColorMap copyFrom: 1 to: (newColorMap size min: realColorMap size). |
2188 newColors := realColorMap copyFrom: 1 to: (newColorMap size min: realColorMap size). |
2117 newColorMap do: |
2189 newColorMap do:[:clr| |
2118 [:clr| |
|
2119 ((newColors size < newColorMap size) and: [(newColors includes: clr) not]) |
2190 ((newColors size < newColorMap size) and: [(newColors includes: clr) not]) |
2120 ifTrue: |
2191 ifTrue:[ |
2121 [ |
|
2122 newColors add: clr |
2192 newColors add: clr |
2123 ] |
2193 ] |
2124 ]. |
2194 ]. |
2125 image colorMap: newColors. |
2195 image colorMap: newColors. |
2126 |
2196 |
2127 (imageEditView image: image) notNil ifTrue: |
2197 (imageEditView image: image) notNil ifTrue:[ |
2128 [ |
|
2129 image fileName: oldFileName. |
2198 image fileName: oldFileName. |
2130 self listOfColors contents: image colorMap. |
2199 self listOfColors contents: image colorMap. |
2131 self findColorMapMode. |
2200 self findColorMapMode. |
2132 self updateLabelsAndHistory. |
2201 self updateLabelsAndHistory. |
2133 ] |
2202 ] |
2316 |
2385 |
2317 newImage colorMap:newColorMap. |
2386 newImage colorMap:newColorMap. |
2318 newImage fileName:oldImage fileName. |
2387 newImage fileName:oldImage fileName. |
2319 newImage mask:(oldImage mask copy). |
2388 newImage mask:(oldImage mask copy). |
2320 |
2389 |
2321 (imageEditView image:newImage) notNil ifTrue: |
2390 (imageEditView image:newImage) notNil ifTrue:[ |
2322 [ |
|
2323 self listOfColors contents: newImage colorMap. |
2391 self listOfColors contents: newImage colorMap. |
2324 self findColorMapMode. |
2392 self findColorMapMode. |
2325 self updateLabelsAndHistory. |
2393 self updateLabelsAndHistory. |
2326 ] |
2394 ] |
2327 ] |
2395 ] |
2506 !ImageEditor methodsFor:'user actions - loading'! |
2574 !ImageEditor methodsFor:'user actions - loading'! |
2507 |
2575 |
2508 doLoadFromClass |
2576 doLoadFromClass |
2509 "opens a dialog for loading an image from class and a (resource-) selector" |
2577 "opens a dialog for loading an image from class and a (resource-) selector" |
2510 |
2578 |
2511 (imageEditView loadFromClass) notNil |
2579 (imageEditView loadFromClass) notNil ifTrue:[ |
2512 ifTrue: |
2580 self image notNil ifTrue: [ |
2513 [ |
|
2514 self image notNil |
|
2515 ifTrue: |
|
2516 [ |
|
2517 self listOfColors contents: self image usedColors asSet asOrderedCollection. |
2581 self listOfColors contents: self image usedColors asSet asOrderedCollection. |
2518 self findColorMapMode. |
2582 self findColorMapMode. |
2519 self updateLabelsAndHistory |
2583 self updateLabelsAndHistory |
2520 ] |
2584 ] ifFalse: [ |
2521 ifFalse: |
2585 self updateForNoImage |
2522 [ |
|
2523 self updateForNoneImage |
|
2524 ] |
2586 ] |
2525 ] |
2587 ] |
2526 ! |
2588 ! |
2527 |
2589 |
2528 doLoadFromFile |
2590 doLoadFromFile |