ImageEditor.st
changeset 1904 46a0b109cb47
parent 1900 41ba86fb1087
child 1905 b389cf085b98
equal deleted inserted replaced
1903:f409fa760169 1904:46a0b109cb47
  2884 !ImageEditor methodsFor:'change & update'!
  2884 !ImageEditor methodsFor:'change & update'!
  2885 
  2885 
  2886 findColorMapMode
  2886 findColorMapMode
  2887     "finds the colorMapMode for a new image"
  2887     "finds the colorMapMode for a new image"
  2888 
  2888 
  2889     |image listOfColors colorMapModeKey|
  2889     |image listOfColors colorMapModeKey drawColor1 drawColor2|
  2890 
  2890 
  2891     image := self image.
  2891     image := self image.
  2892 
  2892 
  2893     image mask notNil ifTrue: [             
  2893     image mask notNil ifTrue: [             
  2894         colorMapModeKey := 'masked'.
  2894         colorMapModeKey := 'masked'.
  2896         colorMapModeKey := 'depth'.
  2896         colorMapModeKey := 'depth'.
  2897     ].
  2897     ].
  2898     colorMapModeKey := colorMapModeKey , image depth printString.
  2898     colorMapModeKey := colorMapModeKey , image depth printString.
  2899     colorMapMode setValue:colorMapModeKey.
  2899     colorMapMode setValue:colorMapModeKey.
  2900 
  2900 
       
  2901     listOfColors := self listOfColors.
  2901     image depth > 12 ifTrue:[
  2902     image depth > 12 ifTrue:[
  2902         self listOfColors removeAll.
  2903         listOfColors removeAll.
  2903         listOfColors := image colorMap.
  2904         image colorMap isEmptyOrNil ifTrue:[
  2904         listOfColors isEmptyOrNil ifTrue:[
  2905             listOfColors add:Color black; add:Color white.
  2905             listOfColors := Array with:Color black with:Color white.
  2906         ] ifFalse:[
       
  2907             listOfColors addAll:(image colorMap).
  2906         ].
  2908         ].
  2907     ] ifFalse:[
  2909     ] ifFalse:[
  2908         (listOfColors := self listOfColors) isEmpty ifTrue:[   
  2910 self halt.
       
  2911         listOfColors isEmpty ifTrue:[   
  2909             self colorMapMode: colorMapMode value.
  2912             self colorMapMode: colorMapMode value.
  2910             listOfColors := self listOfColors.
       
  2911             image := self image.
  2913             image := self image.
  2912         ].                               
  2914         ].                               
  2913     ].                               
  2915     ].                               
  2914     imageEditView drawingColors:(Array
  2916     drawColor1 := listOfColors at:1.
  2915                                     with: (listOfColors at:1) 
  2917     drawColor2 := listOfColors at:2 ifAbsent:drawColor1.
  2916                                     with: (listOfColors at:2 ifAbsent:[listOfColors at:1])).
       
  2917 
  2918 
  2918     self hasMask ifTrue: [             
  2919     self hasMask ifTrue: [             
  2919         (listOfColors contains: [:clr| clr = (Color colorId:0)]) 
  2920         (listOfColors contains: [:clr| clr = (Color colorId:0)]) 
  2920         ifFalse:[
  2921         ifFalse:[
  2921             listOfColors addFirst:(Color colorId:0).
  2922             listOfColors addFirst:(Color colorId:0).
  2922             imageEditView drawingColors: (Array 
  2923             drawColor1 := listOfColors at:2. 
  2923                                             with: (listOfColors at:2) 
  2924             drawColor2 := listOfColors at:3 ifAbsent:drawColor1.
  2924                                             with: (listOfColors at:3 ifAbsent:[listOfColors at:2])).
       
  2925         ]
  2925         ]
  2926     ].
  2926     ].
       
  2927 
       
  2928     imageEditView drawingColors:(Array with: drawColor1 with: drawColor2).
       
  2929 
  2927     self selectionOfColor 
  2930     self selectionOfColor 
  2928         setValue: 0;
  2931         setValue: 0;
  2929         value: (self listOfColors indexOf: imageEditView selectedColor).
  2932         value: (listOfColors indexOf: imageEditView selectedColor).
  2930 !
  2933 !
  2931 
  2934 
  2932 update:something with:aParameter from:changedObject
  2935 update:something with:aParameter from:changedObject
  2933     |clrIndex img clr|
  2936     |clrIndex img clr|
  2934 
  2937 
  3027 !
  3030 !
  3028 
  3031 
  3029 updateColorsFromImage:image
  3032 updateColorsFromImage:image
  3030     |colors|
  3033     |colors|
  3031 
  3034 
  3032     image colorMap notNil ifTrue:[
  3035     colors := image colorMap.
  3033         colors := image colorMap asOrderedCollection.
  3036     colors isNil ifTrue:[
  3034     ] ifFalse:[
  3037         colors := image usedColors asSet.
  3035         colors := image usedColors asSet asOrderedCollection.
  3038     ].
  3036     ].
  3039     self listOfColors contents:(colors asOrderedCollection).
  3037     self listOfColors contents:colors.
       
  3038 !
  3040 !
  3039 
  3041 
  3040 updateForNoImage
  3042 updateForNoImage
  3041     "updates channels and view, if image is loaded"
  3043     "updates channels and view, if image is loaded"
  3042 
  3044 
  3278 
  3280 
  3279     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  3281     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  3280         (img := self image) notNil ifTrue:[
  3282         (img := self image) notNil ifTrue:[
  3281             img := img onDevice:device.
  3283             img := img onDevice:device.
  3282             self updateColorsFromImage:img.
  3284             self updateColorsFromImage:img.
       
  3285             self findColorMapMode.
  3283             self updateLabelsAndHistory.
  3286             self updateLabelsAndHistory.
  3284         ] ifFalse:[
  3287         ] ifFalse:[
  3285             self updateForNoImage
  3288             self updateForNoImage
  3286         ]
  3289         ]
  3287     ]
  3290     ]
  4217         ^ nil
  4220         ^ nil
  4218     ].
  4221     ].
  4219     clrIndex := self selectionOfColor value.
  4222     clrIndex := self selectionOfColor value.
  4220     self hasMask "img mask notNil" ifTrue: [ 
  4223     self hasMask "img mask notNil" ifTrue: [ 
  4221         clrIndex == 1 ifTrue:[^ nil].
  4224         clrIndex == 1 ifTrue:[^ nil].
       
  4225         clrIndex == 0 ifTrue:[^ nil].
  4222         ^ clrIndex - 1 
  4226         ^ clrIndex - 1 
  4223     ].
  4227     ].
  4224     ^ clrIndex
  4228     ^ clrIndex
  4225 !
  4229 !
  4226 
  4230