cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 5 | % W W AAA N N DDDD % |
| 6 | % W W A A NN N D D % |
| 7 | % W W W AAAAA N N N D D % |
| 8 | % WW WW A A N NN D D % |
| 9 | % W W A A N N DDDD % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 10 | % % |
| 11 | % V V IIIII EEEEE W W % |
| 12 | % V V I E W W % |
| 13 | % V V I EEE W W W % |
| 14 | % V V I E WW WW % |
| 15 | % V IIIII EEEEE W W % |
| 16 | % % |
| 17 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 18 | % MagickWand Wand View Methods % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 19 | % % |
| 20 | % Software Design % |
| 21 | % John Cristy % |
| 22 | % March 2003 % |
| 23 | % % |
| 24 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 25 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 26 | % dedicated to making software imaging solutions freely available. % |
| 27 | % % |
| 28 | % You may not use this file except in compliance with the License. You may % |
| 29 | % obtain a copy of the License at % |
| 30 | % % |
| 31 | % http://www.imagemagick.org/script/license.php % |
| 32 | % % |
| 33 | % Unless required by applicable law or agreed to in writing, software % |
| 34 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 35 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 36 | % See the License for the specific language governing permissions and % |
| 37 | % limitations under the License. % |
| 38 | % % |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 40 | % |
| 41 | % |
| 42 | % |
| 43 | */ |
| 44 | |
| 45 | /* |
| 46 | Include declarations. |
| 47 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickWand/studio.h" |
| 49 | #include "MagickWand/MagickWand.h" |
| 50 | #include "MagickWand/magick-wand-private.h" |
| 51 | #include "MagickWand/wand.h" |
| 52 | #include "MagickCore/monitor-private.h" |
| 53 | #include "MagickCore/thread-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 54 | /* |
| 55 | Define declarations. |
| 56 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 57 | #define WandViewId "WandView" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | Typedef declarations. |
| 61 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 62 | struct _WandView |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 63 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 64 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | id; |
| 66 | |
| 67 | char |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 68 | name[MaxTextExtent], |
| 69 | *description; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 71 | RectangleInfo |
| 72 | extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 73 | |
| 74 | MagickWand |
| 75 | *wand; |
| 76 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 77 | Image |
| 78 | *image; |
| 79 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | CacheView |
| 81 | *view; |
| 82 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | PixelWand |
| 84 | ***pixel_wands; |
| 85 | |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 86 | ExceptionInfo |
| 87 | *exception; |
| 88 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 89 | MagickBooleanType |
| 90 | debug; |
| 91 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 92 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 93 | signature; |
| 94 | }; |
| 95 | |
| 96 | /* |
| 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 98 | % % |
| 99 | % % |
| 100 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 101 | % C l o n e W a n d V i e w % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 102 | % % |
| 103 | % % |
| 104 | % % |
| 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 106 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 107 | % CloneWandView() makes a copy of the specified wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 109 | % The format of the CloneWandView method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 111 | % WandView *CloneWandView(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | % |
| 113 | % A description of each parameter follows: |
| 114 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 115 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | % |
| 117 | */ |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 118 | WandExport WandView *CloneWandView(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | { |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 120 | WandView |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 121 | *clone_view; |
| 122 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 123 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | i; |
| 125 | |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 126 | assert(wand_view != (WandView *) NULL); |
| 127 | assert(wand_view->signature == WandSignature); |
| 128 | if (wand_view->debug != MagickFalse) |
| 129 | (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand_view->name); |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 130 | clone_view=(WandView *) AcquireMagickMemory(sizeof(*clone_view)); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 131 | if (clone_view == (WandView *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 132 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 133 | wand_view->name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | (void) ResetMagickMemory(clone_view,0,sizeof(*clone_view)); |
| 135 | clone_view->id=AcquireWandId(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 136 | (void) FormatLocaleString(clone_view->name,MaxTextExtent,"%s-%.20g", |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 137 | WandViewId,(double) clone_view->id); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 138 | clone_view->description=ConstantString(wand_view->description); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 139 | clone_view->image=CloneImage(wand_view->image,0,0,MagickTrue, |
| 140 | wand_view->exception); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 141 | clone_view->view=CloneCacheView(wand_view->view); |
| 142 | clone_view->extent=wand_view->extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | clone_view->exception=AcquireExceptionInfo(); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 144 | InheritException(clone_view->exception,wand_view->exception); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 145 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 146 | clone_view->pixel_wands[i]=ClonePixelWands((const PixelWand **) |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 147 | wand_view->pixel_wands[i],wand_view->extent.width); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 148 | clone_view->debug=wand_view->debug; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 149 | if (clone_view->debug != MagickFalse) |
| 150 | (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_view->name); |
| 151 | clone_view->signature=WandSignature; |
| 152 | return(clone_view); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 157 | % % |
| 158 | % % |
| 159 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 160 | % D e s t r o y W a n d V i e w % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | % % |
| 162 | % % |
| 163 | % % |
| 164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 165 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 166 | % DestroyWandView() deallocates memory associated with a wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 168 | % The format of the DestroyWandView method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 170 | % WandView *DestroyWandView(WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | % |
| 172 | % A description of each parameter follows: |
| 173 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 174 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | % |
| 176 | */ |
| 177 | |
| 178 | static PixelWand ***DestroyPixelsThreadSet(PixelWand ***pixel_wands, |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 179 | const size_t number_wands) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 181 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | i; |
| 183 | |
| 184 | assert(pixel_wands != (PixelWand ***) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 185 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | if (pixel_wands[i] != (PixelWand **) NULL) |
| 187 | pixel_wands[i]=DestroyPixelWands(pixel_wands[i],number_wands); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 188 | pixel_wands=(PixelWand ***) RelinquishMagickMemory(pixel_wands); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | return(pixel_wands); |
| 190 | } |
| 191 | |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 192 | WandExport WandView *DestroyWandView(WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | { |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 194 | assert(wand_view != (WandView *) NULL); |
| 195 | assert(wand_view->signature == WandSignature); |
| 196 | wand_view->pixel_wands=DestroyPixelsThreadSet(wand_view->pixel_wands, |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 197 | wand_view->extent.width); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 198 | wand_view->image=DestroyImage(wand_view->image); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 199 | wand_view->view=DestroyCacheView(wand_view->view); |
| 200 | wand_view->exception=DestroyExceptionInfo(wand_view->exception); |
| 201 | wand_view->signature=(~WandSignature); |
| 202 | RelinquishWandId(wand_view->id); |
| 203 | wand_view=(WandView *) RelinquishMagickMemory(wand_view); |
| 204 | return(wand_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* |
| 208 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 209 | % % |
| 210 | % % |
| 211 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 212 | % D u p l e x T r a n s f e r W a n d V i e w I t e r a t o r % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | % % |
| 214 | % % |
| 215 | % % |
| 216 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 217 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 218 | % DuplexTransferWandViewIterator() iterates over three wand views in |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | % parallel and calls your transfer method for each scanline of the view. The |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 220 | % source and duplex pixel extent is not confined to the image canvas-- that is |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 221 | % you can include negative offsets or widths or heights that exceed the image |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 222 | % dimension. However, the destination wand view is confined to the image |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | % canvas-- that is no negative offsets or widths or heights that exceed the |
| 224 | % image dimension are permitted. |
| 225 | % |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 226 | % The callback signature is: |
| 227 | % |
| 228 | % MagickBooleanType DuplexTransferImageViewMethod(const WandView *source, |
| 229 | % const WandView *duplex,WandView *destination,const ssize_t y, |
| 230 | % const int thread_id,void *context) |
| 231 | % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 232 | % Use this pragma if the view is not single threaded: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | % |
| 234 | % #pragma omp critical |
| 235 | % |
| 236 | % to define a section of code in your callback transfer method that must be |
| 237 | % executed by a single thread at a time. |
| 238 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 239 | % The format of the DuplexTransferWandViewIterator method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 241 | % MagickBooleanType DuplexTransferWandViewIterator(WandView *source, |
| 242 | % WandView *duplex,WandView *destination, |
| 243 | % DuplexTransferWandViewMethod transfer,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 244 | % |
| 245 | % A description of each parameter follows: |
| 246 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 247 | % o source: the source wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 249 | % o duplex: the duplex wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 250 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 251 | % o destination: the destination wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | % |
| 253 | % o transfer: the transfer callback method. |
| 254 | % |
| 255 | % o context: the user defined context. |
| 256 | % |
| 257 | */ |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 258 | WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, |
| 259 | WandView *duplex,WandView *destination,DuplexTransferWandViewMethod transfer, |
| 260 | void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 262 | Image |
| 263 | *destination_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | *source_image; |
| 265 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | MagickBooleanType |
| 267 | status; |
| 268 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 269 | MagickOffsetType |
| 270 | progress; |
| 271 | |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 272 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 273 | size_t |
cristy | 26b6491 | 2012-12-16 18:20:09 +0000 | [diff] [blame] | 274 | height; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 275 | #endif |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 276 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 277 | ssize_t |
| 278 | y; |
| 279 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 280 | assert(source != (WandView *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 281 | assert(source->signature == WandSignature); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 282 | if (transfer == (DuplexTransferWandViewMethod) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | return(MagickFalse); |
| 284 | source_image=source->wand->images; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 285 | destination_image=destination->wand->images; |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 286 | status=SetImageStorageClass(destination_image,DirectClass, |
| 287 | destination->exception); |
| 288 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | return(MagickFalse); |
| 290 | status=MagickTrue; |
| 291 | progress=0; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 292 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 293 | height=source->extent.height-source->extent.y; |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 294 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 295 | magick_threads(source_image,destination_image,height,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 297 | for (y=source->extent.y; y < (ssize_t) source->extent.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 298 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 299 | const int |
| 300 | id = GetOpenMPThreadId(); |
cristy | ad74005 | 2010-07-03 01:38:03 +0000 | [diff] [blame] | 301 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 302 | MagickBooleanType |
| 303 | sync; |
| 304 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 305 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 306 | *restrict duplex_pixels, |
| 307 | *restrict pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 309 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 310 | x; |
| 311 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 312 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 313 | *restrict destination_pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | |
| 315 | if (status == MagickFalse) |
| 316 | continue; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 317 | pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y, |
| 318 | source->extent.width,1,source->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 319 | if (pixels == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 320 | { |
| 321 | status=MagickFalse; |
| 322 | continue; |
| 323 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 324 | for (x=0; x < (ssize_t) source->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 325 | { |
| 326 | PixelSetQuantumPixel(source->image,pixels,source->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 327 | pixels+=GetPixelChannels(source->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 328 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 329 | duplex_pixels=GetCacheViewVirtualPixels(duplex->view,duplex->extent.x,y, |
| 330 | duplex->extent.width,1,duplex->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | if (duplex_pixels == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | { |
| 333 | status=MagickFalse; |
| 334 | continue; |
| 335 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 336 | for (x=0; x < (ssize_t) duplex->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 337 | { |
| 338 | PixelSetQuantumPixel(duplex->image,duplex_pixels, |
| 339 | duplex->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 340 | duplex_pixels+=GetPixelChannels(duplex->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 341 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 342 | destination_pixels=GetCacheViewAuthenticPixels(destination->view, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 343 | destination->extent.x,y,destination->extent.width,1, |
| 344 | destination->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 345 | if (destination_pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | { |
| 347 | status=MagickFalse; |
| 348 | continue; |
| 349 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 350 | for (x=0; x < (ssize_t) destination->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 351 | { |
| 352 | PixelSetQuantumPixel(destination->image,destination_pixels, |
| 353 | destination->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 354 | destination_pixels+=GetPixelChannels(destination->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 355 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 356 | if (transfer(source,duplex,destination,y,id,context) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 357 | status=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 358 | destination_pixels=GetCacheViewAuthenticPixels(destination->view, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 359 | destination->extent.x,y,destination->extent.width,1, |
| 360 | destination->exception); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 361 | for (x=0; x < (ssize_t) destination->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 362 | { |
| 363 | PixelGetQuantumPixel(destination->image,destination->pixel_wands[id][x], |
| 364 | destination_pixels); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 365 | destination_pixels+=GetPixelChannels(destination->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 366 | } |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 367 | sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | if (sync == MagickFalse) |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 369 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 370 | if (source_image->progress_monitor != (MagickProgressMonitor) NULL) |
| 371 | { |
| 372 | MagickBooleanType |
| 373 | proceed; |
| 374 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 375 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1500c3d | 2012-01-17 13:57:52 +0000 | [diff] [blame] | 376 | #pragma omp critical (MagickWand_DuplexTransferWandViewIterator) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 378 | proceed=SetImageProgress(source_image,source->description,progress++, |
| 379 | source->extent.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 380 | if (proceed == MagickFalse) |
| 381 | status=MagickFalse; |
| 382 | } |
| 383 | } |
| 384 | return(status); |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 389 | % % |
| 390 | % % |
| 391 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 392 | % G e t W a n d V i e w E x c e p t i o n % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | % % |
| 394 | % % |
| 395 | % % |
| 396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 397 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 398 | % GetWandViewException() returns the severity, reason, and description of any |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 399 | % error that occurs when utilizing a wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 401 | % The format of the GetWandViewException method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | % |
cristy | 76fa314 | 2012-04-26 11:30:17 +0000 | [diff] [blame] | 403 | % char *GetWandViewException(const WandView *wand_view, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | % ExceptionType *severity) |
| 405 | % |
| 406 | % A description of each parameter follows: |
| 407 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 408 | % o wand_view: the pixel wand_view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | % |
| 410 | % o severity: the severity of the error is returned here. |
| 411 | % |
| 412 | */ |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 413 | WandExport char *GetWandViewException(const WandView *wand_view, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 414 | ExceptionType *severity) |
| 415 | { |
| 416 | char |
| 417 | *description; |
| 418 | |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 419 | assert(wand_view != (const WandView *) NULL); |
| 420 | assert(wand_view->signature == WandSignature); |
| 421 | if (wand_view->debug != MagickFalse) |
| 422 | (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand_view->name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 423 | assert(severity != (ExceptionType *) NULL); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 424 | *severity=wand_view->exception->severity; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 425 | description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent, |
| 426 | sizeof(*description)); |
| 427 | if (description == (char *) NULL) |
| 428 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 429 | wand_view->name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 430 | *description='\0'; |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 431 | if (wand_view->exception->reason != (char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 432 | (void) CopyMagickString(description,GetLocaleExceptionMessage( |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 433 | wand_view->exception->severity,wand_view->exception->reason), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 434 | MaxTextExtent); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 435 | if (wand_view->exception->description != (char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 436 | { |
| 437 | (void) ConcatenateMagickString(description," (",MaxTextExtent); |
| 438 | (void) ConcatenateMagickString(description,GetLocaleExceptionMessage( |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 439 | wand_view->exception->severity,wand_view->exception->description), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 440 | MaxTextExtent); |
| 441 | (void) ConcatenateMagickString(description,")",MaxTextExtent); |
| 442 | } |
| 443 | return(description); |
| 444 | } |
| 445 | |
| 446 | /* |
| 447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 448 | % % |
| 449 | % % |
| 450 | % % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 451 | % G e t W a n d V i e w E x t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | % % |
| 453 | % % |
| 454 | % % |
| 455 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 456 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 457 | % GetWandViewExtent() returns the wand view extent. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 459 | % The format of the GetWandViewExtent method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 461 | % RectangleInfo GetWandViewExtent(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 462 | % |
| 463 | % A description of each parameter follows: |
| 464 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 465 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 466 | % |
| 467 | */ |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 468 | WandExport RectangleInfo GetWandViewExtent(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | { |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 470 | assert(wand_view != (WandView *) NULL); |
| 471 | assert(wand_view->signature == WandSignature); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 472 | return(wand_view->extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /* |
| 476 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 477 | % % |
| 478 | % % |
| 479 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 480 | % G e t W a n d V i e w I t e r a t o r % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | % % |
| 482 | % % |
| 483 | % % |
| 484 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 485 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 486 | % GetWandViewIterator() iterates over the wand view in parallel and calls |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 487 | % your get method for each scanline of the view. The pixel extent is |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 488 | % not confined to the image canvas-- that is you can include negative offsets |
| 489 | % or widths or heights that exceed the image dimension. Any updates to |
| 490 | % the pixels in your callback are ignored. |
| 491 | % |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 492 | % The callback signature is: |
| 493 | % |
| 494 | % MagickBooleanType GetImageViewMethod(const WandView *source, |
| 495 | % const ssize_t y,const int thread_id,void *context) |
| 496 | % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 497 | % Use this pragma if the view is not single threaded: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 498 | % |
| 499 | % #pragma omp critical |
| 500 | % |
| 501 | % to define a section of code in your callback get method that must be |
| 502 | % executed by a single thread at a time. |
| 503 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 504 | % The format of the GetWandViewIterator method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 505 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 506 | % MagickBooleanType GetWandViewIterator(WandView *source, |
| 507 | % GetWandViewMethod get,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | % |
| 509 | % A description of each parameter follows: |
| 510 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 511 | % o source: the source wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 512 | % |
| 513 | % o get: the get callback method. |
| 514 | % |
| 515 | % o context: the user defined context. |
| 516 | % |
| 517 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 518 | WandExport MagickBooleanType GetWandViewIterator(WandView *source, |
| 519 | GetWandViewMethod get,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | Image |
| 522 | *source_image; |
| 523 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | MagickBooleanType |
| 525 | status; |
| 526 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 527 | MagickOffsetType |
| 528 | progress; |
| 529 | |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 530 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 531 | size_t |
cristy | 26b6491 | 2012-12-16 18:20:09 +0000 | [diff] [blame] | 532 | height; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 533 | #endif |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 534 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 535 | ssize_t |
| 536 | y; |
| 537 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 538 | assert(source != (WandView *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 539 | assert(source->signature == WandSignature); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 540 | if (get == (GetWandViewMethod) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 541 | return(MagickFalse); |
| 542 | source_image=source->wand->images; |
| 543 | status=MagickTrue; |
| 544 | progress=0; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 545 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 546 | height=source->extent.height-source->extent.y; |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 547 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 548 | magick_threads(source_image,source_image,height,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 549 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 550 | for (y=source->extent.y; y < (ssize_t) source->extent.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 551 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 552 | const int |
| 553 | id = GetOpenMPThreadId(); |
cristy | ad74005 | 2010-07-03 01:38:03 +0000 | [diff] [blame] | 554 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 555 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 556 | *pixels; |
| 557 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 558 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | x; |
| 560 | |
| 561 | if (status == MagickFalse) |
| 562 | continue; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 563 | pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y, |
| 564 | source->extent.width,1,source->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 565 | if (pixels == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 566 | { |
| 567 | status=MagickFalse; |
| 568 | continue; |
| 569 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 570 | for (x=0; x < (ssize_t) source->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 571 | { |
| 572 | PixelSetQuantumPixel(source->image,pixels,source->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 573 | pixels+=GetPixelChannels(source->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 574 | } |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 575 | if (get(source,y,id,context) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 576 | status=MagickFalse; |
| 577 | if (source_image->progress_monitor != (MagickProgressMonitor) NULL) |
| 578 | { |
| 579 | MagickBooleanType |
| 580 | proceed; |
| 581 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 582 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1500c3d | 2012-01-17 13:57:52 +0000 | [diff] [blame] | 583 | #pragma omp critical (MagickWand_GetWandViewIterator) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 585 | proceed=SetImageProgress(source_image,source->description,progress++, |
| 586 | source->extent.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 587 | if (proceed == MagickFalse) |
| 588 | status=MagickFalse; |
| 589 | } |
| 590 | } |
| 591 | return(status); |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 596 | % % |
| 597 | % % |
| 598 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 599 | % G e t W a n d V i e w P i x e l s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | % % |
| 601 | % % |
| 602 | % % |
| 603 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 604 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 605 | % GetWandViewPixels() returns the wand view pixel_wands. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 606 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 607 | % The format of the GetWandViewPixels method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 608 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 609 | % PixelWand *GetWandViewPixels(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 610 | % |
| 611 | % A description of each parameter follows: |
| 612 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 613 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 614 | % |
| 615 | */ |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 616 | WandExport PixelWand **GetWandViewPixels(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 617 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 618 | const int |
| 619 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 620 | |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 621 | assert(wand_view != (WandView *) NULL); |
| 622 | assert(wand_view->signature == WandSignature); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 623 | return(wand_view->pixel_wands[id]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % % |
| 629 | % % |
| 630 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 631 | % G e t W a n d V i e w W a n d % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 632 | % % |
| 633 | % % |
| 634 | % % |
| 635 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 636 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 637 | % GetWandViewWand() returns the magick wand associated with the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 638 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 639 | % The format of the GetWandViewWand method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 641 | % MagickWand *GetWandViewWand(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 642 | % |
| 643 | % A description of each parameter follows: |
| 644 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 645 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | % |
| 647 | */ |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 648 | WandExport MagickWand *GetWandViewWand(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 649 | { |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 650 | assert(wand_view != (WandView *) NULL); |
| 651 | assert(wand_view->signature == WandSignature); |
| 652 | return(wand_view->wand); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /* |
| 656 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 657 | % % |
| 658 | % % |
| 659 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 660 | % I s W a n d V i e w % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 661 | % % |
| 662 | % % |
| 663 | % % |
| 664 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 665 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 666 | % IsWandView() returns MagickTrue if the the parameter is verified as a wand |
| 667 | % view object. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 669 | % The format of the IsWandView method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 671 | % MagickBooleanType IsWandView(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 672 | % |
| 673 | % A description of each parameter follows: |
| 674 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 675 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 676 | % |
| 677 | */ |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 678 | WandExport MagickBooleanType IsWandView(const WandView *wand_view) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | { |
| 680 | size_t |
| 681 | length; |
| 682 | |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 683 | if (wand_view == (const WandView *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 684 | return(MagickFalse); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 685 | if (wand_view->signature != WandSignature) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 686 | return(MagickFalse); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 687 | length=strlen(WandViewId); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 688 | if (LocaleNCompare(wand_view->name,WandViewId,length) != 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | return(MagickFalse); |
| 690 | return(MagickTrue); |
| 691 | } |
| 692 | |
| 693 | /* |
| 694 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 695 | % % |
| 696 | % % |
| 697 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 698 | % N e w W a n d V i e w % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 699 | % % |
| 700 | % % |
| 701 | % % |
| 702 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 703 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 704 | % NewWandView() returns a wand view required for all other methods in the |
| 705 | % Wand View API. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 706 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 707 | % The format of the NewWandView method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 708 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 709 | % WandView *NewWandView(MagickWand *wand) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 710 | % |
| 711 | % A description of each parameter follows: |
| 712 | % |
| 713 | % o wand: the wand. |
| 714 | % |
| 715 | */ |
| 716 | |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 717 | static PixelWand ***AcquirePixelsThreadSet(const size_t number_wands) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 718 | { |
| 719 | PixelWand |
| 720 | ***pixel_wands; |
| 721 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 722 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 723 | i; |
| 724 | |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 725 | size_t |
| 726 | number_threads; |
| 727 | |
cristy | feeb98d | 2012-05-09 16:32:12 +0000 | [diff] [blame] | 728 | number_threads=GetOpenMPMaximumThreads(); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 729 | pixel_wands=(PixelWand ***) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | sizeof(*pixel_wands)); |
| 731 | if (pixel_wands == (PixelWand ***) NULL) |
| 732 | return((PixelWand ***) NULL); |
| 733 | (void) ResetMagickMemory(pixel_wands,0,number_threads*sizeof(*pixel_wands)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 734 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 735 | { |
| 736 | pixel_wands[i]=NewPixelWands(number_wands); |
| 737 | if (pixel_wands[i] == (PixelWand **) NULL) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 738 | return(DestroyPixelsThreadSet(pixel_wands,number_wands)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | } |
| 740 | return(pixel_wands); |
| 741 | } |
| 742 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 743 | WandExport WandView *NewWandView(MagickWand *wand) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 744 | { |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 745 | ExceptionInfo |
| 746 | *exception; |
| 747 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 748 | WandView |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 749 | *wand_view; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 750 | |
| 751 | assert(wand != (MagickWand *) NULL); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 752 | assert(wand->signature == WandSignature); |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 753 | wand_view=(WandView *) AcquireMagickMemory(sizeof(*wand_view)); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 754 | if (wand_view == (WandView *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 755 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
| 756 | GetExceptionMessage(errno)); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 757 | (void) ResetMagickMemory(wand_view,0,sizeof(*wand_view)); |
| 758 | wand_view->id=AcquireWandId(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 759 | (void) FormatLocaleString(wand_view->name,MaxTextExtent,"%s-%.20g", |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 760 | WandViewId,(double) wand_view->id); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 761 | wand_view->description=ConstantString("WandView"); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 762 | wand_view->wand=wand; |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 763 | exception=AcquireExceptionInfo(); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 764 | wand_view->view=AcquireVirtualCacheView(wand_view->wand->images,exception); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 765 | wand_view->extent.width=wand->images->columns; |
| 766 | wand_view->extent.height=wand->images->rows; |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 767 | wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width); |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 768 | wand_view->exception=exception; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 769 | if (wand_view->pixel_wands == (PixelWand ***) NULL) |
| 770 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
| 771 | GetExceptionMessage(errno)); |
| 772 | wand_view->debug=IsEventLogging(); |
| 773 | wand_view->signature=WandSignature; |
| 774 | return(wand_view); |
| 775 | } |
| 776 | |
| 777 | /* |
| 778 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 779 | % % |
| 780 | % % |
| 781 | % % |
| 782 | % N e w W a n d V i e w E x t e n t % |
| 783 | % % |
| 784 | % % |
| 785 | % % |
| 786 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 787 | % |
| 788 | % NewWandViewExtent() returns a wand view required for all other methods |
| 789 | % in the Wand View API. |
| 790 | % |
| 791 | % The format of the NewWandViewExtent method is: |
| 792 | % |
| 793 | % WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, |
| 794 | % const ssize_t y,const size_t width,const size_t height) |
| 795 | % |
| 796 | % A description of each parameter follows: |
| 797 | % |
| 798 | % o wand: the magick wand. |
| 799 | % |
| 800 | % o x,y,columns,rows: These values define the perimeter of a extent of |
| 801 | % pixel_wands view. |
| 802 | % |
| 803 | */ |
| 804 | WandExport WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, |
| 805 | const ssize_t y,const size_t width,const size_t height) |
| 806 | { |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 807 | ExceptionInfo |
| 808 | *exception; |
| 809 | |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 810 | WandView |
| 811 | *wand_view; |
| 812 | |
| 813 | assert(wand != (MagickWand *) NULL); |
| 814 | assert(wand->signature == WandSignature); |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 815 | wand_view=(WandView *) AcquireMagickMemory(sizeof(*wand_view)); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 816 | if (wand_view == (WandView *) NULL) |
| 817 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
| 818 | GetExceptionMessage(errno)); |
| 819 | (void) ResetMagickMemory(wand_view,0,sizeof(*wand_view)); |
| 820 | wand_view->id=AcquireWandId(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 821 | (void) FormatLocaleString(wand_view->name,MaxTextExtent,"%s-%.20g", |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 822 | WandViewId,(double) wand_view->id); |
| 823 | wand_view->description=ConstantString("WandView"); |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 824 | exception=AcquireExceptionInfo(); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 825 | wand_view->view=AcquireVirtualCacheView(wand_view->wand->images,exception); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 826 | wand_view->wand=wand; |
| 827 | wand_view->extent.width=width; |
| 828 | wand_view->extent.height=height; |
| 829 | wand_view->extent.x=x; |
| 830 | wand_view->extent.y=y; |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 831 | wand_view->exception=exception; |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 832 | wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 833 | if (wand_view->pixel_wands == (PixelWand ***) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 834 | ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", |
| 835 | GetExceptionMessage(errno)); |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 836 | wand_view->debug=IsEventLogging(); |
| 837 | wand_view->signature=WandSignature; |
| 838 | return(wand_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | /* |
| 842 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 843 | % % |
| 844 | % % |
| 845 | % % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 846 | % S e t W a n d V i e w D e s c r i p t i o n % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 847 | % % |
| 848 | % % |
| 849 | % % |
| 850 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 851 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 852 | % SetWandViewDescription() associates a description with an image view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 853 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 854 | % The format of the SetWandViewDescription method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 855 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 856 | % void SetWandViewDescription(WandView *image_view,const char *description) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 857 | % |
| 858 | % A description of each parameter follows: |
| 859 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 860 | % o wand_view: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 861 | % |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 862 | % o description: the wand view description. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 863 | % |
| 864 | */ |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 865 | MagickExport void SetWandViewDescription(WandView *wand_view, |
| 866 | const char *description) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 867 | { |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 868 | assert(wand_view != (WandView *) NULL); |
| 869 | assert(wand_view->signature == WandSignature); |
| 870 | wand_view->description=ConstantString(description); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /* |
| 874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 875 | % % |
| 876 | % % |
| 877 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 878 | % S e t W a n d V i e w I t e r a t o r % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 879 | % % |
| 880 | % % |
| 881 | % % |
| 882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 883 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 884 | % SetWandViewIterator() iterates over the wand view in parallel and calls |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 885 | % your set method for each scanline of the view. The pixel extent is |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 886 | % confined to the image canvas-- that is no negative offsets or widths or |
| 887 | % heights that exceed the image dimension. The pixels are initiallly |
| 888 | % undefined and any settings you make in the callback method are automagically |
| 889 | % synced back to your image. |
| 890 | % |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 891 | % The callback signature is: |
| 892 | % |
| 893 | % MagickBooleanType SetImageViewMethod(ImageView *destination, |
| 894 | % const ssize_t y,const int thread_id,void *context) |
| 895 | % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 896 | % Use this pragma if the view is not single threaded: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 897 | % |
| 898 | % #pragma omp critical |
| 899 | % |
| 900 | % to define a section of code in your callback set method that must be |
| 901 | % executed by a single thread at a time. |
| 902 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 903 | % The format of the SetWandViewIterator method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 904 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 905 | % MagickBooleanType SetWandViewIterator(WandView *destination, |
| 906 | % SetWandViewMethod set,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 907 | % |
| 908 | % A description of each parameter follows: |
| 909 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 910 | % o destination: the wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 911 | % |
| 912 | % o set: the set callback method. |
| 913 | % |
| 914 | % o context: the user defined context. |
| 915 | % |
| 916 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 917 | WandExport MagickBooleanType SetWandViewIterator(WandView *destination, |
| 918 | SetWandViewMethod set,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 919 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 920 | Image |
| 921 | *destination_image; |
| 922 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 923 | MagickBooleanType |
| 924 | status; |
| 925 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 926 | MagickOffsetType |
| 927 | progress; |
| 928 | |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 929 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 930 | size_t |
cristy | 26b6491 | 2012-12-16 18:20:09 +0000 | [diff] [blame] | 931 | height; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 932 | #endif |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 933 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 934 | ssize_t |
| 935 | y; |
| 936 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 937 | assert(destination != (WandView *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 938 | assert(destination->signature == WandSignature); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 939 | if (set == (SetWandViewMethod) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | return(MagickFalse); |
| 941 | destination_image=destination->wand->images; |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 942 | status=SetImageStorageClass(destination_image,DirectClass, |
| 943 | destination->exception); |
| 944 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 945 | return(MagickFalse); |
| 946 | status=MagickTrue; |
| 947 | progress=0; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 948 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 949 | height=destination->extent.height-destination->extent.y; |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 950 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 951 | magick_threads(destination_image,destination_image,height,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 952 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 953 | for (y=destination->extent.y; y < (ssize_t) destination->extent.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 954 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 955 | const int |
| 956 | id = GetOpenMPThreadId(); |
cristy | ad74005 | 2010-07-03 01:38:03 +0000 | [diff] [blame] | 957 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 958 | MagickBooleanType |
| 959 | sync; |
| 960 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 961 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 962 | x; |
| 963 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 964 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 965 | *restrict pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 966 | |
| 967 | if (status == MagickFalse) |
| 968 | continue; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 969 | pixels=GetCacheViewAuthenticPixels(destination->view,destination->extent.x, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 970 | y,destination->extent.width,1,destination->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 971 | if (pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 972 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 973 | status=MagickFalse; |
| 974 | continue; |
| 975 | } |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 976 | if (set(destination,y,id,context) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 977 | status=MagickFalse; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 978 | for (x=0; x < (ssize_t) destination->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 979 | { |
| 980 | PixelGetQuantumPixel(destination->image,destination->pixel_wands[id][x], |
| 981 | pixels); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 982 | pixels+=GetPixelChannels(destination->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 983 | } |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 984 | sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 985 | if (sync == MagickFalse) |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 986 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 987 | if (destination_image->progress_monitor != (MagickProgressMonitor) NULL) |
| 988 | { |
| 989 | MagickBooleanType |
| 990 | proceed; |
| 991 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 992 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1500c3d | 2012-01-17 13:57:52 +0000 | [diff] [blame] | 993 | #pragma omp critical (MagickWand_SetWandViewIterator) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 994 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 995 | proceed=SetImageProgress(destination_image,destination->description, |
| 996 | progress++,destination->extent.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 997 | if (proceed == MagickFalse) |
| 998 | status=MagickFalse; |
| 999 | } |
| 1000 | } |
| 1001 | return(status); |
| 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1006 | % % |
| 1007 | % % |
| 1008 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1009 | % T r a n s f e r W a n d V i e w I t e r a t o r % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1010 | % % |
| 1011 | % % |
| 1012 | % % |
| 1013 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1014 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1015 | % TransferWandViewIterator() iterates over two wand views in parallel and |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1016 | % calls your transfer method for each scanline of the view. The source pixel |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1017 | % extent is not confined to the image canvas-- that is you can include |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1018 | % negative offsets or widths or heights that exceed the image dimension. |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1019 | % However, the destination wand view is confined to the image canvas-- that |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1020 | % is no negative offsets or widths or heights that exceed the image dimension |
| 1021 | % are permitted. |
| 1022 | % |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 1023 | % The callback signature is: |
| 1024 | % |
| 1025 | % MagickBooleanType TransferImageViewMethod(const WandView *source, |
| 1026 | % WandView *destination,const ssize_t y,const int thread_id, |
| 1027 | % void *context) |
| 1028 | % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 1029 | % Use this pragma if the view is not single threaded: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1030 | % |
| 1031 | % #pragma omp critical |
| 1032 | % |
| 1033 | % to define a section of code in your callback transfer method that must be |
| 1034 | % executed by a single thread at a time. |
| 1035 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1036 | % The format of the TransferWandViewIterator method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1037 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1038 | % MagickBooleanType TransferWandViewIterator(WandView *source, |
| 1039 | % WandView *destination,TransferWandViewMethod transfer,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1040 | % |
| 1041 | % A description of each parameter follows: |
| 1042 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1043 | % o source: the source wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1044 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1045 | % o destination: the destination wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1046 | % |
| 1047 | % o transfer: the transfer callback method. |
| 1048 | % |
| 1049 | % o context: the user defined context. |
| 1050 | % |
| 1051 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1052 | WandExport MagickBooleanType TransferWandViewIterator(WandView *source, |
| 1053 | WandView *destination,TransferWandViewMethod transfer,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1054 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1055 | Image |
| 1056 | *destination_image, |
| 1057 | *source_image; |
| 1058 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1059 | MagickBooleanType |
| 1060 | status; |
| 1061 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1062 | MagickOffsetType |
| 1063 | progress; |
| 1064 | |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1065 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1066 | size_t |
cristy | 26b6491 | 2012-12-16 18:20:09 +0000 | [diff] [blame] | 1067 | height; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1068 | #endif |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1069 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1070 | ssize_t |
| 1071 | y; |
| 1072 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1073 | assert(source != (WandView *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1074 | assert(source->signature == WandSignature); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1075 | if (transfer == (TransferWandViewMethod) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | return(MagickFalse); |
| 1077 | source_image=source->wand->images; |
| 1078 | destination_image=destination->wand->images; |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1079 | status=SetImageStorageClass(destination_image,DirectClass, |
| 1080 | destination->exception); |
| 1081 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1082 | return(MagickFalse); |
| 1083 | status=MagickTrue; |
| 1084 | progress=0; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1085 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1086 | height=source->extent.height-source->extent.y; |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 1087 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 1088 | magick_threads(source_image,destination_image,height,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1089 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1090 | for (y=source->extent.y; y < (ssize_t) source->extent.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 1092 | const int |
| 1093 | id = GetOpenMPThreadId(); |
cristy | ad74005 | 2010-07-03 01:38:03 +0000 | [diff] [blame] | 1094 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1095 | MagickBooleanType |
| 1096 | sync; |
| 1097 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1098 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1099 | *restrict pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1101 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1102 | x; |
| 1103 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1104 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1105 | *restrict destination_pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1106 | |
| 1107 | if (status == MagickFalse) |
| 1108 | continue; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1109 | pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y, |
| 1110 | source->extent.width,1,source->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1111 | if (pixels == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1112 | { |
| 1113 | status=MagickFalse; |
| 1114 | continue; |
| 1115 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1116 | for (x=0; x < (ssize_t) source->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1117 | { |
| 1118 | PixelSetQuantumPixel(source->image,pixels,source->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1119 | pixels+=GetPixelChannels(source->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1120 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1121 | destination_pixels=GetCacheViewAuthenticPixels(destination->view, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1122 | destination->extent.x,y,destination->extent.width,1, |
| 1123 | destination->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1124 | if (destination_pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1125 | { |
| 1126 | status=MagickFalse; |
| 1127 | continue; |
| 1128 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1129 | for (x=0; x < (ssize_t) destination->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1130 | { |
| 1131 | PixelSetQuantumPixel(destination->image,destination_pixels, |
| 1132 | destination->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1133 | destination_pixels+=GetPixelChannels(destination->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1134 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1135 | if (transfer(source,destination,y,id,context) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1136 | status=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1137 | destination_pixels=GetCacheViewAuthenticPixels(destination->view, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1138 | destination->extent.x,y,destination->extent.width,1, |
| 1139 | destination->exception); |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1140 | for (x=0; x < (ssize_t) destination->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1141 | { |
| 1142 | PixelGetQuantumPixel(destination->image,destination->pixel_wands[id][x], |
| 1143 | destination_pixels); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1144 | destination_pixels+=GetPixelChannels(destination->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1145 | } |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1146 | sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1147 | if (sync == MagickFalse) |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1148 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1149 | if (source_image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1150 | { |
| 1151 | MagickBooleanType |
| 1152 | proceed; |
| 1153 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1154 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1500c3d | 2012-01-17 13:57:52 +0000 | [diff] [blame] | 1155 | #pragma omp critical (MagickWand_TransferWandViewIterator) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1156 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1157 | proceed=SetImageProgress(source_image,source->description,progress++, |
| 1158 | source->extent.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1159 | if (proceed == MagickFalse) |
| 1160 | status=MagickFalse; |
| 1161 | } |
| 1162 | } |
| 1163 | return(status); |
| 1164 | } |
| 1165 | |
| 1166 | /* |
| 1167 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1168 | % % |
| 1169 | % % |
| 1170 | % % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1171 | % U p d a t e W a n d V i e w I t e r a t o r % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1172 | % % |
| 1173 | % % |
| 1174 | % % |
| 1175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1176 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1177 | % UpdateWandViewIterator() iterates over the wand view in parallel and calls |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1178 | % your update method for each scanline of the view. The pixel extent is |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 | % confined to the image canvas-- that is no negative offsets or widths or |
| 1180 | % heights that exceed the image dimension are permitted. Updates to pixels |
| 1181 | % in your callback are automagically synced back to the image. |
| 1182 | % |
cristy | d6dfc0d | 2010-06-27 19:30:49 +0000 | [diff] [blame] | 1183 | % The callback signature is: |
| 1184 | % |
| 1185 | % MagickBooleanType UpdateImageViewMethod(WandView *source,const ssize_t y, |
| 1186 | % const int thread_id,void *context) |
| 1187 | % |
cristy | 5873947 | 2010-06-26 20:27:18 +0000 | [diff] [blame] | 1188 | % Use this pragma if the view is not single threaded: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1189 | % |
| 1190 | % #pragma omp critical |
| 1191 | % |
| 1192 | % to define a section of code in your callback update method that must be |
| 1193 | % executed by a single thread at a time. |
| 1194 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1195 | % The format of the UpdateWandViewIterator method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1196 | % |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1197 | % MagickBooleanType UpdateWandViewIterator(WandView *source, |
| 1198 | % UpdateWandViewMethod update,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | % |
| 1200 | % A description of each parameter follows: |
| 1201 | % |
cristy | 73b7d4c | 2010-06-27 00:31:00 +0000 | [diff] [blame] | 1202 | % o source: the source wand view. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1203 | % |
| 1204 | % o update: the update callback method. |
| 1205 | % |
| 1206 | % o context: the user defined context. |
| 1207 | % |
| 1208 | */ |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1209 | WandExport MagickBooleanType UpdateWandViewIterator(WandView *source, |
| 1210 | UpdateWandViewMethod update,void *context) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1211 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | Image |
| 1213 | *source_image; |
| 1214 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1215 | MagickBooleanType |
| 1216 | status; |
| 1217 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1218 | MagickOffsetType |
| 1219 | progress; |
| 1220 | |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1221 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1222 | size_t |
cristy | 26b6491 | 2012-12-16 18:20:09 +0000 | [diff] [blame] | 1223 | height; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1224 | #endif |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1225 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1226 | ssize_t |
| 1227 | y; |
| 1228 | |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1229 | assert(source != (WandView *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1230 | assert(source->signature == WandSignature); |
cristy | 7eb1b7a | 2010-06-26 15:47:49 +0000 | [diff] [blame] | 1231 | if (update == (UpdateWandViewMethod) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1232 | return(MagickFalse); |
| 1233 | source_image=source->wand->images; |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1234 | status=SetImageStorageClass(source_image,DirectClass,source->exception); |
| 1235 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1236 | return(MagickFalse); |
| 1237 | status=MagickTrue; |
| 1238 | progress=0; |
glennrp | d30b305 | 2012-09-26 12:17:18 +0000 | [diff] [blame] | 1239 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 1240 | height=source->extent.height-source->extent.y; |
cristy | d643247 | 2013-01-06 16:56:13 +0000 | [diff] [blame] | 1241 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 1242 | magick_threads(source_image,source_image,height,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1243 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1244 | for (y=source->extent.y; y < (ssize_t) source->extent.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1245 | { |
cristy | 83e6d2a | 2010-09-17 17:35:13 +0000 | [diff] [blame] | 1246 | const int |
| 1247 | id = GetOpenMPThreadId(); |
cristy | ad74005 | 2010-07-03 01:38:03 +0000 | [diff] [blame] | 1248 | |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1249 | MagickBooleanType |
| 1250 | sync; |
| 1251 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1252 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1253 | x; |
| 1254 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1255 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1256 | *restrict pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1257 | |
| 1258 | if (status == MagickFalse) |
| 1259 | continue; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1260 | pixels=GetCacheViewAuthenticPixels(source->view,source->extent.x,y, |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1261 | source->extent.width,1,source->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1262 | if (pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1263 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1264 | status=MagickFalse; |
| 1265 | continue; |
| 1266 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1267 | for (x=0; x < (ssize_t) source->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1268 | { |
| 1269 | PixelSetQuantumPixel(source->image,pixels,source->pixel_wands[id][x]); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1270 | pixels+=GetPixelChannels(source->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1271 | } |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1272 | if (update(source,y,id,context) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1273 | status=MagickFalse; |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1274 | for (x=0; x < (ssize_t) source->extent.width; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1275 | { |
| 1276 | PixelGetQuantumPixel(source->image,source->pixel_wands[id][x],pixels); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1277 | pixels+=GetPixelChannels(source->image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1278 | } |
cristy | cad4e1b | 2011-10-16 14:58:39 +0000 | [diff] [blame] | 1279 | sync=SyncCacheViewAuthenticPixels(source->view,source->exception); |
| 1280 | if (sync == MagickFalse) |
| 1281 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1282 | if (source_image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1283 | { |
| 1284 | MagickBooleanType |
| 1285 | proceed; |
| 1286 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1287 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 1500c3d | 2012-01-17 13:57:52 +0000 | [diff] [blame] | 1288 | #pragma omp critical (MagickWand_UpdateWandViewIterator) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1289 | #endif |
cristy | c3ebda2 | 2010-06-27 17:11:57 +0000 | [diff] [blame] | 1290 | proceed=SetImageProgress(source_image,source->description,progress++, |
| 1291 | source->extent.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1292 | if (proceed == MagickFalse) |
| 1293 | status=MagickFalse; |
| 1294 | } |
| 1295 | } |
| 1296 | return(status); |
| 1297 | } |