ImageEditor.st
changeset 3227 2dbc0662a8c7
parent 3224 98a659b6bd10
child 3230 e6d7ba2e0384
equal deleted inserted replaced
3226:cd187ade19da 3227:2dbc0662a8c7
     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
  5396 "/        newImage photometric:oldImage photometric.
  5394 "/        newImage photometric:oldImage photometric.
  5397 
  5395 
  5398         oldFileName := oldImage fileName.
  5396         oldFileName := oldImage fileName.
  5399 
  5397 
  5400         Image imageErrorSignal handle:[:ex|
  5398         Image imageErrorSignal handle:[:ex|
       
  5399             "/ arrive here only if not all colors can be represented;
       
  5400             "/ then do a more expensive nearest color search
  5401             Color colorErrorSignal handle:[:ex|
  5401             Color colorErrorSignal handle:[:ex|
  5402                 colorMapMode value:prevMode.
  5402                 colorMapMode value:prevMode.
  5403                 imageEditView undo.
  5403                 imageEditView undo.
  5404                 ^ self warn:(resources string:'Conversion failed !!')
  5404                 ^ self warn:(resources string:'Conversion failed !!')
  5405             ] do:[
  5405             ] do:[
  5409                     colorMap:newColorMap;
  5409                     colorMap:newColorMap;
  5410                     photometric:#palette;
  5410                     photometric:#palette;
  5411                     bits:(ByteArray new:(newImage bytesPerRow * newImage height));
  5411                     bits:(ByteArray new:(newImage bytesPerRow * newImage height));
  5412                     mask:oldImage mask.
  5412                     mask:oldImage mask.
  5413 
  5413 
  5414                 oldImage colorsFromX:0 y:0 toX:(oldImage width-1) y:(oldImage height-1) do:
  5414                 oldImage 
  5415                 [:x :y :clr |
  5415                     colorsFromX:0 y:0 
  5416                     |newColor|
  5416                     toX:(oldImage width-1) y:(oldImage height-1) 
  5417 
  5417                     do:[:x :y :clr |
  5418                     (newColorMap includes:clr)
  5418                         |newColor|
  5419                         ifTrue: [newColor := clr]
  5419 
  5420                         ifFalse: [
  5420                         (newColorMap includes:clr)
  5421                             newColor := clr nearestIn:newColorMap.
  5421                             ifTrue: [newColor := clr]
  5422                             useNearest ifFalse:[
  5422                             ifFalse: [
  5423                                 (newColor deltaFrom:clr) > 0.5 ifTrue:[
  5423                                 newColor := clr nearestIn:newColorMap.
  5424                                     newColor := oldImage colorFromValue:0
  5424                                 useNearest ifFalse:[
       
  5425                                     (newColor deltaFrom:clr) > 0.5 ifTrue:[
       
  5426                                         newColor := oldImage colorFromValue:0
       
  5427                                     ]
  5425                                 ]
  5428                                 ]
  5426                             ]
  5429                             ].
  5427                         ].
  5430                         newImage colorAtX:x y:y put:newColor.
  5428                     newImage colorAtX:x y:y put:newColor.
  5431                     ].
  5429                 ].
  5432                 
  5430                 image := newImage
  5433                 image := newImage
  5431             ].
  5434             ].
  5432         ] do:[ 
  5435         ] do:[ 
  5433             image := newImage fromImage:oldImage photometric:newImage photometric.
  5436             image := newImage fromImage:oldImage photometric:oldImage photometric.
  5434         ].
  5437         ].
  5435 
  5438 
  5436         (aMode asString startsWith:'mask') ifTrue:[
  5439         (aMode asString startsWith:'mask') ifTrue:[
  5437             image mask isNil ifTrue:[
  5440             image mask isNil ifTrue:[
  5438                 false "(Dialog confirm:'Generate mask from black ?' default:false)" ifTrue:[
  5441                 false "(Dialog confirm:'Generate mask from black ?' default:false)" ifTrue:[