cristy | 0b3cd89 | 2012-08-01 23:13:50 +0000 | [diff] [blame] | 1 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC OOO M M PPPP OOO SSSSS IIIII TTTTT EEEEE % |
| 7 | % C O O MM MM P P O O SS I T E % |
| 8 | % C O O M M M PPPP O O SSS I T EEE % |
| 9 | % C O O M M P O O SS I T E % |
| 10 | % CCCC OOO M M P OOO SSSSS IIIII T EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Composite Methods % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | fe676ee | 2013-11-18 13:03:38 +0000 | [diff] [blame] | 20 | % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
| 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/artifact.h" |
| 45 | #include "MagickCore/cache.h" |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame] | 46 | #include "MagickCore/cache-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/cache-view.h" |
cristy | 6a2180c | 2013-05-27 10:28:36 +0000 | [diff] [blame] | 48 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 49 | #include "MagickCore/client.h" |
| 50 | #include "MagickCore/color.h" |
| 51 | #include "MagickCore/color-private.h" |
| 52 | #include "MagickCore/colorspace.h" |
| 53 | #include "MagickCore/colorspace-private.h" |
| 54 | #include "MagickCore/composite.h" |
| 55 | #include "MagickCore/composite-private.h" |
| 56 | #include "MagickCore/constitute.h" |
| 57 | #include "MagickCore/draw.h" |
| 58 | #include "MagickCore/fx.h" |
| 59 | #include "MagickCore/gem.h" |
| 60 | #include "MagickCore/geometry.h" |
| 61 | #include "MagickCore/image.h" |
| 62 | #include "MagickCore/image-private.h" |
| 63 | #include "MagickCore/list.h" |
| 64 | #include "MagickCore/log.h" |
| 65 | #include "MagickCore/monitor.h" |
| 66 | #include "MagickCore/monitor-private.h" |
| 67 | #include "MagickCore/memory_.h" |
| 68 | #include "MagickCore/option.h" |
| 69 | #include "MagickCore/pixel-accessor.h" |
| 70 | #include "MagickCore/property.h" |
| 71 | #include "MagickCore/quantum.h" |
| 72 | #include "MagickCore/resample.h" |
| 73 | #include "MagickCore/resource_.h" |
| 74 | #include "MagickCore/string_.h" |
| 75 | #include "MagickCore/thread-private.h" |
cristy | 191c0b7 | 2012-08-12 16:29:52 +0000 | [diff] [blame] | 76 | #include "MagickCore/threshold.h" |
cristy | 63a8187 | 2012-03-22 15:52:52 +0000 | [diff] [blame] | 77 | #include "MagickCore/token.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 78 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 79 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 80 | #include "MagickCore/version.h" |
| 81 | |
| 82 | /* |
| 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 84 | % % |
| 85 | % % |
| 86 | % % |
cristy | f4ad9df | 2011-07-08 16:49:03 +0000 | [diff] [blame] | 87 | % C o m p o s i t e I m a g e % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 88 | % % |
| 89 | % % |
| 90 | % % |
| 91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 92 | % |
cristy | f4ad9df | 2011-07-08 16:49:03 +0000 | [diff] [blame] | 93 | % CompositeImage() returns the second image composited onto the first |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 94 | % at the specified offset, using the specified composite method. |
| 95 | % |
cristy | f4ad9df | 2011-07-08 16:49:03 +0000 | [diff] [blame] | 96 | % The format of the CompositeImage method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 97 | % |
| 98 | % MagickBooleanType CompositeImage(Image *image, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 99 | % const Image *composite_image,const CompositeOperator compose, |
| 100 | % const MagickBooleanType clip_to_self,const ssize_t x_offset, |
| 101 | % const ssize_t y_offset,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 102 | % |
| 103 | % A description of each parameter follows: |
| 104 | % |
| 105 | % o image: the destination image, modified by he composition |
| 106 | % |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 107 | % o composite_image: the composite (source) image. |
| 108 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 109 | % o compose: This operator affects how the composite is applied to |
| 110 | % the image. The operators and how they are utilized are listed here |
| 111 | % http://www.w3.org/TR/SVG12/#compositing. |
| 112 | % |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 113 | % o clip_to_self: set to MagickTrue to limit composition to area composed. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 114 | % |
| 115 | % o x_offset: the column offset of the composited image. |
| 116 | % |
| 117 | % o y_offset: the row offset of the composited image. |
| 118 | % |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 119 | % Extra Controls from Image meta-data in 'image' (artifacts) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 120 | % |
| 121 | % o "compose:args" |
| 122 | % A string containing extra numerical arguments for specific compose |
| 123 | % methods, generally expressed as a 'geometry' or a comma separated list |
| 124 | % of numbers. |
| 125 | % |
| 126 | % Compose methods needing such arguments include "BlendCompositeOp" and |
| 127 | % "DisplaceCompositeOp". |
| 128 | % |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 129 | % o exception: return any errors or warnings in this structure. |
| 130 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 131 | */ |
| 132 | |
anthony | ea068a5 | 2012-04-09 05:46:25 +0000 | [diff] [blame] | 133 | /* |
| 134 | Composition based on the SVG specification: |
| 135 | |
| 136 | A Composition is defined by... |
| 137 | Color Function : f(Sc,Dc) where Sc and Dc are the normizalized colors |
| 138 | Blending areas : X = 1 for area of overlap, ie: f(Sc,Dc) |
| 139 | Y = 1 for source preserved |
| 140 | Z = 1 for destination preserved |
| 141 | |
| 142 | Conversion to transparency (then optimized) |
| 143 | Dca' = f(Sc, Dc)*Sa*Da + Y*Sca*(1-Da) + Z*Dca*(1-Sa) |
| 144 | Da' = X*Sa*Da + Y*Sa*(1-Da) + Z*Da*(1-Sa) |
| 145 | |
| 146 | Where... |
| 147 | Sca = Sc*Sa normalized Source color divided by Source alpha |
| 148 | Dca = Dc*Da normalized Dest color divided by Dest alpha |
| 149 | Dc' = Dca'/Da' the desired color value for this channel. |
| 150 | |
| 151 | Da' in in the follow formula as 'gamma' The resulting alpla value. |
| 152 | |
| 153 | Most functions use a blending mode of over (X=1,Y=1,Z=1) this results in |
| 154 | the following optimizations... |
| 155 | gamma = Sa+Da-Sa*Da; |
| 156 | gamma = 1 - QuantiumScale*alpha * QuantiumScale*beta; |
| 157 | opacity = QuantiumScale*alpha*beta; // over blend, optimized 1-Gamma |
| 158 | |
| 159 | The above SVG definitions also definate that Mathematical Composition |
| 160 | methods should use a 'Over' blending mode for Alpha Channel. |
| 161 | It however was not applied for composition modes of 'Plus', 'Minus', |
| 162 | the modulus versions of 'Add' and 'Subtract'. |
| 163 | |
| 164 | Mathematical operator changes to be applied from IM v6.7... |
| 165 | |
| 166 | 1) Modulus modes 'Add' and 'Subtract' are obsoleted and renamed |
| 167 | 'ModulusAdd' and 'ModulusSubtract' for clarity. |
| 168 | |
| 169 | 2) All mathematical compositions work as per the SVG specification |
| 170 | with regard to blending. This now includes 'ModulusAdd' and |
| 171 | 'ModulusSubtract'. |
| 172 | |
| 173 | 3) When the special channel flag 'sync' (syncronize channel updates) |
| 174 | is turned off (enabled by default) then mathematical compositions are |
| 175 | only performed on the channels specified, and are applied |
| 176 | independantally of each other. In other words the mathematics is |
| 177 | performed as 'pure' mathematical operations, rather than as image |
| 178 | operations. |
| 179 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 180 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 181 | static inline MagickRealType MagickMin(const MagickRealType x, |
| 182 | const MagickRealType y) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 183 | { |
| 184 | if (x < y) |
| 185 | return(x); |
| 186 | return(y); |
| 187 | } |
cristy | ddeeea2 | 2012-04-12 01:33:09 +0000 | [diff] [blame] | 188 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 189 | static inline MagickRealType MagickMax(const MagickRealType x, |
| 190 | const MagickRealType y) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 191 | { |
| 192 | if (x > y) |
| 193 | return(x); |
| 194 | return(y); |
| 195 | } |
| 196 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 197 | static void HCLComposite(const MagickRealType hue,const MagickRealType chroma, |
| 198 | const MagickRealType luma,MagickRealType *red,MagickRealType *green, |
| 199 | MagickRealType *blue) |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 200 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 201 | MagickRealType |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 202 | b, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 203 | c, |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 204 | g, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 205 | h, |
| 206 | m, |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 207 | r, |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 208 | x; |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 211 | Convert HCL to RGB colorspace. |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 212 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 213 | assert(red != (MagickRealType *) NULL); |
| 214 | assert(green != (MagickRealType *) NULL); |
| 215 | assert(blue != (MagickRealType *) NULL); |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 216 | h=6.0*hue; |
| 217 | c=chroma; |
| 218 | x=c*(1.0-fabs(fmod(h,2.0)-1.0)); |
| 219 | r=0.0; |
| 220 | g=0.0; |
| 221 | b=0.0; |
| 222 | if ((0.0 <= h) && (h < 1.0)) |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 223 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 224 | r=c; |
| 225 | g=x; |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 226 | } |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 227 | else |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 228 | if ((1.0 <= h) && (h < 2.0)) |
| 229 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 230 | r=x; |
| 231 | g=c; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 232 | } |
| 233 | else |
| 234 | if ((2.0 <= h) && (h < 3.0)) |
| 235 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 236 | g=c; |
| 237 | b=x; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 238 | } |
| 239 | else |
| 240 | if ((3.0 <= h) && (h < 4.0)) |
| 241 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 242 | g=x; |
| 243 | b=c; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 244 | } |
| 245 | else |
| 246 | if ((4.0 <= h) && (h < 5.0)) |
| 247 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 248 | r=x; |
| 249 | b=c; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 250 | } |
| 251 | else |
| 252 | if ((5.0 <= h) && (h < 6.0)) |
| 253 | { |
cristy | e171528 | 2012-08-15 13:10:55 +0000 | [diff] [blame] | 254 | r=c; |
| 255 | b=x; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 256 | } |
cristy | 9e2436a | 2013-05-02 20:35:59 +0000 | [diff] [blame] | 257 | m=luma-(0.298839*r+0.586811*g+0.114350*b); |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 258 | *red=QuantumRange*(r+m); |
| 259 | *green=QuantumRange*(g+m); |
| 260 | *blue=QuantumRange*(b+m); |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 261 | } |
| 262 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 263 | static void CompositeHCL(const MagickRealType red,const MagickRealType green, |
| 264 | const MagickRealType blue,MagickRealType *hue,MagickRealType *chroma, |
| 265 | MagickRealType *luma) |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 266 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 267 | MagickRealType |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 268 | b, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 269 | c, |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 270 | g, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 271 | h, |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 272 | max, |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 273 | r; |
| 274 | |
| 275 | /* |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 276 | Convert RGB to HCL colorspace. |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 277 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 278 | assert(hue != (MagickRealType *) NULL); |
| 279 | assert(chroma != (MagickRealType *) NULL); |
| 280 | assert(luma != (MagickRealType *) NULL); |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 281 | r=red; |
| 282 | g=green; |
| 283 | b=blue; |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 284 | max=MagickMax(r,MagickMax(g,b)); |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 285 | c=max-(MagickRealType) MagickMin(r,MagickMin(g,b)); |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 286 | h=0.0; |
| 287 | if (c == 0) |
| 288 | h=0.0; |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 289 | else |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 290 | if (red == max) |
cristy | 9e2436a | 2013-05-02 20:35:59 +0000 | [diff] [blame] | 291 | h=fmod((g-b)/c+6.0,6.0); |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 292 | else |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 293 | if (green == max) |
| 294 | h=((b-r)/c)+2.0; |
| 295 | else |
| 296 | if (blue == max) |
| 297 | h=((r-g)/c)+4.0; |
| 298 | *hue=(h/6.0); |
| 299 | *chroma=QuantumScale*c; |
cristy | 9e2436a | 2013-05-02 20:35:59 +0000 | [diff] [blame] | 300 | *luma=QuantumScale*(0.298839*r+0.586811*g+0.114350*b); |
cristy | d8f16f7 | 2012-08-13 12:49:50 +0000 | [diff] [blame] | 301 | } |
| 302 | |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 303 | static MagickBooleanType CompositeOverImage(Image *image, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 304 | const Image *composite_image,const MagickBooleanType clip_to_self, |
| 305 | const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 306 | { |
| 307 | #define CompositeImageTag "Composite/Image" |
| 308 | |
| 309 | CacheView |
| 310 | *composite_view, |
| 311 | *image_view; |
| 312 | |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 313 | MagickBooleanType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 314 | status; |
| 315 | |
| 316 | MagickOffsetType |
| 317 | progress; |
| 318 | |
| 319 | ssize_t |
| 320 | y; |
| 321 | |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 322 | /* |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 323 | Composite image. |
| 324 | */ |
| 325 | status=MagickTrue; |
| 326 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 327 | composite_view=AcquireVirtualCacheView(composite_image,exception); |
| 328 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 329 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 330 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 331 | magick_threads(composite_image,image,image->rows,1) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 332 | #endif |
| 333 | for (y=0; y < (ssize_t) image->rows; y++) |
| 334 | { |
| 335 | const Quantum |
| 336 | *pixels; |
| 337 | |
| 338 | register const Quantum |
| 339 | *restrict p; |
| 340 | |
| 341 | register Quantum |
| 342 | *restrict q; |
| 343 | |
| 344 | register ssize_t |
| 345 | x; |
| 346 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 347 | size_t |
| 348 | channels; |
| 349 | |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 350 | if (status == MagickFalse) |
| 351 | continue; |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 352 | if (clip_to_self != MagickFalse) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 353 | { |
| 354 | if (y < y_offset) |
| 355 | continue; |
| 356 | if ((y-y_offset) >= (ssize_t) composite_image->rows) |
| 357 | continue; |
| 358 | } |
| 359 | /* |
| 360 | If pixels is NULL, y is outside overlay region. |
| 361 | */ |
| 362 | pixels=(Quantum *) NULL; |
| 363 | p=(Quantum *) NULL; |
| 364 | if ((y >= y_offset) && ((y-y_offset) < (ssize_t) composite_image->rows)) |
| 365 | { |
| 366 | p=GetCacheViewVirtualPixels(composite_view,0,y-y_offset, |
| 367 | composite_image->columns,1,exception); |
| 368 | if (p == (const Quantum *) NULL) |
| 369 | { |
| 370 | status=MagickFalse; |
| 371 | continue; |
| 372 | } |
| 373 | pixels=p; |
| 374 | if (x_offset < 0) |
| 375 | p-=x_offset*GetPixelChannels(composite_image); |
| 376 | } |
| 377 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 378 | if (q == (Quantum *) NULL) |
| 379 | { |
| 380 | status=MagickFalse; |
| 381 | continue; |
| 382 | } |
| 383 | for (x=0; x < (ssize_t) image->columns; x++) |
| 384 | { |
cristy | 17028dc | 2013-01-24 12:28:39 +0000 | [diff] [blame] | 385 | double |
| 386 | gamma; |
| 387 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 388 | MagickRealType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 389 | alpha, |
| 390 | Da, |
| 391 | Dc, |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 392 | Sa, |
| 393 | Sc; |
| 394 | |
| 395 | register ssize_t |
| 396 | i; |
| 397 | |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 398 | if (clip_to_self != MagickFalse) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 399 | { |
| 400 | if (x < x_offset) |
| 401 | { |
| 402 | q+=GetPixelChannels(image); |
| 403 | continue; |
| 404 | } |
| 405 | if ((x-x_offset) >= (ssize_t) composite_image->columns) |
| 406 | break; |
| 407 | } |
| 408 | if ((pixels == (Quantum *) NULL) || (x < x_offset) || |
| 409 | ((x-x_offset) >= (ssize_t) composite_image->columns)) |
| 410 | { |
| 411 | Quantum |
| 412 | source[MaxPixelChannels]; |
| 413 | |
| 414 | /* |
| 415 | Virtual composite: |
| 416 | Sc: source color. |
| 417 | Dc: destination color. |
| 418 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 419 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 420 | { |
| 421 | q+=GetPixelChannels(image); |
| 422 | continue; |
| 423 | } |
cristy | c94ba6f | 2012-01-29 23:19:58 +0000 | [diff] [blame] | 424 | (void) GetOneVirtualPixel(composite_image,x-x_offset,y-y_offset, |
| 425 | source,exception); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 426 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 427 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 428 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 429 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 430 | PixelTrait composite_traits=GetPixelChannelTraits(composite_image, |
| 431 | channel); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 432 | if ((traits == UndefinedPixelTrait) || |
| 433 | (composite_traits == UndefinedPixelTrait)) |
| 434 | continue; |
| 435 | q[i]=source[channel]; |
| 436 | } |
| 437 | q+=GetPixelChannels(image); |
| 438 | continue; |
| 439 | } |
| 440 | /* |
| 441 | Authentic composite: |
| 442 | Sa: normalized source alpha. |
| 443 | Da: normalized destination alpha. |
| 444 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 445 | if (GetPixelReadMask(composite_image,p) == 0) |
cristy | c94ba6f | 2012-01-29 23:19:58 +0000 | [diff] [blame] | 446 | { |
| 447 | p+=GetPixelChannels(composite_image); |
| 448 | channels=GetPixelChannels(composite_image); |
| 449 | if (p >= (pixels+channels*composite_image->columns)) |
| 450 | p=pixels; |
| 451 | q+=GetPixelChannels(image); |
| 452 | continue; |
| 453 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 454 | Sa=QuantumScale*GetPixelAlpha(composite_image,p); |
| 455 | Da=QuantumScale*GetPixelAlpha(image,q); |
| 456 | alpha=Sa*(-Da)+Sa+Da; |
| 457 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 458 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 459 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 460 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 461 | PixelTrait composite_traits=GetPixelChannelTraits(composite_image, |
| 462 | channel); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 463 | if ((traits == UndefinedPixelTrait) || |
| 464 | (composite_traits == UndefinedPixelTrait)) |
| 465 | continue; |
| 466 | if ((traits & CopyPixelTrait) != 0) |
| 467 | { |
| 468 | if (channel != AlphaPixelChannel) |
| 469 | { |
| 470 | /* |
| 471 | Copy channel. |
| 472 | */ |
| 473 | q[i]=GetPixelChannel(composite_image,channel,p); |
| 474 | continue; |
| 475 | } |
| 476 | /* |
| 477 | Set alpha channel. |
| 478 | */ |
| 479 | q[i]=ClampToQuantum(QuantumRange*alpha); |
| 480 | continue; |
| 481 | } |
| 482 | /* |
| 483 | Sc: source color. |
| 484 | Dc: destination color. |
| 485 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 486 | Sc=(MagickRealType) GetPixelChannel(composite_image,channel,p); |
| 487 | Dc=(MagickRealType) q[i]; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 488 | gamma=PerceptibleReciprocal(alpha); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 489 | q[i]=ClampToQuantum(gamma*(Sa*Sc-Sa*Da*Dc+Da*Dc)); |
| 490 | } |
| 491 | p+=GetPixelChannels(composite_image); |
| 492 | channels=GetPixelChannels(composite_image); |
| 493 | if (p >= (pixels+channels*composite_image->columns)) |
| 494 | p=pixels; |
| 495 | q+=GetPixelChannels(image); |
| 496 | } |
| 497 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 498 | status=MagickFalse; |
| 499 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 500 | { |
| 501 | MagickBooleanType |
| 502 | proceed; |
| 503 | |
| 504 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 505 | #pragma omp critical (MagickCore_CompositeImage) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 506 | #endif |
| 507 | proceed=SetImageProgress(image,CompositeImageTag,progress++, |
| 508 | image->rows); |
| 509 | if (proceed == MagickFalse) |
| 510 | status=MagickFalse; |
| 511 | } |
| 512 | } |
| 513 | composite_view=DestroyCacheView(composite_view); |
| 514 | image_view=DestroyCacheView(image_view); |
| 515 | return(status); |
| 516 | } |
| 517 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 518 | MagickExport MagickBooleanType CompositeImage(Image *image, |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 519 | const Image *composite,const CompositeOperator compose, |
cristy | 44c9841 | 2012-03-31 18:25:40 +0000 | [diff] [blame] | 520 | const MagickBooleanType clip_to_self,const ssize_t x_offset, |
| 521 | const ssize_t y_offset,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 522 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 523 | #define CompositeImageTag "Composite/Image" |
| 524 | |
| 525 | CacheView |
| 526 | *composite_view, |
| 527 | *image_view; |
| 528 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 529 | GeometryInfo |
| 530 | geometry_info; |
| 531 | |
| 532 | Image |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 533 | *composite_image, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 534 | *destination_image; |
| 535 | |
| 536 | MagickBooleanType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 537 | status; |
| 538 | |
| 539 | MagickOffsetType |
| 540 | progress; |
| 541 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 542 | MagickRealType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 543 | amount, |
| 544 | destination_dissolve, |
| 545 | midpoint, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 546 | percent_luma, |
| 547 | percent_chroma, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 548 | source_dissolve, |
| 549 | threshold; |
| 550 | |
| 551 | MagickStatusType |
| 552 | flags; |
| 553 | |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 554 | ssize_t |
| 555 | y; |
| 556 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 557 | assert(image != (Image *) NULL); |
| 558 | assert(image->signature == MagickSignature); |
| 559 | if (image->debug != MagickFalse) |
| 560 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 561 | assert(composite!= (Image *) NULL); |
| 562 | assert(composite->signature == MagickSignature); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 563 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 564 | return(MagickFalse); |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 565 | composite_image=CloneImage(composite,0,0,MagickTrue,exception); |
| 566 | if (composite_image == (const Image *) NULL) |
| 567 | return(MagickFalse); |
cristy | de067e9 | 2013-04-18 00:47:50 +0000 | [diff] [blame] | 568 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
| 569 | (void) SetImageColorspace(image,sRGBColorspace,exception); |
cristy | a4a22a2 | 2012-08-01 23:16:38 +0000 | [diff] [blame] | 570 | (void) SetImageColorspace(composite_image,image->colorspace,exception); |
cristy | 60dc90c | 2013-02-09 18:33:21 +0000 | [diff] [blame] | 571 | if ((image->alpha_trait == BlendPixelTrait) && |
| 572 | (composite_image->alpha_trait != BlendPixelTrait)) |
cristy | dc4bf87 | 2013-03-09 15:08:20 +0000 | [diff] [blame] | 573 | (void) SetImageAlphaChannel(composite_image,SetAlphaChannel,exception); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 574 | if ((compose == OverCompositeOp) || (compose == SrcOverCompositeOp)) |
| 575 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 576 | status=CompositeOverImage(image,composite_image,clip_to_self,x_offset, |
| 577 | y_offset,exception); |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 578 | composite_image=DestroyImage(composite_image); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 579 | return(status); |
| 580 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 581 | destination_image=(Image *) NULL; |
| 582 | amount=0.5; |
| 583 | destination_dissolve=1.0; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 584 | percent_luma=100.0; |
| 585 | percent_chroma=100.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 586 | source_dissolve=1.0; |
| 587 | threshold=0.05f; |
| 588 | switch (compose) |
| 589 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 590 | case CopyCompositeOp: |
| 591 | { |
| 592 | if ((x_offset < 0) || (y_offset < 0)) |
| 593 | break; |
| 594 | if ((x_offset+(ssize_t) composite_image->columns) >= (ssize_t) image->columns) |
| 595 | break; |
| 596 | if ((y_offset+(ssize_t) composite_image->rows) >= (ssize_t) image->rows) |
| 597 | break; |
| 598 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 599 | composite_view=AcquireVirtualCacheView(composite_image,exception); |
| 600 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 601 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 602 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 603 | magick_threads(composite_image,image,composite_image->rows,1) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 604 | #endif |
| 605 | for (y=0; y < (ssize_t) composite_image->rows; y++) |
| 606 | { |
| 607 | MagickBooleanType |
| 608 | sync; |
| 609 | |
| 610 | register const Quantum |
| 611 | *p; |
| 612 | |
| 613 | register Quantum |
| 614 | *q; |
| 615 | |
| 616 | register ssize_t |
| 617 | x; |
| 618 | |
| 619 | if (status == MagickFalse) |
| 620 | continue; |
| 621 | p=GetCacheViewVirtualPixels(composite_view,0,y,composite_image->columns, |
| 622 | 1,exception); |
| 623 | q=GetCacheViewAuthenticPixels(image_view,x_offset,y+y_offset, |
| 624 | composite_image->columns,1,exception); |
| 625 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
| 626 | { |
| 627 | status=MagickFalse; |
| 628 | continue; |
| 629 | } |
| 630 | for (x=0; x < (ssize_t) composite_image->columns; x++) |
| 631 | { |
cristy | bdecccc | 2011-12-24 22:52:16 +0000 | [diff] [blame] | 632 | register ssize_t |
| 633 | i; |
| 634 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 635 | if (GetPixelReadMask(composite_image,p) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 636 | { |
| 637 | p+=GetPixelChannels(composite_image); |
| 638 | q+=GetPixelChannels(image); |
| 639 | continue; |
| 640 | } |
cristy | bdecccc | 2011-12-24 22:52:16 +0000 | [diff] [blame] | 641 | for (i=0; i < (ssize_t) GetPixelChannels(composite_image); i++) |
| 642 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 643 | PixelChannel channel=GetPixelChannelChannel(composite_image,i); |
| 644 | PixelTrait composite_traits=GetPixelChannelTraits(composite_image, |
| 645 | channel); |
| 646 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | bdecccc | 2011-12-24 22:52:16 +0000 | [diff] [blame] | 647 | if ((traits == UndefinedPixelTrait) || |
| 648 | (composite_traits == UndefinedPixelTrait)) |
| 649 | continue; |
| 650 | SetPixelChannel(image,channel,p[i],q); |
| 651 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 652 | p+=GetPixelChannels(composite_image); |
| 653 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 654 | } |
| 655 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 656 | if (sync == MagickFalse) |
| 657 | status=MagickFalse; |
| 658 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 659 | { |
| 660 | MagickBooleanType |
| 661 | proceed; |
| 662 | |
| 663 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | bd0435b | 2012-01-05 16:20:47 +0000 | [diff] [blame] | 664 | #pragma omp critical (MagickCore_CompositeImage) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 665 | #endif |
| 666 | proceed=SetImageProgress(image,CompositeImageTag, |
| 667 | (MagickOffsetType) y,image->rows); |
| 668 | if (proceed == MagickFalse) |
| 669 | status=MagickFalse; |
| 670 | } |
| 671 | } |
| 672 | composite_view=DestroyCacheView(composite_view); |
| 673 | image_view=DestroyCacheView(image_view); |
cristy | 44886b9 | 2012-07-28 13:07:09 +0000 | [diff] [blame] | 674 | composite_image=DestroyImage(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 675 | return(status); |
| 676 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 677 | case CopyAlphaCompositeOp: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 678 | case ChangeMaskCompositeOp: |
cristy | 0cd1f21 | 2012-01-05 15:45:59 +0000 | [diff] [blame] | 679 | case IntensityCompositeOp: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 680 | { |
| 681 | /* |
| 682 | Modify destination outside the overlaid region and require an alpha |
| 683 | channel to exist, to add transparency. |
| 684 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 685 | if (image->alpha_trait != BlendPixelTrait) |
cristy | 42c41de | 2012-05-05 18:36:31 +0000 | [diff] [blame] | 686 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 687 | break; |
| 688 | } |
| 689 | case BlurCompositeOp: |
| 690 | { |
| 691 | CacheView |
| 692 | *composite_view, |
| 693 | *destination_view; |
| 694 | |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 695 | const char |
| 696 | *value; |
| 697 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 698 | MagickRealType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 699 | angle_range, |
| 700 | angle_start, |
| 701 | height, |
| 702 | width; |
| 703 | |
cristy | bce4f4a | 2012-10-14 14:57:47 +0000 | [diff] [blame] | 704 | PixelInfo |
| 705 | pixel; |
| 706 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 707 | ResampleFilter |
| 708 | *resample_filter; |
| 709 | |
| 710 | SegmentInfo |
| 711 | blur; |
| 712 | |
| 713 | /* |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 714 | Blur Image by resampling. |
| 715 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 716 | Blur Image dictated by an overlay gradient map: X = red_channel; |
| 717 | Y = green_channel; compose:args = x_scale[,y_scale[,angle]]. |
| 718 | */ |
| 719 | destination_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 720 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 721 | if (destination_image == (Image *) NULL) |
cristy | 44886b9 | 2012-07-28 13:07:09 +0000 | [diff] [blame] | 722 | { |
| 723 | composite_image=DestroyImage(composite_image); |
| 724 | return(MagickFalse); |
| 725 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 726 | /* |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 727 | Gather the maximum blur sigma values from user. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 728 | */ |
| 729 | SetGeometryInfo(&geometry_info); |
| 730 | flags=NoValue; |
cristy | 1a78095 | 2013-02-10 17:15:30 +0000 | [diff] [blame] | 731 | value=GetImageArtifact(image,"compose:args"); |
| 732 | if (value != (const char *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 733 | flags=ParseGeometry(value,&geometry_info); |
cristy | 1a78095 | 2013-02-10 17:15:30 +0000 | [diff] [blame] | 734 | if ((flags & WidthValue) == 0) |
| 735 | { |
| 736 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, |
| 737 | "InvalidSetting","'%s' '%s'","compose:args",value); |
cristy | 44886b9 | 2012-07-28 13:07:09 +0000 | [diff] [blame] | 738 | composite_image=DestroyImage(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 739 | destination_image=DestroyImage(destination_image); |
| 740 | return(MagickFalse); |
| 741 | } |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 742 | /* |
| 743 | Users input sigma now needs to be converted to the EWA ellipse size. |
| 744 | The filter defaults to a sigma of 0.5 so to make this match the |
| 745 | users input the ellipse size needs to be doubled. |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 746 | */ |
| 747 | width=height=geometry_info.rho*2.0; |
| 748 | if ((flags & HeightValue) != 0 ) |
| 749 | height=geometry_info.sigma*2.0; |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 750 | /* |
| 751 | Default the unrotated ellipse width and height axis vectors. |
| 752 | */ |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 753 | blur.x1=width; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 754 | blur.x2=0.0; |
| 755 | blur.y1=0.0; |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 756 | blur.y2=height; |
| 757 | /* rotate vectors if a rotation angle is given */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 758 | if ((flags & XValue) != 0 ) |
| 759 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 760 | MagickRealType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 761 | angle; |
| 762 | |
| 763 | angle=DegreesToRadians(geometry_info.xi); |
| 764 | blur.x1=width*cos(angle); |
| 765 | blur.x2=width*sin(angle); |
| 766 | blur.y1=(-height*sin(angle)); |
| 767 | blur.y2=height*cos(angle); |
| 768 | } |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 769 | /* Otherwise lets set a angle range and calculate in the loop */ |
| 770 | angle_start=0.0; |
| 771 | angle_range=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 772 | if ((flags & YValue) != 0 ) |
| 773 | { |
| 774 | angle_start=DegreesToRadians(geometry_info.xi); |
| 775 | angle_range=DegreesToRadians(geometry_info.psi)-angle_start; |
| 776 | } |
| 777 | /* |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 778 | Set up a gaussian cylindrical filter for EWA Bluring. |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 779 | |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 780 | As the minimum ellipse radius of support*1.0 the EWA algorithm |
| 781 | can only produce a minimum blur of 0.5 for Gaussian (support=2.0) |
| 782 | This means that even 'No Blur' will be still a little blurry! |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 783 | |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 784 | The solution (as well as the problem of preventing any user |
| 785 | expert filter settings, is to set our own user settings, then |
| 786 | restore them afterwards. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 787 | */ |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 788 | resample_filter=AcquireResampleFilter(image,exception); |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 789 | SetResampleFilter(resample_filter,GaussianFilter); |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 790 | |
| 791 | /* do the variable blurring of each pixel in image */ |
| 792 | GetPixelInfo(image,&pixel); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 793 | composite_view=AcquireVirtualCacheView(composite_image,exception); |
| 794 | destination_view=AcquireAuthenticCacheView(destination_image,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 795 | for (y=0; y < (ssize_t) composite_image->rows; y++) |
| 796 | { |
| 797 | MagickBooleanType |
| 798 | sync; |
| 799 | |
| 800 | register const Quantum |
| 801 | *restrict p; |
| 802 | |
| 803 | register Quantum |
| 804 | *restrict q; |
| 805 | |
| 806 | register ssize_t |
| 807 | x; |
| 808 | |
| 809 | if (((y+y_offset) < 0) || ((y+y_offset) >= (ssize_t) image->rows)) |
| 810 | continue; |
| 811 | p=GetCacheViewVirtualPixels(composite_view,0,y,composite_image->columns, |
| 812 | 1,exception); |
| 813 | q=QueueCacheViewAuthenticPixels(destination_view,0,y, |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 814 | destination_image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 815 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
| 816 | break; |
| 817 | for (x=0; x < (ssize_t) composite_image->columns; x++) |
| 818 | { |
| 819 | if (((x_offset+x) < 0) || ((x_offset+x) >= (ssize_t) image->columns)) |
| 820 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 821 | p+=GetPixelChannels(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 822 | continue; |
| 823 | } |
| 824 | if (fabs(angle_range) > MagickEpsilon) |
| 825 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 826 | MagickRealType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 827 | angle; |
| 828 | |
| 829 | angle=angle_start+angle_range*QuantumScale* |
| 830 | GetPixelBlue(composite_image,p); |
| 831 | blur.x1=width*cos(angle); |
| 832 | blur.x2=width*sin(angle); |
| 833 | blur.y1=(-height*sin(angle)); |
| 834 | blur.y2=height*cos(angle); |
| 835 | } |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 836 | #if 0 |
| 837 | if ( x == 10 && y == 60 ) { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 838 | (void) fprintf(stderr, "blur.x=%lf,%lf, blur.y=%lf,%lf\n",blur.x1, |
| 839 | blur.x2,blur.y1, blur.y2); |
| 840 | (void) fprintf(stderr, "scaled by=%lf,%lf\n",QuantumScale* |
| 841 | GetPixelRed(p),QuantumScale*GetPixelGreen(p)); |
anthony | d292391 | 2012-04-23 13:06:53 +0000 | [diff] [blame] | 842 | #endif |
| 843 | ScaleResampleFilter(resample_filter, |
| 844 | blur.x1*QuantumScale*GetPixelRed(composite_image,p), |
| 845 | blur.y1*QuantumScale*GetPixelGreen(composite_image,p), |
| 846 | blur.x2*QuantumScale*GetPixelRed(composite_image,p), |
| 847 | blur.y2*QuantumScale*GetPixelGreen(composite_image,p) ); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 848 | (void) ResamplePixelColor(resample_filter,(double) x_offset+x, |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 849 | (double) y_offset+y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 850 | SetPixelInfoPixel(destination_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 851 | p+=GetPixelChannels(composite_image); |
| 852 | q+=GetPixelChannels(destination_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 853 | } |
| 854 | sync=SyncCacheViewAuthenticPixels(destination_view,exception); |
| 855 | if (sync == MagickFalse) |
| 856 | break; |
| 857 | } |
| 858 | resample_filter=DestroyResampleFilter(resample_filter); |
| 859 | composite_view=DestroyCacheView(composite_view); |
| 860 | destination_view=DestroyCacheView(destination_view); |
cristy | f661c4d | 2012-07-28 12:57:17 +0000 | [diff] [blame] | 861 | composite_image=DestroyImage(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 862 | composite_image=destination_image; |
| 863 | break; |
| 864 | } |
| 865 | case DisplaceCompositeOp: |
| 866 | case DistortCompositeOp: |
| 867 | { |
| 868 | CacheView |
| 869 | *composite_view, |
| 870 | *destination_view, |
| 871 | *image_view; |
| 872 | |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 873 | const char |
| 874 | *value; |
| 875 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 876 | PixelInfo |
| 877 | pixel; |
| 878 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 879 | MagickRealType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 880 | horizontal_scale, |
| 881 | vertical_scale; |
| 882 | |
| 883 | PointInfo |
| 884 | center, |
| 885 | offset; |
| 886 | |
| 887 | /* |
| 888 | Displace/Distort based on overlay gradient map: |
| 889 | X = red_channel; Y = green_channel; |
| 890 | compose:args = x_scale[,y_scale[,center.x,center.y]] |
| 891 | */ |
| 892 | destination_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 893 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 894 | if (destination_image == (Image *) NULL) |
cristy | 44886b9 | 2012-07-28 13:07:09 +0000 | [diff] [blame] | 895 | { |
| 896 | composite_image=DestroyImage(composite_image); |
| 897 | return(MagickFalse); |
| 898 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 899 | SetGeometryInfo(&geometry_info); |
| 900 | flags=NoValue; |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 901 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 902 | if (value != (char *) NULL) |
| 903 | flags=ParseGeometry(value,&geometry_info); |
| 904 | if ((flags & (WidthValue|HeightValue)) == 0 ) |
| 905 | { |
| 906 | if ((flags & AspectValue) == 0) |
| 907 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 908 | horizontal_scale=(MagickRealType) (composite_image->columns-1.0)/ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 909 | 2.0; |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 910 | vertical_scale=(MagickRealType) (composite_image->rows-1.0)/2.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 911 | } |
| 912 | else |
| 913 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 914 | horizontal_scale=(MagickRealType) (image->columns-1.0)/2.0; |
| 915 | vertical_scale=(MagickRealType) (image->rows-1.0)/2.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | else |
| 919 | { |
| 920 | horizontal_scale=geometry_info.rho; |
| 921 | vertical_scale=geometry_info.sigma; |
| 922 | if ((flags & PercentValue) != 0) |
| 923 | { |
| 924 | if ((flags & AspectValue) == 0) |
| 925 | { |
| 926 | horizontal_scale*=(composite_image->columns-1.0)/200.0; |
| 927 | vertical_scale*=(composite_image->rows-1.0)/200.0; |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | horizontal_scale*=(image->columns-1.0)/200.0; |
| 932 | vertical_scale*=(image->rows-1.0)/200.0; |
| 933 | } |
| 934 | } |
| 935 | if ((flags & HeightValue) == 0) |
| 936 | vertical_scale=horizontal_scale; |
| 937 | } |
| 938 | /* |
| 939 | Determine fixed center point for absolute distortion map |
| 940 | Absolute distort == |
| 941 | Displace offset relative to a fixed absolute point |
| 942 | Select that point according to +X+Y user inputs. |
| 943 | default = center of overlay image |
| 944 | arg flag '!' = locations/percentage relative to background image |
| 945 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 946 | center.x=(MagickRealType) x_offset; |
| 947 | center.y=(MagickRealType) y_offset; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 948 | if (compose == DistortCompositeOp) |
| 949 | { |
| 950 | if ((flags & XValue) == 0) |
| 951 | if ((flags & AspectValue) == 0) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 952 | center.x=(MagickRealType) (x_offset+(composite_image->columns-1)/ |
| 953 | 2.0); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 954 | else |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 955 | center.x=(MagickRealType) ((image->columns-1)/2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 956 | else |
| 957 | if ((flags & AspectValue) == 0) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 958 | center.x=(MagickRealType) x_offset+geometry_info.xi; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 959 | else |
| 960 | center.x=geometry_info.xi; |
| 961 | if ((flags & YValue) == 0) |
| 962 | if ((flags & AspectValue) == 0) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 963 | center.y=(MagickRealType) (y_offset+(composite_image->rows-1)/ |
| 964 | 2.0); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 965 | else |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 966 | center.y=(MagickRealType) ((image->rows-1)/2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 967 | else |
| 968 | if ((flags & AspectValue) == 0) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 969 | center.y=(MagickRealType) y_offset+geometry_info.psi; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 970 | else |
| 971 | center.y=geometry_info.psi; |
| 972 | } |
| 973 | /* |
| 974 | Shift the pixel offset point as defined by the provided, |
| 975 | displacement/distortion map. -- Like a lens... |
| 976 | */ |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 977 | GetPixelInfo(image,&pixel); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 978 | image_view=AcquireVirtualCacheView(image,exception); |
| 979 | composite_view=AcquireVirtualCacheView(composite_image,exception); |
| 980 | destination_view=AcquireAuthenticCacheView(destination_image,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 981 | for (y=0; y < (ssize_t) composite_image->rows; y++) |
| 982 | { |
| 983 | MagickBooleanType |
| 984 | sync; |
| 985 | |
| 986 | register const Quantum |
| 987 | *restrict p; |
| 988 | |
| 989 | register Quantum |
| 990 | *restrict q; |
| 991 | |
| 992 | register ssize_t |
| 993 | x; |
| 994 | |
| 995 | if (((y+y_offset) < 0) || ((y+y_offset) >= (ssize_t) image->rows)) |
| 996 | continue; |
| 997 | p=GetCacheViewVirtualPixels(composite_view,0,y,composite_image->columns, |
| 998 | 1,exception); |
| 999 | q=QueueCacheViewAuthenticPixels(destination_view,0,y, |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 1000 | destination_image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1001 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
| 1002 | break; |
| 1003 | for (x=0; x < (ssize_t) composite_image->columns; x++) |
| 1004 | { |
| 1005 | if (((x_offset+x) < 0) || ((x_offset+x) >= (ssize_t) image->columns)) |
| 1006 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1007 | p+=GetPixelChannels(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1008 | continue; |
| 1009 | } |
| 1010 | /* |
| 1011 | Displace the offset. |
| 1012 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1013 | offset.x=(double) (horizontal_scale*(GetPixelRed(composite_image,p)- |
| 1014 | (((MagickRealType) QuantumRange+1.0)/2.0)))/(((MagickRealType) |
| 1015 | QuantumRange+1.0)/2.0)+center.x+((compose == DisplaceCompositeOp) ? |
| 1016 | x : 0); |
| 1017 | offset.y=(double) (vertical_scale*(GetPixelGreen(composite_image,p)- |
| 1018 | (((MagickRealType) QuantumRange+1.0)/2.0)))/(((MagickRealType) |
| 1019 | QuantumRange+1.0)/2.0)+center.y+((compose == DisplaceCompositeOp) ? |
| 1020 | y : 0); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1021 | (void) InterpolatePixelInfo(image,image_view, |
| 1022 | UndefinedInterpolatePixel,(double) offset.x,(double) offset.y, |
| 1023 | &pixel,exception); |
| 1024 | /* |
| 1025 | Mask with the 'invalid pixel mask' in alpha channel. |
| 1026 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1027 | pixel.alpha=(MagickRealType) QuantumRange*(1.0-(1.0-QuantumScale* |
| 1028 | pixel.alpha)*(1.0-QuantumScale*GetPixelAlpha(composite_image,p))); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 1029 | SetPixelInfoPixel(destination_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1030 | p+=GetPixelChannels(composite_image); |
| 1031 | q+=GetPixelChannels(destination_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1032 | } |
| 1033 | sync=SyncCacheViewAuthenticPixels(destination_view,exception); |
| 1034 | if (sync == MagickFalse) |
| 1035 | break; |
| 1036 | } |
| 1037 | destination_view=DestroyCacheView(destination_view); |
| 1038 | composite_view=DestroyCacheView(composite_view); |
| 1039 | image_view=DestroyCacheView(image_view); |
cristy | f661c4d | 2012-07-28 12:57:17 +0000 | [diff] [blame] | 1040 | composite_image=DestroyImage(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1041 | composite_image=destination_image; |
| 1042 | break; |
| 1043 | } |
| 1044 | case DissolveCompositeOp: |
| 1045 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1046 | const char |
| 1047 | *value; |
| 1048 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1049 | /* |
| 1050 | Geometry arguments to dissolve factors. |
| 1051 | */ |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 1052 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1053 | if (value != (char *) NULL) |
| 1054 | { |
| 1055 | flags=ParseGeometry(value,&geometry_info); |
| 1056 | source_dissolve=geometry_info.rho/100.0; |
| 1057 | destination_dissolve=1.0; |
| 1058 | if ((source_dissolve-MagickEpsilon) < 0.0) |
| 1059 | source_dissolve=0.0; |
| 1060 | if ((source_dissolve+MagickEpsilon) > 1.0) |
| 1061 | { |
| 1062 | destination_dissolve=2.0-source_dissolve; |
| 1063 | source_dissolve=1.0; |
| 1064 | } |
| 1065 | if ((flags & SigmaValue) != 0) |
| 1066 | destination_dissolve=geometry_info.sigma/100.0; |
| 1067 | if ((destination_dissolve-MagickEpsilon) < 0.0) |
| 1068 | destination_dissolve=0.0; |
anthony | 9cb63cc | 2012-04-25 06:10:49 +0000 | [diff] [blame] | 1069 | /* posible speed up? -- from IMv6 update |
| 1070 | clip_to_self=MagickFalse; |
| 1071 | if ((destination_dissolve+MagickEpsilon) > 1.0 ) |
| 1072 | { |
| 1073 | destination_dissolve=1.0; |
| 1074 | clip_to_self=MagickTrue; |
| 1075 | } |
| 1076 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1077 | } |
| 1078 | break; |
| 1079 | } |
| 1080 | case BlendCompositeOp: |
| 1081 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1082 | const char |
| 1083 | *value; |
| 1084 | |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 1085 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1086 | if (value != (char *) NULL) |
| 1087 | { |
| 1088 | flags=ParseGeometry(value,&geometry_info); |
| 1089 | source_dissolve=geometry_info.rho/100.0; |
| 1090 | destination_dissolve=1.0-source_dissolve; |
| 1091 | if ((flags & SigmaValue) != 0) |
| 1092 | destination_dissolve=geometry_info.sigma/100.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | break; |
| 1095 | } |
| 1096 | case MathematicsCompositeOp: |
| 1097 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1098 | const char |
| 1099 | *value; |
| 1100 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1101 | /* |
| 1102 | Just collect the values from "compose:args", setting. |
| 1103 | Unused values are set to zero automagically. |
| 1104 | |
| 1105 | Arguments are normally a comma separated list, so this probably should |
| 1106 | be changed to some 'general comma list' parser, (with a minimum |
| 1107 | number of values) |
| 1108 | */ |
| 1109 | SetGeometryInfo(&geometry_info); |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 1110 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1111 | if (value != (char *) NULL) |
| 1112 | (void) ParseGeometry(value,&geometry_info); |
| 1113 | break; |
| 1114 | } |
| 1115 | case ModulateCompositeOp: |
| 1116 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1117 | const char |
| 1118 | *value; |
| 1119 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1120 | /* |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1121 | Determine the luma and chroma scale. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1122 | */ |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 1123 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1124 | if (value != (char *) NULL) |
| 1125 | { |
| 1126 | flags=ParseGeometry(value,&geometry_info); |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1127 | percent_luma=geometry_info.rho; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1128 | if ((flags & SigmaValue) != 0) |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1129 | percent_chroma=geometry_info.sigma; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1130 | } |
| 1131 | break; |
| 1132 | } |
| 1133 | case ThresholdCompositeOp: |
| 1134 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1135 | const char |
| 1136 | *value; |
| 1137 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1138 | /* |
| 1139 | Determine the amount and threshold. |
| 1140 | */ |
dirk | 55a83c7 | 2014-08-22 18:44:23 +0000 | [diff] [blame] | 1141 | value=GetImageArtifact(image,"compose:args"); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1142 | if (value != (char *) NULL) |
| 1143 | { |
| 1144 | flags=ParseGeometry(value,&geometry_info); |
| 1145 | amount=geometry_info.rho; |
| 1146 | threshold=geometry_info.sigma; |
| 1147 | if ((flags & SigmaValue) == 0) |
| 1148 | threshold=0.05f; |
| 1149 | } |
| 1150 | threshold*=QuantumRange; |
| 1151 | break; |
| 1152 | } |
| 1153 | default: |
| 1154 | break; |
| 1155 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1156 | /* |
| 1157 | Composite image. |
| 1158 | */ |
| 1159 | status=MagickTrue; |
| 1160 | progress=0; |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1161 | midpoint=((MagickRealType) QuantumRange+1.0)/2; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 1162 | composite_view=AcquireVirtualCacheView(composite_image,exception); |
| 1163 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1164 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1165 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 1166 | magick_threads(composite_image,image,image->rows,1) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1167 | #endif |
| 1168 | for (y=0; y < (ssize_t) image->rows; y++) |
| 1169 | { |
| 1170 | const Quantum |
| 1171 | *pixels; |
| 1172 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1173 | MagickRealType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1174 | blue, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1175 | luma, |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1176 | green, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1177 | hue, |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1178 | red, |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1179 | chroma; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1180 | |
cristy | ddeeea2 | 2012-04-12 01:33:09 +0000 | [diff] [blame] | 1181 | PixelInfo |
| 1182 | destination_pixel, |
| 1183 | source_pixel; |
| 1184 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1185 | register const Quantum |
| 1186 | *restrict p; |
| 1187 | |
| 1188 | register Quantum |
| 1189 | *restrict q; |
| 1190 | |
| 1191 | register ssize_t |
| 1192 | x; |
| 1193 | |
| 1194 | if (status == MagickFalse) |
| 1195 | continue; |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1196 | if (clip_to_self != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1197 | { |
| 1198 | if (y < y_offset) |
| 1199 | continue; |
| 1200 | if ((y-y_offset) >= (ssize_t) composite_image->rows) |
| 1201 | continue; |
| 1202 | } |
| 1203 | /* |
| 1204 | If pixels is NULL, y is outside overlay region. |
| 1205 | */ |
| 1206 | pixels=(Quantum *) NULL; |
| 1207 | p=(Quantum *) NULL; |
| 1208 | if ((y >= y_offset) && ((y-y_offset) < (ssize_t) composite_image->rows)) |
| 1209 | { |
| 1210 | p=GetCacheViewVirtualPixels(composite_view,0,y-y_offset, |
| 1211 | composite_image->columns,1,exception); |
| 1212 | if (p == (const Quantum *) NULL) |
| 1213 | { |
| 1214 | status=MagickFalse; |
| 1215 | continue; |
| 1216 | } |
| 1217 | pixels=p; |
| 1218 | if (x_offset < 0) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1219 | p-=x_offset*GetPixelChannels(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1220 | } |
| 1221 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1222 | if (q == (Quantum *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1223 | { |
| 1224 | status=MagickFalse; |
| 1225 | continue; |
| 1226 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1227 | hue=0.0; |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1228 | chroma=0.0; |
| 1229 | luma=0.0; |
cristy | ddeeea2 | 2012-04-12 01:33:09 +0000 | [diff] [blame] | 1230 | GetPixelInfo(image,&destination_pixel); |
| 1231 | GetPixelInfo(composite_image,&source_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1232 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1233 | { |
cristy | 17028dc | 2013-01-24 12:28:39 +0000 | [diff] [blame] | 1234 | double |
| 1235 | gamma; |
| 1236 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1237 | MagickRealType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1238 | alpha, |
| 1239 | Da, |
| 1240 | Dc, |
| 1241 | Dca, |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1242 | Sa, |
| 1243 | Sc, |
| 1244 | Sca; |
| 1245 | |
| 1246 | register ssize_t |
| 1247 | i; |
| 1248 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1249 | size_t |
| 1250 | channels; |
| 1251 | |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 1252 | if (clip_to_self != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1253 | { |
| 1254 | if (x < x_offset) |
| 1255 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1256 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1257 | continue; |
| 1258 | } |
| 1259 | if ((x-x_offset) >= (ssize_t) composite_image->columns) |
| 1260 | break; |
| 1261 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1262 | if ((pixels == (Quantum *) NULL) || (x < x_offset) || |
| 1263 | ((x-x_offset) >= (ssize_t) composite_image->columns)) |
| 1264 | { |
| 1265 | Quantum |
| 1266 | source[MaxPixelChannels]; |
| 1267 | |
| 1268 | /* |
| 1269 | Virtual composite: |
| 1270 | Sc: source color. |
| 1271 | Dc: destination color. |
| 1272 | */ |
| 1273 | (void) GetOneVirtualPixel(composite_image,x-x_offset,y-y_offset, |
| 1274 | source,exception); |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 1275 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1276 | { |
| 1277 | q+=GetPixelChannels(image); |
| 1278 | continue; |
| 1279 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1280 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1281 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1282 | MagickRealType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1283 | pixel; |
| 1284 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 1285 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 1286 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 1287 | PixelTrait composite_traits=GetPixelChannelTraits(composite_image, |
| 1288 | channel); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1289 | if ((traits == UndefinedPixelTrait) || |
| 1290 | (composite_traits == UndefinedPixelTrait)) |
| 1291 | continue; |
| 1292 | switch (compose) |
| 1293 | { |
cristy | c8d6367 | 2012-01-11 13:03:13 +0000 | [diff] [blame] | 1294 | case AlphaCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1295 | case ChangeMaskCompositeOp: |
| 1296 | case CopyAlphaCompositeOp: |
| 1297 | case DstAtopCompositeOp: |
| 1298 | case DstInCompositeOp: |
| 1299 | case InCompositeOp: |
cristy | 0cd1f21 | 2012-01-05 15:45:59 +0000 | [diff] [blame] | 1300 | case IntensityCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1301 | case OutCompositeOp: |
| 1302 | case SrcInCompositeOp: |
| 1303 | case SrcOutCompositeOp: |
| 1304 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1305 | pixel=(MagickRealType) q[i]; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1306 | if (channel == AlphaPixelChannel) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1307 | pixel=(MagickRealType) TransparentAlpha; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1308 | break; |
| 1309 | } |
| 1310 | case ClearCompositeOp: |
| 1311 | case CopyCompositeOp: |
| 1312 | case ReplaceCompositeOp: |
| 1313 | case SrcCompositeOp: |
| 1314 | { |
| 1315 | if (channel == AlphaPixelChannel) |
| 1316 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1317 | pixel=(MagickRealType) TransparentAlpha; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1318 | break; |
| 1319 | } |
| 1320 | pixel=0.0; |
| 1321 | break; |
| 1322 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1323 | case BlendCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1324 | case DissolveCompositeOp: |
| 1325 | { |
| 1326 | if (channel == AlphaPixelChannel) |
| 1327 | { |
| 1328 | pixel=destination_dissolve*GetPixelAlpha(composite_image, |
| 1329 | source); |
| 1330 | break; |
| 1331 | } |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1332 | pixel=(MagickRealType) source[channel]; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1333 | break; |
| 1334 | } |
| 1335 | default: |
| 1336 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1337 | pixel=(MagickRealType) source[channel]; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | } |
| 1341 | q[i]=ClampToQuantum(pixel); |
| 1342 | } |
| 1343 | q+=GetPixelChannels(image); |
| 1344 | continue; |
| 1345 | } |
| 1346 | /* |
| 1347 | Authentic composite: |
| 1348 | Sa: normalized source alpha. |
| 1349 | Da: normalized destination alpha. |
| 1350 | */ |
| 1351 | Sa=QuantumScale*GetPixelAlpha(composite_image,p); |
| 1352 | Da=QuantumScale*GetPixelAlpha(image,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1353 | switch (compose) |
| 1354 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1355 | case BumpmapCompositeOp: |
| 1356 | { |
| 1357 | alpha=GetPixelIntensity(composite_image,p)*Sa; |
| 1358 | break; |
| 1359 | } |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1360 | case ColorBurnCompositeOp: |
cristy | d06bf86 | 2011-12-21 02:18:45 +0000 | [diff] [blame] | 1361 | case ColorDodgeCompositeOp: |
cristy | e0984c8 | 2011-12-20 02:35:37 +0000 | [diff] [blame] | 1362 | case DifferenceCompositeOp: |
| 1363 | case DivideDstCompositeOp: |
| 1364 | case DivideSrcCompositeOp: |
cristy | e0984c8 | 2011-12-20 02:35:37 +0000 | [diff] [blame] | 1365 | case ExclusionCompositeOp: |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1366 | case HardLightCompositeOp: |
cristy | 99fc217 | 2014-06-26 10:30:53 +0000 | [diff] [blame] | 1367 | case HardMixCompositeOp: |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1368 | case LinearBurnCompositeOp: |
| 1369 | case LinearDodgeCompositeOp: |
| 1370 | case LinearLightCompositeOp: |
cristy | d06bf86 | 2011-12-21 02:18:45 +0000 | [diff] [blame] | 1371 | case MathematicsCompositeOp: |
cristy | e0984c8 | 2011-12-20 02:35:37 +0000 | [diff] [blame] | 1372 | case MinusDstCompositeOp: |
| 1373 | case MinusSrcCompositeOp: |
| 1374 | case ModulusAddCompositeOp: |
| 1375 | case ModulusSubtractCompositeOp: |
| 1376 | case MultiplyCompositeOp: |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1377 | case OverlayCompositeOp: |
| 1378 | case PegtopLightCompositeOp: |
| 1379 | case PinLightCompositeOp: |
cristy | e0984c8 | 2011-12-20 02:35:37 +0000 | [diff] [blame] | 1380 | case ScreenCompositeOp: |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1381 | case SoftLightCompositeOp: |
cristy | cdc168f | 2011-12-21 15:24:39 +0000 | [diff] [blame] | 1382 | case VividLightCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1383 | { |
| 1384 | alpha=RoundToUnity(Sa+Da-Sa*Da); |
| 1385 | break; |
| 1386 | } |
| 1387 | case DarkenCompositeOp: |
| 1388 | case DstAtopCompositeOp: |
| 1389 | case DstInCompositeOp: |
| 1390 | case InCompositeOp: |
| 1391 | case LightenCompositeOp: |
| 1392 | case SrcInCompositeOp: |
| 1393 | { |
| 1394 | alpha=Sa*Da; |
| 1395 | break; |
| 1396 | } |
| 1397 | case DissolveCompositeOp: |
| 1398 | { |
| 1399 | alpha=source_dissolve*Sa*(-destination_dissolve*Da)+source_dissolve* |
| 1400 | Sa+destination_dissolve*Da; |
| 1401 | break; |
| 1402 | } |
| 1403 | case DstOverCompositeOp: |
| 1404 | { |
| 1405 | alpha=Da*(-Sa)+Da+Sa; |
| 1406 | break; |
| 1407 | } |
| 1408 | case DstOutCompositeOp: |
| 1409 | { |
| 1410 | alpha=Da*(1.0-Sa); |
| 1411 | break; |
| 1412 | } |
| 1413 | case OutCompositeOp: |
| 1414 | case SrcOutCompositeOp: |
| 1415 | { |
| 1416 | alpha=Sa*(1.0-Da); |
| 1417 | break; |
| 1418 | } |
| 1419 | case OverCompositeOp: |
| 1420 | case SrcOverCompositeOp: |
| 1421 | { |
| 1422 | alpha=Sa*(-Da)+Sa+Da; |
| 1423 | break; |
| 1424 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1425 | case BlendCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1426 | case PlusCompositeOp: |
| 1427 | { |
| 1428 | alpha=RoundToUnity(Sa+Da); |
| 1429 | break; |
| 1430 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1431 | case XorCompositeOp: |
| 1432 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1433 | alpha=Sa+Da-2.0*Sa*Da; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | } |
| 1436 | default: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1437 | { |
| 1438 | alpha=1.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1439 | break; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1440 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1441 | } |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 1442 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1443 | { |
| 1444 | p+=GetPixelChannels(composite_image); |
| 1445 | q+=GetPixelChannels(image); |
| 1446 | continue; |
| 1447 | } |
cristy | 9d3d279 | 2012-04-14 15:15:19 +0000 | [diff] [blame] | 1448 | switch (compose) |
| 1449 | { |
| 1450 | case ColorizeCompositeOp: |
| 1451 | case HueCompositeOp: |
| 1452 | case LuminizeCompositeOp: |
| 1453 | case ModulateCompositeOp: |
| 1454 | case SaturateCompositeOp: |
| 1455 | { |
| 1456 | GetPixelInfoPixel(composite_image,p,&source_pixel); |
| 1457 | GetPixelInfoPixel(image,q,&destination_pixel); |
| 1458 | break; |
| 1459 | } |
| 1460 | default: |
| 1461 | break; |
| 1462 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1463 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1464 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1465 | MagickRealType |
| 1466 | pixel, |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1467 | sans; |
| 1468 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 1469 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 1470 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 1471 | PixelTrait composite_traits=GetPixelChannelTraits(composite_image, |
| 1472 | channel); |
cristy | 0cd1f21 | 2012-01-05 15:45:59 +0000 | [diff] [blame] | 1473 | if (traits == UndefinedPixelTrait) |
| 1474 | continue; |
cristy | a7b0791 | 2012-01-11 20:01:32 +0000 | [diff] [blame] | 1475 | if ((compose != IntensityCompositeOp) && |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1476 | (composite_traits == UndefinedPixelTrait)) |
| 1477 | continue; |
| 1478 | /* |
| 1479 | Sc: source color. |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1480 | Dc: destination color. |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1481 | */ |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1482 | Sc=(MagickRealType) GetPixelChannel(composite_image,channel,p); |
| 1483 | Dc=(MagickRealType) q[i]; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1484 | if ((traits & CopyPixelTrait) != 0) |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1485 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1486 | if (channel != AlphaPixelChannel) |
| 1487 | { |
| 1488 | /* |
| 1489 | Copy channel. |
| 1490 | */ |
| 1491 | q[i]=ClampToQuantum(Sc); |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1492 | continue; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1493 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1494 | /* |
| 1495 | Set alpha channel. |
| 1496 | */ |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1497 | switch (compose) |
| 1498 | { |
cristy | c8d6367 | 2012-01-11 13:03:13 +0000 | [diff] [blame] | 1499 | case AlphaCompositeOp: |
| 1500 | { |
cristy | a7b0791 | 2012-01-11 20:01:32 +0000 | [diff] [blame] | 1501 | pixel=QuantumRange*Sa; |
cristy | c8d6367 | 2012-01-11 13:03:13 +0000 | [diff] [blame] | 1502 | break; |
| 1503 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1504 | case AtopCompositeOp: |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1505 | case CopyBlackCompositeOp: |
| 1506 | case CopyBlueCompositeOp: |
| 1507 | case CopyCyanCompositeOp: |
| 1508 | case CopyGreenCompositeOp: |
| 1509 | case CopyMagentaCompositeOp: |
| 1510 | case CopyRedCompositeOp: |
| 1511 | case CopyYellowCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1512 | case SrcAtopCompositeOp: |
| 1513 | case DstCompositeOp: |
| 1514 | case NoCompositeOp: |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1515 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1516 | pixel=QuantumRange*Da; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1519 | case ChangeMaskCompositeOp: |
| 1520 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1521 | MagickBooleanType |
| 1522 | equivalent; |
| 1523 | |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1524 | if (Da > ((MagickRealType) QuantumRange/2.0)) |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1525 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1526 | pixel=(MagickRealType) TransparentAlpha; |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1527 | break; |
| 1528 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1529 | equivalent=IsFuzzyEquivalencePixel(composite_image,p,image,q); |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1530 | if (equivalent != MagickFalse) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1531 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1532 | pixel=(MagickRealType) TransparentAlpha; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | } |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1535 | pixel=(MagickRealType) OpaqueAlpha; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1536 | break; |
| 1537 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1538 | case ClearCompositeOp: |
| 1539 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1540 | pixel=(MagickRealType) TransparentAlpha; |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | } |
| 1543 | case ColorizeCompositeOp: |
| 1544 | case HueCompositeOp: |
| 1545 | case LuminizeCompositeOp: |
| 1546 | case SaturateCompositeOp: |
| 1547 | { |
| 1548 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
| 1549 | { |
| 1550 | pixel=QuantumRange*Da; |
| 1551 | break; |
| 1552 | } |
| 1553 | if (fabs(QuantumRange*Da-TransparentAlpha) < MagickEpsilon) |
| 1554 | { |
| 1555 | pixel=QuantumRange*Sa; |
| 1556 | break; |
| 1557 | } |
| 1558 | if (Sa < Da) |
| 1559 | { |
| 1560 | pixel=QuantumRange*Da; |
| 1561 | break; |
| 1562 | } |
| 1563 | pixel=QuantumRange*Sa; |
| 1564 | break; |
| 1565 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1566 | case CopyAlphaCompositeOp: |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 1567 | { |
| 1568 | pixel=QuantumRange*Sa; |
cristy | 1a941d7 | 2013-03-08 01:04:41 +0000 | [diff] [blame] | 1569 | if (composite_image->alpha_trait == BlendPixelTrait) |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 1570 | pixel=GetPixelIntensity(composite_image,p); |
| 1571 | break; |
| 1572 | } |
| 1573 | case CopyCompositeOp: |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1574 | case DisplaceCompositeOp: |
| 1575 | case DistortCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1576 | case DstAtopCompositeOp: |
| 1577 | case ReplaceCompositeOp: |
| 1578 | case SrcCompositeOp: |
| 1579 | { |
| 1580 | pixel=QuantumRange*Sa; |
| 1581 | break; |
| 1582 | } |
| 1583 | case DarkenIntensityCompositeOp: |
| 1584 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1585 | pixel=(1.0-Sa)*GetPixelIntensity(composite_image,p) < |
| 1586 | (1.0-Da)*GetPixelIntensity(image,q) ? Sa : Da; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | } |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 1589 | case IntensityCompositeOp: |
| 1590 | { |
cristy | f13c594 | 2012-08-08 23:50:11 +0000 | [diff] [blame] | 1591 | pixel=GetPixelIntensity(composite_image,p); |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 1592 | break; |
| 1593 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1594 | case LightenIntensityCompositeOp: |
| 1595 | { |
| 1596 | pixel=Sa*GetPixelIntensity(composite_image,p) > |
| 1597 | Da*GetPixelIntensity(image,q) ? Sa : Da; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1598 | break; |
| 1599 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1600 | case ModulateCompositeOp: |
| 1601 | { |
| 1602 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
| 1603 | { |
| 1604 | pixel=QuantumRange*Da; |
| 1605 | break; |
| 1606 | } |
| 1607 | pixel=QuantumRange*Da; |
| 1608 | break; |
| 1609 | } |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1610 | default: |
| 1611 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1612 | pixel=QuantumRange*alpha; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | } |
| 1615 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1616 | q[i]=ClampToQuantum(pixel); |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1617 | continue; |
| 1618 | } |
| 1619 | /* |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1620 | Porter-Duff compositions: |
| 1621 | Sca: source normalized color multiplied by alpha. |
| 1622 | Dca: normalized destination color multiplied by alpha. |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1623 | */ |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1624 | Sca=QuantumScale*Sa*Sc; |
| 1625 | Dca=QuantumScale*Da*Dc; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1626 | switch (compose) |
| 1627 | { |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1628 | case DarkenCompositeOp: |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1629 | case LightenCompositeOp: |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1630 | case ModulusSubtractCompositeOp: |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1631 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1632 | gamma=1.0-alpha; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1633 | break; |
| 1634 | } |
| 1635 | default: |
| 1636 | break; |
| 1637 | } |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 1638 | gamma=PerceptibleReciprocal(alpha); |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 1639 | pixel=Dc; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1640 | switch (compose) |
| 1641 | { |
cristy | a7b0791 | 2012-01-11 20:01:32 +0000 | [diff] [blame] | 1642 | case AlphaCompositeOp: |
| 1643 | { |
| 1644 | pixel=QuantumRange*Sa; |
| 1645 | break; |
| 1646 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1647 | case AtopCompositeOp: |
| 1648 | case SrcAtopCompositeOp: |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1649 | { |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1650 | pixel=Sc*Sa+Dc*(1.0-Sa); |
| 1651 | break; |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 1652 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1653 | case BlendCompositeOp: |
| 1654 | { |
| 1655 | pixel=gamma*(source_dissolve*Sa*Sc+destination_dissolve*Da*Dc); |
| 1656 | break; |
| 1657 | } |
| 1658 | case BlurCompositeOp: |
| 1659 | case DisplaceCompositeOp: |
| 1660 | case DistortCompositeOp: |
| 1661 | case CopyCompositeOp: |
| 1662 | case ReplaceCompositeOp: |
| 1663 | case SrcCompositeOp: |
| 1664 | { |
| 1665 | pixel=Sc; |
| 1666 | break; |
| 1667 | } |
| 1668 | case BumpmapCompositeOp: |
| 1669 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1670 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1671 | { |
| 1672 | pixel=Dc; |
| 1673 | break; |
| 1674 | } |
| 1675 | pixel=QuantumScale*GetPixelIntensity(composite_image,p)*Dc; |
| 1676 | break; |
| 1677 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1678 | case ChangeMaskCompositeOp: |
| 1679 | { |
| 1680 | pixel=Dc; |
| 1681 | break; |
| 1682 | } |
| 1683 | case ClearCompositeOp: |
| 1684 | { |
| 1685 | pixel=0.0; |
| 1686 | break; |
| 1687 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1688 | case ColorBurnCompositeOp: |
| 1689 | { |
| 1690 | /* |
| 1691 | Refer to the March 2009 SVG specification. |
| 1692 | */ |
| 1693 | if ((fabs(Sca) < MagickEpsilon) && (fabs(Dca-Da) < MagickEpsilon)) |
| 1694 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1695 | pixel=QuantumRange*gamma*(Sa*Da+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1696 | break; |
| 1697 | } |
| 1698 | if (Sca < MagickEpsilon) |
| 1699 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1700 | pixel=QuantumRange*gamma*(Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1701 | break; |
| 1702 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1703 | pixel=QuantumRange*gamma*(Sa*Da-Sa*MagickMin(Da,(Da-Dca)*Sa/Sca)+ |
| 1704 | Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1705 | break; |
| 1706 | } |
| 1707 | case ColorDodgeCompositeOp: |
| 1708 | { |
cristy | 98a3920 | 2013-07-09 13:25:52 +0000 | [diff] [blame] | 1709 | if ((Sca*Da+Dca*Sa) >= Sa*Da) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1710 | { |
cristy | 31784be | 2013-07-09 13:55:34 +0000 | [diff] [blame] | 1711 | pixel=QuantumRange*gamma*(Sa*Da+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1714 | pixel=QuantumRange*gamma*(Dca*Sa*Sa/(Sa-Sca)+Sca*(1.0-Da)+Dca* |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1715 | (1.0-Sa)); |
| 1716 | break; |
| 1717 | } |
| 1718 | case ColorizeCompositeOp: |
| 1719 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1720 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1721 | { |
| 1722 | pixel=Dc; |
| 1723 | break; |
| 1724 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1725 | if (fabs(QuantumRange*Da-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1726 | { |
| 1727 | pixel=Sc; |
| 1728 | break; |
| 1729 | } |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1730 | CompositeHCL(destination_pixel.red,destination_pixel.green, |
| 1731 | destination_pixel.blue,&sans,&sans,&luma); |
| 1732 | CompositeHCL(source_pixel.red,source_pixel.green,source_pixel.blue, |
| 1733 | &hue,&chroma,&sans); |
| 1734 | HCLComposite(hue,chroma,luma,&red,&green,&blue); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1735 | switch (channel) |
| 1736 | { |
| 1737 | case RedPixelChannel: pixel=red; break; |
| 1738 | case GreenPixelChannel: pixel=green; break; |
| 1739 | case BluePixelChannel: pixel=blue; break; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1740 | default: pixel=Dc; break; |
| 1741 | } |
| 1742 | break; |
| 1743 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1744 | case CopyAlphaCompositeOp: |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 1745 | case IntensityCompositeOp: |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1746 | { |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 1747 | pixel=Dc; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1748 | break; |
| 1749 | } |
| 1750 | case CopyBlackCompositeOp: |
| 1751 | { |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 1752 | if (channel == BlackPixelChannel) |
cristy | 2fda00b | 2013-10-21 16:12:19 +0000 | [diff] [blame] | 1753 | pixel=(MagickRealType) (QuantumRange- |
| 1754 | GetPixelBlack(composite_image,p)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1755 | break; |
| 1756 | } |
| 1757 | case CopyBlueCompositeOp: |
| 1758 | case CopyYellowCompositeOp: |
| 1759 | { |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 1760 | if (channel == BluePixelChannel) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1761 | pixel=(MagickRealType) GetPixelBlue(composite_image,p); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1762 | break; |
| 1763 | } |
| 1764 | case CopyGreenCompositeOp: |
| 1765 | case CopyMagentaCompositeOp: |
| 1766 | { |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 1767 | if (channel == GreenPixelChannel) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1768 | pixel=(MagickRealType) GetPixelGreen(composite_image,p); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | } |
| 1771 | case CopyRedCompositeOp: |
| 1772 | case CopyCyanCompositeOp: |
| 1773 | { |
cristy | d197cbb | 2012-01-13 02:14:12 +0000 | [diff] [blame] | 1774 | if (channel == RedPixelChannel) |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 1775 | pixel=(MagickRealType) GetPixelRed(composite_image,p); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1776 | break; |
| 1777 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1778 | case DarkenCompositeOp: |
| 1779 | { |
| 1780 | /* |
| 1781 | Darken is equivalent to a 'Minimum' method |
| 1782 | OR a greyscale version of a binary 'Or' |
| 1783 | OR the 'Intersection' of pixel sets. |
| 1784 | */ |
| 1785 | if (Sc < Dc) |
| 1786 | { |
| 1787 | pixel=gamma*(Sa*Sc-Sa*Da*Dc+Da*Dc); |
| 1788 | break; |
| 1789 | } |
| 1790 | pixel=gamma*(Da*Dc-Da*Sa*Sc+Sa*Sc); |
| 1791 | break; |
| 1792 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1793 | case DarkenIntensityCompositeOp: |
| 1794 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1795 | pixel=(1.0-Sa)*GetPixelIntensity(composite_image,p) < |
| 1796 | (1.0-Da)*GetPixelIntensity(image,q) ? Sc : Dc; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1797 | break; |
| 1798 | } |
| 1799 | case DifferenceCompositeOp: |
| 1800 | { |
| 1801 | pixel=gamma*(Sa*Sc+Da*Dc-Sa*Da*2.0*MagickMin(Sc,Dc)); |
| 1802 | break; |
| 1803 | } |
| 1804 | case DissolveCompositeOp: |
| 1805 | { |
| 1806 | pixel=gamma*(source_dissolve*Sa*Sc-source_dissolve*Sa* |
| 1807 | destination_dissolve*Da*Dc+destination_dissolve*Da*Dc); |
| 1808 | break; |
| 1809 | } |
| 1810 | case DivideDstCompositeOp: |
| 1811 | { |
| 1812 | if ((fabs(Sca) < MagickEpsilon) && (fabs(Dca) < MagickEpsilon)) |
| 1813 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1814 | pixel=QuantumRange*gamma*(Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1815 | break; |
| 1816 | } |
| 1817 | if (fabs(Dca) < MagickEpsilon) |
| 1818 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1819 | pixel=QuantumRange*gamma*(Sa*Da+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1822 | pixel=QuantumRange*gamma*(Sca*Da*Da/Dca+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1823 | break; |
| 1824 | } |
| 1825 | case DivideSrcCompositeOp: |
| 1826 | { |
| 1827 | if ((fabs(Dca) < MagickEpsilon) && (fabs(Sca) < MagickEpsilon)) |
| 1828 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1829 | pixel=QuantumRange*gamma*(Dca*(1.0-Sa)+Sca*(1.0-Da)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1830 | break; |
| 1831 | } |
| 1832 | if (fabs(Sca) < MagickEpsilon) |
| 1833 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1834 | pixel=QuantumRange*gamma*(Da*Sa+Dca*(1.0-Sa)+Sca*(1.0-Da)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1835 | break; |
| 1836 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1837 | pixel=QuantumRange*gamma*(Dca*Sa*Sa/Sca+Dca*(1.0-Sa)+Sca*(1.0-Da)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1838 | break; |
| 1839 | } |
| 1840 | case DstAtopCompositeOp: |
| 1841 | { |
| 1842 | pixel=Dc*Da+Sc*(1.0-Da); |
| 1843 | break; |
| 1844 | } |
| 1845 | case DstCompositeOp: |
| 1846 | case NoCompositeOp: |
| 1847 | { |
| 1848 | pixel=Dc; |
| 1849 | break; |
| 1850 | } |
| 1851 | case DstInCompositeOp: |
| 1852 | { |
| 1853 | pixel=gamma*(Sa*Dc*Sa); |
| 1854 | break; |
| 1855 | } |
| 1856 | case DstOutCompositeOp: |
| 1857 | { |
| 1858 | pixel=gamma*(Da*Dc*(1.0-Sa)); |
| 1859 | break; |
| 1860 | } |
| 1861 | case DstOverCompositeOp: |
| 1862 | { |
| 1863 | pixel=gamma*(Da*Dc-Da*Sa*Sc+Sa*Sc); |
| 1864 | break; |
| 1865 | } |
| 1866 | case ExclusionCompositeOp: |
| 1867 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1868 | pixel=QuantumRange*gamma*(Sca*Da+Dca*Sa-2.0*Sca*Dca+Sca*(1.0-Da)+ |
| 1869 | Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1870 | break; |
| 1871 | } |
| 1872 | case HardLightCompositeOp: |
| 1873 | { |
| 1874 | if ((2.0*Sca) < Sa) |
| 1875 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1876 | pixel=QuantumRange*gamma*(2.0*Sca*Dca+Sca*(1.0-Da)+Dca* |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1877 | (1.0-Sa)); |
| 1878 | break; |
| 1879 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1880 | pixel=QuantumRange*gamma*(Sa*Da-2.0*(Da-Dca)*(Sa-Sca)+Sca*(1.0-Da)+ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1881 | Dca*(1.0-Sa)); |
| 1882 | break; |
| 1883 | } |
cristy | 99fc217 | 2014-06-26 10:30:53 +0000 | [diff] [blame] | 1884 | case HardMixCompositeOp: |
| 1885 | { |
cristy | a978145 | 2014-06-26 10:58:54 +0000 | [diff] [blame] | 1886 | double |
| 1887 | gamma; |
| 1888 | |
cristy | aa19c35 | 2014-06-26 12:46:02 +0000 | [diff] [blame] | 1889 | if ((Sa+Da) < 1.0) |
cristy | a978145 | 2014-06-26 10:58:54 +0000 | [diff] [blame] | 1890 | gamma=0.0; |
| 1891 | else |
| 1892 | gamma=1.0; |
cristy | aa19c35 | 2014-06-26 12:46:02 +0000 | [diff] [blame] | 1893 | pixel=(gamma*(1.0-Sca)*(1.0-Dca))+Sa*(1.0-Sca)*Dca+Da*(1.0-Dca)*Sca; |
cristy | 99fc217 | 2014-06-26 10:30:53 +0000 | [diff] [blame] | 1894 | break; |
| 1895 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1896 | case HueCompositeOp: |
| 1897 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1898 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1899 | { |
| 1900 | pixel=Dc; |
| 1901 | break; |
| 1902 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1903 | if (fabs(QuantumRange*Da-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1904 | { |
| 1905 | pixel=Sc; |
| 1906 | break; |
| 1907 | } |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1908 | CompositeHCL(destination_pixel.red,destination_pixel.green, |
| 1909 | destination_pixel.blue,&hue,&chroma,&luma); |
| 1910 | CompositeHCL(source_pixel.red,source_pixel.green,source_pixel.blue, |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1911 | &hue,&sans,&sans); |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1912 | HCLComposite(hue,chroma,luma,&red,&green,&blue); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1913 | switch (channel) |
| 1914 | { |
| 1915 | case RedPixelChannel: pixel=red; break; |
| 1916 | case GreenPixelChannel: pixel=green; break; |
| 1917 | case BluePixelChannel: pixel=blue; break; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1918 | default: pixel=Dc; break; |
| 1919 | } |
| 1920 | break; |
| 1921 | } |
| 1922 | case InCompositeOp: |
| 1923 | case SrcInCompositeOp: |
| 1924 | { |
| 1925 | pixel=gamma*(Da*Sc*Da); |
| 1926 | break; |
| 1927 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1928 | case LinearBurnCompositeOp: |
| 1929 | { |
| 1930 | /* |
| 1931 | LinearBurn: as defined by Abode Photoshop, according to |
| 1932 | http://www.simplefilter.de/en/basics/mixmods.html is: |
| 1933 | |
| 1934 | f(Sc,Dc) = Sc + Dc - 1 |
| 1935 | */ |
| 1936 | pixel=QuantumRange*gamma*(Sca+Dca-Sa*Da); |
| 1937 | break; |
| 1938 | } |
| 1939 | case LinearDodgeCompositeOp: |
| 1940 | { |
| 1941 | pixel=QuantumRange*gamma*(Sa*Sc+Da*Dc); |
| 1942 | break; |
| 1943 | } |
| 1944 | case LinearLightCompositeOp: |
| 1945 | { |
| 1946 | /* |
| 1947 | LinearLight: as defined by Abode Photoshop, according to |
| 1948 | http://www.simplefilter.de/en/basics/mixmods.html is: |
| 1949 | |
| 1950 | f(Sc,Dc) = Dc + 2*Sc - 1 |
| 1951 | */ |
| 1952 | pixel=QuantumRange*gamma*((Sca-Sa)*Da+Sca+Dca); |
| 1953 | break; |
| 1954 | } |
| 1955 | case LightenCompositeOp: |
| 1956 | { |
| 1957 | if (Sc > Dc) |
| 1958 | { |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 1959 | pixel=gamma*(Sa*Sc-Sa*Da*Dc+Da*Dc); |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1960 | break; |
| 1961 | } |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 1962 | pixel=gamma*(Da*Dc-Da*Sa*Sc+Sa*Sc); |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1965 | case LightenIntensityCompositeOp: |
| 1966 | { |
| 1967 | /* |
| 1968 | Lighten is equivalent to a 'Maximum' method |
| 1969 | OR a greyscale version of a binary 'And' |
| 1970 | OR the 'Union' of pixel sets. |
| 1971 | */ |
| 1972 | pixel=Sa*GetPixelIntensity(composite_image,p) > |
| 1973 | Da*GetPixelIntensity(image,q) ? Sc : Dc; |
| 1974 | break; |
| 1975 | } |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1976 | case LuminizeCompositeOp: |
| 1977 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1978 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1979 | { |
| 1980 | pixel=Dc; |
| 1981 | break; |
| 1982 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 1983 | if (fabs(QuantumRange*Da-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1984 | { |
| 1985 | pixel=Sc; |
| 1986 | break; |
| 1987 | } |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 1988 | CompositeHCL(destination_pixel.red,destination_pixel.green, |
| 1989 | destination_pixel.blue,&hue,&chroma,&luma); |
| 1990 | CompositeHCL(source_pixel.red,source_pixel.green,source_pixel.blue, |
| 1991 | &sans,&sans,&luma); |
| 1992 | HCLComposite(hue,chroma,luma,&red,&green,&blue); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1993 | switch (channel) |
| 1994 | { |
| 1995 | case RedPixelChannel: pixel=red; break; |
| 1996 | case GreenPixelChannel: pixel=green; break; |
| 1997 | case BluePixelChannel: pixel=blue; break; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 1998 | default: pixel=Dc; break; |
| 1999 | } |
| 2000 | break; |
| 2001 | } |
| 2002 | case MathematicsCompositeOp: |
| 2003 | { |
| 2004 | /* |
| 2005 | 'Mathematics' a free form user control mathematical composition |
| 2006 | is defined as... |
| 2007 | |
| 2008 | f(Sc,Dc) = A*Sc*Dc + B*Sc + C*Dc + D |
| 2009 | |
| 2010 | Where the arguments A,B,C,D are (currently) passed to composite |
| 2011 | as a command separated 'geometry' string in "compose:args" image |
| 2012 | artifact. |
| 2013 | |
| 2014 | A = a->rho, B = a->sigma, C = a->xi, D = a->psi |
| 2015 | |
| 2016 | Applying the SVG transparency formula (see above), we get... |
| 2017 | |
| 2018 | Dca' = Sa*Da*f(Sc,Dc) + Sca*(1.0-Da) + Dca*(1.0-Sa) |
| 2019 | |
| 2020 | Dca' = A*Sca*Dca + B*Sca*Da + C*Dca*Sa + D*Sa*Da + Sca*(1.0-Da) + |
| 2021 | Dca*(1.0-Sa) |
| 2022 | */ |
| 2023 | pixel=gamma*geometry_info.rho*Sa*Sc*Da*Dc+geometry_info.sigma* |
| 2024 | Sa*Sc*Da+geometry_info.xi*Da*Dc*Sa+geometry_info.psi*Sa*Da+ |
| 2025 | Sa*Sc*(1.0-Da)+Da*Dc*(1.0-Sa); |
| 2026 | break; |
| 2027 | } |
| 2028 | case MinusDstCompositeOp: |
| 2029 | { |
| 2030 | pixel=gamma*(Sa*Sc+Da*Dc-2.0*Da*Dc*Sa); |
| 2031 | break; |
| 2032 | } |
| 2033 | case MinusSrcCompositeOp: |
| 2034 | { |
| 2035 | /* |
| 2036 | Minus source from destination. |
| 2037 | |
| 2038 | f(Sc,Dc) = Sc - Dc |
| 2039 | */ |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2040 | pixel=QuantumRange*gamma*(Da*Dc+Sa*Sc-2.0*Sa*Sc*Da); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | } |
| 2043 | case ModulateCompositeOp: |
| 2044 | { |
| 2045 | ssize_t |
| 2046 | offset; |
| 2047 | |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2048 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2049 | { |
| 2050 | pixel=Dc; |
| 2051 | break; |
| 2052 | } |
| 2053 | offset=(ssize_t) (GetPixelIntensity(composite_image,p)-midpoint); |
| 2054 | if (offset == 0) |
| 2055 | { |
| 2056 | pixel=Dc; |
| 2057 | break; |
| 2058 | } |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 2059 | CompositeHCL(destination_pixel.red,destination_pixel.green, |
| 2060 | destination_pixel.blue,&hue,&chroma,&luma); |
| 2061 | luma+=(0.01*percent_luma*offset)/midpoint; |
| 2062 | chroma*=0.01*percent_chroma; |
| 2063 | HCLComposite(hue,chroma,luma,&red,&green,&blue); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2064 | switch (channel) |
| 2065 | { |
| 2066 | case RedPixelChannel: pixel=red; break; |
| 2067 | case GreenPixelChannel: pixel=green; break; |
| 2068 | case BluePixelChannel: pixel=blue; break; |
| 2069 | default: pixel=Dc; break; |
| 2070 | } |
| 2071 | break; |
| 2072 | } |
| 2073 | case ModulusAddCompositeOp: |
| 2074 | { |
| 2075 | pixel=Sc+Dc; |
| 2076 | if (pixel > QuantumRange) |
cristy | 516edc1 | 2013-10-27 10:53:42 +0000 | [diff] [blame] | 2077 | pixel-=QuantumRange; |
cristy | 91de9ea | 2013-11-17 14:45:54 +0000 | [diff] [blame] | 2078 | pixel=gamma*(Sa*Da*pixel+Sa*Sc*(1.0-Da)+Da*Dc*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | } |
| 2081 | case ModulusSubtractCompositeOp: |
| 2082 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2083 | pixel=Sc-Dc; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2084 | if (pixel < 0.0) |
cristy | 516edc1 | 2013-10-27 10:53:42 +0000 | [diff] [blame] | 2085 | pixel+=QuantumRange; |
cristy | 91de9ea | 2013-11-17 14:45:54 +0000 | [diff] [blame] | 2086 | pixel=gamma*(Sa*Da*pixel+Sa*Sc*(1.0-Da)+Da*Dc*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2087 | break; |
| 2088 | } |
| 2089 | case MultiplyCompositeOp: |
| 2090 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2091 | pixel=QuantumRange*gamma*(Sca*Dca+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | } |
| 2094 | case OutCompositeOp: |
| 2095 | case SrcOutCompositeOp: |
| 2096 | { |
| 2097 | pixel=gamma*(Sa*Sc*(1.0-Da)); |
| 2098 | break; |
| 2099 | } |
| 2100 | case OverCompositeOp: |
| 2101 | case SrcOverCompositeOp: |
| 2102 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2103 | pixel=QuantumRange*gamma*(Sa*Sc-Sa*Da*Dc+Da*Dc); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | } |
| 2106 | case OverlayCompositeOp: |
| 2107 | { |
| 2108 | if ((2.0*Dca) < Da) |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2109 | { |
| 2110 | pixel=QuantumRange*gamma*(2.0*Dca*Sca+Dca*(1.0-Sa)+Sca* |
| 2111 | (1.0-Da)); |
| 2112 | break; |
| 2113 | } |
| 2114 | pixel=QuantumRange*gamma*(Da*Sa-2.0*(Sa-Sca)*(Da-Dca)+Dca*(1.0-Sa)+ |
| 2115 | Sca*(1.0-Da)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | } |
| 2118 | case PegtopLightCompositeOp: |
| 2119 | { |
| 2120 | /* |
| 2121 | PegTop: A Soft-Light alternative: A continuous version of the |
| 2122 | Softlight function, producing very similar results. |
| 2123 | |
| 2124 | f(Sc,Dc) = Dc^2*(1-2*Sc) + 2*Sc*Dc |
| 2125 | |
| 2126 | http://www.pegtop.net/delphi/articles/blendmodes/softlight.htm. |
| 2127 | */ |
| 2128 | if (fabs(Da) < MagickEpsilon) |
| 2129 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2130 | pixel=QuantumRange*gamma*(Sca); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2131 | break; |
| 2132 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2133 | pixel=QuantumRange*gamma*(Dca*Dca*(Sa-2.0*Sca)/Da+Sca*(2.0*Dca+1.0- |
| 2134 | Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | } |
| 2137 | case PinLightCompositeOp: |
| 2138 | { |
| 2139 | /* |
| 2140 | PinLight: A Photoshop 7 composition method |
| 2141 | http://www.simplefilter.de/en/basics/mixmods.html |
| 2142 | |
| 2143 | f(Sc,Dc) = Dc<2*Sc-1 ? 2*Sc-1 : Dc>2*Sc ? 2*Sc : Dc |
| 2144 | */ |
| 2145 | if ((Dca*Sa) < (Da*(2.0*Sca-Sa))) |
| 2146 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2147 | pixel=QuantumRange*gamma*(Sca*(Da+1.0)-Sa*Da+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2148 | break; |
| 2149 | } |
| 2150 | if ((Dca*Sa) > (2.0*Sca*Da)) |
| 2151 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2152 | pixel=QuantumRange*gamma*(Sca*Da+Sca+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2153 | break; |
| 2154 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2155 | pixel=QuantumRange*gamma*(Sca*(1.0-Da)+Dca); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | } |
| 2158 | case PlusCompositeOp: |
| 2159 | { |
cristy | 24d5d72 | 2012-05-17 12:27:27 +0000 | [diff] [blame] | 2160 | pixel=gamma*(Sa*Sc+Da*Dc); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2161 | break; |
| 2162 | } |
| 2163 | case SaturateCompositeOp: |
| 2164 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2165 | if (fabs(QuantumRange*Sa-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2166 | { |
| 2167 | pixel=Dc; |
| 2168 | break; |
| 2169 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2170 | if (fabs(QuantumRange*Da-TransparentAlpha) < MagickEpsilon) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2171 | { |
| 2172 | pixel=Sc; |
| 2173 | break; |
| 2174 | } |
cristy | 7133e64 | 2012-08-14 11:04:11 +0000 | [diff] [blame] | 2175 | CompositeHCL(destination_pixel.red,destination_pixel.green, |
| 2176 | destination_pixel.blue,&hue,&chroma,&luma); |
| 2177 | CompositeHCL(source_pixel.red,source_pixel.green,source_pixel.blue, |
| 2178 | &sans,&chroma,&sans); |
| 2179 | HCLComposite(hue,chroma,luma,&red,&green,&blue); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2180 | switch (channel) |
| 2181 | { |
| 2182 | case RedPixelChannel: pixel=red; break; |
| 2183 | case GreenPixelChannel: pixel=green; break; |
| 2184 | case BluePixelChannel: pixel=blue; break; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2185 | default: pixel=Dc; break; |
| 2186 | } |
| 2187 | break; |
| 2188 | } |
| 2189 | case ScreenCompositeOp: |
| 2190 | { |
| 2191 | /* |
| 2192 | Screen: a negated multiply: |
| 2193 | |
| 2194 | f(Sc,Dc) = 1.0-(1.0-Sc)*(1.0-Dc) |
| 2195 | */ |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2196 | pixel=QuantumRange*gamma*(Sca+Dca-Sca*Dca); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2197 | break; |
| 2198 | } |
| 2199 | case SoftLightCompositeOp: |
| 2200 | { |
| 2201 | /* |
| 2202 | Refer to the March 2009 SVG specification. |
| 2203 | */ |
| 2204 | if ((2.0*Sca) < Sa) |
| 2205 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2206 | pixel=QuantumRange*gamma*(Dca*(Sa+(2.0*Sca-Sa)*(1.0-(Dca/Da)))+ |
| 2207 | Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | } |
| 2210 | if (((2.0*Sca) > Sa) && ((4.0*Dca) <= Da)) |
| 2211 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2212 | pixel=QuantumRange*gamma*(Dca*Sa+Da*(2.0*Sca-Sa)*(4.0*(Dca/Da)* |
| 2213 | (4.0*(Dca/Da)+1.0)*((Dca/Da)-1.0)+7.0*(Dca/Da))+Sca*(1.0-Da)+ |
| 2214 | Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2217 | pixel=QuantumRange*gamma*(Dca*Sa+Da*(2.0*Sca-Sa)*(pow((Dca/Da),0.5)- |
| 2218 | (Dca/Da))+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2219 | break; |
| 2220 | } |
| 2221 | case ThresholdCompositeOp: |
| 2222 | { |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 2223 | MagickRealType |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2224 | delta; |
| 2225 | |
| 2226 | delta=Sc-Dc; |
cristy | 7159f66 | 2012-10-28 17:32:43 +0000 | [diff] [blame] | 2227 | if ((MagickRealType) fabs((double) (2.0*delta)) < threshold) |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2228 | { |
| 2229 | pixel=gamma*Dc; |
| 2230 | break; |
| 2231 | } |
| 2232 | pixel=gamma*(Dc+delta*amount); |
| 2233 | break; |
| 2234 | } |
| 2235 | case VividLightCompositeOp: |
| 2236 | { |
| 2237 | /* |
| 2238 | VividLight: A Photoshop 7 composition method. See |
| 2239 | http://www.simplefilter.de/en/basics/mixmods.html. |
| 2240 | |
| 2241 | f(Sc,Dc) = (2*Sc < 1) ? 1-(1-Dc)/(2*Sc) : Dc/(2*(1-Sc)) |
| 2242 | */ |
| 2243 | if ((fabs(Sa) < MagickEpsilon) || (fabs(Sca-Sa) < MagickEpsilon)) |
| 2244 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2245 | pixel=QuantumRange*gamma*(Sa*Da+Sca*(1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | } |
| 2248 | if ((2.0*Sca) <= Sa) |
| 2249 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2250 | pixel=QuantumRange*gamma*(Sa*(Da+Sa*(Dca-Da)/(2.0*Sca))+Sca* |
| 2251 | (1.0-Da)+Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2252 | break; |
| 2253 | } |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2254 | pixel=QuantumRange*gamma*(Dca*Sa*Sa/(2.0*(Sa-Sca))+Sca*(1.0-Da)+ |
| 2255 | Dca*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | } |
| 2258 | case XorCompositeOp: |
| 2259 | { |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 2260 | pixel=QuantumRange*gamma*(Sc*Sa*(1.0-Da)+Dc*Da*(1.0-Sa)); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2261 | break; |
| 2262 | } |
| 2263 | default: |
| 2264 | { |
| 2265 | pixel=Sc; |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | q[i]=ClampToQuantum(pixel); |
cristy | e10859a | 2011-12-18 22:28:59 +0000 | [diff] [blame] | 2270 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2271 | p+=GetPixelChannels(composite_image); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 2272 | channels=GetPixelChannels(composite_image); |
| 2273 | if (p >= (pixels+channels*composite_image->columns)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2274 | p=pixels; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2275 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2276 | } |
| 2277 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2278 | status=MagickFalse; |
| 2279 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 2280 | { |
| 2281 | MagickBooleanType |
| 2282 | proceed; |
| 2283 | |
| 2284 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | bd0435b | 2012-01-05 16:20:47 +0000 | [diff] [blame] | 2285 | #pragma omp critical (MagickCore_CompositeImage) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2286 | #endif |
| 2287 | proceed=SetImageProgress(image,CompositeImageTag,progress++, |
| 2288 | image->rows); |
| 2289 | if (proceed == MagickFalse) |
| 2290 | status=MagickFalse; |
| 2291 | } |
| 2292 | } |
| 2293 | composite_view=DestroyCacheView(composite_view); |
| 2294 | image_view=DestroyCacheView(image_view); |
| 2295 | if (destination_image != (Image * ) NULL) |
| 2296 | destination_image=DestroyImage(destination_image); |
cristy | f661c4d | 2012-07-28 12:57:17 +0000 | [diff] [blame] | 2297 | else |
| 2298 | composite_image=DestroyImage(composite_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2299 | return(status); |
| 2300 | } |
| 2301 | |
| 2302 | /* |
| 2303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2304 | % % |
| 2305 | % % |
| 2306 | % % |
| 2307 | % T e x t u r e I m a g e % |
| 2308 | % % |
| 2309 | % % |
| 2310 | % % |
| 2311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2312 | % |
| 2313 | % TextureImage() repeatedly tiles the texture image across and down the image |
| 2314 | % canvas. |
| 2315 | % |
| 2316 | % The format of the TextureImage method is: |
| 2317 | % |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2318 | % MagickBooleanType TextureImage(Image *image,const Image *texture, |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 2319 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2320 | % |
| 2321 | % A description of each parameter follows: |
| 2322 | % |
| 2323 | % o image: the image. |
| 2324 | % |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2325 | % o texture_image: This image is the texture to layer on the background. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2326 | % |
| 2327 | */ |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2328 | MagickExport MagickBooleanType TextureImage(Image *image,const Image *texture, |
| 2329 | ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2330 | { |
| 2331 | #define TextureImageTag "Texture/Image" |
| 2332 | |
| 2333 | CacheView |
| 2334 | *image_view, |
| 2335 | *texture_view; |
| 2336 | |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2337 | Image |
| 2338 | *texture_image; |
| 2339 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2340 | MagickBooleanType |
| 2341 | status; |
| 2342 | |
| 2343 | ssize_t |
| 2344 | y; |
| 2345 | |
| 2346 | assert(image != (Image *) NULL); |
| 2347 | if (image->debug != MagickFalse) |
| 2348 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2349 | assert(image->signature == MagickSignature); |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2350 | if (texture == (const Image *) NULL) |
| 2351 | return(MagickFalse); |
| 2352 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
| 2353 | return(MagickFalse); |
| 2354 | texture_image=CloneImage(texture,0,0,MagickTrue,exception); |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2355 | if (texture_image == (const Image *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2356 | return(MagickFalse); |
cristy | a865ccd | 2012-07-28 00:33:10 +0000 | [diff] [blame] | 2357 | (void) TransformImageColorspace(texture_image,image->colorspace,exception); |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 2358 | (void) SetImageVirtualPixelMethod(texture_image,TileVirtualPixelMethod, |
| 2359 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2360 | status=MagickTrue; |
| 2361 | if ((image->compose != CopyCompositeOp) && |
cristy | 974a2a8 | 2013-04-23 12:57:16 +0000 | [diff] [blame] | 2362 | ((image->compose != OverCompositeOp) || |
| 2363 | (image->alpha_trait == BlendPixelTrait) || |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 2364 | (texture_image->alpha_trait == BlendPixelTrait))) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2365 | { |
| 2366 | /* |
| 2367 | Tile texture onto the image background. |
| 2368 | */ |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2369 | for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) texture_image->rows) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2370 | { |
| 2371 | register ssize_t |
| 2372 | x; |
| 2373 | |
| 2374 | if (status == MagickFalse) |
| 2375 | continue; |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2376 | for (x=0; x < (ssize_t) image->columns; x+=(ssize_t) texture_image->columns) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2377 | { |
| 2378 | MagickBooleanType |
| 2379 | thread_status; |
| 2380 | |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 2381 | thread_status=CompositeImage(image,texture_image,image->compose, |
| 2382 | MagickFalse,x+texture_image->tile_offset.x,y+ |
| 2383 | texture_image->tile_offset.y,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2384 | if (thread_status == MagickFalse) |
| 2385 | { |
| 2386 | status=thread_status; |
| 2387 | break; |
| 2388 | } |
| 2389 | } |
| 2390 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 2391 | { |
| 2392 | MagickBooleanType |
| 2393 | proceed; |
| 2394 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2395 | proceed=SetImageProgress(image,TextureImageTag,(MagickOffsetType) |
| 2396 | y,image->rows); |
| 2397 | if (proceed == MagickFalse) |
| 2398 | status=MagickFalse; |
| 2399 | } |
| 2400 | } |
| 2401 | (void) SetImageProgress(image,TextureImageTag,(MagickOffsetType) |
| 2402 | image->rows,image->rows); |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2403 | texture_image=DestroyImage(texture_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2404 | return(status); |
| 2405 | } |
| 2406 | /* |
| 2407 | Tile texture onto the image background (optimized). |
| 2408 | */ |
| 2409 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 2410 | texture_view=AcquireVirtualCacheView(texture_image,exception); |
| 2411 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | e891439 | 2012-12-16 21:16:11 +0000 | [diff] [blame] | 2412 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 2413 | #pragma omp parallel for schedule(static,4) shared(status) \ |
| 2414 | magick_threads(texture_image,image,1,1) |
cristy | e891439 | 2012-12-16 21:16:11 +0000 | [diff] [blame] | 2415 | #endif |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2416 | for (y=0; y < (ssize_t) image->rows; y++) |
| 2417 | { |
| 2418 | MagickBooleanType |
| 2419 | sync; |
| 2420 | |
| 2421 | register const Quantum |
| 2422 | *p, |
| 2423 | *pixels; |
| 2424 | |
| 2425 | register ssize_t |
| 2426 | x; |
| 2427 | |
| 2428 | register Quantum |
| 2429 | *q; |
| 2430 | |
| 2431 | size_t |
| 2432 | width; |
| 2433 | |
| 2434 | if (status == MagickFalse) |
| 2435 | continue; |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2436 | pixels=GetCacheViewVirtualPixels(texture_view,texture_image->tile_offset.x, |
| 2437 | (y+texture_image->tile_offset.y) % texture_image->rows, |
| 2438 | texture_image->columns,1,exception); |
| 2439 | q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2440 | if ((pixels == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
| 2441 | { |
| 2442 | status=MagickFalse; |
| 2443 | continue; |
| 2444 | } |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2445 | for (x=0; x < (ssize_t) image->columns; x+=(ssize_t) texture_image->columns) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2446 | { |
| 2447 | register ssize_t |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2448 | j; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2449 | |
| 2450 | p=pixels; |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2451 | width=texture_image->columns; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2452 | if ((x+(ssize_t) width) > (ssize_t) image->columns) |
| 2453 | width=image->columns-x; |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2454 | for (j=0; j < (ssize_t) width; j++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2455 | { |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2456 | register ssize_t |
| 2457 | i; |
| 2458 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 2459 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 2460 | { |
| 2461 | p+=GetPixelChannels(texture_image); |
| 2462 | q+=GetPixelChannels(image); |
| 2463 | continue; |
| 2464 | } |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2465 | for (i=0; i < (ssize_t) GetPixelChannels(texture_image); i++) |
| 2466 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 2467 | PixelChannel channel=GetPixelChannelChannel(texture_image,i); |
| 2468 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 2469 | PixelTrait texture_traits=GetPixelChannelTraits(texture_image, |
| 2470 | channel); |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 2471 | if ((traits == UndefinedPixelTrait) || |
| 2472 | (texture_traits == UndefinedPixelTrait)) |
| 2473 | continue; |
| 2474 | SetPixelChannel(image,channel,p[i],q); |
| 2475 | } |
| 2476 | p+=GetPixelChannels(texture_image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2477 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 2481 | if (sync == MagickFalse) |
| 2482 | status=MagickFalse; |
| 2483 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 2484 | { |
| 2485 | MagickBooleanType |
| 2486 | proceed; |
| 2487 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2488 | proceed=SetImageProgress(image,TextureImageTag,(MagickOffsetType) y, |
| 2489 | image->rows); |
| 2490 | if (proceed == MagickFalse) |
| 2491 | status=MagickFalse; |
| 2492 | } |
| 2493 | } |
| 2494 | texture_view=DestroyCacheView(texture_view); |
| 2495 | image_view=DestroyCacheView(image_view); |
cristy | 30d8c94 | 2012-02-07 13:44:59 +0000 | [diff] [blame] | 2496 | texture_image=DestroyImage(texture_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2497 | return(status); |
| 2498 | } |