13955 ^ (width // 2) @ (height // 2) |
13955 ^ (width // 2) @ (height // 2) |
13956 |
13956 |
13957 "Created: 22.10.1997 / 23:52:40 / cg" |
13957 "Created: 22.10.1997 / 23:52:40 / cg" |
13958 ! |
13958 ! |
13959 |
13959 |
|
13960 chromaBlueOfYCbCr:pixel |
|
13961 "if the receiver is an YCbCr-image: |
|
13962 return the blue-chroma (Cb) component, scaled to (0 .. 1)" |
|
13963 |
|
13964 |cbBits "{ Class: SmallInteger }" |
|
13965 crBits "{ Class: SmallInteger }" |
|
13966 s "{ Class: SmallInteger }"| |
|
13967 |
|
13968 photometric == #YCbCr ifTrue:[ |
|
13969 samplesPerPixel == 3 ifTrue:[ |
|
13970 "/ assume that the Y bits are the leftMost bits |
|
13971 cbBits := bitsPerSample at:2. |
|
13972 cbBits == 0 ifTrue:[^ 0]. |
|
13973 crBits := bitsPerSample at:3. |
|
13974 |
|
13975 s := (1 bitShift:cbBits) - 1. |
|
13976 |
|
13977 ^ 1.0 / s * ((pixel rightShift:crBits) bitAnd:(1 bitShift:cbBits)-1) |
|
13978 ]. |
|
13979 ]. |
|
13980 self subclassResponsibility |
|
13981 |
|
13982 "Created: / 26-08-2017 / 22:09:31 / cg" |
|
13983 ! |
|
13984 |
|
13985 chromaRedOfYCbCr:pixel |
|
13986 "if the receiver is an YCbCr-image: |
|
13987 return the red-chroma (Cr) component, scaled to (0 .. 1)" |
|
13988 |
|
13989 |crBits "{ Class: SmallInteger }" |
|
13990 s "{ Class: SmallInteger }"| |
|
13991 |
|
13992 samplesPerPixel >= 3 ifTrue:[ |
|
13993 "/ assume that the red bits are the leftMost bits |
|
13994 |
|
13995 crBits := bitsPerSample at:3. |
|
13996 crBits == 0 ifTrue:[^ 0]. |
|
13997 |
|
13998 s := (1 bitShift:crBits) - 1. |
|
13999 |
|
14000 ^ 1.0 / s * (pixel bitAnd:(1 bitShift:crBits)-1) |
|
14001 ]. |
|
14002 |
|
14003 self subclassResponsibility |
|
14004 |
|
14005 " |
|
14006 (self basicNew |
|
14007 bitsPerSample:#(8 8 8); |
|
14008 photometric:#YCbCr; |
|
14009 samplesPerPixel:3; |
|
14010 yourself |
|
14011 ) chromaRedOfYCbCr: 16r10107F |
|
14012 |
|
14013 (self basicNew |
|
14014 bitsPerSample:#(8 8 8); |
|
14015 photometric:#YCbCr; |
|
14016 samplesPerPixel:3; |
|
14017 yourself |
|
14018 ) chromaRedOfYCbCr: 16r1010FF |
|
14019 |
|
14020 (self basicNew |
|
14021 bitsPerSample:#(8 8 8); |
|
14022 photometric:#YCbCr; |
|
14023 samplesPerPixel:3; |
|
14024 yourself |
|
14025 ) chromaBlueOfYCbCr: 16r107F10 |
|
14026 |
|
14027 (self basicNew |
|
14028 bitsPerSample:#(8 8 8); |
|
14029 photometric:#YCbCr; |
|
14030 samplesPerPixel:3; |
|
14031 yourself |
|
14032 ) chromaBlueOfYCbCr: 16r10FF10 |
|
14033 |
|
14034 (self basicNew |
|
14035 bitsPerSample:#(8 8 8); |
|
14036 photometric:#YCbCr; |
|
14037 samplesPerPixel:3; |
|
14038 yourself |
|
14039 ) lumaOfYCbCr: 16r7F1010 |
|
14040 |
|
14041 (self basicNew |
|
14042 bitsPerSample:#(8 8 8); |
|
14043 photometric:#YCbCr; |
|
14044 samplesPerPixel:3; |
|
14045 yourself |
|
14046 ) lumaOfYCbCr: 16rFF1010 |
|
14047 " |
|
14048 |
|
14049 "Created: / 26-08-2017 / 22:11:31 / cg" |
|
14050 ! |
|
14051 |
13960 colorFromValue:pixelValue |
14052 colorFromValue:pixelValue |
13961 "given a pixel value, return the corresponding color. |
14053 "given a pixel value, return the corresponding color. |
13962 Pixel values start with 0. |
14054 Pixel values start with 0. |
13963 The implementation below is generic and slow |
14055 The implementation below is generic and slow |
13964 - this method is typically redefined in subclasses." |
14056 - this method is typically redefined in subclasses." |
14221 ^ false |
14313 ^ false |
14222 |
14314 |
14223 "Created: 22.4.1997 / 14:12:02 / cg" |
14315 "Created: 22.4.1997 / 14:12:02 / cg" |
14224 ! |
14316 ! |
14225 |
14317 |
|
14318 lumaOfYCbCr:pixel |
|
14319 "if the receiver is an YCbCr-image: |
|
14320 return the luma (Y) component, scaled to (0 .. 1)" |
|
14321 |
|
14322 photometric == #YCbCr ifTrue:[ |
|
14323 samplesPerPixel == 3 ifTrue:[ |
|
14324 "/ assume that the Y bits are the leftMost bits |
|
14325 (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[ |
|
14326 ^ 1.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF) |
|
14327 ] |
|
14328 ]. |
|
14329 ]. |
|
14330 self subclassResponsibility |
|
14331 |
|
14332 "Created: / 26-08-2017 / 22:06:36 / cg" |
|
14333 ! |
|
14334 |
14226 magentaComponentOfCMY:pixel |
14335 magentaComponentOfCMY:pixel |
14227 "if the receiver is a cmy-image: |
14336 "if the receiver is a cmy-image: |
14228 return the magenta component scaled to a percentage (0 .. 100) of a pixelValue." |
14337 return the magenta component scaled to a percentage (0 .. 100) of a pixelValue." |
14229 |
14338 |
14230 samplesPerPixel == 3 ifTrue:[ |
14339 samplesPerPixel == 3 ifTrue:[ |
14504 "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB). |
14613 "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB). |
14505 Pixel value is in 0..2^depth - 1. |
14614 Pixel value is in 0..2^depth - 1. |
14506 The implementation below is generic and slow |
14615 The implementation below is generic and slow |
14507 - this method is typically redefined in subclasses." |
14616 - this method is typically redefined in subclasses." |
14508 |
14617 |
14509 |p maxPixel clr r g b c m y k| |
14618 |p maxPixel clr r g b c m y k cb cr| |
14510 |
14619 |
14511 p := photometric. |
14620 p := photometric. |
14512 p isNil ifTrue:[ |
14621 p isNil ifTrue:[ |
14513 colorMap notNil ifTrue:[ |
14622 colorMap notNil ifTrue:[ |
14514 p := #palette |
14623 p := #palette |
14565 m := self magentaComponentOfCMY:pixelValue. |
14674 m := self magentaComponentOfCMY:pixelValue. |
14566 y := self yellowComponentOfCMY:pixelValue. |
14675 y := self yellowComponentOfCMY:pixelValue. |
14567 ^ (Color cyan:c magenta:m yellow:y) rgbValue. |
14676 ^ (Color cyan:c magenta:m yellow:y) rgbValue. |
14568 ]. |
14677 ]. |
14569 |
14678 |
|
14679 p == #YCbCr ifTrue:[ |
|
14680 y := self lumaOfYCbCr:pixelValue. |
|
14681 cb := self chromaBlueOfYCbCr:pixelValue. |
|
14682 cr := self chromaRedOfYCbCr:pixelValue. |
|
14683 ^ (Color luma:y chromaBlue:cb chromaRed:cr) rgbValue. |
|
14684 ]. |
|
14685 |
14570 self error:'invalid (unsupported) photometric' |
14686 self error:'invalid (unsupported) photometric' |
14571 |
14687 |
14572 "Modified: / 22-08-2017 / 18:31:36 / cg" |
14688 " |
|
14689 (self basicNew |
|
14690 bitsPerSample:#(8 8 8); |
|
14691 photometric:#YCbCr; |
|
14692 samplesPerPixel:3; |
|
14693 yourself |
|
14694 ) rgbFromValue: 16r7F1010 |
|
14695 |
|
14696 (self basicNew |
|
14697 bitsPerSample:#(8 8 8); |
|
14698 photometric:#YCbCr; |
|
14699 samplesPerPixel:3; |
|
14700 yourself |
|
14701 ) rgbFromValue: 16rFF1010 |
|
14702 |
|
14703 (self basicNew |
|
14704 bitsPerSample:#(8 8 8); |
|
14705 photometric:#YCbCr; |
|
14706 samplesPerPixel:3; |
|
14707 yourself |
|
14708 ) rgbFromValue: 16rFF0000 |
|
14709 " |
|
14710 |
|
14711 "Modified: / 26-08-2017 / 20:56:49 / cg" |
|
14712 "Modified (comment): / 26-08-2017 / 22:18:14 / cg" |
14573 ! |
14713 ! |
14574 |
14714 |
14575 usedColors |
14715 usedColors |
14576 "return a collection of colors used in the receiver. |
14716 "return a collection of colors used in the receiver. |
14577 This looks at the colorMap only if present. |
14717 This looks at the colorMap only if present. |