diff -r 294d0e102881 -r 27b19cd0274b ImageEditor.st --- a/ImageEditor.st Fri Aug 05 15:29:41 2005 +0200 +++ b/ImageEditor.st Fri Aug 05 16:06:28 2005 +0200 @@ -3842,73 +3842,75 @@ ((prevMode = aMode) or:[depth > oldImage depth or:[self confirm:(resources string:quest)]]) ifTrue:[ - - "/ keep the colormap - newColorMap atAllPut:Color black. - depth > oldImage depth ifTrue:[ - "/ easy - simply copy the part - numColors := 1 bitShift:oldImage depth. - 0 to:numColors-1 do:[:pixel | - newColorMap at:(pixel+1) put:(oldImage colorFromValue:pixel) - ]. - ] ifFalse:[ - "/ see if all used color fit the new colormap - usedColors := oldImage usedColorsMax:(1 bitShift:depth). - (usedColors notNil and:[usedColors size > (1 bitShift:depth)]) ifTrue:[ - usedColors := oldImage realUsedColors - ]. - (usedColors notNil and:[usedColors size <= (1 bitShift:depth)]) ifTrue:[ - "/ yea - just install them - usedColors asArray keysAndValuesDo:[:idx :clr | - newColorMap at:idx put:clr + (newColorMap isFixedPalette) ifFalse:[ + + "/ keep the colormap + newColorMap atAllPut:Color black. + depth > oldImage depth ifTrue:[ + "/ easy - simply copy the part + numColors := 1 bitShift:oldImage depth. + 0 to:numColors-1 do:[:pixel | + newColorMap at:(pixel+1) put:(oldImage colorFromValue:pixel) ]. ] ifFalse:[ - "/ copy over those that are most often used. - oldImage depth < 8 ifTrue:[ - tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). - oldImage bits - expandPixels:(oldImage depth) - width:oldImage width - height:oldImage height - into:tmpBits - mapping:nil. + "/ see if all used color fit the new colormap + usedColors := oldImage usedColorsMax:(1 bitShift:depth). + (usedColors notNil and:[usedColors size > (1 bitShift:depth)]) ifTrue:[ + usedColors := oldImage realUsedColors + ]. + (usedColors notNil and:[usedColors size <= (1 bitShift:depth)]) ifTrue:[ + "/ yea - just install them + usedColors asArray keysAndValuesDo:[:idx :clr | + newColorMap at:idx put:clr + ]. ] ifFalse:[ - oldImage depth == 8 ifTrue:[ - tmpBits := oldImage bits + "/ copy over those that are most often used. + oldImage depth < 8 ifTrue:[ + tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). + oldImage bits + expandPixels:(oldImage depth) + width:oldImage width + height:oldImage height + into:tmpBits + mapping:nil. ] ifFalse:[ + oldImage depth == 8 ifTrue:[ + tmpBits := oldImage bits + ] ifFalse:[ + colorMapMode value:prevMode. + self findColorMapMode. + self warn:('Too many used colors in image (', oldImage usedColors size printString , ').'). + ^ self + "/ (self confirm:('Too many used colors in image (', oldImage usedColors size printString , ').\\Dither ?' withCRs)) + "/ ifFalse:[. + "/ ^ self + "/ ]. + "/ self image: (Image newForDepth:depth) fromImage:oldImage. + "/ ^ self. + ] + ]. + usageCounts := tmpBits usageCounts. + tmpMap := Array new:usageCounts size. + oldImage colorMap asArray keysAndValuesDo:[:i :clr | + tmpMap at:i put:clr + ]. + usageCounts sort:[:a :b | a > b] with:tmpMap. + + 1 to:(1 bitShift:depth) do:[:idx | + newColorMap at:idx put:(tmpMap at:idx) + ]. + + useNearest := Dialog + confirmWithCancel:(resources + stringWithCRs:'Image requires %1 colors.\ColorMap has only space for %2\\Use nearest (or map to first color) ?' + with:usedColors size + with:(1 bitShift:depth)) + labels:(resources array:#('Cancel' 'First' 'Nearest')). + useNearest isNil ifTrue:[ colorMapMode value:prevMode. - self findColorMapMode. - self warn:('Too many used colors in image (', oldImage usedColors size printString , ').'). - ^ self -"/ (self confirm:('Too many used colors in image (', oldImage usedColors size printString , ').\\Dither ?' withCRs)) -"/ ifFalse:[. -"/ ^ self -"/ ]. -"/ self image: (Image newForDepth:depth) fromImage:oldImage. -"/ ^ self. - ] - ]. - usageCounts := tmpBits usageCounts. - tmpMap := Array new:usageCounts size. - oldImage colorMap asArray keysAndValuesDo:[:i :clr | - tmpMap at:i put:clr - ]. - usageCounts sort:[:a :b | a > b] with:tmpMap. - - 1 to:(1 bitShift:depth) do:[:idx | - newColorMap at:idx put:(tmpMap at:idx) - ]. - - useNearest := Dialog - confirmWithCancel:(resources - stringWithCRs:'Image requires %1 colors.\ColorMap has only space for %2\\Use nearest (or map to first color) ?' - with:usedColors size - with:(1 bitShift:depth)) - labels:(resources array:#('Cancel' 'First' 'Nearest')). - useNearest isNil ifTrue:[ - colorMapMode value:prevMode. - ^ self "/ cancel - ]. + ^ self "/ cancel + ]. + ] ] ] ] ifFalse:[ @@ -3985,18 +3987,21 @@ ] ifFalse:[ image mask: nil. ]. - realColorMap := OrderedCollection new. - image realColorMap do:[:clr| - (realColorMap includes: clr) ifFalse: [realColorMap add: clr] + + newColorMap isFixedPalette ifFalse:[ + realColorMap := OrderedCollection new. + image realColorMap do:[:clr| + (realColorMap includes: clr) ifFalse: [realColorMap add: clr] + ]. + newColors := realColorMap copyFrom: 1 to: (newColorMap size min: realColorMap size). + newColorMap do:[:clr| + ((newColors size < newColorMap size) and: [(newColors includes: clr) not]) + ifTrue:[ + newColors add: clr + ] + ]. + image colorMap: newColors. ]. - newColors := realColorMap copyFrom: 1 to: (newColorMap size min: realColorMap size). - newColorMap do:[:clr| - ((newColors size < newColorMap size) and: [(newColors includes: clr) not]) - ifTrue:[ - newColors add: clr - ] - ]. - image colorMap: newColors. image fileName: oldFileName. (imageEditView image: image) notNil ifTrue:[