ImageEditor.st
changeset 3830 bf667c58b12e
parent 3811 1c02ea1990b5
child 3832 13ecc96c64fd
equal deleted inserted replaced
3829:7a5b398e1316 3830:bf667c58b12e
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1997-1998 by eXept Software AG
     2  COPYRIGHT (c) 1997-1998 by eXept Software AG
     5               All Rights Reserved
     3               All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
  5841     resourceClass notNil ifTrue:[
  5839     resourceClass notNil ifTrue:[
  5842         resourceSelector := imageEditView resourceSelector.
  5840         resourceSelector := imageEditView resourceSelector.
  5843         resourceSelector notNil ifTrue:[
  5841         resourceSelector notNil ifTrue:[
  5844             ^ resources 
  5842             ^ resources 
  5845                     string:(self modified 
  5843                     string:(self modified 
  5846                             ifTrue:['ImageEditor (modified): %1 » %2']
  5844                             ifTrue:['ImageEditor (modified): %1 » %2']
  5847                             ifFalse:['ImageEditor: %1 » %2'])
  5845                             ifFalse:['ImageEditor: %1 » %2'])
  5848                     with:resourceClass name
  5846                     with:resourceClass name
  5849                     with:resourceSelector
  5847                     with:resourceSelector
  5850         ].
  5848         ].
  5851     ].
  5849     ].
  5852     
  5850     
  5875     resourceClass notNil ifTrue:[
  5873     resourceClass notNil ifTrue:[
  5876         resourceSelector := imageEditView resourceSelector.
  5874         resourceSelector := imageEditView resourceSelector.
  5877         resourceSelector notNil ifTrue:[
  5875         resourceSelector notNil ifTrue:[
  5878             ^ resources 
  5876             ^ resources 
  5879                     string:(self modified 
  5877                     string:(self modified 
  5880                             ifTrue:['Image (modified) from: %1 » %2']
  5878                             ifTrue:['Image (modified) from: %1 » %2']
  5881                             ifFalse:['Image from: %1 » %2'])
  5879                             ifFalse:['Image from: %1 » %2'])
  5882                     with:resourceClass name
  5880                     with:resourceClass name
  5883                     with:resourceSelector
  5881                     with:resourceSelector
  5884         ].
  5882         ].
  5885     ].
  5883     ].
  5886     
  5884     
  7017      (if depth is smaller)"
  7015      (if depth is smaller)"
  7018 
  7016 
  7019     |depth numColors newColorMap newImage 
  7017     |depth numColors newColorMap newImage 
  7020      oldImage image newColors realColorMap oldFileName
  7018      oldImage image newColors realColorMap oldFileName
  7021      usedColors useNearest usageCounts tmpBits tmpMap quest
  7019      usedColors useNearest usageCounts tmpBits tmpMap quest
  7022      prevMode maskThreshold maskImage| 
  7020      prevMode maskThreshold maskImage oldColors| 
  7023 
  7021 
  7024     oldImage := self image.
  7022     oldImage := self image.
  7025 
  7023 
  7026     "/ rubbish; the mode is already changed
  7024     "/ rubbish; the mode is already changed
  7027     "/ prevMode := colorMapMode value.
  7025     "/ prevMode := colorMapMode value.
  7108     "/                            ^ self.
  7106     "/                            ^ self.
  7109                             ]
  7107                             ]
  7110                         ].
  7108                         ].
  7111                         usageCounts := tmpBits usageCounts.
  7109                         usageCounts := tmpBits usageCounts.
  7112                         tmpMap := Array new:usageCounts size.
  7110                         tmpMap := Array new:usageCounts size.
  7113                         oldImage colorMap asArray keysAndValuesDo:[:i :clr |
  7111                         oldColors := oldImage colorMap asArray.
  7114                             tmpMap at:i put:clr
  7112                         "/ sigh: there seem to be images around where the cmap has more entries
       
  7113                         "/ than expected (i.e. 257 colors in an 8 bit image)
       
  7114                         oldColors keysAndValuesDo:[:i :clr |
       
  7115                             i <= tmpMap size ifTrue:[
       
  7116                                 tmpMap at:i put:clr
       
  7117                             ]
  7115                         ].
  7118                         ].
  7116                         usageCounts sort:[:a :b | a > b] with:tmpMap.
  7119                         usageCounts sort:[:a :b | a > b] with:tmpMap.
  7117 
  7120 
  7118                         1 to:(1 bitShift:depth) do:[:idx |
  7121                         1 to:(1 bitShift:depth) do:[:idx |
  7119                             newColorMap at:idx put:(tmpMap at:idx)
  7122                             newColorMap at:idx put:(tmpMap at:idx)