ImageEditor.st
changeset 1900 41ba86fb1087
parent 1899 f7d3fd244804
child 1904 46a0b109cb47
equal deleted inserted replaced
1899:f7d3fd244804 1900:41ba86fb1087
  1406                                       miniScrollerHorizontal: true
  1406                                       miniScrollerHorizontal: true
  1407                                       miniScrollerVertical: true
  1407                                       miniScrollerVertical: true
  1408                                       dataList: listOfColors
  1408                                       dataList: listOfColors
  1409                                       has3Dsepartors: true
  1409                                       has3Dsepartors: true
  1410                                       has3Dseparators: true
  1410                                       has3Dseparators: true
  1411                                       columnHolder: tableColumns
  1411                                       columnHolder: colorTableColumns
  1412                                       verticalSpacing: 1
  1412                                       verticalSpacing: 1
  1413                                       columns: 
  1413 "/                                      columns: 
  1414                                      (OrderedCollection
  1414 "/                                     (OrderedCollection
  1415                                         
  1415 "/                                        
  1416                                        (DataSetColumnSpec
  1416 "/                                       (DataSetColumnSpec
  1417                                           labelButtonType: Button
  1417 "/                                          labelButtonType: Button
  1418                                           rendererType: rowSelector
  1418 "/                                          rendererType: rowSelector
  1419                                           backgroundSelector: theColorItSelf:
  1419 "/                                          backgroundSelector: theColorItSelf:
  1420                                         ) 
  1420 "/                                        ) 
  1421                                        (DataSetColumnSpec
  1421 "/                                       (DataSetColumnSpec
  1422                                           label: 'R'
  1422 "/                                          label: 'R'
  1423                                           labelAlignment: left
  1423 "/                                          labelAlignment: left
  1424                                           labelButtonType: Button
  1424 "/                                          labelButtonType: Button
  1425                                           columnAlignment: right
  1425 "/                                          columnAlignment: right
  1426                                           editorType: InputField
  1426 "/                                          editorType: InputField
  1427                                           type: number
  1427 "/                                          type: number
  1428                                           model: redFromColor:
  1428 "/                                          model: redFromColor:
  1429                                           writeSelector: redAtColor:put:
  1429 "/                                          writeSelector: redAtColor:put:
  1430                                           selectSelector: canSelectRedInColor:
  1430 "/                                          selectSelector: canSelectRedInColor:
  1431                                         )
  1431 "/                                        )
  1432                                         
  1432 "/                                        
  1433                                        (DataSetColumnSpec
  1433 "/                                       (DataSetColumnSpec
  1434                                           label: 'G'
  1434 "/                                          label: 'G'
  1435                                           labelAlignment: left
  1435 "/                                          labelAlignment: left
  1436                                           labelButtonType: Button
  1436 "/                                          labelButtonType: Button
  1437                                           columnAlignment: right
  1437 "/                                          columnAlignment: right
  1438                                           editorType: InputField
  1438 "/                                          editorType: InputField
  1439                                           type: number
  1439 "/                                          type: number
  1440                                           model: greenFromColor:
  1440 "/                                          model: greenFromColor:
  1441                                           writeSelector: greenAtColor:put:
  1441 "/                                          writeSelector: greenAtColor:put:
  1442                                           selectSelector: canSelectGreenInColor:
  1442 "/                                          selectSelector: canSelectGreenInColor:
  1443                                         ) 
  1443 "/                                        ) 
  1444                                        (DataSetColumnSpec
  1444 "/                                       (DataSetColumnSpec
  1445                                           label: 'B'
  1445 "/                                          label: 'B'
  1446                                           labelAlignment: left
  1446 "/                                          labelAlignment: left
  1447                                           labelButtonType: Button
  1447 "/                                          labelButtonType: Button
  1448                                           columnAlignment: right
  1448 "/                                          columnAlignment: right
  1449                                           editorType: InputField
  1449 "/                                          editorType: InputField
  1450                                           type: number
  1450 "/                                          type: number
  1451                                           model: blueFromColor:
  1451 "/                                          model: blueFromColor:
  1452                                           writeSelector: blueAtColor:put:
  1452 "/                                          writeSelector: blueAtColor:put:
  1453                                           selectSelector: canSelectBlueInColor:
  1453 "/                                          selectSelector: canSelectBlueInColor:
  1454                                         )
  1454 "/                                        )
  1455                                       )
  1455 "/                                      )
  1456                                       columnAdaptor: colorColumnAdaptor
  1456                                       columnAdaptor: colorColumnAdaptor
  1457                                     )
  1457                                     )
  1458                                    )
  1458                                    )
  1459                                  
  1459                                  
  1460                                 )
  1460                                 )
  2635       )
  2635       )
  2636 ! !
  2636 ! !
  2637 
  2637 
  2638 !ImageEditor class methodsFor:'tableColumns specs'!
  2638 !ImageEditor class methodsFor:'tableColumns specs'!
  2639 
  2639 
  2640 tableColumns
  2640 colorTableColumns
  2641     "This resource specification was automatically generated
  2641     "This resource specification was automatically generated
  2642      by the DataSetBuilder of ST/X."
  2642      by the DataSetBuilder of ST/X."
  2643 
  2643 
  2644     "Do not manually edit this!! If it is corrupted,
  2644     "Do not manually edit this!! If it is corrupted,
  2645      the DataSetBuilder may not be able to read the specification."
  2645      the DataSetBuilder may not be able to read the specification."
  2690          model: blueFromColor:
  2690          model: blueFromColor:
  2691          writeSelector: blueAtColor:put:
  2691          writeSelector: blueAtColor:put:
  2692          selectSelector: canSelectBlueInColor:
  2692          selectSelector: canSelectBlueInColor:
  2693        )
  2693        )
  2694       )
  2694       )
  2695     
       
  2696 ! !
  2695 ! !
  2697 
  2696 
  2698 !ImageEditor methodsFor:'accessing'!
  2697 !ImageEditor methodsFor:'accessing'!
  2699 
  2698 
  2700 image
  2699 image
  2914     ].                               
  2913     ].                               
  2915     imageEditView drawingColors:(Array
  2914     imageEditView drawingColors:(Array
  2916                                     with: (listOfColors at:1) 
  2915                                     with: (listOfColors at:1) 
  2917                                     with: (listOfColors at:2 ifAbsent:[listOfColors at:1])).
  2916                                     with: (listOfColors at:2 ifAbsent:[listOfColors at:1])).
  2918 
  2917 
  2919     self hasMask "image mask" notNil ifTrue: [             
  2918     self hasMask ifTrue: [             
  2920         (listOfColors contains: [:clr| clr = (Color colorId:0)]) 
  2919         (listOfColors contains: [:clr| clr = (Color colorId:0)]) 
  2921         ifFalse:[
  2920         ifFalse:[
  2922             listOfColors addFirst:(Color colorId:0).
  2921             listOfColors addFirst:(Color colorId:0).
  2923             imageEditView drawingColors: (Array 
  2922             imageEditView drawingColors: (Array 
  2924                                             with: (listOfColors at:2) 
  2923                                             with: (listOfColors at:2) 
  3025     super update:something with:aParameter from:changedObject
  3024     super update:something with:aParameter from:changedObject
  3026 
  3025 
  3027     "Modified: / 10.2.2000 / 23:36:49 / cg"
  3026     "Modified: / 10.2.2000 / 23:36:49 / cg"
  3028 !
  3027 !
  3029 
  3028 
       
  3029 updateColorsFromImage:image
       
  3030     |colors|
       
  3031 
       
  3032     image colorMap notNil ifTrue:[
       
  3033         colors := image colorMap asOrderedCollection.
       
  3034     ] ifFalse:[
       
  3035         colors := image usedColors asSet asOrderedCollection.
       
  3036     ].
       
  3037     self listOfColors contents:colors.
       
  3038 !
       
  3039 
  3030 updateForNoImage
  3040 updateForNoImage
  3031     "updates channels and view, if image is loaded"
  3041     "updates channels and view, if image is loaded"
  3032 
  3042 
  3033     self imageIsLoaded value: false.
  3043     self imageIsLoaded value: false.
  3034     self listOfColors removeAll.
  3044     self listOfColors removeAll.
  3222     |img|
  3232     |img|
  3223 
  3233 
  3224     self withCursor:Cursor wait do:[
  3234     self withCursor:Cursor wait do:[
  3225         (imageEditView loadFromFile: aFileName) notNil ifTrue:[
  3235         (imageEditView loadFromFile: aFileName) notNil ifTrue:[
  3226             (img := self image) notNil ifTrue:[          
  3236             (img := self image) notNil ifTrue:[          
  3227                 img colorMap notNil ifTrue:[
  3237                 self updateColorsFromImage:img.
  3228                     self listOfColors contents:(img usedColors asSet asOrderedCollection).
       
  3229                 ] ifFalse:[
       
  3230                     self listOfColors removeAll.
       
  3231                 ].
       
  3232                 self findColorMapMode.     
  3238                 self findColorMapMode.     
  3233                 self updateLabelsAndHistory.
  3239                 self updateLabelsAndHistory.
  3234                 img := img onDevice:device.
  3240                 img := img onDevice:device.
  3235                 imageEditView image:img.
  3241                 imageEditView image:img.
  3236             ] ifFalse:[
  3242             ] ifFalse:[
  3253 
  3259 
  3254     imageEditView image:img.
  3260     imageEditView image:img.
  3255     imageEditView clearModified.
  3261     imageEditView clearModified.
  3256 
  3262 
  3257     img notNil ifTrue:[    
  3263     img notNil ifTrue:[    
  3258         img colorMap notNil ifTrue:[
  3264         self updateColorsFromImage:img.
  3259             self listOfColors contents:(img usedColors asSet asOrderedCollection).
       
  3260         ] ifFalse:[
       
  3261             self listOfColors removeAll.
       
  3262         ].
       
  3263         self findColorMapMode.
  3265         self findColorMapMode.
  3264         self updateLabelsAndHistory.
  3266         self updateLabelsAndHistory.
  3265     ] ifFalse:[
  3267     ] ifFalse:[
  3266         self updateForNoImage
  3268         self updateForNoImage
  3267     ]
  3269     ]
  3275     |img|
  3277     |img|
  3276 
  3278 
  3277     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  3279     (imageEditView loadFromMessage: aMessage) notNil ifTrue:[
  3278         (img := self image) notNil ifTrue:[
  3280         (img := self image) notNil ifTrue:[
  3279             img := img onDevice:device.
  3281             img := img onDevice:device.
  3280             img colorMap isNil ifTrue:[
  3282             self updateColorsFromImage:img.
  3281                 self listOfColors contents:(img usedColors asSet asOrderedCollection).
       
  3282             ].
       
  3283 "/            self findColorMapMode.
       
  3284             self updateLabelsAndHistory.
  3283             self updateLabelsAndHistory.
  3285             "/ imageEditView image:img.
       
  3286         ] ifFalse:[
  3284         ] ifFalse:[
  3287             self updateForNoImage
  3285             self updateForNoImage
  3288         ]
  3286         ]
  3289     ]
  3287     ]
  3290 
  3288 
  3294 loadFromOrPrepareForMessage: aMessage
  3292 loadFromOrPrepareForMessage: aMessage
  3295     "loads an image by evaluating aMessage;
  3293     "loads an image by evaluating aMessage;
  3296      if no image could extract from aMessage; do set the class and the selector from 
  3294      if no image could extract from aMessage; do set the class and the selector from 
  3297      the aMessage for a saving at the end of editing"
  3295      the aMessage for a saving at the end of editing"
  3298 
  3296 
  3299     (imageEditView loadFromMessage: aMessage) notNil
  3297     (imageEditView loadFromMessage: aMessage) notNil ifTrue: [
  3300     ifTrue: [
  3298         self updateColorsFromImage:self image.
  3301         self listOfColors contents: self image usedColors asSet asOrderedCollection.
       
  3302         self findColorMapMode.
  3299         self findColorMapMode.
  3303     ] ifFalse: [
  3300     ] ifFalse: [
  3304         imageEditView resourceMessage: aMessage.
  3301         imageEditView resourceMessage: aMessage.
  3305     ].
  3302     ].
  3306     self updateLabelsAndHistory.
  3303     self updateLabelsAndHistory.
  3878         image colorMap: newColors.   
  3875         image colorMap: newColors.   
  3879         image fileName: oldFileName.
  3876         image fileName: oldFileName.
  3880 
  3877 
  3881         (imageEditView image: image) notNil ifTrue:[
  3878         (imageEditView image: image) notNil ifTrue:[
  3882             self fetchImageData.
  3879             self fetchImageData.
  3883 "/            self listOfColors contents: image colorMap.
       
  3884 "/            self findColorMapMode.
       
  3885 "/            self updateLabelsAndHistory.
       
  3886         ]
  3880         ]
  3887     ]
  3881     ]
  3888 
  3882 
  3889     "Modified: / 16.3.1999 / 21:55:39 / cg"
  3883     "Modified: / 16.3.1999 / 21:55:39 / cg"
  3890 !
  3884 !
  3980         newImage mask:(oldImage mask copy).
  3974         newImage mask:(oldImage mask copy).
  3981 
  3975 
  3982         (imageEditView image:newImage) notNil ifTrue:
  3976         (imageEditView image:newImage) notNil ifTrue:
  3983         [
  3977         [
  3984             self fetchImageData.
  3978             self fetchImageData.
  3985 "/            self listOfColors contents: newImage colorMap.
       
  3986 "/            self findColorMapMode.
       
  3987 "/            self updateLabelsAndHistory.
       
  3988         ]
  3979         ]
  3989     ]
  3980     ]
  3990 
  3981 
  3991     "Created: / 28.7.1998 / 20:03:11 / cg"
  3982     "Created: / 28.7.1998 / 20:03:11 / cg"
  3992     "Modified: / 15.9.1998 / 17:53:32 / cg"
  3983     "Modified: / 15.9.1998 / 17:53:32 / cg"
  4205         ] ifTrue:[
  4196         ] ifTrue:[
  4206             img := imageEditView image.
  4197             img := imageEditView image.
  4207             imageEditView image:img.
  4198             imageEditView image:img.
  4208 
  4199 
  4209             self fetchImageData.
  4200             self fetchImageData.
  4210 "/            self listOfColors contents:(img colorMap).
       
  4211 "/            self findColorMapMode.
       
  4212 "/            self updateLabelsAndHistory.
       
  4213             usedColors := img usedColorsMax:10000.
  4201             usedColors := img usedColorsMax:10000.
  4214             usedColors size == 10000 ifTrue:[
  4202             usedColors size == 10000 ifTrue:[
  4215                 Dialog information:('>= ' , usedColors size printString , ' colors used.')
  4203                 Dialog information:('>= ' , usedColors size printString , ' colors used.')
  4216             ] ifFalse:[
  4204             ] ifFalse:[
  4217                 Dialog information:(usedColors size printString , ' colors used.')
  4205                 Dialog information:(usedColors size printString , ' colors used.')
  4238 
  4226 
  4239 selectedColorOrNil
  4227 selectedColorOrNil
  4240     |cmapIndex img cMap|
  4228     |cmapIndex img cMap|
  4241 
  4229 
  4242     cmapIndex := self selectedColorIndexOrNil.
  4230     cmapIndex := self selectedColorIndexOrNil.
  4243     cmapIndex isNil ifTrue:[^ self].
  4231     cmapIndex isNil ifTrue:[^ nil].
  4244 
  4232 
  4245     img := self image.
  4233     img := self image.
  4246     cMap := img colorMap.
  4234     cMap := img colorMap.
  4247     cMap isNil ifTrue:[
  4235     cMap isNil ifTrue:[
  4248         self warn:('Image has no colormap.\Please change the colorMap mode first.' withCRs).
  4236         self warn:('Image has no colormap.\Please change the colorMap mode first.' withCRs).
  4249         ^ self
  4237         ^ nil
  4250     ].
  4238     ].
  4251     ^ cMap at:cmapIndex.
  4239     ^ cMap at:cmapIndex.
  4252 !
  4240 !
  4253 
  4241 
  4254 sortColorMap
  4242 sortColorMap
  4331         newImage fileName:oldImage fileName.
  4319         newImage fileName:oldImage fileName.
  4332         newImage mask:(oldImage mask copy).
  4320         newImage mask:(oldImage mask copy).
  4333 
  4321 
  4334         (imageEditView image:newImage) notNil ifTrue:[
  4322         (imageEditView image:newImage) notNil ifTrue:[
  4335             self fetchImageData.
  4323             self fetchImageData.
  4336 "/            self listOfColors contents: newImage colorMap.
       
  4337 "/            self findColorMapMode.
       
  4338 "/            self updateLabelsAndHistory.
       
  4339         ]
  4324         ]
  4340     ]
  4325     ]
  4341 
  4326 
  4342     "Modified: / 15.9.1998 / 17:53:32 / cg"
  4327     "Modified: / 15.9.1998 / 17:53:32 / cg"
  4343     "Created: / 30.9.1998 / 23:51:23 / cg"
  4328     "Created: / 30.9.1998 / 23:51:23 / cg"
  4729     |img|
  4714     |img|
  4730 
  4715 
  4731     (imageEditView loadFromClass) notNil ifTrue:[
  4716     (imageEditView loadFromClass) notNil ifTrue:[
  4732         imageSeqNr := nil.
  4717         imageSeqNr := nil.
  4733         (img := self image) notNil ifTrue: [
  4718         (img := self image) notNil ifTrue: [
  4734             self listOfColors contents: img usedColors asSet asOrderedCollection.
  4719             self updateColorsFromImage:img.
  4735             self findColorMapMode.
  4720             self findColorMapMode.
  4736             self updateLabelsAndHistory.
  4721             self updateLabelsAndHistory.
  4737         ] ifFalse: [
  4722         ] ifFalse: [
  4738             self updateForNoImage
  4723             self updateForNoImage
  4739         ].
  4724         ].
  4821 
  4806 
  4822     image := imageEditView clipBoard.
  4807     image := imageEditView clipBoard.
  4823 
  4808 
  4824     (imageEditView image:image) notNil
  4809     (imageEditView image:image) notNil
  4825     ifTrue:[
  4810     ifTrue:[
  4826         self listOfColors contents:(image colorMap).
  4811         self updateColorsFromImage:image.
  4827         self findColorMapMode.
  4812         self findColorMapMode.
  4828         self updateLabelsAndHistory.
  4813         self updateLabelsAndHistory.
  4829     ]
  4814     ]
  4830 !
  4815 !
  4831 
  4816