ImageEditor.st
changeset 2893 feb4eeba44ad
parent 2884 b24f5e13e650
child 2932 7f305ee14e98
equal deleted inserted replaced
2892:a1349bc5e2fe 2893:feb4eeba44ad
  5109 !
  5109 !
  5110 
  5110 
  5111 compressColorMap
  5111 compressColorMap
  5112     "calculates a new color map for the image, using only used colors"
  5112     "calculates a new color map for the image, using only used colors"
  5113 
  5113 
  5114     |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| 
  5114     |newImage| 
  5115 
  5115 
  5116     oldImage := self image.
  5116     newImage := self image.
  5117     depth := oldImage depth.
  5117     newImage compressColorMap.
  5118 
       
  5119     usedColors := oldImage realUsedColors.
       
  5120 
       
  5121     "/ translation table
       
  5122     oldToNew := ByteArray new:(1 bitShift:depth).
       
  5123     newColorMap := usedColors asArray.
       
  5124     newColorMap sort:self sortBlockForColors.
       
  5125     oldImage colorMap notNil ifTrue:[
       
  5126         oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
       
  5127             |newPixel|
       
  5128 
       
  5129             (usedColors includes:clr) ifTrue:[
       
  5130                 newPixel := newColorMap indexOf:clr.
       
  5131                 oldToNew at:oldIdx put:newPixel-1.
       
  5132             ]
       
  5133         ].
       
  5134     ].
       
  5135 
       
  5136     oldBits := oldImage bits.
       
  5137     newBits := ByteArray new:(oldBits size).
       
  5138     depth ~~ 8 ifTrue:[
       
  5139         "/ expand/compress can only handle 8bits
       
  5140         tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
       
  5141         oldBits
       
  5142             expandPixels:depth
       
  5143             width:oldImage width
       
  5144             height:oldImage height 
       
  5145             into:tmpBits
       
  5146             mapping:oldToNew.
       
  5147         tmpBits
       
  5148             compressPixels:depth 
       
  5149             width:oldImage width 
       
  5150             height:oldImage height 
       
  5151             into:newBits 
       
  5152             mapping:nil
       
  5153     ] ifFalse:[
       
  5154         oldBits
       
  5155             expandPixels:depth
       
  5156             width:oldImage width
       
  5157             height:oldImage height 
       
  5158             into:newBits
       
  5159             mapping:oldToNew.
       
  5160     ].
       
  5161 
       
  5162     newImage := oldImage species new
       
  5163                     width:oldImage width
       
  5164                     height:oldImage height
       
  5165                     depth:depth
       
  5166                     fromArray:newBits.
       
  5167 
       
  5168     newImage colorMap:newColorMap.  
       
  5169     newImage fileName:oldImage fileName.
       
  5170     newImage mask:(oldImage mask copy).
       
  5171 
  5118 
  5172     (imageEditView image:newImage) notNil ifTrue:[
  5119     (imageEditView image:newImage) notNil ifTrue:[
  5173         self fetchImageData.
  5120         self fetchImageData.
  5174     ]
  5121     ]
  5175 
       
  5176     "Created: / 28.7.1998 / 20:03:11 / cg"
       
  5177     "Modified: / 15.9.1998 / 17:53:32 / cg"
       
  5178 !
  5122 !
  5179 
  5123 
  5180 copyColorFromColormap
  5124 copyColorFromColormap
  5181     imageEditView setClipboardObject:(self selectedColorOrNil)
  5125     imageEditView setClipboardObject:(self selectedColorOrNil)
  5182 !
  5126 !
  5421 !
  5365 !
  5422 
  5366 
  5423 menu_compressColorMap
  5367 menu_compressColorMap
  5424     "calculates a new color map for the image, using only used colors"
  5368     "calculates a new color map for the image, using only used colors"
  5425 
  5369 
  5426     |depth oldImage usedColors| 
  5370     |depth oldImage usedColors colorMap| 
  5427 
  5371 
  5428     oldImage := self image.
  5372     oldImage := self image.
  5429     depth := oldImage depth.
       
  5430 
  5373 
  5431     oldImage photometric ~~ #palette ifTrue:[
  5374     oldImage photometric ~~ #palette ifTrue:[
  5432         self information:'Compress colorMap: Only palette images have colormaps.'.
  5375         self information:'Compress colorMap: Only palette images have colormaps.'.
  5433         ^ self
  5376         ^ self
  5434     ].
  5377     ].
       
  5378     depth := oldImage depth.
       
  5379     colorMap := oldImage colorMap asArray asSet.
  5435     usedColors := oldImage realUsedColors.
  5380     usedColors := oldImage realUsedColors.
  5436     usedColors size == (1 bitShift:depth) ifTrue:[
  5381     usedColors size == colorMap size ifTrue:[
  5437         self information:'Compress colorMap: All colors are used - no compression.'.
       
  5438         ^ self
       
  5439     ].
       
  5440     usedColors size == oldImage colorMap size ifTrue:[
       
  5441         self information:'Compress colorMap: Colormap already compressed - no compression.'.
  5382         self information:'Compress colorMap: Colormap already compressed - no compression.'.
  5442         ^ self
  5383         ^ self
  5443     ].
  5384     ].
  5444 
  5385 
  5445     imageEditView makeUndo.
  5386     imageEditView makeUndo.