4637 |
4637 |
4638 "Created: / 07-07-2006 / 13:22:10 / cg" |
4638 "Created: / 07-07-2006 / 13:22:10 / cg" |
4639 ! |
4639 ! |
4640 |
4640 |
4641 ditherToDepth:depth |
4641 ditherToDepth:depth |
4642 |ditherColors newImage| |
4642 |ditherColors newImage useStandardColors nGrey greyColorsAlready additionalGreyColors moreColors d| |
4643 |
4643 |
4644 depth = 1 ifTrue:[ |
4644 useStandardColors := true. |
4645 ditherColors := Array with:(Color black) with:(Color white). |
4645 "/ useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'. |
4646 ] ifFalse:[ depth = 2 ifTrue:[ |
4646 "/ useStandardColors isNil ifTrue:[^ self]. |
4647 ditherColors := Array |
4647 |
4648 with:(Color black) |
4648 useStandardColors ifTrue:[ |
4649 with:(Color darkGrey) |
4649 depth = 1 ifTrue:[ |
4650 with:(Color lightGrey) |
4650 ditherColors := Array with:(Color black) with:(Color white). |
4651 with:(Color white). |
4651 ] ifFalse:[ depth = 2 ifTrue:[ |
4652 ] ifFalse:[ depth = 3 ifTrue:[ |
4652 ditherColors := Array |
4653 ditherColors := Color colorCubeWithRed:2 green:2 blue:2. |
4653 with:(Color black) |
4654 ] ifFalse:[ depth = 4 ifTrue:[ |
4654 with:(Color darkGrey) |
4655 ditherColors := Color vgaColors. |
4655 with:(Color lightGrey) |
4656 ] ifFalse:[ depth = 5 ifTrue:[ |
4656 with:(Color white). |
4657 ditherColors := Color colorCubeWithRed:4 green:4 blue:2. |
4657 ] ifFalse:[ depth = 3 ifTrue:[ |
4658 ] ifFalse:[ depth = 5 ifTrue:[ |
4658 ditherColors := Color colorCubeWithRed:2 green:2 blue:2. |
4659 ditherColors := Color colorCubeWithRed:4 green:4 blue:3. |
4659 ] ifFalse:[ depth = 4 ifTrue:[ |
4660 ] ifFalse:[ depth <= 8 ifTrue:[ |
4660 ditherColors := Color vgaColors. |
4661 ditherColors := Color colorCubeWithRed:6 green:6 blue:5. |
4661 ] ifFalse:[ depth = 5 ifTrue:[ |
4662 ] ifFalse:[ |
4662 ditherColors := Color colorCubeWithRed:4 green:4 blue:2. |
4663 self error:'unsupported depth'. |
4663 ] ifFalse:[ depth = 6 ifTrue:[ |
4664 ]]]]]]]. |
4664 ditherColors := Color colorCubeWithRed:4 green:4 blue:3. |
|
4665 ] ifFalse:[ depth <= 8 ifTrue:[ |
|
4666 ditherColors := Color colorCubeWithRed:6 green:6 blue:5. |
|
4667 ] ifFalse:[ |
|
4668 self error:'unsupported depth'. |
|
4669 ]]]]]]]. |
|
4670 |
|
4671 nGrey := (2 raisedTo:depth) - ditherColors size. |
|
4672 nGrey > 0 ifTrue:[ |
|
4673 nGrey := nGrey min:128. |
|
4674 greyColorsAlready := ditherColors select:[:clr | clr isGreyColor]. |
|
4675 d := 1 / nGrey. |
|
4676 moreColors := (1 to:nGrey-1) |
|
4677 collect:[:i | Color brightness:(d * i)] |
|
4678 thenReject:[:clr | greyColorsAlready includes:clr ]. |
|
4679 |
|
4680 ditherColors := ditherColors , moreColors. |
|
4681 ]. |
|
4682 ] ifFalse:[ |
|
4683 self halt. |
|
4684 ]. |
4665 |
4685 |
4666 self withExecuteCursorDo:[ |
4686 self withExecuteCursorDo:[ |
|
4687 "/ newImage := self image asDitheredImageUsing:ditherColors depth:depth. |
4667 newImage := self image asDitheredImageUsing:ditherColors depth:8. |
4688 newImage := self image asDitheredImageUsing:ditherColors depth:8. |
4668 |
4689 |
4669 imageEditView makeUndo. |
4690 imageEditView makeUndo. |
4670 imageEditView image:newImage. |
4691 imageEditView image:newImage. |
4671 imageEditView setModified. |
4692 imageEditView setModified. |