ImageEditor.st
changeset 1847 d7e8ec4f3696
parent 1843 771731481a20
child 1852 c40abf408dc4
equal deleted inserted replaced
1846:65558eb9f4d3 1847:d7e8ec4f3696
   173     1 to: 25 do:
   173     1 to: 25 do:
   174     [:g|                             
   174     [:g|                             
   175         colorMap add: (Color redByte: (g*255//26) ceiling greenByte: (g*255//26) ceiling blueByte: (g*255//26) ceiling)
   175         colorMap add: (Color redByte: (g*255//26) ceiling greenByte: (g*255//26) ceiling blueByte: (g*255//26) ceiling)
   176     ].
   176     ].
   177 
   177 
   178     ^Dictionary new
   178     ^ Dictionary new
   179         at: '8-plane' put: colorMap;
   179         at: #depth24 put:(FixedPalette redShift:16 redMask:16rFF greenShift:8 greenMask:16rFF blueShift:0 blueMask:16rFF);
   180         at: '8-plane + mask' put: colorMap;
   180         at: #masked24 put:(FixedPalette redShift:16 redMask:16rFF greenShift:8 greenMask:16rFF blueShift:0 blueMask:16rFF);
   181         at: '4-plane' put: (colorMap copyFrom: 1 to: 16);
   181         at: #depth16 put:(FixedPalette redShift:11 redMask:16r1F greenShift:5 greenMask:16r3F blueShift:0 blueMask:16r1F);
   182         at: '4-plane + mask' put: (colorMap copyFrom: 1 to: 16);
   182         at: #masked16 put:(FixedPalette redShift:11 redMask:16r1F greenShift:5 greenMask:16r3F blueShift:0 blueMask:16r1F);
   183         at: '2-plane' put: (colorMap copyFrom: 1 to: 4);
   183         at: #depth8  put: colorMap;
   184         at: '2-plane + mask' put: (colorMap copyFrom: 1 to: 4);
   184         at: #masked8 put: colorMap;
   185         at: '1-plane' put: (colorMap copyFrom: 1 to: 2);
   185         at: #depth4  put: (colorMap copyFrom: 1 to: 16);
   186         at: '1-plane + mask' put: (colorMap copyFrom: 1 to: 2);
   186         at: #masked4 put: (colorMap copyFrom: 1 to: 16);
       
   187         at: #depth2  put: (colorMap copyFrom: 1 to: 4);
       
   188         at: #masked2 put: (colorMap copyFrom: 1 to: 4);
       
   189         at: #depth1  put: (colorMap copyFrom: 1 to: 2);
       
   190         at: #masked1 put: (colorMap copyFrom: 1 to: 2);
   187         yourself
   191         yourself
   188 !
   192 !
   189 
   193 
   190 listOfDefaultSizes
   194 listOfDefaultSizes
   191     "returns the list of default sizes for a new image"
   195     "returns the list of default sizes for a new image"
   192 
   196 
   193     ^#('8x8' '16x16' '22x22' '32x32' '48x48' '64x64')
   197     ^#('8x8' '16x16' '22x22' '32x32' '48x48' '64x64')
   194 
   198 
   195     "Modified: / 31.7.1998 / 01:57:34 / cg"
   199     "Modified: / 31.7.1998 / 01:57:34 / cg"
       
   200 !
       
   201 
       
   202 namesOfColorMaps
       
   203     ^ Dictionary new
       
   204         at: #depth24 put: '24-plane';
       
   205         at: #masked24 put: '24-plane + mask';
       
   206         at: #depth16 put: '16-plane';
       
   207         at: #masked16 put: '16-plane + mask';
       
   208         at: #depth8  put: ' 8-plane';
       
   209         at: #masked8 put: ' 8-plane + mask';
       
   210         at: #depth4  put: ' 4-plane';
       
   211         at: #masked4 put: ' 4-plane + mask';
       
   212         at: #depth2  put: ' 2-plane';
       
   213         at: #masked2 put: ' 2-plane + mask';
       
   214         at: #depth1  put: ' 1-plane';
       
   215         at: #masked1 put: ' 1-plane + mask' ;
       
   216         yourself
   196 ! !
   217 ! !
   197 
   218 
   198 !ImageEditor class methodsFor:'help specs'!
   219 !ImageEditor class methodsFor:'help specs'!
   199 
   220 
   200 flyByHelpSpec
   221 flyByHelpSpec
  1039                           name: 'colorMapComboBox'
  1060                           name: 'colorMapComboBox'
  1040                           layout: (LayoutFrame 0 0.0 10 0.0 0 1 35 0.0)
  1061                           layout: (LayoutFrame 0 0.0 10 0.0 0 1 35 0.0)
  1041                           model: selectionOfColorMap
  1062                           model: selectionOfColorMap
  1042                           comboList: listOfColorMaps
  1063                           comboList: listOfColorMaps
  1043                           useIndex: false
  1064                           useIndex: false
       
  1065                           hidePullDownMenuButton: false
  1044                         )
  1066                         )
  1045                        )
  1067                        )
  1046                      
  1068                      
  1047                     )
  1069                     )
  1048                   )
  1070                   )
  1559 
  1581 
  1560     "Do not manually edit this!! If it is corrupted,
  1582     "Do not manually edit this!! If it is corrupted,
  1561      the MenuEditor may not be able to read the specification."
  1583      the MenuEditor may not be able to read the specification."
  1562 
  1584 
  1563     "
  1585     "
  1564      MenuEditor new openOnClass:ImageEditor andSelector:#menuSpec
  1586      MenuEditor new openOnClass:ImageEditor andSelector:#colorMapMenu
  1565      (Menu new fromLiteralArrayEncoding:(ImageEditor menuSpec)) startUp
  1587      (Menu new fromLiteralArrayEncoding:(ImageEditor colorMapMenu)) startUp
  1566     "
  1588     "
  1567 
  1589 
  1568     <resource: #menu>
  1590     <resource: #menu>
  1569 
  1591 
  1570     ^
  1592     ^ 
  1571      
  1593      #(Menu
  1572        #(#Menu
  1594         (
  1573           
  1595          (MenuItem
  1574            #(
  1596             enabled: hasColormap
  1575              #(#MenuItem
  1597             label: 'Add Color'
  1576                 #label: 'Add Color'
  1598             itemValue: addColorToColormap
  1577                 #translateLabel: true
  1599             translateLabel: true
  1578                 #value: #addColorToColormap
  1600           )
  1579                 #enabled: #hasColormap
  1601          (MenuItem
  1580             )
  1602             enabled: hasColormap
  1581              #(#MenuItem
  1603             label: 'Pick and Add Color'
  1582                 #label: 'Pick and Add Color'
  1604             itemValue: pickAndAddColorToColormap
  1583                 #translateLabel: true
  1605             translateLabel: true
  1584                 #value: #pickAndAddColorToColormap
  1606           )
  1585                 #enabled: #hasColormap
  1607          (MenuItem
  1586             )
  1608             label: '-'
  1587              #(#MenuItem
  1609           )
  1588                 #label: '-'
  1610          (MenuItem
  1589             )
  1611             enabled: hasColormap
  1590              #(#MenuItem
  1612             label: 'Brighter'
  1591                 #label: 'Brighter'
  1613             itemValue: makeSelectedColorBrighter
  1592                 #translateLabel: true
  1614             translateLabel: true
  1593                 #value: #makeSelectedColorBrighter
  1615           )
  1594                 #enabled: #hasColormap
  1616          (MenuItem
  1595             )
  1617             enabled: hasColormap
  1596              #(#MenuItem
  1618             label: 'Darker'
  1597                 #label: 'Darker'
  1619             itemValue: makeSelectedColorDarker
  1598                 #translateLabel: true
  1620             translateLabel: true
  1599                 #value: #makeSelectedColorDarker
  1621           )
  1600                 #enabled: #hasColormap
  1622          (MenuItem
  1601             )
  1623             enabled: hasColormap
  1602              #(#MenuItem
  1624             label: 'Edit Color'
  1603                 #label: '-'
  1625             itemValue: editSelectedColor
  1604             )
  1626             translateLabel: true
  1605              #(#MenuItem
  1627           )
  1606                 #label: 'Inspect Color'
  1628          (MenuItem
  1607                 #translateLabel: true
  1629             label: '-'
  1608                 #value: #inspectColor
  1630           )
  1609                 #enabled: #hasColormap
  1631          (MenuItem
  1610             )
  1632             enabled: hasColormap
  1611           ) nil
  1633             label: 'Inspect Color'
  1612           nil
  1634             itemValue: inspectColor
       
  1635             translateLabel: true
       
  1636           )
       
  1637          )
       
  1638         nil
       
  1639         nil
  1613       )
  1640       )
  1614 
       
  1615     "Created: / 12.3.1999 / 00:19:00 / cg"
       
  1616 !
  1641 !
  1617 
  1642 
  1618 menu
  1643 menu
  1619     "This resource specification was automatically generated
  1644     "This resource specification was automatically generated
  1620      by the MenuEditor of ST/X."
  1645      by the MenuEditor of ST/X."
  1931                      #(#MenuItem
  1956                      #(#MenuItem
  1932                         #activeHelpKey: #colorMap8
  1957                         #activeHelpKey: #colorMap8
  1933                         #label: '8-Plane'
  1958                         #label: '8-Plane'
  1934                         #itemValue: #colorMapMode:
  1959                         #itemValue: #colorMapMode:
  1935                         #translateLabel: true
  1960                         #translateLabel: true
  1936                         #argument: '8-plane'
  1961                         #argument: #depth8
  1937                         #choice: #colorMapMode
  1962                         #choice: #colorMapMode
  1938                         #choiceValue: '8-plane'
  1963                         #choiceValue: #depth8
  1939                       )
  1964                       )
  1940                      #(#MenuItem
  1965                      #(#MenuItem
  1941                         #activeHelpKey: #colorMap4
  1966                         #activeHelpKey: #colorMap4
  1942                         #label: '4-Plane'
  1967                         #label: '4-Plane'
  1943                         #itemValue: #colorMapMode:
  1968                         #itemValue: #colorMapMode:
  1944                         #translateLabel: true
  1969                         #translateLabel: true
  1945                         #argument: '4-plane'
  1970                         #argument: #depth4
  1946                         #choice: #colorMapMode
  1971                         #choice: #colorMapMode
  1947                         #choiceValue: '4-plane'
  1972                         #choiceValue: #depth4
  1948                       )
  1973                       )
  1949                      #(#MenuItem
  1974                      #(#MenuItem
  1950                         #activeHelpKey: #colorMap2
  1975                         #activeHelpKey: #colorMap2
  1951                         #label: '2-Plane'
  1976                         #label: '2-Plane'
  1952                         #itemValue: #colorMapMode:
  1977                         #itemValue: #colorMapMode:
  1953                         #translateLabel: true
  1978                         #translateLabel: true
  1954                         #argument: '2-plane'
  1979                         #argument: #depth2
  1955                         #choice: #colorMapMode
  1980                         #choice: #colorMapMode
  1956                         #choiceValue: '2-plane'
  1981                         #choiceValue: #depth2
  1957                       )
  1982                       )
  1958                      #(#MenuItem
  1983                      #(#MenuItem
  1959                         #activeHelpKey: #colorMap1
  1984                         #activeHelpKey: #colorMap1
  1960                         #label: '1-Plane'
  1985                         #label: '1-Plane'
  1961                         #itemValue: #colorMapMode:
  1986                         #itemValue: #colorMapMode:
  1962                         #translateLabel: true
  1987                         #translateLabel: true
  1963                         #argument: '1-plane'
  1988                         #argument: #depth1
  1964                         #choice: #colorMapMode
  1989                         #choice: #colorMapMode
  1965                         #choiceValue: '1-plane'
  1990                         #choiceValue: #depth1
  1966                       )
  1991                       )
  1967                      #(#MenuItem
  1992                      #(#MenuItem
  1968                         #label: '-'
  1993                         #label: '-'
  1969                       )
  1994                       )
  1970                      #(#MenuItem
  1995                      #(#MenuItem
  1971                         #activeHelpKey: #colorMap8M
  1996                         #activeHelpKey: #colorMap8M
  1972                         #label: '8-Plane + Mask'
  1997                         #label: '8-Plane + Mask'
  1973                         #itemValue: #colorMapMode:
  1998                         #itemValue: #colorMapMode:
  1974                         #translateLabel: true
  1999                         #translateLabel: true
  1975                         #argument: '8-plane + mask'
  2000                         #argument: #masked8
  1976                         #choice: #colorMapMode
  2001                         #choice: #colorMapMode
  1977                         #choiceValue: '8-plane + mask'
  2002                         #choiceValue: #masked8
  1978                       )
  2003                       )
  1979                      #(#MenuItem
  2004                      #(#MenuItem
  1980                         #activeHelpKey: #colorMap4M
  2005                         #activeHelpKey: #colorMap4M
  1981                         #label: '4-Plane + Mask'
  2006                         #label: '4-Plane + Mask'
  1982                         #itemValue: #colorMapMode:
  2007                         #itemValue: #colorMapMode:
  1983                         #translateLabel: true
  2008                         #translateLabel: true
  1984                         #argument: '4-plane + mask'
  2009                         #argument: #masked4
  1985                         #choice: #colorMapMode
  2010                         #choice: #colorMapMode
  1986                         #choiceValue: '4-plane + mask'
  2011                         #choiceValue: #masked4
  1987                       )
  2012                       )
  1988                      #(#MenuItem
  2013                      #(#MenuItem
  1989                         #activeHelpKey: #colorMap2M
  2014                         #activeHelpKey: #colorMap2M
  1990                         #label: '2-Plane + Mask'
  2015                         #label: '2-Plane + Mask'
  1991                         #itemValue: #colorMapMode:
  2016                         #itemValue: #colorMapMode:
  1992                         #translateLabel: true
  2017                         #translateLabel: true
  1993                         #argument: '2-plane + mask'
  2018                         #argument: #masked2
  1994                         #choice: #colorMapMode
  2019                         #choice: #colorMapMode
  1995                         #choiceValue: '2-plane + mask'
  2020                         #choiceValue: #masked2
  1996                       )
  2021                       )
  1997                      #(#MenuItem
  2022                      #(#MenuItem
  1998                         #activeHelpKey: #colorMap1M
  2023                         #activeHelpKey: #colorMap1M
  1999                         #label: '1-Plane + Mask'
  2024                         #label: '1-Plane + Mask'
  2000                         #itemValue: #colorMapMode:
  2025                         #itemValue: #colorMapMode:
  2001                         #translateLabel: true
  2026                         #translateLabel: true
  2002                         #argument: '1-plane + mask'
  2027                         #argument: #masked1
  2003                         #choice: #colorMapMode
  2028                         #choice: #colorMapMode
  2004                         #choiceValue: '1-plane + mask'
  2029                         #choiceValue: #masked1
  2005                       )
  2030                       )
  2006                      )
  2031                      )
  2007                     nil
  2032                     nil
  2008                     nil
  2033                     nil
  2009                   )
  2034                   )
  2810 !ImageEditor methodsFor:'change & update'!
  2835 !ImageEditor methodsFor:'change & update'!
  2811 
  2836 
  2812 findColorMapMode
  2837 findColorMapMode
  2813     "finds the colorMapMode for a new image"
  2838     "finds the colorMapMode for a new image"
  2814 
  2839 
  2815     |image listOfColors|
  2840     |image listOfColors colorMapModeKey|
  2816 
  2841 
  2817     image := self image.
  2842     image := self image.
  2818     image depth > 8 ifTrue: [
  2843 
  2819         colorMapMode value: ''. 
  2844     image mask notNil ifTrue: [             
  2820         self listOfColors removeAll. 
  2845         colorMapModeKey := 'masked' , image depth printString.
  2821         ^ nil
  2846     ] ifFalse:[
  2822     ].
  2847         colorMapModeKey := 'depth' , image depth printString.
  2823 
  2848     ].
  2824     colorMapMode value:(image depth printString, '-plane').
  2849 
  2825 
  2850     colorMapMode value:colorMapModeKey.
  2826     (listOfColors := self listOfColors) isEmpty ifTrue:[   
  2851 
  2827         self colorMapMode: colorMapMode value.
  2852     image depth > 12 ifTrue:[
  2828         listOfColors := self listOfColors.
  2853         self listOfColors removeAll.
  2829         image := self image.
  2854         listOfColors := image colorMap.
       
  2855         listOfColors isEmptyOrNil ifTrue:[
       
  2856             listOfColors := Array with:Color black with:Color white.
       
  2857         ].
       
  2858     ] ifFalse:[
       
  2859         (listOfColors := self listOfColors) isEmpty ifTrue:[   
       
  2860             self colorMapMode: colorMapMode value.
       
  2861             listOfColors := self listOfColors.
       
  2862             image := self image.
       
  2863         ].                               
  2830     ].                               
  2864     ].                               
  2831     imageEditView drawingColors:(Array
  2865     imageEditView drawingColors:(Array
  2832                                     with: (listOfColors at:1) 
  2866                                     with: (listOfColors at:1) 
  2833                                     with: (listOfColors at:2 ifAbsent:[listOfColors at:1])).
  2867                                     with: (listOfColors at:2 ifAbsent:[listOfColors at:1])).
  2834 
  2868 
  2835     image mask notNil ifTrue: [             
  2869     image mask notNil ifTrue: [             
  2836         colorMapMode value:(colorMapMode value, ' + mask').
       
  2837 
       
  2838         (listOfColors detect: [:clr| clr = (Color colorId:0)] ifNone: nil) isNil
  2870         (listOfColors detect: [:clr| clr = (Color colorId:0)] ifNone: nil) isNil
  2839         ifTrue:[
  2871         ifTrue:[
  2840             listOfColors addFirst:(Color colorId:0).
  2872             listOfColors addFirst:(Color colorId:0).
  2841             imageEditView drawingColors: (Array 
  2873             imageEditView drawingColors: (Array 
  2842                                             with:(listOfColors at:2 ifAbsent:[listOfColors at:1]) 
  2874                                             with:(listOfColors at:2 ifAbsent:[listOfColors at:1]) 
  2891         ^ self.
  2923         ^ self.
  2892     ].
  2924     ].
  2893 
  2925 
  2894     changedObject == imageEditView ifTrue:[
  2926     changedObject == imageEditView ifTrue:[
  2895         something == #imageColors ifTrue:[
  2927         something == #imageColors ifTrue:[
  2896             self listOfColors contents:img colorMap.
  2928             self updateListOfColorsAndColormapMode.
  2897             self findColorMapMode.
       
  2898             ^ self.
  2929             ^ self.
  2899         ].
  2930         ].
  2900         something == #image ifTrue:[
  2931         something == #image ifTrue:[
  2901             self imagePreView image:img.
  2932             self imagePreView image:img.
  2902             self listOfColors contents:img colorMap.
  2933             self updateListOfColorsAndColormapMode.
  2903             self findColorMapMode.
       
  2904             self tileModeHolder value ifTrue:[
  2934             self tileModeHolder value ifTrue:[
  2905                 self imagePreView tileMode:true tileOffset:(img extent).
  2935                 self imagePreView tileMode:true tileOffset:(img extent).
  2906             ].
  2936             ].
  2907             ^ self.
  2937             ^ self.
  2908         ].
  2938         ].
  2968     self image fileName notNil
  2998     self image fileName notNil
  2969         ifTrue: [self addToHistory: self image fileName -> #loadFromFile:].
  2999         ifTrue: [self addToHistory: self image fileName -> #loadFromFile:].
  2970 
  3000 
  2971 
  3001 
  2972 
  3002 
       
  3003 !
       
  3004 
       
  3005 updateListOfColorsAndColormapMode
       
  3006     |colorMap image|
       
  3007 
       
  3008     image := self image.
       
  3009     colorMap := image colorMap.
       
  3010     colorMap size <= 4096 ifTrue:[
       
  3011         self listOfColors contents:colorMap.
       
  3012     ] ifFalse:[
       
  3013         self listOfColors removeAll.
       
  3014         colorMap isFixedPalette ifTrue:[
       
  3015             image colorMap:nil.
       
  3016             image photometric:#rgb.
       
  3017             image samplesPerPixel:3.
       
  3018             
       
  3019             image bitsPerSample:(Array 
       
  3020                                     with:(colorMap bitsRed)
       
  3021                                     with:(colorMap bitsGreen)
       
  3022                                     with:(colorMap bitsBlue)).
       
  3023         ].
       
  3024     ].
       
  3025     self findColorMapMode.
  2973 ! !
  3026 ! !
  2974 
  3027 
  2975 !ImageEditor methodsFor:'data access'!
  3028 !ImageEditor methodsFor:'data access'!
  2976 
  3029 
  2977 atColor:aOldColor put:aNewColor
  3030 atColor:aOldColor put:aNewColor
  3198 ! !
  3251 ! !
  3199 
  3252 
  3200 !ImageEditor methodsFor:'menu modes'!
  3253 !ImageEditor methodsFor:'menu modes'!
  3201 
  3254 
  3202 colorMapMode
  3255 colorMapMode
  3203     "returns colorMapMode"
  3256     "returns the colorMapMode"
  3204 
  3257 
  3205     colorMapMode isNil ifTrue: [colorMapMode := '' asValue].
  3258     colorMapMode isNil ifTrue: [colorMapMode := '' asValue].
  3206 
  3259 
  3207     ^colorMapMode
  3260     ^colorMapMode
  3208 !
  3261 !
  3251 ! !
  3304 ! !
  3252 
  3305 
  3253 !ImageEditor methodsFor:'queries'!
  3306 !ImageEditor methodsFor:'queries'!
  3254 
  3307 
  3255 hasMask
  3308 hasMask
  3256     ^ colorMapMode value notNil and:[colorMapMode value endsWith:'mask']
  3309     ^ colorMapMode value notNil and:[colorMapMode value startsWith:'mask']
  3257 
  3310 
  3258     "Created: / 18.8.1998 / 17:17:38 / cg"
  3311     "Created: / 18.8.1998 / 17:17:38 / cg"
  3259 !
  3312 !
  3260 
  3313 
  3261 preferredExtent
  3314 preferredExtent
  3407     or:[cMap size == (1 bitShift:depth)]) ifTrue:[
  3460     or:[cMap size == (1 bitShift:depth)]) ifTrue:[
  3408         depth >= 8 ifTrue:[
  3461         depth >= 8 ifTrue:[
  3409             self warn:'No space for more colors in colormap.'.
  3462             self warn:'No space for more colors in colormap.'.
  3410             ^ self
  3463             ^ self
  3411         ].
  3464         ].
  3412         (self confirm:'No space for more colors in colormap.\Change depth first.' withCRs)
  3465         (self confirm:'No space for more colors in colormap.\Change depth ?' withCRs)
  3413         ifFalse:[
  3466         ifFalse:[
  3414             ^ self
  3467             ^ self
  3415         ].
  3468         ].
  3416 
  3469 
  3417         imageEditView makeUndo.
  3470         imageEditView makeUndo.
  3418         newMode := (depth*2) printString , (colorMapMode value copyFrom:2).
  3471         img mask notNil ifTrue:[
       
  3472             newMode := 'masked' , (depth*2) printString.
       
  3473         ] ifFalse:[
       
  3474             newMode := 'depth' , (depth*2) printString.
       
  3475         ].
  3419         self colorMapMode:newMode.
  3476         self colorMapMode:newMode.
  3420     ] ifFalse:[
  3477     ] ifFalse:[
  3421         imageEditView makeUndo.
  3478         imageEditView makeUndo.
  3422     ].
  3479     ].
  3423 
  3480 
  3424     cMap := cMap asArray.
  3481     cMap := cMap asArray.
  3425     listOfColors := self listOfColors.
  3482     listOfColors := self listOfColors.
  3426     oldCListSize := listOfColors size.
  3483     oldCListSize := listOfColors size.
  3427 
       
  3428 "/    (colorMapMode value asString endsWith:'mask') ifTrue:[
       
  3429 "/        cMap last = Color noColor ifTrue:[
       
  3430 "/            cMap := cMap copyWithoutLast:1
       
  3431 "/        ] ifFalse:[
       
  3432 "/            cMap first = Color noColor ifTrue:[
       
  3433 "/                cMap := cMap copyFrom:2
       
  3434 "/            ]
       
  3435 "/        ].
       
  3436 "/    ].
       
  3437 "/
       
  3438 
  3484 
  3439     newColorMap := cMap copyWith:newColor.
  3485     newColorMap := cMap copyWith:newColor.
  3440 
  3486 
  3441     newImage := img species new
  3487     newImage := img species new
  3442                     width:img width
  3488                     width:img width
  3598 
  3644 
  3599     self withExecuteCursorDo:[
  3645     self withExecuteCursorDo:[
  3600         oldImage := self image.
  3646         oldImage := self image.
  3601 
  3647 
  3602         prevMode := colorMapMode value.
  3648         prevMode := colorMapMode value.
  3603         oldImage depth > 8 ifTrue:[
       
  3604             prevMode := nil
       
  3605         ].
       
  3606 
  3649 
  3607         newColorMap := self class listOfColorMaps at:aMode.
  3650         newColorMap := self class listOfColorMaps at:aMode.
  3608         depth       := (newColorMap size log: 2) asInteger. 
  3651         depth       := (newColorMap size log:2) asInteger. 
  3609 
  3652 
  3610         useNearest := false.
  3653         useNearest := false.
  3611         depth == 1 ifTrue:[
  3654         depth == 1 ifTrue:[
  3612             quest := 'Keep colormap (or use standard B&W)'
  3655             quest := 'Keep colormap (or use standard B&W)'
  3613         ] ifFalse:[
  3656         ] ifFalse:[
  3742             ].
  3785             ].
  3743         ] do:[ 
  3786         ] do:[ 
  3744             image := newImage fromImage:oldImage
  3787             image := newImage fromImage:oldImage
  3745         ].
  3788         ].
  3746 
  3789 
  3747         (aMode asString endsWith:'mask') ifTrue:[
  3790         (aMode asString startsWith:'mask') ifTrue:[
  3748             image mask isNil ifTrue:[
  3791             image mask isNil ifTrue:[
  3749                 (Dialog confirm:'Generate mask from black ?' default:false) ifTrue:[
  3792                 (Dialog confirm:'Generate mask from black ?' default:false) ifTrue:[
  3750                     maskThreshold := 0.1.
  3793                     maskThreshold := 0.1.
  3751                     maskImage := Depth1Image fromImage:(image asThresholdMonochromeImage:maskThreshold). 
  3794                     maskImage := Depth1Image fromImage:(image asThresholdMonochromeImage:maskThreshold). 
  3752                 ] ifFalse:[
  3795                 ] ifFalse:[
  3895 
  3938 
  3896     mask := self image mask.
  3939     mask := self image mask.
  3897     MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
  3940     MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
  3898 !
  3941 !
  3899 
  3942 
       
  3943 editSelectedColor
       
  3944     self processSelectedColorWith:[:clr | 
       
  3945         |editor|
       
  3946 
       
  3947         editor := ColorEditDialog new.
       
  3948         editor color:clr.
       
  3949         editor open.
       
  3950         editor accepted ifFalse:[
       
  3951             AbortOperationRequest raise.
       
  3952         ].
       
  3953         editor color
       
  3954     ]
       
  3955 !
       
  3956 
  3900 fetchImageData
  3957 fetchImageData
  3901     |image|
  3958     |image|
  3902 
  3959 
  3903     (image := imageEditView image) notNil ifTrue:[
  3960     (image := imageEditView image) notNil ifTrue:[
  3904         self listOfColors contents:(image colorMap).
  3961         self listOfColors contents:(image colorMap).
  4000 pickAndAddColorToColormap
  4057 pickAndAddColorToColormap
  4001     self addColorToColormap:(Color fromUser)
  4058     self addColorToColormap:(Color fromUser)
  4002 !
  4059 !
  4003 
  4060 
  4004 processSelectedColorWith:aBlock
  4061 processSelectedColorWith:aBlock
  4005     |img cMap clr newImage selectedColorIndex oldSelection|
  4062     |img cMap modifiedColormap clr newImage selectedColorIndex oldSelection|
  4006 
  4063 
  4007     selectedColorIndex := self selectedColorIndexOrNil.
  4064     selectedColorIndex := self selectedColorIndexOrNil.
  4008     selectedColorIndex isNil ifTrue:[^ self].
  4065     selectedColorIndex isNil ifTrue:[^ self].
  4009 
  4066 
  4010     img := self image.
  4067     img := self image.
  4013         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
  4070         self warn:'Image has no colormap\change colorMap mode first.' withCRs.
  4014         ^ self
  4071         ^ self
  4015     ].
  4072     ].
  4016     imageEditView makeUndo.
  4073     imageEditView makeUndo.
  4017 
  4074 
  4018     cMap := cMap asArray.
  4075     modifiedColormap := cMap asArray copy.
  4019     clr := cMap at:selectedColorIndex.
  4076     clr := modifiedColormap at:selectedColorIndex.
  4020     cMap at:selectedColorIndex put:(aBlock value:clr).
  4077     modifiedColormap at:selectedColorIndex put:(aBlock value:clr).
  4021 
  4078 
  4022     newImage := img species new
  4079     newImage := img species new
  4023                     width:img width
  4080                     width:img width
  4024                     height:img height
  4081                     height:img height
  4025                     depth:img depth
  4082                     depth:img depth
  4026                     fromArray:img bits.
  4083                     fromArray:img bits.
  4027 
  4084 
  4028     newImage colorMap:cMap.  
  4085     newImage colorMap:modifiedColormap.  
  4029     newImage fileName:img fileName.
  4086     newImage fileName:img fileName.
  4030     newImage mask:(img mask copy).
  4087     newImage mask:(img mask copy).
  4031 
  4088 
  4032     oldSelection := self selectionOfColor value.
  4089     oldSelection := self selectionOfColor value.
  4033 
  4090 
  4083     img isNil ifTrue:[
  4140     img isNil ifTrue:[
  4084         self warn:'No Image.'.
  4141         self warn:'No Image.'.
  4085         ^ nil
  4142         ^ nil
  4086     ].
  4143     ].
  4087     clrIndex := self selectionOfColor value.
  4144     clrIndex := self selectionOfColor value.
  4088     img mask notNil ifTrue: [ clrIndex := clrIndex - 1 ].
  4145     img mask notNil ifTrue: [ 
       
  4146         clrIndex == 1 ifTrue:[^ nil].
       
  4147         clrIndex := clrIndex - 1 
       
  4148     ].
  4089     ^ clrIndex
  4149     ^ clrIndex
  4090 !
  4150 !
  4091 
  4151 
  4092 sortColorMap
  4152 sortColorMap
  4093     "calculates a new color map for the image, sorting colors"
  4153     "calculates a new color map for the image, sorting colors"
  4591 !
  4651 !
  4592 
  4652 
  4593 doNewImage
  4653 doNewImage
  4594     "opens a dialog with choices of size and color map for creating a new image"
  4654     "opens a dialog with choices of size and color map for creating a new image"
  4595 
  4655 
  4596     |aspects width height cMapString cMap imageClass image szString|
  4656     |aspects width height cMapString cMapMode cMap imageClass image szString defaultSize|
       
  4657 
       
  4658     defaultSize := (self class listOfDefaultSizes includes:'32x32') 
       
  4659                         ifTrue:['32x32'] 
       
  4660                         ifFalse:[self class listOfDefaultSizes first].
  4597 
  4661 
  4598     aspects  := IdentityDictionary new
  4662     aspects  := IdentityDictionary new
  4599         at:#listOfSizes         put: self class listOfDefaultSizes asValue;
  4663         at:#listOfSizes         put: self class listOfDefaultSizes asValue;
  4600         at:#listOfColorMaps     put: self class listOfColorMaps keys asSortedCollection asValue;
  4664         at:#listOfColorMaps     put: self class namesOfColorMaps values asSortedCollection asValue;
  4601         at:#selectionOfSize     put: (LastSizeString ? self class listOfDefaultSizes first copy) asValue;
  4665         at:#selectionOfSize     put: (LastSizeString ? defaultSize) asValue;
  4602         at:#selectionOfColorMap put: (LastColormapMode ? self class listOfColorMaps keys asSortedCollection first) asValue;
  4666         at:#selectionOfColorMap put: (LastColormapMode ? self class namesOfColorMaps values asSortedCollection first) asValue;
  4603         yourself.
  4667         yourself.
  4604 
  4668 
  4605     (self openDialogInterface:#dialogSpecForNewImage withBindings:aspects)
  4669     (self openDialogInterface:#dialogSpecForNewImage withBindings:aspects)
  4606     ifTrue:[
  4670     ifTrue:[
  4607         szString := (aspects at:#selectionOfSize) value.
  4671         szString := (aspects at:#selectionOfSize) value.
  4608         width  := 128 min: (Integer readFromString: (szString upTo: $x) onError:[24]).
  4672         width  := 128 min: (Integer readFromString: (szString upTo: $x) onError:[24]).
  4609         height := 128 min: (Integer readFromString: (szString copy reverse upTo: $x) reverse onError:[24]).
  4673         height := 128 min: (Integer readFromString: (szString copy reverse upTo: $x) reverse onError:[24]).
  4610 
  4674 
  4611         cMapString := (aspects at:#selectionOfColorMap) value.
  4675         cMapString := (aspects at:#selectionOfColorMap) value.
  4612         cMap       := (self class listOfColorMaps at: (colorMapMode value: (aspects at:#selectionOfColorMap) value) value).
  4676         cMapMode   := self class namesOfColorMaps keyAtEqualValue:cMapString.
  4613         imageClass := Image implementorForDepth: ((cMap size log: 2) asInteger).
  4677         cMap       := self class listOfColorMaps at:cMapMode.
  4614         image      := imageClass width: width height: height fromArray: (ByteArray new: width*height).
  4678         imageClass := Image implementorForDepth:(cMap size highBit-1).
       
  4679         image      := imageClass width: width height: height.
       
  4680         image bits:(ByteArray new:(image bytesPerRow*height)).
  4615 
  4681 
  4616         LastSizeString := szString.
  4682         LastSizeString := szString.
  4617         LastColormapMode := cMapString.
  4683         LastColormapMode := cMapString.
  4618 
  4684 
  4619         (colorMapMode value endsWith: 'mask')
  4685         (cMapMode startsWith: 'mask') ifTrue:[
  4620         ifTrue:
       
  4621         [
       
  4622             image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels
  4686             image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels
  4623         ].
  4687         ].
  4624         image colorMap: cMap.
  4688         image colorMap: cMap.
       
  4689         (imageEditView image: image) notNil ifTrue:[
       
  4690             self updateListOfColorsAndColormapMode.
       
  4691             self updateLabelsAndHistory.
       
  4692         ].
  4625         image fillRectangleX:0 y:0 width:width height:height with:Color white.
  4693         image fillRectangleX:0 y:0 width:width height:height with:Color white.
  4626         (imageEditView image: image) notNil
       
  4627         ifTrue:
       
  4628         [
       
  4629             self listOfColors contents: cMap.
       
  4630             self findColorMapMode.
       
  4631             self updateLabelsAndHistory.
       
  4632         ]
       
  4633     ]
  4694     ]
  4634 !
  4695 !
  4635 
  4696 
  4636 doNewImageFromClipboard
  4697 doNewImageFromClipboard
  4637     |image|
  4698     |image|