1954 ( |
1954 ( |
1955 (MenuItem |
1955 (MenuItem |
1956 activeHelpKey: compressColormap |
1956 activeHelpKey: compressColormap |
1957 enabled: hasColormap |
1957 enabled: hasColormap |
1958 label: 'Compress Colormap' |
1958 label: 'Compress Colormap' |
1959 itemValue: compressColorMap |
1959 itemValue: menu_compressColorMap |
1960 translateLabel: true |
1960 translateLabel: true |
1961 ) |
1961 ) |
1962 (MenuItem |
1962 (MenuItem |
1963 enabled: hasColormap |
1963 enabled: hasColormap |
1964 label: 'Sort Colormap' |
1964 label: 'Sort Colormap' |
1965 itemValue: sortColorMap |
1965 itemValue: menu_sortColorMap |
1966 translateLabel: true |
1966 translateLabel: true |
1967 ) |
1967 ) |
1968 (MenuItem |
1968 (MenuItem |
1969 label: 'Reduce Number of Colors by Rounding...' |
1969 label: 'Reduce Number of Colors by Rounding...' |
1970 itemValue: reduceNumberOfColors2 |
1970 itemValue: reduceNumberOfColors2 |
2067 ( |
2067 ( |
2068 (MenuItem |
2068 (MenuItem |
2069 activeHelpKey: copyMask |
2069 activeHelpKey: copyMask |
2070 enabled: hasMask |
2070 enabled: hasMask |
2071 label: 'Copy Mask' |
2071 label: 'Copy Mask' |
2072 itemValue: copyMask |
2072 itemValue: menu_copyMask |
2073 translateLabel: true |
2073 translateLabel: true |
2074 ) |
2074 ) |
2075 (MenuItem |
2075 (MenuItem |
2076 activeHelpKey: pasteMask |
2076 activeHelpKey: pasteMask |
2077 enabled: hasMask |
2077 enabled: hasMask |
2078 label: 'Paste Mask' |
2078 label: 'Paste Mask' |
2079 itemValue: pasteMask |
2079 itemValue: menu_pasteMask |
2080 translateLabel: true |
2080 translateLabel: true |
2081 ) |
2081 ) |
2082 (MenuItem |
2082 (MenuItem |
2083 enabled: hasMask |
2083 enabled: hasMask |
2084 label: 'Clear Masked Pixels' |
2084 label: 'Clear Masked Pixels' |
2085 itemValue: clearMaskedPixels |
2085 itemValue: menu_clearMaskedPixels |
|
2086 translateLabel: true |
|
2087 ) |
|
2088 (MenuItem |
|
2089 enabled: hasMask |
|
2090 label: 'Clear ColormapEntry for Masked Pixels' |
|
2091 itemValue: menu_clearColormapEntry0AndMaskedPixels |
2086 translateLabel: true |
2092 translateLabel: true |
2087 ) |
2093 ) |
2088 ) |
2094 ) |
2089 nil |
2095 nil |
2090 nil |
2096 nil |
4280 self updateImage. |
4286 self updateImage. |
4281 self updateImagePreView. |
4287 self updateImagePreView. |
4282 ]. |
4288 ]. |
4283 ! |
4289 ! |
4284 |
4290 |
|
4291 clearColormapEntry0AndMaskedPixels |
|
4292 "ensure that there is a colorMap entry with 0/0/0 at position |
|
4293 0 and then clear all masked pixels (to pixelValue 0). |
|
4294 This is required for windows icons to be really transparent" |
|
4295 |
|
4296 |index colorMap| |
|
4297 |
|
4298 self compressColorMap. |
|
4299 colorMap := self image colorMap. |
|
4300 (colorMap includes:(Color black)) ifFalse:[ |
|
4301 self addColorToColormap:(Color black). |
|
4302 colorMap := self image colorMap. |
|
4303 ]. |
|
4304 index := colorMap indexOf:(Color black). |
|
4305 index == 1 ifFalse:[ |
|
4306 self sortColorMap. |
|
4307 colorMap := self image colorMap. |
|
4308 ]. |
|
4309 self clearMaskedPixels |
|
4310 ! |
|
4311 |
4285 clearMaskedPixels |
4312 clearMaskedPixels |
4286 "clear all masked pixels (to pixelValue 0)" |
4313 "clear all masked pixels (to pixelValue 0)" |
4287 |
4314 |
4288 |newImage oldImage| |
4315 |newImage| |
4289 |
4316 |
4290 oldImage := self image. |
4317 newImage := self image clearMaskedPixels. |
4291 |
4318 0 to:newImage height - 1 do:[:y | |
4292 imageEditView makeUndo. |
4319 0 to:newImage width - 1 do:[:x | |
4293 |
4320 (newImage maskAtX:x y:y) == 0 ifTrue:[ |
4294 self withExecuteCursorDo:[ |
4321 newImage pixelAtX:x y:y put:0 |
4295 newImage := oldImage clearMaskedPixels. |
|
4296 0 to:newImage height - 1 do:[:y | |
|
4297 0 to:newImage width - 1 do:[:x | |
|
4298 (newImage maskAtX:x y:y) == 0 ifTrue:[ |
|
4299 newImage pixelAtX:x y:y put:0 |
|
4300 ] |
|
4301 ] |
4322 ] |
4302 ]. |
|
4303 |
|
4304 (imageEditView image:newImage) notNil ifTrue:[ |
|
4305 self fetchImageData. |
|
4306 ] |
4323 ] |
|
4324 ]. |
|
4325 |
|
4326 (imageEditView image:newImage) notNil ifTrue:[ |
|
4327 self fetchImageData. |
4307 ] |
4328 ] |
4308 ! |
4329 ! |
4309 |
4330 |
4310 colorMapChanged |
4331 colorMapChanged |
4311 |img| |
4332 |img| |
4634 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
4655 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
4635 |
4656 |
4636 oldImage := self image. |
4657 oldImage := self image. |
4637 depth := oldImage depth. |
4658 depth := oldImage depth. |
4638 |
4659 |
4639 oldImage photometric ~~ #palette ifTrue:[ |
|
4640 self information:'Compress colorMap: Only palette images have colormaps.'. |
|
4641 ^ self |
|
4642 ]. |
|
4643 |
|
4644 usedColors := oldImage realUsedColors. |
4660 usedColors := oldImage realUsedColors. |
4645 usedColors size == (1 bitShift:depth) ifTrue:[ |
4661 |
4646 self information:'Compress colorMap: All colors are used - no compression.'. |
4662 "/ translation table |
4647 ^ self |
4663 oldToNew := ByteArray new:(1 bitShift:depth). |
4648 ]. |
4664 newColorMap := usedColors asArray. |
4649 usedColors size == oldImage colorMap size ifTrue:[ |
4665 newColorMap sort:self sortBlockForColors. |
4650 self information:'Compress colorMap: Colormap already compressed - no compression.'. |
4666 |
4651 ^ self |
4667 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
4652 ]. |
4668 |newPixel| |
4653 |
4669 |
4654 imageEditView makeUndo. |
4670 (usedColors includes:clr) ifTrue:[ |
4655 |
4671 newPixel := newColorMap indexOf:clr. |
4656 "/ self information:('Compress colorMap: %1 colors used.' bindWith:usedColors size). |
4672 oldToNew at:oldIdx put:newPixel-1. |
4657 |
|
4658 self withExecuteCursorDo:[ |
|
4659 "/ newColorMap := Array new:usedColors size. |
|
4660 |
|
4661 "/ translation table |
|
4662 oldToNew := ByteArray new:(1 bitShift:depth). |
|
4663 newColorMap := usedColors asArray. |
|
4664 newColorMap sort:self sortBlockForColors. |
|
4665 |
|
4666 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
|
4667 |newPixel| |
|
4668 |
|
4669 (usedColors includes:clr) ifTrue:[ |
|
4670 newPixel := newColorMap indexOf:clr. |
|
4671 oldToNew at:oldIdx put:newPixel-1. |
|
4672 ] |
|
4673 ]. |
|
4674 |
|
4675 oldBits := oldImage bits. |
|
4676 newBits := ByteArray new:(oldBits size). |
|
4677 depth ~~ 8 ifTrue:[ |
|
4678 "/ expand/compress can only handle 8bits |
|
4679 tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
4680 oldBits |
|
4681 expandPixels:depth |
|
4682 width:oldImage width |
|
4683 height:oldImage height |
|
4684 into:tmpBits |
|
4685 mapping:oldToNew. |
|
4686 tmpBits |
|
4687 compressPixels:depth |
|
4688 width:oldImage width |
|
4689 height:oldImage height |
|
4690 into:newBits |
|
4691 mapping:nil |
|
4692 ] ifFalse:[ |
|
4693 oldBits |
|
4694 expandPixels:depth |
|
4695 width:oldImage width |
|
4696 height:oldImage height |
|
4697 into:newBits |
|
4698 mapping:oldToNew. |
|
4699 ]. |
|
4700 |
|
4701 newImage := oldImage species new |
|
4702 width:oldImage width |
|
4703 height:oldImage height |
|
4704 depth:depth |
|
4705 fromArray:newBits. |
|
4706 |
|
4707 newImage colorMap:newColorMap. |
|
4708 newImage fileName:oldImage fileName. |
|
4709 newImage mask:(oldImage mask copy). |
|
4710 |
|
4711 (imageEditView image:newImage) notNil ifTrue: |
|
4712 [ |
|
4713 self fetchImageData. |
|
4714 ] |
4673 ] |
|
4674 ]. |
|
4675 |
|
4676 oldBits := oldImage bits. |
|
4677 newBits := ByteArray new:(oldBits size). |
|
4678 depth ~~ 8 ifTrue:[ |
|
4679 "/ expand/compress can only handle 8bits |
|
4680 tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
4681 oldBits |
|
4682 expandPixels:depth |
|
4683 width:oldImage width |
|
4684 height:oldImage height |
|
4685 into:tmpBits |
|
4686 mapping:oldToNew. |
|
4687 tmpBits |
|
4688 compressPixels:depth |
|
4689 width:oldImage width |
|
4690 height:oldImage height |
|
4691 into:newBits |
|
4692 mapping:nil |
|
4693 ] ifFalse:[ |
|
4694 oldBits |
|
4695 expandPixels:depth |
|
4696 width:oldImage width |
|
4697 height:oldImage height |
|
4698 into:newBits |
|
4699 mapping:oldToNew. |
|
4700 ]. |
|
4701 |
|
4702 newImage := oldImage species new |
|
4703 width:oldImage width |
|
4704 height:oldImage height |
|
4705 depth:depth |
|
4706 fromArray:newBits. |
|
4707 |
|
4708 newImage colorMap:newColorMap. |
|
4709 newImage fileName:oldImage fileName. |
|
4710 newImage mask:(oldImage mask copy). |
|
4711 |
|
4712 (imageEditView image:newImage) notNil ifTrue:[ |
|
4713 self fetchImageData. |
4715 ] |
4714 ] |
4716 |
4715 |
4717 "Created: / 28.7.1998 / 20:03:11 / cg" |
4716 "Created: / 28.7.1998 / 20:03:11 / cg" |
4718 "Modified: / 15.9.1998 / 17:53:32 / cg" |
4717 "Modified: / 15.9.1998 / 17:53:32 / cg" |
4719 ! |
4718 ! |
4720 |
4719 |
4721 copyColorFromColormap |
4720 copyColorFromColormap |
4722 imageEditView setClipboardObject:(self selectedColorOrNil) |
4721 imageEditView setClipboardObject:(self selectedColorOrNil) |
4723 ! |
|
4724 |
|
4725 copyMask |
|
4726 |mask| |
|
4727 |
|
4728 mask := self image mask. |
|
4729 MaskClipboard := mask subImageIn: (0@0 extent:mask extent). |
|
4730 ! |
4722 ! |
4731 |
4723 |
4732 ditherToDepth |
4724 ditherToDepth |
4733 |depth| |
4725 |depth| |
4734 |
4726 |
4916 |
4908 |
4917 makeSelectedColorGray |
4909 makeSelectedColorGray |
4918 self processSelectedColorWith:[:clr | Color brightness:(clr brightness)] |
4910 self processSelectedColorWith:[:clr | Color brightness:(clr brightness)] |
4919 ! |
4911 ! |
4920 |
4912 |
4921 pasteColorIntoColormap |
4913 menu_clearColormapEntry0AndMaskedPixels |
4922 |copyBufferColor| |
4914 "ensure that there is a colorMap entry with 0/0/0 at position |
4923 |
4915 0 and then clear all masked pixels (to pixelValue 0)" |
4924 copyBufferColor := imageEditView getClipboardObject. |
4916 |
4925 copyBufferColor isColor ifFalse:[ |
4917 imageEditView makeUndo. |
4926 UserPreferences current beepInEditor ifTrue:[ |
4918 self withExecuteCursorDo:[ |
4927 self window beep. |
4919 self clearColormapEntry0AndMaskedPixels |
4928 ]. |
4920 ] |
|
4921 ! |
|
4922 |
|
4923 menu_clearMaskedPixels |
|
4924 "clear all masked pixels (to pixelValue 0)" |
|
4925 |
|
4926 imageEditView makeUndo. |
|
4927 |
|
4928 self withExecuteCursorDo:[ |
|
4929 self clearMaskedPixels |
|
4930 ] |
|
4931 ! |
|
4932 |
|
4933 menu_compressColorMap |
|
4934 "calculates a new color map for the image, using only used colors" |
|
4935 |
|
4936 |depth oldImage usedColors| |
|
4937 |
|
4938 oldImage := self image. |
|
4939 depth := oldImage depth. |
|
4940 |
|
4941 oldImage photometric ~~ #palette ifTrue:[ |
|
4942 self information:'Compress colorMap: Only palette images have colormaps.'. |
4929 ^ self |
4943 ^ self |
4930 ]. |
4944 ]. |
4931 |
4945 usedColors := oldImage realUsedColors. |
4932 self processSelectedColorWith:[:clr | |
4946 usedColors size == (1 bitShift:depth) ifTrue:[ |
4933 copyBufferColor |
4947 self information:'Compress colorMap: All colors are used - no compression.'. |
|
4948 ^ self |
|
4949 ]. |
|
4950 usedColors size == oldImage colorMap size ifTrue:[ |
|
4951 self information:'Compress colorMap: Colormap already compressed - no compression.'. |
|
4952 ^ self |
|
4953 ]. |
|
4954 |
|
4955 imageEditView makeUndo. |
|
4956 |
|
4957 self withExecuteCursorDo:[ |
|
4958 self compressColorMap |
4934 ] |
4959 ] |
4935 ! |
4960 ! |
4936 |
4961 |
4937 pasteMask |
4962 menu_copyMask |
|
4963 |mask| |
|
4964 |
|
4965 mask := self image mask. |
|
4966 MaskClipboard := mask subImageIn: (0@0 extent:mask extent). |
|
4967 ! |
|
4968 |
|
4969 menu_pasteMask |
4938 |img mask| |
4970 |img mask| |
4939 |
4971 |
4940 imageEditView makeUndo. |
4972 imageEditView makeUndo. |
4941 |
4973 |
4942 img := self image. |
4974 img := self image. |
4949 width:(mask width min:MaskClipboard width) |
4981 width:(mask width min:MaskClipboard width) |
4950 height:(mask height min:MaskClipboard height). |
4982 height:(mask height min:MaskClipboard height). |
4951 img mask:mask. |
4983 img mask:mask. |
4952 (imageEditView image:img copy) notNil ifTrue:[ |
4984 (imageEditView image:img copy) notNil ifTrue:[ |
4953 self fetchImageData. |
4985 self fetchImageData. |
|
4986 ] |
|
4987 ! |
|
4988 |
|
4989 menu_sortColorMap |
|
4990 "calculates a new color map for the image, sorting colors" |
|
4991 |
|
4992 self menu_sortColorMapWith:self sortBlockForColors |
|
4993 ! |
|
4994 |
|
4995 menu_sortColorMapWith:sortBlock |
|
4996 "calculates a new color map for the image, sorting colors" |
|
4997 |
|
4998 self image photometric ~~ #palette ifTrue:[ |
|
4999 self information:'Compress colorMap: Only palette images have colormaps.'. |
|
5000 ^ self |
|
5001 ]. |
|
5002 |
|
5003 imageEditView makeUndo. |
|
5004 |
|
5005 self withExecuteCursorDo:[ |
|
5006 self sortColorMapWith:sortBlock |
|
5007 ] |
|
5008 |
|
5009 "Modified: / 15.9.1998 / 17:53:32 / cg" |
|
5010 "Created: / 30.9.1998 / 23:51:23 / cg" |
|
5011 ! |
|
5012 |
|
5013 pasteColorIntoColormap |
|
5014 |copyBufferColor| |
|
5015 |
|
5016 copyBufferColor := imageEditView getClipboardObject. |
|
5017 copyBufferColor isColor ifFalse:[ |
|
5018 UserPreferences current beepInEditor ifTrue:[ |
|
5019 self window beep. |
|
5020 ]. |
|
5021 ^ self |
|
5022 ]. |
|
5023 |
|
5024 self processSelectedColorWith:[:clr | |
|
5025 copyBufferColor |
4954 ] |
5026 ] |
4955 ! |
5027 ! |
4956 |
5028 |
4957 pickAndAddColorToColormap |
5029 pickAndAddColorToColormap |
4958 self addColorToColormap:(Color fromUser) |
5030 self addColorToColormap:(Color fromUser) |
5182 ! |
5254 ! |
5183 |
5255 |
5184 sortColorMap |
5256 sortColorMap |
5185 "calculates a new color map for the image, sorting colors" |
5257 "calculates a new color map for the image, sorting colors" |
5186 |
5258 |
5187 self |
5259 self sortColorMapWith:self sortBlockForColors |
5188 sortColorMapWith:self sortBlockForColors |
|
5189 ! |
5260 ! |
5190 |
5261 |
5191 sortColorMapWith:sortBlock |
5262 sortColorMapWith:sortBlock |
5192 "calculates a new color map for the image, sorting colors" |
5263 "calculates a new color map for the image, sorting colors" |
5193 |
5264 |
5194 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
5265 |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| |
5195 |
5266 |
5196 oldImage := self image. |
5267 oldImage := self image. |
5197 depth := oldImage depth. |
5268 depth := oldImage depth. |
5198 |
5269 |
5199 oldImage photometric ~~ #palette ifTrue:[ |
|
5200 self information:'Compress colorMap: Only palette images have colormaps.'. |
|
5201 ^ self |
|
5202 ]. |
|
5203 |
|
5204 usedColors := oldImage realColorMap. |
5270 usedColors := oldImage realColorMap. |
5205 |
5271 |
5206 imageEditView makeUndo. |
5272 |
5207 |
5273 "/ translation table |
5208 self withExecuteCursorDo:[ |
5274 oldToNew := ByteArray new:(1 bitShift:depth). |
5209 "/ newColorMap := Array new:usedColors size. |
5275 newColorMap := usedColors asArray. |
5210 |
5276 newColorMap sort:sortBlock. |
5211 "/ translation table |
5277 |
5212 oldToNew := ByteArray new:(1 bitShift:depth). |
5278 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
5213 newColorMap := usedColors asArray. |
5279 |newPixel| |
5214 newColorMap sort:sortBlock. |
5280 |
5215 |
5281 (usedColors includes:clr) ifTrue:[ |
5216 oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr | |
5282 newPixel := newColorMap indexOf:clr. |
5217 |newPixel| |
5283 oldToNew at:oldIdx put:newPixel-1. |
5218 |
|
5219 (usedColors includes:clr) ifTrue:[ |
|
5220 newPixel := newColorMap indexOf:clr. |
|
5221 oldToNew at:oldIdx put:newPixel-1. |
|
5222 ] |
|
5223 ]. |
|
5224 |
|
5225 oldBits := oldImage bits. |
|
5226 newBits := ByteArray new:(oldBits size). |
|
5227 depth ~~ 8 ifTrue:[ |
|
5228 "/ expand/compress can only handle 8bits |
|
5229 tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
5230 oldBits |
|
5231 expandPixels:depth |
|
5232 width:oldImage width |
|
5233 height:oldImage height |
|
5234 into:tmpBits |
|
5235 mapping:oldToNew. |
|
5236 tmpBits |
|
5237 compressPixels:depth |
|
5238 width:oldImage width |
|
5239 height:oldImage height |
|
5240 into:newBits |
|
5241 mapping:nil |
|
5242 ] ifFalse:[ |
|
5243 oldBits |
|
5244 expandPixels:depth |
|
5245 width:oldImage width |
|
5246 height:oldImage height |
|
5247 into:newBits |
|
5248 mapping:oldToNew. |
|
5249 ]. |
|
5250 |
|
5251 newImage := oldImage species new |
|
5252 width:oldImage width |
|
5253 height:oldImage height |
|
5254 depth:depth |
|
5255 fromArray:newBits. |
|
5256 |
|
5257 newImage colorMap:newColorMap. |
|
5258 newImage fileName:oldImage fileName. |
|
5259 newImage mask:(oldImage mask copy). |
|
5260 |
|
5261 (imageEditView image:newImage) notNil ifTrue:[ |
|
5262 self fetchImageData. |
|
5263 ] |
5284 ] |
|
5285 ]. |
|
5286 |
|
5287 oldBits := oldImage bits. |
|
5288 newBits := ByteArray new:(oldBits size). |
|
5289 depth ~~ 8 ifTrue:[ |
|
5290 "/ expand/compress can only handle 8bits |
|
5291 tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). |
|
5292 oldBits |
|
5293 expandPixels:depth |
|
5294 width:oldImage width |
|
5295 height:oldImage height |
|
5296 into:tmpBits |
|
5297 mapping:oldToNew. |
|
5298 tmpBits |
|
5299 compressPixels:depth |
|
5300 width:oldImage width |
|
5301 height:oldImage height |
|
5302 into:newBits |
|
5303 mapping:nil |
|
5304 ] ifFalse:[ |
|
5305 oldBits |
|
5306 expandPixels:depth |
|
5307 width:oldImage width |
|
5308 height:oldImage height |
|
5309 into:newBits |
|
5310 mapping:oldToNew. |
|
5311 ]. |
|
5312 |
|
5313 newImage := oldImage species new |
|
5314 width:oldImage width |
|
5315 height:oldImage height |
|
5316 depth:depth |
|
5317 fromArray:newBits. |
|
5318 |
|
5319 newImage colorMap:newColorMap. |
|
5320 newImage fileName:oldImage fileName. |
|
5321 newImage mask:(oldImage mask copy). |
|
5322 |
|
5323 (imageEditView image:newImage) notNil ifTrue:[ |
|
5324 self fetchImageData. |
5264 ] |
5325 ] |
5265 |
5326 |
5266 "Modified: / 15.9.1998 / 17:53:32 / cg" |
5327 "Modified: / 15.9.1998 / 17:53:32 / cg" |
5267 "Created: / 30.9.1998 / 23:51:23 / cg" |
5328 "Created: / 30.9.1998 / 23:51:23 / cg" |
5268 ! ! |
5329 ! ! |