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