ImageEditor.st
changeset 1928 06c3681a79b3
parent 1927 c5068006116d
child 1929 13237e16b048
equal deleted inserted replaced
1927:c5068006116d 1928:06c3681a79b3
  2911     ].
  2911     ].
  2912     colorMapModeKey := colorMapModeKey , image depth printString.
  2912     colorMapModeKey := colorMapModeKey , image depth printString.
  2913     colorMapMode setValue:colorMapModeKey.
  2913     colorMapMode setValue:colorMapModeKey.
  2914 
  2914 
  2915     listOfColors := self listOfColors.
  2915     listOfColors := self listOfColors.
       
  2916 
  2916     image depth > 12 ifTrue:[
  2917     image depth > 12 ifTrue:[
  2917         listOfColors removeAll.
  2918         listOfColors removeAll.
  2918         image colorMap isEmptyOrNil ifTrue:[
  2919         image colorMap isEmptyOrNil ifTrue:[
  2919             someOrAllUsedColors := image usedColorsMax:10000.
  2920             someOrAllUsedColors := image usedColorsMax:10000.
       
  2921             someOrAllUsedColors := someOrAllUsedColors asArray.
       
  2922             someOrAllUsedColors sort:[:a :b |
       
  2923                                     a redByte == b redByte ifTrue:[
       
  2924                                         a greenByte == b greenByte ifTrue:[
       
  2925                                             a blueByte < b blueByte
       
  2926                                         ] ifFalse:[
       
  2927                                             a greenByte < b greenByte 
       
  2928                                         ]
       
  2929                                     ] ifFalse:[
       
  2930                                         a redByte < b redByte 
       
  2931                                     ]
       
  2932                               ].
  2920             listOfColors addAll:someOrAllUsedColors.
  2933             listOfColors addAll:someOrAllUsedColors.
  2921             "/ listOfColors add:Color black; add:Color white.
  2934             "/ listOfColors add:Color black; add:Color white.
  2922         ] ifFalse:[
  2935         ] ifFalse:[
  2923             listOfColors addAll:(image colorMap).
  2936             listOfColors addAll:(image colorMap).
  2924         ].
  2937         ].
  2946         setValue: 0;
  2959         setValue: 0;
  2947         value: (listOfColors indexOf: imageEditView selectedColor).
  2960         value: (listOfColors indexOf: imageEditView selectedColor).
  2948 !
  2961 !
  2949 
  2962 
  2950 update:something with:aParameter from:changedObject
  2963 update:something with:aParameter from:changedObject
  2951     |clrIndex img clr|
  2964     |clrIndex img clr changedColor|
  2952 
  2965 
  2953     img := self image.
  2966     img := self image.
  2954 
  2967 
  2955     changedObject == self tileModeHolder ifTrue:[
  2968     changedObject == self tileModeHolder ifTrue:[
  2956         self imagePreView 
  2969         self imagePreView 
  2976 
  2989 
  2977             clrIndex := aParameter.
  2990             clrIndex := aParameter.
  2978             (self hasMask) ifTrue:[
  2991             (self hasMask) ifTrue:[
  2979                 clrIndex := clrIndex - 1.
  2992                 clrIndex := clrIndex - 1.
  2980             ].
  2993             ].
  2981 
  2994             changedColor := changedObject at:aParameter.
  2982             (img colorMap ? drawingColormap) at:clrIndex put:(changedObject at:aParameter).
  2995             img colorMap notNil ifTrue:[
  2983             self colorMapChanged.
  2996                 img colorMap at:clrIndex put:changedColor.
       
  2997                 self colorMapChanged.
       
  2998             ] ifFalse:[
       
  2999                 drawingColormap notNil ifTrue:[
       
  3000                     drawingColormap at:clrIndex put:changedColor.
       
  3001                 ].
       
  3002             ].
  2984             ^ self
  3003             ^ self
  2985         ].
  3004         ].
  2986         ^ self
  3005         ^ self
  2987     ].
  3006     ].
  2988 
  3007 
  3112     self findColorMapMode.
  3131     self findColorMapMode.
  3113 ! !
  3132 ! !
  3114 
  3133 
  3115 !ImageEditor methodsFor:'data access'!
  3134 !ImageEditor methodsFor:'data access'!
  3116 
  3135 
  3117 atColor:aOldColor put:aNewColor
  3136 atColor:aOldColor put:newColor
  3118     "a color changed to a new color
  3137     "a color changed to a new color
  3119     "
  3138     "
  3120     |index list|
  3139     |index list oldColor image newImage|
  3121 
  3140 
  3122     list  := self listOfColors.
  3141     list  := self listOfColors.
  3123     index := list identityIndexOf:aOldColor.
  3142     index := list identityIndexOf:aOldColor.
  3124 
  3143 
  3125     index ~~ 0 ifTrue:[
  3144     index ~~ 0 ifTrue:[
  3126         list at:index put:aNewColor
  3145         oldColor := list at:index.
       
  3146         list at:index put:newColor
  3127     ] ifFalse:[
  3147     ] ifFalse:[
  3128         self error:'internal error' mayProceed:true.
  3148         self error:'internal error' mayProceed:true.
  3129         list add:aNewColor
  3149         list add:newColor
       
  3150     ].
       
  3151 
       
  3152     image := self image.
       
  3153     (image colorMap isNil 
       
  3154     and:[drawingColormap isNil]) ifTrue:[
       
  3155         oldColor notNil ifTrue:[
       
  3156             imageEditView makeUndo.
       
  3157             newImage := image copy.
       
  3158             newImage
       
  3159                 colorsFromX:0 y:0 toX:(image width-1) y:(image height-1) 
       
  3160                 do:[:x :y :clr |
       
  3161                     |newClr|
       
  3162 
       
  3163                     newClr := (clr = oldColor) ifTrue:newColor ifFalse:clr.
       
  3164                     newImage colorAtX:x y:y put:newClr
       
  3165                 ].
       
  3166             imageEditView image:newImage.
       
  3167             imageEditView setModified.
       
  3168             self updateImage.
       
  3169             self updateImagePreView.
       
  3170         ]
  3130     ].
  3171     ].
  3131 !
  3172 !
  3132 
  3173 
  3133 blueAtColor:aColor put:newBlue
  3174 blueAtColor:aColor put:newBlue
  3134     "helper used to return a new row element, when blue is changed"
  3175     "helper used to return a new row element, when blue is changed"
  3788                     ] ifFalse:[
  3829                     ] ifFalse:[
  3789                         oldImage depth == 8 ifTrue:[
  3830                         oldImage depth == 8 ifTrue:[
  3790                             tmpBits := oldImage bits
  3831                             tmpBits := oldImage bits
  3791                         ] ifFalse:[
  3832                         ] ifFalse:[
  3792                             colorMapMode value:prevMode.
  3833                             colorMapMode value:prevMode.
       
  3834                             self findColorMapMode.    
  3793                             self warn:('Too many used colors in image (', oldImage usedColors size printString , ').').
  3835                             self warn:('Too many used colors in image (', oldImage usedColors size printString , ').').
  3794                             ^ self
  3836                             ^ self
  3795 "/                            (self confirm:('Too many used colors in image (', oldImage usedColors size printString , ').\\Dither ?' withCRs))
  3837 "/                            (self confirm:('Too many used colors in image (', oldImage usedColors size printString , ').\\Dither ?' withCRs))
  3796 "/                            ifFalse:[.
  3838 "/                            ifFalse:[.
  3797 "/                                ^ self
  3839 "/                                ^ self