8394 ]. |
8394 ]. |
8395 |
8395 |
8396 "Modified: 24.4.1997 / 16:18:31 / cg" |
8396 "Modified: 24.4.1997 / 16:18:31 / cg" |
8397 ! |
8397 ! |
8398 |
8398 |
|
8399 applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle |
|
8400 "helper for withPixelFunctionAppliedToValues: |
|
8401 enumerate pixelValues and evaluate the block for each. |
|
8402 To be redefined by subclasses for better performance." |
|
8403 |
|
8404 |w "{Class: SmallInteger }" |
|
8405 h "{Class: SmallInteger }" |
|
8406 x0 "{Class: SmallInteger }" |
|
8407 y0 "{Class: SmallInteger }" |
|
8408 x1 "{Class: SmallInteger }" |
|
8409 y1 "{Class: SmallInteger }" |
|
8410 y "{Class: SmallInteger }" |
|
8411 newPixel newPixelRow pixelRow| |
|
8412 |
|
8413 x0 := aRectangle left. |
|
8414 y0 := aRectangle top. |
|
8415 w := aRectangle width. |
|
8416 h := aRectangle height. |
|
8417 |
|
8418 newPixelRow := Array new:w. |
|
8419 pixelRow := self pixelArraySpecies new:width. |
|
8420 |
|
8421 y := y0. |
|
8422 h timesRepeat:[ |
|
8423 self rowAt:y into:pixelRow. |
|
8424 1 to:w do:[:runCol | |
|
8425 newPixel := pixelFunctionBlock |
|
8426 value:self |
|
8427 value:(pixelRow at:runCol+x0) |
|
8428 value:(runCol+x0-1) |
|
8429 value:y. |
|
8430 newPixelRow at:runCol put:newPixel. |
|
8431 ]. |
|
8432 pixelRow replaceFrom:x0+1 to:x0+1+w-1 with:newPixelRow startingAt:1. |
|
8433 newImage rowAt:y putAll:newPixelRow. |
|
8434 y := y + 1. |
|
8435 ]. |
|
8436 |
|
8437 "Modified: 24.4.1997 / 16:18:31 / cg" |
|
8438 ! |
|
8439 |
8399 colorMapProcessing:aBlock |
8440 colorMapProcessing:aBlock |
8400 "a helper for all kinds of colormap manipulations. |
8441 "a helper for all kinds of colormap manipulations. |
8401 The argument, aBlock is called for every colormap entry, |
8442 The argument, aBlock is called for every colormap entry, |
8402 and the returned value will replace the original entry in the map. |
8443 and the returned value will replace the original entry in the map. |
8403 This will fail for non-palette images. |
8444 This will fail for non-palette images. |
9864 ((x between:100 and:200) |
9906 ((x between:100 and:200) |
9865 and:[y between:100 and:200]) ifTrue:[ |
9907 and:[y between:100 and:200]) ifTrue:[ |
9866 oldColor |
9908 oldColor |
9867 ] ifFalse:[ |
9909 ] ifFalse:[ |
9868 black. |
9910 black. |
|
9911 ] |
|
9912 ]) inspect. |
|
9913 " |
|
9914 "brighten a frame: |
|
9915 |
|
9916 |i black w h| |
|
9917 |
|
9918 i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
|
9919 i inspect. |
|
9920 |
|
9921 w := i width. |
|
9922 h := i height. |
|
9923 (i withPixelFunctionApplied:[:oldImage :oldColor :x :y | |
|
9924 ((x between:0 and:10) |
|
9925 or:[(y between:0 and:10) |
|
9926 or:[(x between:w-10 and:w) |
|
9927 or:[y between:h-10 and:h]]]) ifTrue:[ |
|
9928 oldColor lightened nearestIn:i colorMap |
|
9929 ] ifFalse:[ |
|
9930 oldColor. |
9869 ] |
9931 ] |
9870 ]) inspect. |
9932 ]) inspect. |
9871 " |
9933 " |
9872 |
9934 |
9873 "Modified: 24.4.1997 / 18:36:59 / cg" |
9935 "Modified: 24.4.1997 / 18:36:59 / cg" |
10619 ^ width * (self bitsPerPixel). |
10681 ^ width * (self bitsPerPixel). |
10620 ! |
10682 ! |
10621 |
10683 |
10622 blackComponentOfCMYK:pixel |
10684 blackComponentOfCMYK:pixel |
10623 "if the receiver is a cmyk-image: |
10685 "if the receiver is a cmyk-image: |
10624 return the black component (0 .. 100) of a pixelValue." |
10686 return the black component scaled to a percentage (0 .. 100) of a pixelValue." |
10625 |
10687 |
10626 samplesPerPixel == 4 ifTrue:[ |
10688 samplesPerPixel == 4 ifTrue:[ |
10627 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10689 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10628 |
10690 |
10629 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10691 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10635 |
10697 |
10636 ! |
10698 ! |
10637 |
10699 |
10638 blueBitsOf:pixel |
10700 blueBitsOf:pixel |
10639 "if the receiver is an rgb-image: |
10701 "if the receiver is an rgb-image: |
10640 return the blue bits of a pixelValue. |
10702 return the blue bits of a pixelValue as integer 0..maxBlueValue. |
|
10703 MaxGreenValue is of course the largest integer representable by the number |
|
10704 of blue bits i.e. (1 bitShift:bitsBlue)-1. |
10641 This has to be redefined by subclasses." |
10705 This has to be redefined by subclasses." |
10642 |
10706 |
10643 |blueBits| |
10707 |blueBits| |
10644 |
10708 |
10645 samplesPerPixel >= 3 ifTrue:[ |
10709 samplesPerPixel >= 3 ifTrue:[ |
10657 "Modified: 10.6.1996 / 14:59:44 / cg" |
10721 "Modified: 10.6.1996 / 14:59:44 / cg" |
10658 ! |
10722 ! |
10659 |
10723 |
10660 blueComponentOf:pixel |
10724 blueComponentOf:pixel |
10661 "if the receiver is an rgb-image: |
10725 "if the receiver is an rgb-image: |
10662 return the blue component (0 .. 100) of a pixelValue. |
10726 return the blue component scaled to a percentage (0 .. 100) of a pixelValue. |
10663 This has to be redefined by subclasses." |
10727 This has to be redefined by subclasses." |
10664 |
10728 |
10665 |blueBits "{ Class: SmallInteger }" |
10729 |blueBits "{ Class: SmallInteger }" |
10666 s "{ Class: SmallInteger }"| |
10730 s "{ Class: SmallInteger }"| |
10667 |
10731 |
10791 "Modified: 28.1.1997 / 12:05:22 / cg" |
10855 "Modified: 28.1.1997 / 12:05:22 / cg" |
10792 ! |
10856 ! |
10793 |
10857 |
10794 cyanComponentOfCMY:pixel |
10858 cyanComponentOfCMY:pixel |
10795 "if the receiver is a cmy-image: |
10859 "if the receiver is a cmy-image: |
10796 return the cyan component (0 .. 100) of a pixelValue." |
10860 return the cyan component scaled to a percentage (0 .. 100) of a pixelValue." |
10797 |
10861 |
10798 samplesPerPixel == 3 ifTrue:[ |
10862 samplesPerPixel == 3 ifTrue:[ |
10799 "/ assume that the cyan bits are the leftMost bits (cmy) |
10863 "/ assume that the cyan bits are the leftMost bits (cmy) |
10800 |
10864 |
10801 bitsPerSample = #(8 8 8) ifTrue:[ |
10865 bitsPerSample = #(8 8 8) ifTrue:[ |
10807 |
10871 |
10808 ! |
10872 ! |
10809 |
10873 |
10810 cyanComponentOfCMYK:pixel |
10874 cyanComponentOfCMYK:pixel |
10811 "if the receiver is a cmyk-image: |
10875 "if the receiver is a cmyk-image: |
10812 return the cyan component (0 .. 100) of a pixelValue." |
10876 return the cyan component scaled to a percentage (0 .. 100) of a pixelValue." |
10813 |
10877 |
10814 samplesPerPixel == 4 ifTrue:[ |
10878 samplesPerPixel == 4 ifTrue:[ |
10815 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10879 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10816 |
10880 |
10817 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10881 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10823 |
10887 |
10824 ! |
10888 ! |
10825 |
10889 |
10826 greenBitsOf:pixel |
10890 greenBitsOf:pixel |
10827 "if the receiver is an rgb-image: |
10891 "if the receiver is an rgb-image: |
10828 return the green bits of a pixelValue. |
10892 return the green bits of a pixelValue as integer 0..maxGreenValue. |
|
10893 MaxGreenValue is of course the largest integer representable by the number |
|
10894 of green bits i.e. (1 bitShift:bitsGreen)-1. |
10829 This has to be redefined by subclasses." |
10895 This has to be redefined by subclasses." |
10830 |
10896 |
10831 |blueBits greenBits| |
10897 |blueBits greenBits| |
10832 |
10898 |
10833 samplesPerPixel >= 3 ifTrue:[ |
10899 samplesPerPixel >= 3 ifTrue:[ |
10846 "Modified: 10.6.1996 / 14:59:35 / cg" |
10912 "Modified: 10.6.1996 / 14:59:35 / cg" |
10847 ! |
10913 ! |
10848 |
10914 |
10849 greenComponentOf:pixel |
10915 greenComponentOf:pixel |
10850 "if the receiver is an rgb-image: |
10916 "if the receiver is an rgb-image: |
10851 return the green component (0..100) of a pixelValue. |
10917 return the green component scaled to a percentage (0..100) of a pixelValue. |
10852 This has to be redefined by subclasses." |
10918 This has to be redefined by subclasses." |
10853 |
10919 |
10854 |greenBits "{ Class: SmallInteger }" |
10920 |greenBits "{ Class: SmallInteger }" |
10855 blueBits "{ Class: SmallInteger }" |
10921 blueBits "{ Class: SmallInteger }" |
10856 s "{ Class: SmallInteger }"| |
10922 s "{ Class: SmallInteger }"| |
10904 "Created: 22.4.1997 / 14:12:02 / cg" |
10970 "Created: 22.4.1997 / 14:12:02 / cg" |
10905 ! |
10971 ! |
10906 |
10972 |
10907 magentaComponentOfCMY:pixel |
10973 magentaComponentOfCMY:pixel |
10908 "if the receiver is a cmy-image: |
10974 "if the receiver is a cmy-image: |
10909 return the magenta component (0 .. 100) of a pixelValue." |
10975 return the magenta component scaled to a percentage (0 .. 100) of a pixelValue." |
10910 |
10976 |
10911 samplesPerPixel == 3 ifTrue:[ |
10977 samplesPerPixel == 3 ifTrue:[ |
10912 "/ assume that the cyan bits are the leftMost bits (cmy) |
10978 "/ assume that the cyan bits are the leftMost bits (cmy) |
10913 |
10979 |
10914 bitsPerSample = #(8 8 8) ifTrue:[ |
10980 bitsPerSample = #(8 8 8) ifTrue:[ |
10920 |
10986 |
10921 ! |
10987 ! |
10922 |
10988 |
10923 magentaComponentOfCMYK:pixel |
10989 magentaComponentOfCMYK:pixel |
10924 "if the receiver is a cmyk-image: |
10990 "if the receiver is a cmyk-image: |
10925 return the magenta component (0 .. 100) of a pixelValue." |
10991 return the magenta component scaled to a percentage (0 .. 100) of a pixelValue." |
10926 |
10992 |
10927 samplesPerPixel == 4 ifTrue:[ |
10993 samplesPerPixel == 4 ifTrue:[ |
10928 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10994 "/ assume that the cyan bits are the leftMost bits (cmyk) |
10929 |
10995 |
10930 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10996 bitsPerSample = #(8 8 8 8) ifTrue:[ |
10980 "Modified: 11.7.1996 / 20:49:21 / cg" |
11046 "Modified: 11.7.1996 / 20:49:21 / cg" |
10981 ! |
11047 ! |
10982 |
11048 |
10983 redBitsOf:pixel |
11049 redBitsOf:pixel |
10984 "if the receiver is an rgb-image: |
11050 "if the receiver is an rgb-image: |
10985 return the red component of a pixelValue. |
11051 return the red component of a pixelValue as integer 0..maxRedValue. |
|
11052 MaxRedValue is of course the largest integer representable by the number |
|
11053 of red bits i.e. (1 bitShift:bitsRed)-1. |
10986 This has to be redefined by subclasses." |
11054 This has to be redefined by subclasses." |
10987 |
11055 |
10988 |redBits greenBits blueBits| |
11056 |redBits greenBits blueBits| |
10989 |
11057 |
10990 samplesPerPixel >= 3 ifTrue:[ |
11058 samplesPerPixel >= 3 ifTrue:[ |
11005 "Modified: 10.6.1996 / 14:59:05 / cg" |
11073 "Modified: 10.6.1996 / 14:59:05 / cg" |
11006 ! |
11074 ! |
11007 |
11075 |
11008 redComponentOf:pixel |
11076 redComponentOf:pixel |
11009 "if the receiver is an rgb-image: |
11077 "if the receiver is an rgb-image: |
11010 return the red component (0..100) of a pixelValue. |
11078 return the red component scaled to a percentage (0..100) of a pixelValue. |
11011 This has to be redefined by subclasses." |
11079 This has to be redefined by subclasses." |
11012 |
11080 |
11013 |redBits "{ Class: SmallInteger }" |
11081 |redBits "{ Class: SmallInteger }" |
11014 greenBits "{ Class: SmallInteger }" |
11082 greenBits "{ Class: SmallInteger }" |
11015 blueBits "{ Class: SmallInteger }" |
11083 blueBits "{ Class: SmallInteger }" |
11174 ^ nil |
11242 ^ nil |
11175 |
11243 |
11176 "Modified: / 30.9.1998 / 22:03:50 / cg" |
11244 "Modified: / 30.9.1998 / 22:03:50 / cg" |
11177 ! |
11245 ! |
11178 |
11246 |
|
11247 valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
11248 "given a rgb bits, each in 0..maxXXXValue (i.e. according to |
|
11249 r/g/b channels number of bits, return the corresponding pixel value. |
|
11250 For now, only useful with RGB images" |
|
11251 |
|
11252 |pixel numGreenBits numBlueBits| |
|
11253 |
|
11254 photometric == #rgb ifTrue:[ |
|
11255 samplesPerPixel >= 3 ifTrue:[ |
|
11256 numGreenBits := bitsPerSample at:2. |
|
11257 numBlueBits := bitsPerSample at:3. |
|
11258 |
|
11259 pixel := (((redBits bitShift:numGreenBits) + greenBits) bitShift:numBlueBits) + blueBits. |
|
11260 ^ pixel |
|
11261 ] |
|
11262 ]. |
|
11263 |
|
11264 ImageErrorSignal raiseErrorString:'format not supported'. |
|
11265 ^ nil |
|
11266 |
|
11267 "Modified: / 30.9.1998 / 22:03:50 / cg" |
|
11268 ! |
|
11269 |
11179 widthOn:aGC |
11270 widthOn:aGC |
11180 "return my width, if displayed on aGC; |
11271 "return my width, if displayed on aGC; |
11181 since my width is independent of the device (the number of pixels), |
11272 since my width is independent of the device (the number of pixels), |
11182 return the pixel-width" |
11273 return the pixel-width" |
11183 |
11274 |
11187 "Modified: 13.5.1996 / 10:26:42 / cg" |
11278 "Modified: 13.5.1996 / 10:26:42 / cg" |
11188 ! |
11279 ! |
11189 |
11280 |
11190 yellowComponentOfCMY:pixel |
11281 yellowComponentOfCMY:pixel |
11191 "if the receiver is a cmy-image: |
11282 "if the receiver is a cmy-image: |
11192 return the yellow component (0 .. 100) of a pixelValue." |
11283 return the yellow component scaled to a percentage (0 .. 100) of a pixelValue." |
11193 |
11284 |
11194 samplesPerPixel == 3 ifTrue:[ |
11285 samplesPerPixel == 3 ifTrue:[ |
11195 "/ assume that the cyan bits are the leftMost bits (cmy) |
11286 "/ assume that the cyan bits are the leftMost bits (cmy) |
11196 |
11287 |
11197 bitsPerSample = #(8 8 8) ifTrue:[ |
11288 bitsPerSample = #(8 8 8) ifTrue:[ |
11204 |
11295 |
11205 ! |
11296 ! |
11206 |
11297 |
11207 yellowComponentOfCMYK:pixel |
11298 yellowComponentOfCMYK:pixel |
11208 "if the receiver is a cmyk-image: |
11299 "if the receiver is a cmyk-image: |
11209 return the yellow component (0 .. 100) of a pixelValue." |
11300 return the yellow component scaled to a percentage (0 .. 100) of a pixelValue." |
11210 |
11301 |
11211 samplesPerPixel == 4 ifTrue:[ |
11302 samplesPerPixel == 4 ifTrue:[ |
11212 "/ assume that the cyan bits are the leftMost bits (cmyk) |
11303 "/ assume that the cyan bits are the leftMost bits (cmyk) |
11213 |
11304 |
11214 bitsPerSample = #(8 8 8 8) ifTrue:[ |
11305 bitsPerSample = #(8 8 8 8) ifTrue:[ |