2970 image depth > 12 ifTrue:[ |
2970 image depth > 12 ifTrue:[ |
2971 listOfColors removeAll. |
2971 listOfColors removeAll. |
2972 image colorMap isEmptyOrNil ifTrue:[ |
2972 image colorMap isEmptyOrNil ifTrue:[ |
2973 someOrAllUsedColors := image usedColorsMax:10000. |
2973 someOrAllUsedColors := image usedColorsMax:10000. |
2974 someOrAllUsedColors := someOrAllUsedColors asArray. |
2974 someOrAllUsedColors := someOrAllUsedColors asArray. |
2975 someOrAllUsedColors sort:[:a :b | |
2975 someOrAllUsedColors sort:self sortBlockForColors. |
2976 a redByte == b redByte ifTrue:[ |
|
2977 a greenByte == b greenByte ifTrue:[ |
|
2978 a blueByte < b blueByte |
|
2979 ] ifFalse:[ |
|
2980 a greenByte < b greenByte |
|
2981 ] |
|
2982 ] ifFalse:[ |
|
2983 a redByte < b redByte |
|
2984 ] |
|
2985 ]. |
|
2986 listOfColors addAll:someOrAllUsedColors. |
2976 listOfColors addAll:someOrAllUsedColors. |
2987 "/ listOfColors add:Color black; add:Color white. |
2977 "/ listOfColors add:Color black; add:Color white. |
2988 ] ifFalse:[ |
2978 ] ifFalse:[ |
2989 listOfColors addAll:(image colorMap). |
2979 listOfColors addAll:(image colorMap). |
2990 ]. |
2980 ]. |
3462 |
3452 |
3463 "Modified: / 10.2.2000 / 23:16:42 / cg" |
3453 "Modified: / 10.2.2000 / 23:16:42 / cg" |
3464 ! ! |
3454 ! ! |
3465 |
3455 |
3466 !ImageEditor methodsFor:'private'! |
3456 !ImageEditor methodsFor:'private'! |
|
3457 |
|
3458 sortBlockForColors |
|
3459 ^ [:a :b | |
|
3460 a redByte == b redByte ifTrue:[ |
|
3461 a greenByte == b greenByte ifTrue:[ |
|
3462 a blueByte < b blueByte |
|
3463 ] ifFalse:[ |
|
3464 a greenByte < b greenByte |
|
3465 ] |
|
3466 ] ifFalse:[ |
|
3467 a redByte < b redByte |
|
3468 ] |
|
3469 ] |
|
3470 ! |
3467 |
3471 |
3468 updateImage |
3472 updateImage |
3469 |img| |
3473 |img| |
3470 |
3474 |
3471 img := imageEditView image. |
3475 img := imageEditView image. |
4055 "/ newColorMap := Array new:usedColors size. |
4059 "/ newColorMap := Array new:usedColors size. |
4056 |
4060 |
4057 "/ translation table |
4061 "/ translation table |
4058 oldToNew := ByteArray new:(1 bitShift:depth). |
4062 oldToNew := ByteArray new:(1 bitShift:depth). |
4059 newColorMap := usedColors asArray. |
4063 newColorMap := usedColors asArray. |
4060 newColorMap sort:[:a :b | |
4064 newColorMap sort:self sortBlockForColors. |
4061 a redByte == b redByte ifTrue:[ |
|
4062 a greenByte == b greenByte ifTrue:[ |
|
4063 a blueByte < b blueByte |
|
4064 ] ifFalse:[ |
|
4065 a greenByte < b greenByte |
|
4066 ] |
|
4067 ] ifFalse:[ |
|
4068 a redByte < b redByte |
|
4069 ] |
|
4070 ]. |
|
4071 |
4065 |
4072 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
4066 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
4073 |newPixel| |
4067 |newPixel| |
4074 |
4068 |
4075 (usedColors includes:clr) ifTrue:[ |
4069 (usedColors includes:clr) ifTrue:[ |
4359 |s rndR rndG rndB usedColors image newImage| |
4353 |s rndR rndG rndB usedColors image newImage| |
4360 |
4354 |
4361 s := Dialog request:'Rounding Interval red (2..) ?' initialAnswer:4. |
4355 s := Dialog request:'Rounding Interval red (2..) ?' initialAnswer:4. |
4362 s size == 0 ifTrue:[^ self]. |
4356 s size == 0 ifTrue:[^ self]. |
4363 rndR := Integer readFrom:s onError:0. |
4357 rndR := Integer readFrom:s onError:0. |
4364 (rndR > 1) ifFalse:[ |
4358 |
4365 Dialog warn:'Image unchanged'. |
|
4366 ^ self |
|
4367 ]. |
|
4368 s := Dialog request:'Rounding Interval green (2..) ?' initialAnswer:2. |
4359 s := Dialog request:'Rounding Interval green (2..) ?' initialAnswer:2. |
4369 s size == 0 ifTrue:[^ self]. |
4360 s size == 0 ifTrue:[^ self]. |
4370 rndG := Integer readFrom:s onError:0. |
4361 rndG := Integer readFrom:s onError:0. |
4371 (rndG > 1) ifFalse:[ |
4362 |
4372 Dialog warn:'Image unchanged'. |
|
4373 ^ self |
|
4374 ]. |
|
4375 s := Dialog request:'Rounding Interval blue (2..) ?' initialAnswer:10. |
4363 s := Dialog request:'Rounding Interval blue (2..) ?' initialAnswer:10. |
4376 s size == 0 ifTrue:[^ self]. |
4364 s size == 0 ifTrue:[^ self]. |
4377 rndB := Integer readFrom:s onError:0. |
4365 rndB := Integer readFrom:s onError:0. |
4378 (rndB > 1) ifFalse:[ |
4366 |
|
4367 ((rndR > 1) or:[(rndG > 1) or:[(rndB > 1)]]) ifFalse:[ |
4379 Dialog warn:'Image unchanged'. |
4368 Dialog warn:'Image unchanged'. |
4380 ^ self |
4369 ^ self |
4381 ]. |
4370 ]. |
4382 |
4371 |
4383 self withExecuteCursorDo:[ |
4372 self withExecuteCursorDo:[ |
4450 ! |
4439 ! |
4451 |
4440 |
4452 sortColorMap |
4441 sortColorMap |
4453 "calculates a new color map for the image, sorting colors" |
4442 "calculates a new color map for the image, sorting colors" |
4454 |
4443 |
|
4444 self |
|
4445 sortColorMapWith:self sortBlockForColors |
|
4446 ! |
|
4447 |
|
4448 sortColorMapWith:sortBlock |
|
4449 "calculates a new color map for the image, sorting colors" |
|
4450 |
4455 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
4451 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
4456 |
4452 |
4457 oldImage := self image. |
4453 oldImage := self image. |
4458 depth := oldImage depth. |
4454 depth := oldImage depth. |
4459 |
4455 |
4470 "/ newColorMap := Array new:usedColors size. |
4466 "/ newColorMap := Array new:usedColors size. |
4471 |
4467 |
4472 "/ translation table |
4468 "/ translation table |
4473 oldToNew := ByteArray new:(1 bitShift:depth). |
4469 oldToNew := ByteArray new:(1 bitShift:depth). |
4474 newColorMap := usedColors asArray. |
4470 newColorMap := usedColors asArray. |
4475 newColorMap sort:[:a :b | |
4471 newColorMap sort:sortBlock. |
4476 a redByte == b redByte ifTrue:[ |
|
4477 a greenByte == b greenByte ifTrue:[ |
|
4478 a blueByte < b blueByte |
|
4479 ] ifFalse:[ |
|
4480 a greenByte < b greenByte |
|
4481 ] |
|
4482 ] ifFalse:[ |
|
4483 a redByte < b redByte |
|
4484 ] |
|
4485 ]. |
|
4486 |
4472 |
4487 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
4473 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
4488 |newPixel| |
4474 |newPixel| |
4489 |
4475 |
4490 (usedColors includes:clr) ifTrue:[ |
4476 (usedColors includes:clr) ifTrue:[ |