cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC AAA CCCC H H EEEEE % |
| 7 | % C A A C H H E % |
| 8 | % C AAAAA C HHHHH EEE % |
| 9 | % C A A C H H E % |
| 10 | % CCCC A A CCCC H H EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Pixel Cache Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1999 % |
| 18 | % % |
| 19 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/cache-private.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/composite-private.h" |
| 50 | #include "MagickCore/exception.h" |
| 51 | #include "MagickCore/exception-private.h" |
| 52 | #include "MagickCore/geometry.h" |
| 53 | #include "MagickCore/list.h" |
| 54 | #include "MagickCore/log.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
cristy | d2d11ec | 2012-03-28 13:53:49 +0000 | [diff] [blame] | 57 | #include "MagickCore/nt-base-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 58 | #include "MagickCore/pixel.h" |
| 59 | #include "MagickCore/pixel-accessor.h" |
| 60 | #include "MagickCore/policy.h" |
| 61 | #include "MagickCore/quantum.h" |
| 62 | #include "MagickCore/random_.h" |
| 63 | #include "MagickCore/resource_.h" |
| 64 | #include "MagickCore/semaphore.h" |
| 65 | #include "MagickCore/splay-tree.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/string-private.h" |
| 68 | #include "MagickCore/thread-private.h" |
| 69 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 70 | #include "MagickCore/utility-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 71 | #if defined(MAGICKCORE_ZLIB_DELEGATE) |
| 72 | #include "zlib.h" |
| 73 | #endif |
| 74 | |
| 75 | /* |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 76 | Define declarations. |
| 77 | */ |
| 78 | #define CacheTick(offset,extent) QuantumTick((MagickOffsetType) offset,extent) |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 79 | #define IsFileDescriptorLimitExceeded() (GetMagickResource(FileResource) > \ |
| 80 | GetMagickResourceLimit(FileResource) ? MagickTrue : MagickFalse) |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 81 | |
| 82 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | Typedef declarations. |
| 84 | */ |
| 85 | typedef struct _MagickModulo |
| 86 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 87 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 88 | quotient, |
| 89 | remainder; |
| 90 | } MagickModulo; |
| 91 | |
| 92 | struct _NexusInfo |
| 93 | { |
| 94 | MagickBooleanType |
| 95 | mapped; |
| 96 | |
| 97 | RectangleInfo |
| 98 | region; |
| 99 | |
| 100 | MagickSizeType |
| 101 | length; |
| 102 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 103 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 104 | *cache, |
| 105 | *pixels; |
| 106 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 107 | void |
| 108 | *metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 110 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 111 | signature; |
| 112 | }; |
| 113 | |
| 114 | /* |
| 115 | Forward declarations. |
| 116 | */ |
| 117 | #if defined(__cplusplus) || defined(c_plusplus) |
| 118 | extern "C" { |
| 119 | #endif |
| 120 | |
cristy | 19596d6 | 2012-02-19 00:24:59 +0000 | [diff] [blame] | 121 | static Cache |
| 122 | GetImagePixelCache(Image *,const MagickBooleanType,ExceptionInfo *) |
| 123 | magick_hot_spot; |
| 124 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 125 | static const Quantum |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 126 | *GetVirtualPixelCache(const Image *,const VirtualPixelMethod,const ssize_t, |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 127 | const ssize_t,const size_t,const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | *GetVirtualPixelsCache(const Image *); |
| 129 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 130 | static const void |
| 131 | *GetVirtualMetacontentFromCache(const Image *); |
| 132 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 133 | static MagickBooleanType |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 134 | GetOneAuthenticPixelFromCache(Image *,const ssize_t,const ssize_t, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 135 | Quantum *,ExceptionInfo *), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 136 | GetOneVirtualPixelFromCache(const Image *,const VirtualPixelMethod, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 137 | const ssize_t,const ssize_t,Quantum *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | OpenPixelCache(Image *,const MapMode,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 139 | ReadPixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | ReadPixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *), |
| 141 | SyncAuthenticPixelsCache(Image *,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 142 | WritePixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | WritePixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *); |
| 144 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 145 | static Quantum |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 146 | *GetAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 147 | const size_t,ExceptionInfo *), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 148 | *QueueAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 149 | const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | *SetPixelCacheNexusPixels(const Image *,const RectangleInfo *,NexusInfo *, |
cristy | 19596d6 | 2012-02-19 00:24:59 +0000 | [diff] [blame] | 151 | ExceptionInfo *) magick_hot_spot; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | |
| 153 | #if defined(__cplusplus) || defined(c_plusplus) |
| 154 | } |
| 155 | #endif |
| 156 | |
| 157 | /* |
| 158 | Global declarations. |
| 159 | */ |
| 160 | static volatile MagickBooleanType |
| 161 | instantiate_cache = MagickFalse; |
| 162 | |
| 163 | static SemaphoreInfo |
| 164 | *cache_semaphore = (SemaphoreInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 168 | % % |
| 169 | % % |
| 170 | % % |
| 171 | + A c q u i r e P i x e l C a c h e % |
| 172 | % % |
| 173 | % % |
| 174 | % % |
| 175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 176 | % |
| 177 | % AcquirePixelCache() acquires a pixel cache. |
| 178 | % |
| 179 | % The format of the AcquirePixelCache() method is: |
| 180 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 181 | % Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | % |
| 183 | % A description of each parameter follows: |
| 184 | % |
| 185 | % o number_threads: the number of nexus threads. |
| 186 | % |
| 187 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 188 | MagickPrivate Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | { |
| 190 | CacheInfo |
| 191 | *cache_info; |
| 192 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 193 | cache_info=(CacheInfo *) AcquireQuantumMemory(1,sizeof(*cache_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 194 | if (cache_info == (CacheInfo *) NULL) |
| 195 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 196 | (void) ResetMagickMemory(cache_info,0,sizeof(*cache_info)); |
| 197 | cache_info->type=UndefinedCache; |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 198 | cache_info->mode=IOMode; |
cristy | c511e88 | 2012-04-16 21:11:14 +0000 | [diff] [blame] | 199 | cache_info->colorspace=sRGBColorspace; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | cache_info->file=(-1); |
| 201 | cache_info->id=GetMagickThreadId(); |
| 202 | cache_info->number_threads=number_threads; |
| 203 | if (number_threads == 0) |
| 204 | cache_info->number_threads=GetOpenMPMaximumThreads(); |
| 205 | cache_info->nexus_info=AcquirePixelCacheNexus(cache_info->number_threads); |
| 206 | if (cache_info->nexus_info == (NexusInfo **) NULL) |
| 207 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | cache_info->semaphore=AllocateSemaphoreInfo(); |
cristy | 93505cf | 2010-08-10 21:37:49 +0000 | [diff] [blame] | 209 | cache_info->reference_count=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 210 | cache_info->disk_semaphore=AllocateSemaphoreInfo(); |
| 211 | cache_info->debug=IsEventLogging(); |
| 212 | cache_info->signature=MagickSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | return((Cache ) cache_info); |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | % % |
| 219 | % % |
| 220 | % % |
| 221 | % A c q u i r e P i x e l C a c h e N e x u s % |
| 222 | % % |
| 223 | % % |
| 224 | % % |
| 225 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 226 | % |
| 227 | % AcquirePixelCacheNexus() allocates the NexusInfo structure. |
| 228 | % |
| 229 | % The format of the AcquirePixelCacheNexus method is: |
| 230 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 231 | % NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 232 | % |
| 233 | % A description of each parameter follows: |
| 234 | % |
| 235 | % o number_threads: the number of nexus threads. |
| 236 | % |
| 237 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 238 | MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | NexusInfo |
| 241 | **nexus_info; |
| 242 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 243 | register ssize_t |
| 244 | i; |
| 245 | |
cristy | 64c3edf | 2012-04-13 18:50:13 +0000 | [diff] [blame] | 246 | nexus_info=(NexusInfo **) AcquireAlignedMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 247 | sizeof(*nexus_info)); |
| 248 | if (nexus_info == (NexusInfo **) NULL) |
| 249 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | e5f87c8 | 2012-02-14 12:44:17 +0000 | [diff] [blame] | 250 | nexus_info[0]=(NexusInfo *) AcquireQuantumMemory(number_threads, |
| 251 | sizeof(**nexus_info)); |
| 252 | if (nexus_info[0] == (NexusInfo *) NULL) |
| 253 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 254 | (void) ResetMagickMemory(nexus_info[0],0,number_threads*sizeof(**nexus_info)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 255 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 256 | { |
cristy | e5f87c8 | 2012-02-14 12:44:17 +0000 | [diff] [blame] | 257 | nexus_info[i]=(&nexus_info[0][i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | nexus_info[i]->signature=MagickSignature; |
| 259 | } |
| 260 | return(nexus_info); |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 265 | % % |
| 266 | % % |
| 267 | % % |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 268 | + A c q u i r e P i x e l C a c h e P i x e l s % |
| 269 | % % |
| 270 | % % |
| 271 | % % |
| 272 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 273 | % |
| 274 | % AcquirePixelCachePixels() returns the pixels associated with the specified |
| 275 | % image. |
| 276 | % |
| 277 | % The format of the AcquirePixelCachePixels() method is: |
| 278 | % |
| 279 | % const void *AcquirePixelCachePixels(const Image *image, |
| 280 | % MagickSizeType *length,ExceptionInfo *exception) |
| 281 | % |
| 282 | % A description of each parameter follows: |
| 283 | % |
| 284 | % o image: the image. |
| 285 | % |
| 286 | % o length: the pixel cache length. |
| 287 | % |
| 288 | % o exception: return any errors or warnings in this structure. |
| 289 | % |
| 290 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 291 | MagickPrivate const void *AcquirePixelCachePixels(const Image *image, |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 292 | MagickSizeType *length,ExceptionInfo *exception) |
| 293 | { |
| 294 | CacheInfo |
| 295 | *cache_info; |
| 296 | |
| 297 | assert(image != (const Image *) NULL); |
| 298 | assert(image->signature == MagickSignature); |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 299 | assert(exception != (ExceptionInfo *) NULL); |
| 300 | assert(exception->signature == MagickSignature); |
| 301 | assert(image->cache != (Cache) NULL); |
| 302 | cache_info=(CacheInfo *) image->cache; |
| 303 | assert(cache_info->signature == MagickSignature); |
| 304 | *length=0; |
| 305 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
| 306 | return((const void *) NULL); |
| 307 | *length=cache_info->length; |
| 308 | return((const void *) cache_info->pixels); |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 313 | % % |
| 314 | % % |
| 315 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 316 | + C a c h e C o m p o n e n t G e n e s i s % |
| 317 | % % |
| 318 | % % |
| 319 | % % |
| 320 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 321 | % |
| 322 | % CacheComponentGenesis() instantiates the cache component. |
| 323 | % |
| 324 | % The format of the CacheComponentGenesis method is: |
| 325 | % |
| 326 | % MagickBooleanType CacheComponentGenesis(void) |
| 327 | % |
| 328 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 329 | MagickPrivate MagickBooleanType CacheComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 330 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 331 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 332 | return(MagickTrue); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 337 | % % |
| 338 | % % |
| 339 | % % |
| 340 | + C a c h e C o m p o n e n t T e r m i n u s % |
| 341 | % % |
| 342 | % % |
| 343 | % % |
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 345 | % |
| 346 | % CacheComponentTerminus() destroys the cache component. |
| 347 | % |
| 348 | % The format of the CacheComponentTerminus() method is: |
| 349 | % |
| 350 | % CacheComponentTerminus(void) |
| 351 | % |
| 352 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 353 | MagickPrivate void CacheComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 354 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 355 | if (cache_semaphore == (SemaphoreInfo *) NULL) |
| 356 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 357 | LockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 358 | instantiate_cache=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 359 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 360 | DestroySemaphoreInfo(&cache_semaphore); |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 365 | % % |
| 366 | % % |
| 367 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | + C l o n e P i x e l C a c h e % |
| 369 | % % |
| 370 | % % |
| 371 | % % |
| 372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 373 | % |
| 374 | % ClonePixelCache() clones a pixel cache. |
| 375 | % |
| 376 | % The format of the ClonePixelCache() method is: |
| 377 | % |
| 378 | % Cache ClonePixelCache(const Cache cache) |
| 379 | % |
| 380 | % A description of each parameter follows: |
| 381 | % |
| 382 | % o cache: the pixel cache. |
| 383 | % |
| 384 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 385 | MagickPrivate Cache ClonePixelCache(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | { |
| 387 | CacheInfo |
| 388 | *clone_info; |
| 389 | |
| 390 | const CacheInfo |
| 391 | *cache_info; |
| 392 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 393 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 394 | cache_info=(const CacheInfo *) cache; |
| 395 | assert(cache_info->signature == MagickSignature); |
| 396 | if (cache_info->debug != MagickFalse) |
| 397 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 398 | cache_info->filename); |
| 399 | clone_info=(CacheInfo *) AcquirePixelCache(cache_info->number_threads); |
| 400 | if (clone_info == (Cache) NULL) |
| 401 | return((Cache) NULL); |
| 402 | clone_info->virtual_pixel_method=cache_info->virtual_pixel_method; |
| 403 | return((Cache ) clone_info); |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 408 | % % |
| 409 | % % |
| 410 | % % |
cristy | 60c44a8 | 2009-10-07 00:58:49 +0000 | [diff] [blame] | 411 | + C l o n e P i x e l C a c h e P i x e l s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 | % % |
| 413 | % % |
| 414 | % % |
| 415 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % |
| 416 | % ClonePixelCachePixels() clones the source pixel cache to the destination |
| 417 | % cache. |
| 418 | % |
| 419 | % The format of the ClonePixelCachePixels() method is: |
| 420 | % |
| 421 | % MagickBooleanType ClonePixelCachePixels(CacheInfo *cache_info, |
| 422 | % CacheInfo *source_info,ExceptionInfo *exception) |
| 423 | % |
| 424 | % A description of each parameter follows: |
| 425 | % |
| 426 | % o cache_info: the pixel cache. |
| 427 | % |
| 428 | % o source_info: the source pixel cache. |
| 429 | % |
| 430 | % o exception: return any errors or warnings in this structure. |
| 431 | % |
| 432 | */ |
| 433 | |
| 434 | static MagickBooleanType ClosePixelCacheOnDisk(CacheInfo *cache_info) |
| 435 | { |
| 436 | int |
| 437 | status; |
| 438 | |
cristy | 5ee247a | 2010-02-12 15:42:34 +0000 | [diff] [blame] | 439 | status=(-1); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 440 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 508d931 | 2010-02-10 21:10:30 +0000 | [diff] [blame] | 441 | if (cache_info->file != -1) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 442 | { |
| 443 | status=close(cache_info->file); |
| 444 | cache_info->file=(-1); |
| 445 | RelinquishMagickResource(FileResource,1); |
| 446 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 447 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | return(status == -1 ? MagickFalse : MagickTrue); |
| 449 | } |
| 450 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | static inline MagickSizeType MagickMax(const MagickSizeType x, |
| 452 | const MagickSizeType y) |
| 453 | { |
| 454 | if (x > y) |
| 455 | return(x); |
| 456 | return(y); |
| 457 | } |
| 458 | |
| 459 | static inline MagickSizeType MagickMin(const MagickSizeType x, |
| 460 | const MagickSizeType y) |
| 461 | { |
| 462 | if (x < y) |
| 463 | return(x); |
| 464 | return(y); |
| 465 | } |
| 466 | |
| 467 | static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info, |
| 468 | const MapMode mode) |
| 469 | { |
| 470 | int |
| 471 | file; |
| 472 | |
| 473 | /* |
| 474 | Open pixel cache on disk. |
| 475 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 476 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | if (cache_info->file != -1) |
| 478 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 479 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 480 | return(MagickTrue); /* cache already open */ |
| 481 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | if (*cache_info->cache_filename == '\0') |
| 483 | file=AcquireUniqueFileResource(cache_info->cache_filename); |
| 484 | else |
| 485 | switch (mode) |
| 486 | { |
| 487 | case ReadMode: |
| 488 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 489 | file=open_utf8(cache_info->cache_filename,O_RDONLY | O_BINARY,0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 490 | break; |
| 491 | } |
| 492 | case WriteMode: |
| 493 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 494 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_CREAT | |
| 495 | O_BINARY | O_EXCL,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 496 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 497 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 498 | break; |
| 499 | } |
| 500 | case IOMode: |
| 501 | default: |
| 502 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 503 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_CREAT | O_BINARY | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 504 | O_EXCL,S_MODE); |
| 505 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 506 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | } |
| 510 | if (file == -1) |
| 511 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 512 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 513 | return(MagickFalse); |
| 514 | } |
| 515 | (void) AcquireMagickResource(FileResource,1); |
| 516 | cache_info->file=file; |
cristy | 4d9c192 | 2011-12-31 18:37:34 +0000 | [diff] [blame] | 517 | cache_info->mode=mode; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 518 | cache_info->timestamp=time(0); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 519 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | return(MagickTrue); |
| 521 | } |
| 522 | |
| 523 | static inline MagickOffsetType ReadPixelCacheRegion(CacheInfo *cache_info, |
| 524 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 525 | unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 526 | { |
| 527 | register MagickOffsetType |
| 528 | i; |
| 529 | |
| 530 | ssize_t |
| 531 | count; |
| 532 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 533 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 535 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 536 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 538 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 539 | return((MagickOffsetType) -1); |
| 540 | } |
| 541 | #endif |
| 542 | count=0; |
| 543 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 544 | { |
| 545 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| 546 | count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 547 | (MagickSizeType) SSIZE_MAX)); |
| 548 | #else |
| 549 | count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 550 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 551 | #endif |
| 552 | if (count > 0) |
| 553 | continue; |
| 554 | count=0; |
| 555 | if (errno != EINTR) |
| 556 | { |
| 557 | i=(-1); |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 562 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 563 | #endif |
| 564 | return(i); |
| 565 | } |
| 566 | |
| 567 | static inline MagickOffsetType WritePixelCacheRegion(CacheInfo *cache_info, |
| 568 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 569 | const unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 570 | { |
| 571 | register MagickOffsetType |
| 572 | i; |
| 573 | |
| 574 | ssize_t |
| 575 | count; |
| 576 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 577 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 578 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 579 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 580 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 581 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 582 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 583 | return((MagickOffsetType) -1); |
| 584 | } |
| 585 | #endif |
| 586 | count=0; |
| 587 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 588 | { |
| 589 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| 590 | count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 591 | (MagickSizeType) SSIZE_MAX)); |
| 592 | #else |
| 593 | count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 594 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 595 | #endif |
| 596 | if (count > 0) |
| 597 | continue; |
| 598 | count=0; |
| 599 | if (errno != EINTR) |
| 600 | { |
| 601 | i=(-1); |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 606 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 607 | #endif |
| 608 | return(i); |
| 609 | } |
| 610 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 611 | static MagickBooleanType DiskToDiskPixelCacheClone(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 612 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 613 | { |
| 614 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 615 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 617 | register MagickOffsetType |
| 618 | i; |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 619 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 620 | size_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 621 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 622 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 623 | unsigned char |
| 624 | *blob; |
| 625 | |
| 626 | /* |
| 627 | Clone pixel cache (both caches on disk). |
| 628 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | if (cache_info->debug != MagickFalse) |
| 630 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 631 | blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 632 | sizeof(*blob)); |
| 633 | if (blob == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 634 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 635 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 636 | ResourceLimitError,"MemoryAllocationFailed","'%s'", |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 637 | cache_info->filename); |
| 638 | return(MagickFalse); |
| 639 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 640 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 641 | { |
| 642 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 643 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 644 | cache_info->cache_filename); |
| 645 | return(MagickFalse); |
| 646 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 647 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 648 | { |
| 649 | (void) ClosePixelCacheOnDisk(cache_info); |
| 650 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 651 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 652 | clone_info->cache_filename); |
| 653 | return(MagickFalse); |
| 654 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 655 | count=0; |
| 656 | for (i=0; i < (MagickOffsetType) cache_info->length; i+=count) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 657 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 658 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+i, |
| 659 | MagickMin(cache_info->length-i,(MagickSizeType) MagickMaxBufferExtent), |
| 660 | blob); |
| 661 | if (count <= 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 663 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 664 | cache_info->cache_filename); |
| 665 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 666 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 667 | length=(size_t) count; |
| 668 | count=WritePixelCacheRegion(clone_info,clone_info->offset+i,length,blob); |
| 669 | if ((MagickSizeType) count != length) |
| 670 | { |
| 671 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 672 | clone_info->cache_filename); |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | (void) ClosePixelCacheOnDisk(clone_info); |
| 677 | (void) ClosePixelCacheOnDisk(cache_info); |
| 678 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 679 | if (i < (MagickOffsetType) cache_info->length) |
| 680 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 681 | return(MagickTrue); |
| 682 | } |
| 683 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 684 | static MagickBooleanType PixelCacheCloneOptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 685 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 686 | { |
| 687 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 688 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 690 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 691 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 692 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 693 | Clone pixel cache (both caches in memory). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 695 | if (cache_info->debug != MagickFalse) |
| 696 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 697 | (void) memcpy(clone_info->pixels,cache_info->pixels,(size_t) |
| 698 | cache_info->length); |
| 699 | return(MagickTrue); |
| 700 | } |
| 701 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 702 | { |
| 703 | /* |
| 704 | Clone pixel cache (one cache on disk, one in memory). |
| 705 | */ |
| 706 | if (cache_info->debug != MagickFalse) |
| 707 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 708 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 709 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 710 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 711 | cache_info->cache_filename); |
| 712 | return(MagickFalse); |
| 713 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 714 | count=ReadPixelCacheRegion(cache_info,cache_info->offset, |
| 715 | cache_info->length,(unsigned char *) clone_info->pixels); |
| 716 | (void) ClosePixelCacheOnDisk(cache_info); |
| 717 | if ((MagickSizeType) count != cache_info->length) |
| 718 | { |
| 719 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 720 | cache_info->cache_filename); |
| 721 | return(MagickFalse); |
| 722 | } |
| 723 | return(MagickTrue); |
| 724 | } |
| 725 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 726 | { |
| 727 | /* |
| 728 | Clone pixel cache (one cache on disk, one in memory). |
| 729 | */ |
| 730 | if (clone_info->debug != MagickFalse) |
| 731 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 732 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
| 733 | { |
| 734 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 735 | clone_info->cache_filename); |
| 736 | return(MagickFalse); |
| 737 | } |
| 738 | count=WritePixelCacheRegion(clone_info,clone_info->offset, |
| 739 | clone_info->length,(unsigned char *) cache_info->pixels); |
| 740 | (void) ClosePixelCacheOnDisk(clone_info); |
| 741 | if ((MagickSizeType) count != clone_info->length) |
| 742 | { |
| 743 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 744 | clone_info->cache_filename); |
| 745 | return(MagickFalse); |
| 746 | } |
| 747 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 748 | } |
| 749 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 750 | Clone pixel cache (both caches on disk). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 751 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 752 | return(DiskToDiskPixelCacheClone(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 753 | } |
| 754 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 755 | static MagickBooleanType PixelCacheCloneUnoptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 756 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 757 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 758 | MagickBooleanType |
| 759 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 760 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 761 | MagickOffsetType |
| 762 | cache_offset, |
| 763 | clone_offset, |
| 764 | count; |
| 765 | |
| 766 | register ssize_t |
| 767 | x; |
| 768 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 769 | register unsigned char |
| 770 | *p; |
| 771 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 772 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | length; |
| 774 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 775 | ssize_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 776 | y; |
| 777 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 778 | unsigned char |
| 779 | *blob; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 780 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 781 | /* |
| 782 | Clone pixel cache (unoptimized). |
| 783 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 784 | if (cache_info->debug != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 785 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 786 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
| 787 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 788 | else |
| 789 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 790 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 791 | else |
| 792 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 793 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 794 | else |
| 795 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
| 796 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 797 | length=(size_t) MagickMax(MagickMax(cache_info->number_channels, |
| 798 | clone_info->number_channels)*sizeof(Quantum),MagickMax( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 799 | cache_info->metacontent_extent,clone_info->metacontent_extent)); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 800 | blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(*blob)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 801 | if (blob == (unsigned char *) NULL) |
| 802 | { |
| 803 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 804 | ResourceLimitError,"MemoryAllocationFailed","'%s'", |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 805 | cache_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 806 | return(MagickFalse); |
| 807 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 808 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 809 | cache_offset=0; |
| 810 | clone_offset=0; |
| 811 | if (cache_info->type == DiskCache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 812 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 813 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 814 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 815 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 816 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 817 | cache_info->cache_filename); |
| 818 | return(MagickFalse); |
| 819 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 820 | cache_offset=cache_info->offset; |
| 821 | } |
| 822 | if (clone_info->type == DiskCache) |
| 823 | { |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 824 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 825 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 826 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 827 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 828 | clone_info->cache_filename); |
| 829 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 830 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 831 | clone_offset=clone_info->offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 832 | } |
| 833 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 834 | Clone pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 835 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 836 | status=MagickTrue; |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 837 | p=blob; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 838 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 839 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 840 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 841 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 842 | register ssize_t |
| 843 | i; |
| 844 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 846 | Read a set of pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 847 | */ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 848 | length=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 849 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 850 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 851 | else |
| 852 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 853 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 854 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 855 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 856 | status=MagickFalse; |
| 857 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | } |
| 859 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 860 | cache_offset+=length; |
| 861 | if ((y < (ssize_t) clone_info->rows) && |
| 862 | (x < (ssize_t) clone_info->columns)) |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 863 | for (i=0; i < (ssize_t) clone_info->number_channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 864 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 865 | PixelChannel |
| 866 | channel; |
| 867 | |
| 868 | PixelTrait |
| 869 | traits; |
| 870 | |
| 871 | ssize_t |
| 872 | offset; |
| 873 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 874 | /* |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 875 | Write a set of pixel channels. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 876 | */ |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 877 | channel=clone_info->channel_map[i].channel; |
| 878 | traits=cache_info->channel_map[channel].traits; |
| 879 | if (traits == UndefinedPixelTrait) |
| 880 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 881 | clone_offset+=sizeof(Quantum); |
| 882 | continue; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 883 | } |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 884 | offset=cache_info->channel_map[channel].offset; |
| 885 | if (clone_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 886 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,p+ |
| 887 | offset*sizeof(Quantum),sizeof(Quantum)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 888 | else |
| 889 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 890 | count=WritePixelCacheRegion(clone_info,clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 891 | sizeof(Quantum),p+offset*sizeof(Quantum)); |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 892 | if ((MagickSizeType) count != sizeof(Quantum)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 893 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 894 | status=MagickFalse; |
| 895 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 898 | clone_offset+=sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 899 | } |
| 900 | } |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 901 | if (y < clone_info->rows) |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 902 | { |
| 903 | /* |
| 904 | Set remaining columns as undefined. |
| 905 | */ |
cristy | 888e613 | 2012-04-23 19:54:54 +0000 | [diff] [blame] | 906 | length=clone_info->number_channels*sizeof(Quantum); |
| 907 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 908 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 909 | { |
| 910 | if (clone_info->type != DiskCache) |
| 911 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 912 | blob,length); |
| 913 | else |
| 914 | { |
| 915 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 916 | if ((MagickSizeType) count != length) |
| 917 | { |
| 918 | status=MagickFalse; |
| 919 | break; |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 920 | } |
cristy | 888e613 | 2012-04-23 19:54:54 +0000 | [diff] [blame] | 921 | } |
| 922 | clone_offset+=length; |
| 923 | } |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 924 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 925 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 926 | length=clone_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 927 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 928 | for ( ; y < (ssize_t) clone_info->rows; y++) |
| 929 | { |
| 930 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 931 | Set remaining rows as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 932 | */ |
| 933 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 934 | { |
| 935 | if (clone_info->type != DiskCache) |
| 936 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,blob, |
| 937 | length); |
| 938 | else |
| 939 | { |
| 940 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 941 | if ((MagickSizeType) count != length) |
| 942 | { |
| 943 | status=MagickFalse; |
| 944 | break; |
| 945 | } |
| 946 | } |
| 947 | clone_offset+=length; |
| 948 | } |
| 949 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 950 | if ((cache_info->metacontent_extent != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 951 | (clone_info->metacontent_extent != 0)) |
| 952 | { |
| 953 | /* |
| 954 | Clone metacontent. |
| 955 | */ |
| 956 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
| 957 | { |
| 958 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
| 959 | { |
| 960 | /* |
| 961 | Read a set of metacontent. |
| 962 | */ |
| 963 | length=cache_info->metacontent_extent; |
| 964 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 965 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 966 | else |
| 967 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 968 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 969 | if ((MagickSizeType) count != length) |
| 970 | { |
| 971 | status=MagickFalse; |
| 972 | break; |
| 973 | } |
| 974 | } |
| 975 | cache_offset+=length; |
| 976 | if ((y < (ssize_t) clone_info->rows) && |
| 977 | (x < (ssize_t) clone_info->columns)) |
| 978 | { |
| 979 | /* |
| 980 | Write a set of metacontent. |
| 981 | */ |
| 982 | length=clone_info->metacontent_extent; |
| 983 | if (clone_info->type != DiskCache) |
| 984 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 985 | p,length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 986 | else |
| 987 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 988 | count=WritePixelCacheRegion(clone_info,clone_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 989 | if ((MagickSizeType) count != length) |
| 990 | { |
| 991 | status=MagickFalse; |
| 992 | break; |
| 993 | } |
| 994 | } |
| 995 | clone_offset+=length; |
| 996 | } |
| 997 | } |
| 998 | length=clone_info->metacontent_extent; |
| 999 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1000 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 1001 | { |
| 1002 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1003 | Set remaining columns as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1004 | */ |
| 1005 | if (clone_info->type != DiskCache) |
| 1006 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 1007 | blob,length); |
| 1008 | else |
| 1009 | { |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1010 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1011 | if ((MagickSizeType) count != length) |
| 1012 | { |
| 1013 | status=MagickFalse; |
| 1014 | break; |
| 1015 | } |
| 1016 | } |
| 1017 | clone_offset+=length; |
| 1018 | } |
| 1019 | } |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 1020 | if (y < clone_info->rows) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1021 | { |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 1022 | /* |
| 1023 | Set remaining rows as undefined. |
| 1024 | */ |
cristy | 888e613 | 2012-04-23 19:54:54 +0000 | [diff] [blame] | 1025 | length=clone_info->metacontent_extent; |
| 1026 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1027 | for ( ; y < (ssize_t) clone_info->rows; y++) |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 1028 | { |
cristy | 888e613 | 2012-04-23 19:54:54 +0000 | [diff] [blame] | 1029 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 1030 | { |
| 1031 | if (clone_info->type != DiskCache) |
| 1032 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 1033 | blob,length); |
| 1034 | else |
| 1035 | { |
| 1036 | count=WritePixelCacheRegion(clone_info,clone_offset,length, |
| 1037 | blob); |
| 1038 | if ((MagickSizeType) count != length) |
| 1039 | { |
| 1040 | status=MagickFalse; |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | clone_offset+=length; |
| 1045 | } |
cristy | e04362f | 2012-04-23 15:33:05 +0000 | [diff] [blame] | 1046 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1047 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1048 | } |
| 1049 | if (clone_info->type == DiskCache) |
| 1050 | (void) ClosePixelCacheOnDisk(clone_info); |
| 1051 | if (cache_info->type == DiskCache) |
| 1052 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1053 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 1054 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | static MagickBooleanType ClonePixelCachePixels(CacheInfo *clone_info, |
| 1058 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 1059 | { |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1060 | PixelChannelMap |
| 1061 | *p, |
| 1062 | *q; |
| 1063 | |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 1064 | if (cache_info->type == PingCache) |
| 1065 | return(MagickTrue); |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1066 | p=cache_info->channel_map; |
| 1067 | q=clone_info->channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1068 | if ((cache_info->columns == clone_info->columns) && |
| 1069 | (cache_info->rows == clone_info->rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1070 | (cache_info->number_channels == clone_info->number_channels) && |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1071 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1072 | (cache_info->metacontent_extent == clone_info->metacontent_extent)) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1073 | return(PixelCacheCloneOptimized(clone_info,cache_info,exception)); |
| 1074 | return(PixelCacheCloneUnoptimized(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1079 | % % |
| 1080 | % % |
| 1081 | % % |
| 1082 | + C l o n e P i x e l C a c h e M e t h o d s % |
| 1083 | % % |
| 1084 | % % |
| 1085 | % % |
| 1086 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1087 | % |
| 1088 | % ClonePixelCacheMethods() clones the pixel cache methods from one cache to |
| 1089 | % another. |
| 1090 | % |
| 1091 | % The format of the ClonePixelCacheMethods() method is: |
| 1092 | % |
| 1093 | % void ClonePixelCacheMethods(Cache clone,const Cache cache) |
| 1094 | % |
| 1095 | % A description of each parameter follows: |
| 1096 | % |
| 1097 | % o clone: Specifies a pointer to a Cache structure. |
| 1098 | % |
| 1099 | % o cache: the pixel cache. |
| 1100 | % |
| 1101 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1102 | MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1103 | { |
| 1104 | CacheInfo |
| 1105 | *cache_info, |
| 1106 | *source_info; |
| 1107 | |
| 1108 | assert(clone != (Cache) NULL); |
| 1109 | source_info=(CacheInfo *) clone; |
| 1110 | assert(source_info->signature == MagickSignature); |
| 1111 | if (source_info->debug != MagickFalse) |
| 1112 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1113 | source_info->filename); |
| 1114 | assert(cache != (Cache) NULL); |
| 1115 | cache_info=(CacheInfo *) cache; |
| 1116 | assert(cache_info->signature == MagickSignature); |
| 1117 | source_info->methods=cache_info->methods; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1122 | % % |
| 1123 | % % |
| 1124 | % % |
| 1125 | + D e s t r o y I m a g e P i x e l C a c h e % |
| 1126 | % % |
| 1127 | % % |
| 1128 | % % |
| 1129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1130 | % |
| 1131 | % DestroyImagePixelCache() deallocates memory associated with the pixel cache. |
| 1132 | % |
| 1133 | % The format of the DestroyImagePixelCache() method is: |
| 1134 | % |
| 1135 | % void DestroyImagePixelCache(Image *image) |
| 1136 | % |
| 1137 | % A description of each parameter follows: |
| 1138 | % |
| 1139 | % o image: the image. |
| 1140 | % |
| 1141 | */ |
| 1142 | static void DestroyImagePixelCache(Image *image) |
| 1143 | { |
| 1144 | assert(image != (Image *) NULL); |
| 1145 | assert(image->signature == MagickSignature); |
| 1146 | if (image->debug != MagickFalse) |
| 1147 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1148 | if (image->cache == (void *) NULL) |
| 1149 | return; |
| 1150 | image->cache=DestroyPixelCache(image->cache); |
| 1151 | } |
| 1152 | |
| 1153 | /* |
| 1154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1155 | % % |
| 1156 | % % |
| 1157 | % % |
| 1158 | + D e s t r o y I m a g e P i x e l s % |
| 1159 | % % |
| 1160 | % % |
| 1161 | % % |
| 1162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1163 | % |
| 1164 | % DestroyImagePixels() deallocates memory associated with the pixel cache. |
| 1165 | % |
| 1166 | % The format of the DestroyImagePixels() method is: |
| 1167 | % |
| 1168 | % void DestroyImagePixels(Image *image) |
| 1169 | % |
| 1170 | % A description of each parameter follows: |
| 1171 | % |
| 1172 | % o image: the image. |
| 1173 | % |
| 1174 | */ |
| 1175 | MagickExport void DestroyImagePixels(Image *image) |
| 1176 | { |
| 1177 | CacheInfo |
| 1178 | *cache_info; |
| 1179 | |
| 1180 | assert(image != (const Image *) NULL); |
| 1181 | assert(image->signature == MagickSignature); |
| 1182 | if (image->debug != MagickFalse) |
| 1183 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1184 | assert(image->cache != (Cache) NULL); |
| 1185 | cache_info=(CacheInfo *) image->cache; |
| 1186 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1187 | if (cache_info->methods.destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 1188 | { |
| 1189 | cache_info->methods.destroy_pixel_handler(image); |
| 1190 | return; |
| 1191 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1192 | image->cache=DestroyPixelCache(image->cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1197 | % % |
| 1198 | % % |
| 1199 | % % |
| 1200 | + D e s t r o y P i x e l C a c h e % |
| 1201 | % % |
| 1202 | % % |
| 1203 | % % |
| 1204 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1205 | % |
| 1206 | % DestroyPixelCache() deallocates memory associated with the pixel cache. |
| 1207 | % |
| 1208 | % The format of the DestroyPixelCache() method is: |
| 1209 | % |
| 1210 | % Cache DestroyPixelCache(Cache cache) |
| 1211 | % |
| 1212 | % A description of each parameter follows: |
| 1213 | % |
| 1214 | % o cache: the pixel cache. |
| 1215 | % |
| 1216 | */ |
| 1217 | |
| 1218 | static inline void RelinquishPixelCachePixels(CacheInfo *cache_info) |
| 1219 | { |
| 1220 | switch (cache_info->type) |
| 1221 | { |
| 1222 | case MemoryCache: |
| 1223 | { |
| 1224 | if (cache_info->mapped == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1225 | cache_info->pixels=(Quantum *) RelinquishMagickMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1226 | cache_info->pixels); |
| 1227 | else |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1228 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1229 | (size_t) cache_info->length); |
| 1230 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 1231 | break; |
| 1232 | } |
| 1233 | case MapCache: |
| 1234 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1235 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1236 | cache_info->length); |
| 1237 | RelinquishMagickResource(MapResource,cache_info->length); |
| 1238 | } |
| 1239 | case DiskCache: |
| 1240 | { |
| 1241 | if (cache_info->file != -1) |
| 1242 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1243 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 1244 | break; |
| 1245 | } |
| 1246 | default: |
| 1247 | break; |
| 1248 | } |
| 1249 | cache_info->type=UndefinedCache; |
| 1250 | cache_info->mapped=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1251 | cache_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1254 | MagickPrivate Cache DestroyPixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1255 | { |
| 1256 | CacheInfo |
| 1257 | *cache_info; |
| 1258 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1259 | assert(cache != (Cache) NULL); |
| 1260 | cache_info=(CacheInfo *) cache; |
| 1261 | assert(cache_info->signature == MagickSignature); |
| 1262 | if (cache_info->debug != MagickFalse) |
| 1263 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1264 | cache_info->filename); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1265 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1266 | cache_info->reference_count--; |
| 1267 | if (cache_info->reference_count != 0) |
| 1268 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1269 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | return((Cache) NULL); |
| 1271 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1272 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1273 | if (cache_info->debug != MagickFalse) |
| 1274 | { |
| 1275 | char |
| 1276 | message[MaxTextExtent]; |
| 1277 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1278 | (void) FormatLocaleString(message,MaxTextExtent,"destroy %s", |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1279 | cache_info->filename); |
| 1280 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 1281 | } |
cristy | c2e1bdd | 2009-09-10 23:43:34 +0000 | [diff] [blame] | 1282 | if ((cache_info->mode == ReadMode) || ((cache_info->type != MapCache) && |
| 1283 | (cache_info->type != DiskCache))) |
| 1284 | RelinquishPixelCachePixels(cache_info); |
| 1285 | else |
| 1286 | { |
| 1287 | RelinquishPixelCachePixels(cache_info); |
| 1288 | (void) RelinquishUniqueFileResource(cache_info->cache_filename); |
| 1289 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1290 | *cache_info->cache_filename='\0'; |
| 1291 | if (cache_info->nexus_info != (NexusInfo **) NULL) |
| 1292 | cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info, |
| 1293 | cache_info->number_threads); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1294 | if (cache_info->random_info != (RandomInfo *) NULL) |
| 1295 | cache_info->random_info=DestroyRandomInfo(cache_info->random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1296 | if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL) |
| 1297 | DestroySemaphoreInfo(&cache_info->disk_semaphore); |
| 1298 | if (cache_info->semaphore != (SemaphoreInfo *) NULL) |
| 1299 | DestroySemaphoreInfo(&cache_info->semaphore); |
cristy | 154a1e2 | 2010-02-15 00:28:37 +0000 | [diff] [blame] | 1300 | cache_info->signature=(~MagickSignature); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 1301 | cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1302 | cache=(Cache) NULL; |
| 1303 | return(cache); |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1308 | % % |
| 1309 | % % |
| 1310 | % % |
| 1311 | + D e s t r o y P i x e l C a c h e N e x u s % |
| 1312 | % % |
| 1313 | % % |
| 1314 | % % |
| 1315 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1316 | % |
| 1317 | % DestroyPixelCacheNexus() destroys a pixel cache nexus. |
| 1318 | % |
| 1319 | % The format of the DestroyPixelCacheNexus() method is: |
| 1320 | % |
| 1321 | % NexusInfo **DestroyPixelCacheNexus(NexusInfo *nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1322 | % const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1323 | % |
| 1324 | % A description of each parameter follows: |
| 1325 | % |
| 1326 | % o nexus_info: the nexus to destroy. |
| 1327 | % |
| 1328 | % o number_threads: the number of nexus threads. |
| 1329 | % |
| 1330 | */ |
| 1331 | |
| 1332 | static inline void RelinquishCacheNexusPixels(NexusInfo *nexus_info) |
| 1333 | { |
| 1334 | if (nexus_info->mapped == MagickFalse) |
cristy | 64c3edf | 2012-04-13 18:50:13 +0000 | [diff] [blame] | 1335 | (void) RelinquishMagickMemory(nexus_info->cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1336 | else |
| 1337 | (void) UnmapBlob(nexus_info->cache,(size_t) nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1338 | nexus_info->cache=(Quantum *) NULL; |
| 1339 | nexus_info->pixels=(Quantum *) NULL; |
| 1340 | nexus_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1341 | nexus_info->length=0; |
| 1342 | nexus_info->mapped=MagickFalse; |
| 1343 | } |
| 1344 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1345 | MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1346 | const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1347 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1348 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1349 | i; |
| 1350 | |
| 1351 | assert(nexus_info != (NexusInfo **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1352 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1353 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1354 | if (nexus_info[i]->cache != (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | RelinquishCacheNexusPixels(nexus_info[i]); |
| 1356 | nexus_info[i]->signature=(~MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1357 | } |
cristy | e5f87c8 | 2012-02-14 12:44:17 +0000 | [diff] [blame] | 1358 | nexus_info[0]=(NexusInfo *) RelinquishMagickMemory(nexus_info[0]); |
cristy | 64c3edf | 2012-04-13 18:50:13 +0000 | [diff] [blame] | 1359 | nexus_info=(NexusInfo **) RelinquishAlignedMemory(nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1360 | return(nexus_info); |
| 1361 | } |
| 1362 | |
| 1363 | /* |
| 1364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1365 | % % |
| 1366 | % % |
| 1367 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1368 | % G e t A u t h e n t i c M e t a c o n t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1369 | % % |
| 1370 | % % |
| 1371 | % % |
| 1372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1373 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1374 | % GetAuthenticMetacontent() returns the authentic metacontent corresponding |
| 1375 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 1376 | % returned if the associated pixels are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1377 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1378 | % The format of the GetAuthenticMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1379 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1380 | % void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1381 | % |
| 1382 | % A description of each parameter follows: |
| 1383 | % |
| 1384 | % o image: the image. |
| 1385 | % |
| 1386 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1387 | MagickExport void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1388 | { |
| 1389 | CacheInfo |
| 1390 | *cache_info; |
| 1391 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1392 | const int |
| 1393 | id = GetOpenMPThreadId(); |
| 1394 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1395 | void |
| 1396 | *metacontent; |
| 1397 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1398 | assert(image != (const Image *) NULL); |
| 1399 | assert(image->signature == MagickSignature); |
| 1400 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1401 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1402 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1403 | if (cache_info->methods.get_authentic_metacontent_from_handler != |
| 1404 | (GetAuthenticMetacontentFromHandler) NULL) |
| 1405 | { |
| 1406 | metacontent=cache_info->methods. |
| 1407 | get_authentic_metacontent_from_handler(image); |
| 1408 | return(metacontent); |
| 1409 | } |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1410 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1411 | metacontent=GetPixelCacheNexusMetacontent(cache_info, |
| 1412 | cache_info->nexus_info[id]); |
| 1413 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1418 | % % |
| 1419 | % % |
| 1420 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1421 | + G e t A u t h e n t i c M e t a c o n t e n t F r o m C a c h e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1422 | % % |
| 1423 | % % |
| 1424 | % % |
| 1425 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1426 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1427 | % GetAuthenticMetacontentFromCache() returns the meta-content corresponding |
| 1428 | % with the last call to QueueAuthenticPixelsCache() or |
| 1429 | % GetAuthenticPixelsCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1430 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1431 | % The format of the GetAuthenticMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1432 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1433 | % void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1434 | % |
| 1435 | % A description of each parameter follows: |
| 1436 | % |
| 1437 | % o image: the image. |
| 1438 | % |
| 1439 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1440 | static void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | { |
| 1442 | CacheInfo |
| 1443 | *cache_info; |
| 1444 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1445 | const int |
| 1446 | id = GetOpenMPThreadId(); |
| 1447 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1448 | void |
| 1449 | *metacontent; |
| 1450 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1451 | assert(image != (const Image *) NULL); |
| 1452 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1453 | assert(image->cache != (Cache) NULL); |
| 1454 | cache_info=(CacheInfo *) image->cache; |
| 1455 | assert(cache_info->signature == MagickSignature); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1456 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1457 | metacontent=GetPixelCacheNexusMetacontent(image->cache, |
| 1458 | cache_info->nexus_info[id]); |
| 1459 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /* |
| 1463 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1464 | % % |
| 1465 | % % |
| 1466 | % % |
| 1467 | + G e t A u t h e n t i c P i x e l C a c h e N e x u s % |
| 1468 | % % |
| 1469 | % % |
| 1470 | % % |
| 1471 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1472 | % |
| 1473 | % GetAuthenticPixelCacheNexus() gets authentic pixels from the in-memory or |
| 1474 | % disk pixel cache as defined by the geometry parameters. A pointer to the |
| 1475 | % pixels is returned if the pixels are transferred, otherwise a NULL is |
| 1476 | % returned. |
| 1477 | % |
| 1478 | % The format of the GetAuthenticPixelCacheNexus() method is: |
| 1479 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1480 | % Quantum *GetAuthenticPixelCacheNexus(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1481 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1483 | % |
| 1484 | % A description of each parameter follows: |
| 1485 | % |
| 1486 | % o image: the image. |
| 1487 | % |
| 1488 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1489 | % pixels. |
| 1490 | % |
| 1491 | % o nexus_info: the cache nexus to return. |
| 1492 | % |
| 1493 | % o exception: return any errors or warnings in this structure. |
| 1494 | % |
| 1495 | */ |
| 1496 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1497 | static inline MagickBooleanType IsPixelAuthentic(const CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1498 | NexusInfo *nexus_info) |
| 1499 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1500 | MagickBooleanType |
| 1501 | status; |
| 1502 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1503 | MagickOffsetType |
| 1504 | offset; |
| 1505 | |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 1506 | if (cache_info->type == PingCache) |
| 1507 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1508 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 1509 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1510 | status=nexus_info->pixels == (cache_info->pixels+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1511 | cache_info->number_channels) ? MagickTrue : MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1512 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1515 | MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image, |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 1516 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1517 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1518 | { |
| 1519 | CacheInfo |
| 1520 | *cache_info; |
| 1521 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1522 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1523 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1524 | |
| 1525 | /* |
| 1526 | Transfer pixels from the cache. |
| 1527 | */ |
| 1528 | assert(image != (Image *) NULL); |
| 1529 | assert(image->signature == MagickSignature); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 1530 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickTrue,nexus_info, |
| 1531 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1532 | if (q == (Quantum *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1533 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1534 | cache_info=(CacheInfo *) image->cache; |
| 1535 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1536 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1537 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1538 | if (ReadPixelCachePixels(cache_info,nexus_info,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1539 | return((Quantum *) NULL); |
| 1540 | if (cache_info->metacontent_extent != 0) |
| 1541 | if (ReadPixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse) |
| 1542 | return((Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1543 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | /* |
| 1547 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1548 | % % |
| 1549 | % % |
| 1550 | % % |
| 1551 | + G e t A u t h e n t i c P i x e l s F r o m C a c h e % |
| 1552 | % % |
| 1553 | % % |
| 1554 | % % |
| 1555 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1556 | % |
| 1557 | % GetAuthenticPixelsFromCache() returns the pixels associated with the last |
| 1558 | % call to the QueueAuthenticPixelsCache() or GetAuthenticPixelsCache() methods. |
| 1559 | % |
| 1560 | % The format of the GetAuthenticPixelsFromCache() method is: |
| 1561 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1562 | % Quantum *GetAuthenticPixelsFromCache(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | % |
| 1564 | % A description of each parameter follows: |
| 1565 | % |
| 1566 | % o image: the image. |
| 1567 | % |
| 1568 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1569 | static Quantum *GetAuthenticPixelsFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1570 | { |
| 1571 | CacheInfo |
| 1572 | *cache_info; |
| 1573 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1574 | const int |
| 1575 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1576 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1577 | assert(image != (const Image *) NULL); |
| 1578 | assert(image->signature == MagickSignature); |
| 1579 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1580 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1581 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1582 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 1583 | return(GetPixelCacheNexusPixels(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /* |
| 1587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1588 | % % |
| 1589 | % % |
| 1590 | % % |
| 1591 | % G e t A u t h e n t i c P i x e l Q u e u e % |
| 1592 | % % |
| 1593 | % % |
| 1594 | % % |
| 1595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1596 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1597 | % GetAuthenticPixelQueue() returns the authentic pixels associated |
| 1598 | % corresponding with the last call to QueueAuthenticPixels() or |
| 1599 | % GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1600 | % |
| 1601 | % The format of the GetAuthenticPixelQueue() method is: |
| 1602 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1603 | % Quantum *GetAuthenticPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1604 | % |
| 1605 | % A description of each parameter follows: |
| 1606 | % |
| 1607 | % o image: the image. |
| 1608 | % |
| 1609 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1610 | MagickExport Quantum *GetAuthenticPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1611 | { |
| 1612 | CacheInfo |
| 1613 | *cache_info; |
| 1614 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1615 | const int |
| 1616 | id = GetOpenMPThreadId(); |
| 1617 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1618 | assert(image != (const Image *) NULL); |
| 1619 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1620 | assert(image->cache != (Cache) NULL); |
| 1621 | cache_info=(CacheInfo *) image->cache; |
| 1622 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1623 | if (cache_info->methods.get_authentic_pixels_from_handler != |
| 1624 | (GetAuthenticPixelsFromHandler) NULL) |
| 1625 | return(cache_info->methods.get_authentic_pixels_from_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1626 | assert(id < (int) cache_info->number_threads); |
| 1627 | return(GetPixelCacheNexusPixels(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1632 | % % |
| 1633 | % % |
| 1634 | % % |
| 1635 | % G e t A u t h e n t i c P i x e l s % |
| 1636 | % % |
| 1637 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1638 | % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1639 | % |
| 1640 | % GetAuthenticPixels() obtains a pixel region for read/write access. If the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1641 | % region is successfully accessed, a pointer to a Quantum array |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1642 | % representing the region is returned, otherwise NULL is returned. |
| 1643 | % |
| 1644 | % The returned pointer may point to a temporary working copy of the pixels |
| 1645 | % or it may point to the original pixels in memory. Performance is maximized |
| 1646 | % if the selected region is part of one row, or one or more full rows, since |
| 1647 | % then there is opportunity to access the pixels in-place (without a copy) |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 1648 | % if the image is in memory, or in a memory-mapped file. The returned pointer |
| 1649 | % must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1650 | % |
| 1651 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1652 | % Quantum. If the image has corresponding metacontent,call |
| 1653 | % GetAuthenticMetacontent() after invoking GetAuthenticPixels() to obtain the |
| 1654 | % meta-content corresponding to the region. Once the Quantum array has |
| 1655 | % been updated, the changes must be saved back to the underlying image using |
| 1656 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1657 | % |
| 1658 | % The format of the GetAuthenticPixels() method is: |
| 1659 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1660 | % Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 1661 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | % ExceptionInfo *exception) |
| 1663 | % |
| 1664 | % A description of each parameter follows: |
| 1665 | % |
| 1666 | % o image: the image. |
| 1667 | % |
| 1668 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1669 | % pixels. |
| 1670 | % |
| 1671 | % o exception: return any errors or warnings in this structure. |
| 1672 | % |
| 1673 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1674 | MagickExport Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1675 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1676 | ExceptionInfo *exception) |
| 1677 | { |
| 1678 | CacheInfo |
| 1679 | *cache_info; |
| 1680 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1681 | const int |
| 1682 | id = GetOpenMPThreadId(); |
| 1683 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1684 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1685 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1686 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1687 | assert(image != (Image *) NULL); |
| 1688 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | assert(image->cache != (Cache) NULL); |
| 1690 | cache_info=(CacheInfo *) image->cache; |
| 1691 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1692 | if (cache_info->methods.get_authentic_pixels_handler != |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1693 | (GetAuthenticPixelsHandler) NULL) |
| 1694 | { |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1695 | q=cache_info->methods.get_authentic_pixels_handler(image,x,y,columns,rows, |
| 1696 | exception); |
| 1697 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1698 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1699 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1700 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1701 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1702 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /* |
| 1706 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1707 | % % |
| 1708 | % % |
| 1709 | % % |
| 1710 | + G e t A u t h e n t i c P i x e l s C a c h e % |
| 1711 | % % |
| 1712 | % % |
| 1713 | % % |
| 1714 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1715 | % |
| 1716 | % GetAuthenticPixelsCache() gets pixels from the in-memory or disk pixel cache |
| 1717 | % as defined by the geometry parameters. A pointer to the pixels is returned |
| 1718 | % if the pixels are transferred, otherwise a NULL is returned. |
| 1719 | % |
| 1720 | % The format of the GetAuthenticPixelsCache() method is: |
| 1721 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1722 | % Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1723 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1724 | % ExceptionInfo *exception) |
| 1725 | % |
| 1726 | % A description of each parameter follows: |
| 1727 | % |
| 1728 | % o image: the image. |
| 1729 | % |
| 1730 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1731 | % pixels. |
| 1732 | % |
| 1733 | % o exception: return any errors or warnings in this structure. |
| 1734 | % |
| 1735 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1736 | static Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1737 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1738 | ExceptionInfo *exception) |
| 1739 | { |
| 1740 | CacheInfo |
| 1741 | *cache_info; |
| 1742 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1743 | const int |
| 1744 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1745 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1746 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1747 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1748 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1749 | assert(image != (const Image *) NULL); |
| 1750 | assert(image->signature == MagickSignature); |
| 1751 | assert(image->cache != (Cache) NULL); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 1752 | cache_info=(CacheInfo *) image->cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1753 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1754 | return((Quantum *) NULL); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1755 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1756 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1757 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1758 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1759 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | /* |
| 1763 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1764 | % % |
| 1765 | % % |
| 1766 | % % |
| 1767 | + G e t I m a g e E x t e n t % |
| 1768 | % % |
| 1769 | % % |
| 1770 | % % |
| 1771 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1772 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1773 | % GetImageExtent() returns the extent of the pixels associated corresponding |
| 1774 | % with the last call to QueueAuthenticPixels() or GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1775 | % |
| 1776 | % The format of the GetImageExtent() method is: |
| 1777 | % |
| 1778 | % MagickSizeType GetImageExtent(const Image *image) |
| 1779 | % |
| 1780 | % A description of each parameter follows: |
| 1781 | % |
| 1782 | % o image: the image. |
| 1783 | % |
| 1784 | */ |
| 1785 | MagickExport MagickSizeType GetImageExtent(const Image *image) |
| 1786 | { |
| 1787 | CacheInfo |
| 1788 | *cache_info; |
| 1789 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1790 | const int |
| 1791 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1792 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1793 | assert(image != (Image *) NULL); |
| 1794 | assert(image->signature == MagickSignature); |
| 1795 | if (image->debug != MagickFalse) |
| 1796 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1797 | assert(image->cache != (Cache) NULL); |
| 1798 | cache_info=(CacheInfo *) image->cache; |
| 1799 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1800 | assert(id < (int) cache_info->number_threads); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1801 | return(GetPixelCacheNexusExtent(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | /* |
| 1805 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1806 | % % |
| 1807 | % % |
| 1808 | % % |
| 1809 | + G e t I m a g e P i x e l C a c h e % |
| 1810 | % % |
| 1811 | % % |
| 1812 | % % |
| 1813 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1814 | % |
| 1815 | % GetImagePixelCache() ensures that there is only a single reference to the |
| 1816 | % pixel cache to be modified, updating the provided cache pointer to point to |
| 1817 | % a clone of the original pixel cache if necessary. |
| 1818 | % |
| 1819 | % The format of the GetImagePixelCache method is: |
| 1820 | % |
| 1821 | % Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 1822 | % ExceptionInfo *exception) |
| 1823 | % |
| 1824 | % A description of each parameter follows: |
| 1825 | % |
| 1826 | % o image: the image. |
| 1827 | % |
| 1828 | % o clone: any value other than MagickFalse clones the cache pixels. |
| 1829 | % |
| 1830 | % o exception: return any errors or warnings in this structure. |
| 1831 | % |
| 1832 | */ |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 1833 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1834 | static inline MagickBooleanType ValidatePixelCacheMorphology(const Image *image) |
| 1835 | { |
| 1836 | CacheInfo |
| 1837 | *cache_info; |
| 1838 | |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1839 | PixelChannelMap |
| 1840 | *p, |
| 1841 | *q; |
| 1842 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1843 | /* |
| 1844 | Does the image match the pixel cache morphology? |
| 1845 | */ |
| 1846 | cache_info=(CacheInfo *) image->cache; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1847 | p=image->channel_map; |
| 1848 | q=cache_info->channel_map; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1849 | if ((image->storage_class != cache_info->storage_class) || |
| 1850 | (image->colorspace != cache_info->colorspace) || |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 1851 | (image->matte != cache_info->matte) || |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 1852 | (image->mask != cache_info->mask) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1853 | (image->columns != cache_info->columns) || |
| 1854 | (image->rows != cache_info->rows) || |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1855 | (image->number_channels != cache_info->number_channels) || |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1856 | (memcmp(p,q,image->number_channels*sizeof(*p)) != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1857 | (image->metacontent_extent != cache_info->metacontent_extent) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1858 | (cache_info->nexus_info == (NexusInfo **) NULL) || |
| 1859 | (cache_info->number_threads < GetOpenMPMaximumThreads())) |
| 1860 | return(MagickFalse); |
| 1861 | return(MagickTrue); |
| 1862 | } |
| 1863 | |
cristy | cd01fae | 2011-08-06 23:52:42 +0000 | [diff] [blame] | 1864 | static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 1865 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1866 | { |
| 1867 | CacheInfo |
| 1868 | *cache_info; |
| 1869 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1870 | MagickBooleanType |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1871 | destroy, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1872 | status; |
| 1873 | |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 1874 | static MagickSizeType |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1875 | cpu_throttle = 0, |
| 1876 | cycles = 0, |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 1877 | time_limit = 0; |
| 1878 | |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1879 | static time_t |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1880 | cache_timestamp = 0; |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1881 | |
cristy | c4f9f13 | 2010-03-04 18:50:01 +0000 | [diff] [blame] | 1882 | status=MagickTrue; |
| 1883 | LockSemaphoreInfo(image->semaphore); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1884 | if (cpu_throttle == 0) |
| 1885 | { |
| 1886 | char |
| 1887 | *limit; |
| 1888 | |
| 1889 | /* |
| 1890 | Set CPU throttle in milleseconds. |
| 1891 | */ |
| 1892 | cpu_throttle=MagickResourceInfinity; |
| 1893 | limit=GetEnvironmentValue("MAGICK_THROTTLE"); |
| 1894 | if (limit == (char *) NULL) |
| 1895 | limit=GetPolicyValue("throttle"); |
| 1896 | if (limit != (char *) NULL) |
| 1897 | { |
| 1898 | cpu_throttle=(MagickSizeType) StringToInteger(limit); |
| 1899 | limit=DestroyString(limit); |
| 1900 | } |
| 1901 | } |
| 1902 | if ((cpu_throttle != MagickResourceInfinity) && ((cycles++ % 32) == 0)) |
| 1903 | MagickDelay(cpu_throttle); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1904 | if (time_limit == 0) |
| 1905 | { |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1906 | /* |
| 1907 | Set the exire time in seconds. |
| 1908 | */ |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1909 | time_limit=GetMagickResourceLimit(TimeResource); |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1910 | cache_timestamp=time((time_t *) NULL); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1911 | } |
| 1912 | if ((time_limit != MagickResourceInfinity) && |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1913 | ((MagickSizeType) (time((time_t *) NULL)-cache_timestamp) >= time_limit)) |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1914 | ThrowFatalException(ResourceLimitFatalError,"TimeLimitExceeded"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1915 | assert(image->cache != (Cache) NULL); |
| 1916 | cache_info=(CacheInfo *) image->cache; |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1917 | destroy=MagickFalse; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1918 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1919 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1920 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 1921 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1922 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1923 | Image |
| 1924 | clone_image; |
| 1925 | |
| 1926 | CacheInfo |
| 1927 | *clone_info; |
| 1928 | |
| 1929 | /* |
| 1930 | Clone pixel cache. |
| 1931 | */ |
| 1932 | clone_image=(*image); |
| 1933 | clone_image.semaphore=AllocateSemaphoreInfo(); |
| 1934 | clone_image.reference_count=1; |
| 1935 | clone_image.cache=ClonePixelCache(cache_info); |
| 1936 | clone_info=(CacheInfo *) clone_image.cache; |
| 1937 | status=OpenPixelCache(&clone_image,IOMode,exception); |
| 1938 | if (status != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1939 | { |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 1940 | if (clone != MagickFalse) |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 1941 | status=ClonePixelCachePixels(clone_info,cache_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1942 | if (status != MagickFalse) |
| 1943 | { |
cristy | 979bf77 | 2011-08-08 00:04:15 +0000 | [diff] [blame] | 1944 | if (cache_info->mode == ReadMode) |
| 1945 | cache_info->nexus_info=(NexusInfo **) NULL; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1946 | destroy=MagickTrue; |
| 1947 | image->cache=clone_image.cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1948 | } |
| 1949 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1950 | DestroySemaphoreInfo(&clone_image.semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1951 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1952 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1953 | } |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1954 | if (destroy != MagickFalse) |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 1955 | cache_info=(CacheInfo *) DestroyPixelCache(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1956 | if (status != MagickFalse) |
| 1957 | { |
| 1958 | /* |
| 1959 | Ensure the image matches the pixel cache morphology. |
| 1960 | */ |
| 1961 | image->taint=MagickTrue; |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 1962 | image->type=UndefinedType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1963 | if (ValidatePixelCacheMorphology(image) == MagickFalse) |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 1964 | { |
| 1965 | status=OpenPixelCache(image,IOMode,exception); |
| 1966 | cache_info=(CacheInfo *) image->cache; |
| 1967 | if (cache_info->type == DiskCache) |
| 1968 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1969 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1970 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1971 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1972 | if (status == MagickFalse) |
| 1973 | return((Cache) NULL); |
| 1974 | return(image->cache); |
| 1975 | } |
| 1976 | |
| 1977 | /* |
| 1978 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1979 | % % |
| 1980 | % % |
| 1981 | % % |
| 1982 | % G e t O n e A u t h e n t i c P i x e l % |
| 1983 | % % |
| 1984 | % % |
| 1985 | % % |
| 1986 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1987 | % |
| 1988 | % GetOneAuthenticPixel() returns a single pixel at the specified (x,y) |
| 1989 | % location. The image background color is returned if an error occurs. |
| 1990 | % |
| 1991 | % The format of the GetOneAuthenticPixel() method is: |
| 1992 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1993 | % MagickBooleanType GetOneAuthenticPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 1994 | % const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1995 | % |
| 1996 | % A description of each parameter follows: |
| 1997 | % |
| 1998 | % o image: the image. |
| 1999 | % |
| 2000 | % o x,y: These values define the location of the pixel to return. |
| 2001 | % |
| 2002 | % o pixel: return a pixel at the specified (x,y) location. |
| 2003 | % |
| 2004 | % o exception: return any errors or warnings in this structure. |
| 2005 | % |
| 2006 | */ |
cristy | acbbb7c | 2010-06-30 18:56:48 +0000 | [diff] [blame] | 2007 | MagickExport MagickBooleanType GetOneAuthenticPixel(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2008 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2009 | { |
| 2010 | CacheInfo |
| 2011 | *cache_info; |
| 2012 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2013 | register Quantum |
| 2014 | *q; |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2015 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2016 | register ssize_t |
| 2017 | i; |
| 2018 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2019 | assert(image != (Image *) NULL); |
| 2020 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2021 | assert(image->cache != (Cache) NULL); |
| 2022 | cache_info=(CacheInfo *) image->cache; |
| 2023 | assert(cache_info->signature == MagickSignature); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2024 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 2025 | if (cache_info->methods.get_one_authentic_pixel_from_handler != |
| 2026 | (GetOneAuthenticPixelFromHandler) NULL) |
| 2027 | return(cache_info->methods.get_one_authentic_pixel_from_handler(image,x,y, |
| 2028 | pixel,exception)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2029 | q=GetAuthenticPixelsCache(image,x,y,1UL,1UL,exception); |
| 2030 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2031 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2032 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2033 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2034 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2035 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2036 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2037 | return(MagickFalse); |
| 2038 | } |
| 2039 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2040 | { |
| 2041 | PixelChannel |
| 2042 | channel; |
| 2043 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2044 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2045 | pixel[channel]=q[i]; |
| 2046 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2047 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | /* |
| 2051 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2052 | % % |
| 2053 | % % |
| 2054 | % % |
| 2055 | + G e t O n e A u t h e n t i c P i x e l F r o m C a c h e % |
| 2056 | % % |
| 2057 | % % |
| 2058 | % % |
| 2059 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2060 | % |
| 2061 | % GetOneAuthenticPixelFromCache() returns a single pixel at the specified (x,y) |
| 2062 | % location. The image background color is returned if an error occurs. |
| 2063 | % |
| 2064 | % The format of the GetOneAuthenticPixelFromCache() method is: |
| 2065 | % |
| 2066 | % MagickBooleanType GetOneAuthenticPixelFromCache(const Image image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2067 | % const ssize_t x,const ssize_t y,Quantum *pixel, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 2068 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2069 | % |
| 2070 | % A description of each parameter follows: |
| 2071 | % |
| 2072 | % o image: the image. |
| 2073 | % |
| 2074 | % o x,y: These values define the location of the pixel to return. |
| 2075 | % |
| 2076 | % o pixel: return a pixel at the specified (x,y) location. |
| 2077 | % |
| 2078 | % o exception: return any errors or warnings in this structure. |
| 2079 | % |
| 2080 | */ |
| 2081 | static MagickBooleanType GetOneAuthenticPixelFromCache(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2082 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2083 | { |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2084 | CacheInfo |
| 2085 | *cache_info; |
| 2086 | |
| 2087 | const int |
| 2088 | id = GetOpenMPThreadId(); |
| 2089 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2090 | register Quantum |
| 2091 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2092 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2093 | register ssize_t |
| 2094 | i; |
| 2095 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2096 | assert(image != (const Image *) NULL); |
| 2097 | assert(image->signature == MagickSignature); |
| 2098 | assert(image->cache != (Cache) NULL); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2099 | cache_info=(CacheInfo *) image->cache; |
| 2100 | assert(cache_info->signature == MagickSignature); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2101 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2102 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2103 | q=GetAuthenticPixelCacheNexus(image,x,y,1UL,1UL,cache_info->nexus_info[id], |
| 2104 | exception); |
| 2105 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2106 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2107 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2108 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2109 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2110 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2111 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2112 | return(MagickFalse); |
| 2113 | } |
| 2114 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2115 | { |
| 2116 | PixelChannel |
| 2117 | channel; |
| 2118 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2119 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2120 | pixel[channel]=q[i]; |
| 2121 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2122 | return(MagickTrue); |
| 2123 | } |
| 2124 | |
| 2125 | /* |
| 2126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2127 | % % |
| 2128 | % % |
| 2129 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2130 | % G e t O n e V i r t u a l P i x e l % |
| 2131 | % % |
| 2132 | % % |
| 2133 | % % |
| 2134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2135 | % |
| 2136 | % GetOneVirtualPixel() returns a single virtual pixel at the specified |
| 2137 | % (x,y) location. The image background color is returned if an error occurs. |
| 2138 | % If you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2139 | % |
| 2140 | % The format of the GetOneVirtualPixel() method is: |
| 2141 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2142 | % MagickBooleanType GetOneVirtualPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2143 | % const ssize_t y,Quantum *pixel,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2144 | % |
| 2145 | % A description of each parameter follows: |
| 2146 | % |
| 2147 | % o image: the image. |
| 2148 | % |
| 2149 | % o x,y: These values define the location of the pixel to return. |
| 2150 | % |
| 2151 | % o pixel: return a pixel at the specified (x,y) location. |
| 2152 | % |
| 2153 | % o exception: return any errors or warnings in this structure. |
| 2154 | % |
| 2155 | */ |
| 2156 | MagickExport MagickBooleanType GetOneVirtualPixel(const Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2157 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2159 | CacheInfo |
| 2160 | *cache_info; |
| 2161 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2162 | const int |
| 2163 | id = GetOpenMPThreadId(); |
| 2164 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2165 | const Quantum |
| 2166 | *p; |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2167 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2168 | register ssize_t |
| 2169 | i; |
| 2170 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2171 | assert(image != (const Image *) NULL); |
| 2172 | assert(image->signature == MagickSignature); |
| 2173 | assert(image->cache != (Cache) NULL); |
| 2174 | cache_info=(CacheInfo *) image->cache; |
| 2175 | assert(cache_info->signature == MagickSignature); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2176 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 2177 | if (cache_info->methods.get_one_virtual_pixel_from_handler != |
| 2178 | (GetOneVirtualPixelFromHandler) NULL) |
| 2179 | return(cache_info->methods.get_one_virtual_pixel_from_handler(image, |
| 2180 | GetPixelCacheVirtualMethod(image),x,y,pixel,exception)); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2181 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2182 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2183 | 1UL,1UL,cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2184 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2185 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2186 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2187 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2188 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2189 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2190 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2191 | return(MagickFalse); |
| 2192 | } |
| 2193 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2194 | { |
| 2195 | PixelChannel |
| 2196 | channel; |
| 2197 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2198 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2199 | pixel[channel]=p[i]; |
| 2200 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2201 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | /* |
| 2205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2206 | % % |
| 2207 | % % |
| 2208 | % % |
| 2209 | + G e t O n e V i r t u a l P i x e l F r o m C a c h e % |
| 2210 | % % |
| 2211 | % % |
| 2212 | % % |
| 2213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2214 | % |
| 2215 | % GetOneVirtualPixelFromCache() returns a single virtual pixel at the |
| 2216 | % specified (x,y) location. The image background color is returned if an |
| 2217 | % error occurs. |
| 2218 | % |
| 2219 | % The format of the GetOneVirtualPixelFromCache() method is: |
| 2220 | % |
| 2221 | % MagickBooleanType GetOneVirtualPixelFromCache(const Image image, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2222 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2223 | % Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2224 | % |
| 2225 | % A description of each parameter follows: |
| 2226 | % |
| 2227 | % o image: the image. |
| 2228 | % |
| 2229 | % o virtual_pixel_method: the virtual pixel method. |
| 2230 | % |
| 2231 | % o x,y: These values define the location of the pixel to return. |
| 2232 | % |
| 2233 | % o pixel: return a pixel at the specified (x,y) location. |
| 2234 | % |
| 2235 | % o exception: return any errors or warnings in this structure. |
| 2236 | % |
| 2237 | */ |
| 2238 | static MagickBooleanType GetOneVirtualPixelFromCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2239 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2240 | Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2241 | { |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2242 | CacheInfo |
| 2243 | *cache_info; |
| 2244 | |
| 2245 | const int |
| 2246 | id = GetOpenMPThreadId(); |
| 2247 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2248 | const Quantum |
| 2249 | *p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2250 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2251 | register ssize_t |
| 2252 | i; |
| 2253 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2254 | assert(image != (const Image *) NULL); |
| 2255 | assert(image->signature == MagickSignature); |
| 2256 | assert(image->cache != (Cache) NULL); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2257 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2258 | assert(cache_info->signature == MagickSignature); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2259 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2260 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2261 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2262 | cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2263 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2264 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2265 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2266 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2267 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2268 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2269 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2270 | return(MagickFalse); |
| 2271 | } |
| 2272 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2273 | { |
| 2274 | PixelChannel |
| 2275 | channel; |
| 2276 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2277 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2278 | pixel[channel]=p[i]; |
| 2279 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2280 | return(MagickTrue); |
| 2281 | } |
| 2282 | |
| 2283 | /* |
| 2284 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2285 | % % |
| 2286 | % % |
| 2287 | % % |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 2288 | % G e t O n e V i r t u a l P i x e l I n f o % |
| 2289 | % % |
| 2290 | % % |
| 2291 | % % |
| 2292 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2293 | % |
| 2294 | % GetOneVirtualPixelInfo() returns a single pixel at the specified (x,y) |
| 2295 | % location. The image background color is returned if an error occurs. If |
| 2296 | % you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2297 | % |
| 2298 | % The format of the GetOneVirtualPixelInfo() method is: |
| 2299 | % |
| 2300 | % MagickBooleanType GetOneVirtualPixelInfo(const Image image, |
| 2301 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 2302 | % const ssize_t y,PixelInfo *pixel,ExceptionInfo exception) |
| 2303 | % |
| 2304 | % A description of each parameter follows: |
| 2305 | % |
| 2306 | % o image: the image. |
| 2307 | % |
| 2308 | % o virtual_pixel_method: the virtual pixel method. |
| 2309 | % |
| 2310 | % o x,y: these values define the location of the pixel to return. |
| 2311 | % |
| 2312 | % o pixel: return a pixel at the specified (x,y) location. |
| 2313 | % |
| 2314 | % o exception: return any errors or warnings in this structure. |
| 2315 | % |
| 2316 | */ |
| 2317 | MagickExport MagickBooleanType GetOneVirtualPixelInfo(const Image *image, |
| 2318 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 2319 | PixelInfo *pixel,ExceptionInfo *exception) |
| 2320 | { |
| 2321 | CacheInfo |
| 2322 | *cache_info; |
| 2323 | |
| 2324 | const int |
| 2325 | id = GetOpenMPThreadId(); |
| 2326 | |
| 2327 | register const Quantum |
| 2328 | *p; |
| 2329 | |
| 2330 | assert(image != (const Image *) NULL); |
| 2331 | assert(image->signature == MagickSignature); |
| 2332 | assert(image->cache != (Cache) NULL); |
| 2333 | cache_info=(CacheInfo *) image->cache; |
| 2334 | assert(cache_info->signature == MagickSignature); |
| 2335 | assert(id < (int) cache_info->number_threads); |
cristy | f82cff8 | 2012-04-16 16:54:17 +0000 | [diff] [blame] | 2336 | GetPixelInfo(image,pixel); |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 2337 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
| 2338 | cache_info->nexus_info[id],exception); |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 2339 | if (p == (const Quantum *) NULL) |
| 2340 | return(MagickFalse); |
| 2341 | GetPixelInfoPixel(image,p,pixel); |
| 2342 | return(MagickTrue); |
| 2343 | } |
| 2344 | |
| 2345 | /* |
| 2346 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2347 | % % |
| 2348 | % % |
| 2349 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2350 | + G e t P i x e l C a c h e C o l o r s p a c e % |
| 2351 | % % |
| 2352 | % % |
| 2353 | % % |
| 2354 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2355 | % |
| 2356 | % GetPixelCacheColorspace() returns the class type of the pixel cache. |
| 2357 | % |
| 2358 | % The format of the GetPixelCacheColorspace() method is: |
| 2359 | % |
| 2360 | % Colorspace GetPixelCacheColorspace(Cache cache) |
| 2361 | % |
| 2362 | % A description of each parameter follows: |
| 2363 | % |
| 2364 | % o cache: the pixel cache. |
| 2365 | % |
| 2366 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2367 | MagickPrivate ColorspaceType GetPixelCacheColorspace(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2368 | { |
| 2369 | CacheInfo |
| 2370 | *cache_info; |
| 2371 | |
| 2372 | assert(cache != (Cache) NULL); |
| 2373 | cache_info=(CacheInfo *) cache; |
| 2374 | assert(cache_info->signature == MagickSignature); |
| 2375 | if (cache_info->debug != MagickFalse) |
| 2376 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2377 | cache_info->filename); |
| 2378 | return(cache_info->colorspace); |
| 2379 | } |
| 2380 | |
| 2381 | /* |
| 2382 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2383 | % % |
| 2384 | % % |
| 2385 | % % |
| 2386 | + G e t P i x e l C a c h e M e t h o d s % |
| 2387 | % % |
| 2388 | % % |
| 2389 | % % |
| 2390 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2391 | % |
| 2392 | % GetPixelCacheMethods() initializes the CacheMethods structure. |
| 2393 | % |
| 2394 | % The format of the GetPixelCacheMethods() method is: |
| 2395 | % |
| 2396 | % void GetPixelCacheMethods(CacheMethods *cache_methods) |
| 2397 | % |
| 2398 | % A description of each parameter follows: |
| 2399 | % |
| 2400 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 2401 | % |
| 2402 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2403 | MagickPrivate void GetPixelCacheMethods(CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2404 | { |
| 2405 | assert(cache_methods != (CacheMethods *) NULL); |
| 2406 | (void) ResetMagickMemory(cache_methods,0,sizeof(*cache_methods)); |
| 2407 | cache_methods->get_virtual_pixel_handler=GetVirtualPixelCache; |
| 2408 | cache_methods->get_virtual_pixels_handler=GetVirtualPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2409 | cache_methods->get_virtual_metacontent_from_handler= |
| 2410 | GetVirtualMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2411 | cache_methods->get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromCache; |
| 2412 | cache_methods->get_authentic_pixels_handler=GetAuthenticPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2413 | cache_methods->get_authentic_metacontent_from_handler= |
| 2414 | GetAuthenticMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2415 | cache_methods->get_authentic_pixels_from_handler=GetAuthenticPixelsFromCache; |
| 2416 | cache_methods->get_one_authentic_pixel_from_handler= |
| 2417 | GetOneAuthenticPixelFromCache; |
| 2418 | cache_methods->queue_authentic_pixels_handler=QueueAuthenticPixelsCache; |
| 2419 | cache_methods->sync_authentic_pixels_handler=SyncAuthenticPixelsCache; |
| 2420 | cache_methods->destroy_pixel_handler=DestroyImagePixelCache; |
| 2421 | } |
| 2422 | |
| 2423 | /* |
| 2424 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2425 | % % |
| 2426 | % % |
| 2427 | % % |
| 2428 | + G e t P i x e l C a c h e N e x u s E x t e n t % |
| 2429 | % % |
| 2430 | % % |
| 2431 | % % |
| 2432 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2433 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2434 | % GetPixelCacheNexusExtent() returns the extent of the pixels associated |
| 2435 | % corresponding with the last call to SetPixelCacheNexusPixels() or |
| 2436 | % GetPixelCacheNexusPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2437 | % |
| 2438 | % The format of the GetPixelCacheNexusExtent() method is: |
| 2439 | % |
| 2440 | % MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
| 2441 | % NexusInfo *nexus_info) |
| 2442 | % |
| 2443 | % A description of each parameter follows: |
| 2444 | % |
| 2445 | % o nexus_info: the nexus info. |
| 2446 | % |
| 2447 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2448 | MagickPrivate MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2449 | NexusInfo *nexus_info) |
| 2450 | { |
| 2451 | CacheInfo |
| 2452 | *cache_info; |
| 2453 | |
| 2454 | MagickSizeType |
| 2455 | extent; |
| 2456 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2457 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2458 | cache_info=(CacheInfo *) cache; |
| 2459 | assert(cache_info->signature == MagickSignature); |
| 2460 | extent=(MagickSizeType) nexus_info->region.width*nexus_info->region.height; |
| 2461 | if (extent == 0) |
| 2462 | return((MagickSizeType) cache_info->columns*cache_info->rows); |
| 2463 | return(extent); |
| 2464 | } |
| 2465 | |
| 2466 | /* |
| 2467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2468 | % % |
| 2469 | % % |
| 2470 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2471 | + G e t P i x e l C a c h e N e x u s M e t a c o n t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2472 | % % |
| 2473 | % % |
| 2474 | % % |
| 2475 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2476 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2477 | % GetPixelCacheNexusMetacontent() returns the meta-content for the specified |
| 2478 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2479 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2480 | % The format of the GetPixelCacheNexusMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2481 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2482 | % void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2483 | % NexusInfo *nexus_info) |
| 2484 | % |
| 2485 | % A description of each parameter follows: |
| 2486 | % |
| 2487 | % o cache: the pixel cache. |
| 2488 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2489 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2490 | % |
| 2491 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2492 | MagickPrivate void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2493 | NexusInfo *nexus_info) |
| 2494 | { |
| 2495 | CacheInfo |
| 2496 | *cache_info; |
| 2497 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2498 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2499 | cache_info=(CacheInfo *) cache; |
| 2500 | assert(cache_info->signature == MagickSignature); |
| 2501 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2502 | return((void *) NULL); |
| 2503 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | /* |
| 2507 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2508 | % % |
| 2509 | % % |
| 2510 | % % |
| 2511 | + G e t P i x e l C a c h e N e x u s P i x e l s % |
| 2512 | % % |
| 2513 | % % |
| 2514 | % % |
| 2515 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2516 | % |
| 2517 | % GetPixelCacheNexusPixels() returns the pixels associated with the specified |
| 2518 | % cache nexus. |
| 2519 | % |
| 2520 | % The format of the GetPixelCacheNexusPixels() method is: |
| 2521 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2522 | % Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2523 | % NexusInfo *nexus_info) |
| 2524 | % |
| 2525 | % A description of each parameter follows: |
| 2526 | % |
| 2527 | % o cache: the pixel cache. |
| 2528 | % |
| 2529 | % o nexus_info: the cache nexus to return the pixels. |
| 2530 | % |
| 2531 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2532 | MagickPrivate Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2533 | NexusInfo *nexus_info) |
| 2534 | { |
| 2535 | CacheInfo |
| 2536 | *cache_info; |
| 2537 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2538 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2539 | cache_info=(CacheInfo *) cache; |
| 2540 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2541 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2542 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2543 | return(nexus_info->pixels); |
| 2544 | } |
| 2545 | |
| 2546 | /* |
| 2547 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2548 | % % |
| 2549 | % % |
| 2550 | % % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2551 | + G e t P i x e l C a c h e P i x e l s % |
| 2552 | % % |
| 2553 | % % |
| 2554 | % % |
| 2555 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2556 | % |
| 2557 | % GetPixelCachePixels() returns the pixels associated with the specified image. |
| 2558 | % |
| 2559 | % The format of the GetPixelCachePixels() method is: |
| 2560 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2561 | % void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
| 2562 | % ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2563 | % |
| 2564 | % A description of each parameter follows: |
| 2565 | % |
| 2566 | % o image: the image. |
| 2567 | % |
| 2568 | % o length: the pixel cache length. |
| 2569 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2570 | % o exception: return any errors or warnings in this structure. |
| 2571 | % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2572 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2573 | MagickPrivate void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2574 | ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2575 | { |
| 2576 | CacheInfo |
| 2577 | *cache_info; |
| 2578 | |
| 2579 | assert(image != (const Image *) NULL); |
| 2580 | assert(image->signature == MagickSignature); |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2581 | assert(image->cache != (Cache) NULL); |
cristy | 654fdaf | 2011-02-24 15:24:33 +0000 | [diff] [blame] | 2582 | assert(length != (MagickSizeType *) NULL); |
| 2583 | assert(exception != (ExceptionInfo *) NULL); |
| 2584 | assert(exception->signature == MagickSignature); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 2585 | cache_info=(CacheInfo *) image->cache; |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2586 | assert(cache_info->signature == MagickSignature); |
| 2587 | *length=0; |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 2588 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2589 | return((void *) NULL); |
| 2590 | *length=cache_info->length; |
| 2591 | return((void *) cache_info->pixels); |
| 2592 | } |
| 2593 | |
| 2594 | /* |
| 2595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2596 | % % |
| 2597 | % % |
| 2598 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2599 | + G e t P i x e l C a c h e S t o r a g e C l a s s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2600 | % % |
| 2601 | % % |
| 2602 | % % |
| 2603 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2604 | % |
| 2605 | % GetPixelCacheStorageClass() returns the class type of the pixel cache. |
| 2606 | % |
| 2607 | % The format of the GetPixelCacheStorageClass() method is: |
| 2608 | % |
| 2609 | % ClassType GetPixelCacheStorageClass(Cache cache) |
| 2610 | % |
| 2611 | % A description of each parameter follows: |
| 2612 | % |
| 2613 | % o type: GetPixelCacheStorageClass returns DirectClass or PseudoClass. |
| 2614 | % |
| 2615 | % o cache: the pixel cache. |
| 2616 | % |
| 2617 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2618 | MagickPrivate ClassType GetPixelCacheStorageClass(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2619 | { |
| 2620 | CacheInfo |
| 2621 | *cache_info; |
| 2622 | |
| 2623 | assert(cache != (Cache) NULL); |
| 2624 | cache_info=(CacheInfo *) cache; |
| 2625 | assert(cache_info->signature == MagickSignature); |
| 2626 | if (cache_info->debug != MagickFalse) |
| 2627 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2628 | cache_info->filename); |
| 2629 | return(cache_info->storage_class); |
| 2630 | } |
| 2631 | |
| 2632 | /* |
| 2633 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2634 | % % |
| 2635 | % % |
| 2636 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2637 | + G e t P i x e l C a c h e T i l e S i z e % |
| 2638 | % % |
| 2639 | % % |
| 2640 | % % |
| 2641 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2642 | % |
| 2643 | % GetPixelCacheTileSize() returns the pixel cache tile size. |
| 2644 | % |
| 2645 | % The format of the GetPixelCacheTileSize() method is: |
| 2646 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2647 | % void GetPixelCacheTileSize(const Image *image,size_t *width, |
| 2648 | % size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2649 | % |
| 2650 | % A description of each parameter follows: |
| 2651 | % |
| 2652 | % o image: the image. |
| 2653 | % |
| 2654 | % o width: the optimize cache tile width in pixels. |
| 2655 | % |
| 2656 | % o height: the optimize cache tile height in pixels. |
| 2657 | % |
| 2658 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2659 | MagickPrivate void GetPixelCacheTileSize(const Image *image,size_t *width, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2660 | size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2661 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2662 | CacheInfo |
| 2663 | *cache_info; |
| 2664 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2665 | assert(image != (Image *) NULL); |
| 2666 | assert(image->signature == MagickSignature); |
| 2667 | if (image->debug != MagickFalse) |
| 2668 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2669 | cache_info=(CacheInfo *) image->cache; |
| 2670 | assert(cache_info->signature == MagickSignature); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2671 | *width=2048UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2672 | if (GetPixelCacheType(image) == DiskCache) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2673 | *width=8192UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2674 | *height=(*width); |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2679 | % % |
| 2680 | % % |
| 2681 | % % |
| 2682 | + G e t P i x e l C a c h e T y p e % |
| 2683 | % % |
| 2684 | % % |
| 2685 | % % |
| 2686 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2687 | % |
| 2688 | % GetPixelCacheType() returns the pixel cache type (e.g. memory, disk, etc.). |
| 2689 | % |
| 2690 | % The format of the GetPixelCacheType() method is: |
| 2691 | % |
| 2692 | % CacheType GetPixelCacheType(const Image *image) |
| 2693 | % |
| 2694 | % A description of each parameter follows: |
| 2695 | % |
| 2696 | % o image: the image. |
| 2697 | % |
| 2698 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2699 | MagickPrivate CacheType GetPixelCacheType(const Image *image) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2700 | { |
| 2701 | CacheInfo |
| 2702 | *cache_info; |
| 2703 | |
| 2704 | assert(image != (Image *) NULL); |
| 2705 | assert(image->signature == MagickSignature); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2706 | assert(image->cache != (Cache) NULL); |
| 2707 | cache_info=(CacheInfo *) image->cache; |
| 2708 | assert(cache_info->signature == MagickSignature); |
| 2709 | return(cache_info->type); |
| 2710 | } |
| 2711 | |
| 2712 | /* |
| 2713 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2714 | % % |
| 2715 | % % |
| 2716 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2717 | + G e t P i x e l C a c h e V i r t u a l M e t h o d % |
| 2718 | % % |
| 2719 | % % |
| 2720 | % % |
| 2721 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2722 | % |
| 2723 | % GetPixelCacheVirtualMethod() gets the "virtual pixels" method for the |
| 2724 | % pixel cache. A virtual pixel is any pixel access that is outside the |
| 2725 | % boundaries of the image cache. |
| 2726 | % |
| 2727 | % The format of the GetPixelCacheVirtualMethod() method is: |
| 2728 | % |
| 2729 | % VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
| 2730 | % |
| 2731 | % A description of each parameter follows: |
| 2732 | % |
| 2733 | % o image: the image. |
| 2734 | % |
| 2735 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2736 | MagickPrivate VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2737 | { |
| 2738 | CacheInfo |
| 2739 | *cache_info; |
| 2740 | |
| 2741 | assert(image != (Image *) NULL); |
| 2742 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2743 | assert(image->cache != (Cache) NULL); |
| 2744 | cache_info=(CacheInfo *) image->cache; |
| 2745 | assert(cache_info->signature == MagickSignature); |
| 2746 | return(cache_info->virtual_pixel_method); |
| 2747 | } |
| 2748 | |
| 2749 | /* |
| 2750 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2751 | % % |
| 2752 | % % |
| 2753 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2754 | + G e t V i r t u a l M e t a c o n t e n t F r o m C a c h e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2755 | % % |
| 2756 | % % |
| 2757 | % % |
| 2758 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2759 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2760 | % GetVirtualMetacontentFromCache() returns the meta-content corresponding with |
| 2761 | % the last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2762 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2763 | % The format of the GetVirtualMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2764 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2765 | % void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2766 | % |
| 2767 | % A description of each parameter follows: |
| 2768 | % |
| 2769 | % o image: the image. |
| 2770 | % |
| 2771 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2772 | static const void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2773 | { |
| 2774 | CacheInfo |
| 2775 | *cache_info; |
| 2776 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 2777 | const int |
| 2778 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2779 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2780 | const void |
| 2781 | *metacontent; |
| 2782 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2783 | assert(image != (const Image *) NULL); |
| 2784 | assert(image->signature == MagickSignature); |
| 2785 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2786 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2787 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2788 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2789 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 2790 | cache_info->nexus_info[id]); |
| 2791 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | /* |
| 2795 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2796 | % % |
| 2797 | % % |
| 2798 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2799 | + G e t V i r t u a l M e t a c o n t e n t F r o m N e x u s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2800 | % % |
| 2801 | % % |
| 2802 | % % |
| 2803 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2804 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2805 | % GetVirtualMetacontentFromNexus() returns the meta-content for the specified |
| 2806 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2807 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2808 | % The format of the GetVirtualMetacontentFromNexus() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2809 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2810 | % const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2811 | % NexusInfo *nexus_info) |
| 2812 | % |
| 2813 | % A description of each parameter follows: |
| 2814 | % |
| 2815 | % o cache: the pixel cache. |
| 2816 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2817 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2818 | % |
| 2819 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2820 | MagickPrivate const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 2821 | NexusInfo *nexus_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2822 | { |
| 2823 | CacheInfo |
| 2824 | *cache_info; |
| 2825 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2826 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2827 | cache_info=(CacheInfo *) cache; |
| 2828 | assert(cache_info->signature == MagickSignature); |
| 2829 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2830 | return((void *) NULL); |
| 2831 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | /* |
| 2835 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2836 | % % |
| 2837 | % % |
| 2838 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2839 | % G e t V i r t u a l M e t a c o n t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2840 | % % |
| 2841 | % % |
| 2842 | % % |
| 2843 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2844 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2845 | % GetVirtualMetacontent() returns the virtual metacontent corresponding with |
| 2846 | % the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 2847 | % returned if the meta-content are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2848 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2849 | % The format of the GetVirtualMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2850 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2851 | % const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2852 | % |
| 2853 | % A description of each parameter follows: |
| 2854 | % |
| 2855 | % o image: the image. |
| 2856 | % |
| 2857 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2858 | MagickExport const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2859 | { |
| 2860 | CacheInfo |
| 2861 | *cache_info; |
| 2862 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2863 | const int |
| 2864 | id = GetOpenMPThreadId(); |
| 2865 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2866 | const void |
| 2867 | *metacontent; |
| 2868 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2869 | assert(image != (const Image *) NULL); |
| 2870 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2871 | assert(image->cache != (Cache) NULL); |
| 2872 | cache_info=(CacheInfo *) image->cache; |
| 2873 | assert(cache_info->signature == MagickSignature); |
cristy | a26c662 | 2012-02-14 14:00:20 +0000 | [diff] [blame] | 2874 | metacontent=cache_info->methods.get_virtual_metacontent_from_handler(image); |
| 2875 | if (metacontent != (GetVirtualMetacontentFromHandler) NULL) |
| 2876 | return(metacontent); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2877 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2878 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 2879 | cache_info->nexus_info[id]); |
| 2880 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | /* |
| 2884 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2885 | % % |
| 2886 | % % |
| 2887 | % % |
| 2888 | + G e t V i r t u a l P i x e l s F r o m N e x u s % |
| 2889 | % % |
| 2890 | % % |
| 2891 | % % |
| 2892 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2893 | % |
| 2894 | % GetVirtualPixelsFromNexus() gets virtual pixels from the in-memory or disk |
| 2895 | % pixel cache as defined by the geometry parameters. A pointer to the pixels |
| 2896 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 2897 | % |
| 2898 | % The format of the GetVirtualPixelsFromNexus() method is: |
| 2899 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2900 | % Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2901 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 2902 | % const size_t columns,const size_t rows,NexusInfo *nexus_info, |
| 2903 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2904 | % |
| 2905 | % A description of each parameter follows: |
| 2906 | % |
| 2907 | % o image: the image. |
| 2908 | % |
| 2909 | % o virtual_pixel_method: the virtual pixel method. |
| 2910 | % |
| 2911 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 2912 | % pixels. |
| 2913 | % |
| 2914 | % o nexus_info: the cache nexus to acquire. |
| 2915 | % |
| 2916 | % o exception: return any errors or warnings in this structure. |
| 2917 | % |
| 2918 | */ |
| 2919 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2920 | static ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2921 | DitherMatrix[64] = |
| 2922 | { |
| 2923 | 0, 48, 12, 60, 3, 51, 15, 63, |
| 2924 | 32, 16, 44, 28, 35, 19, 47, 31, |
| 2925 | 8, 56, 4, 52, 11, 59, 7, 55, |
| 2926 | 40, 24, 36, 20, 43, 27, 39, 23, |
| 2927 | 2, 50, 14, 62, 1, 49, 13, 61, |
| 2928 | 34, 18, 46, 30, 33, 17, 45, 29, |
| 2929 | 10, 58, 6, 54, 9, 57, 5, 53, |
| 2930 | 42, 26, 38, 22, 41, 25, 37, 21 |
| 2931 | }; |
| 2932 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2933 | static inline ssize_t DitherX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2934 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2935 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2936 | index; |
| 2937 | |
| 2938 | index=x+DitherMatrix[x & 0x07]-32L; |
| 2939 | if (index < 0L) |
| 2940 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2941 | if (index >= (ssize_t) columns) |
| 2942 | return((ssize_t) columns-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2943 | return(index); |
| 2944 | } |
| 2945 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2946 | static inline ssize_t DitherY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2947 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2948 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2949 | index; |
| 2950 | |
| 2951 | index=y+DitherMatrix[y & 0x07]-32L; |
| 2952 | if (index < 0L) |
| 2953 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2954 | if (index >= (ssize_t) rows) |
| 2955 | return((ssize_t) rows-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2956 | return(index); |
| 2957 | } |
| 2958 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2959 | static inline ssize_t EdgeX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2960 | { |
| 2961 | if (x < 0L) |
| 2962 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2963 | if (x >= (ssize_t) columns) |
| 2964 | return((ssize_t) (columns-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2965 | return(x); |
| 2966 | } |
| 2967 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2968 | static inline ssize_t EdgeY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2969 | { |
| 2970 | if (y < 0L) |
| 2971 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2972 | if (y >= (ssize_t) rows) |
| 2973 | return((ssize_t) (rows-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2974 | return(y); |
| 2975 | } |
| 2976 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2977 | static inline ssize_t RandomX(RandomInfo *random_info,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2978 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2979 | return((ssize_t) (columns*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2982 | static inline ssize_t RandomY(RandomInfo *random_info,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2983 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2984 | return((ssize_t) (rows*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2987 | static inline MagickModulo VirtualPixelModulo(const ssize_t offset, |
| 2988 | const size_t extent) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2989 | { |
| 2990 | MagickModulo |
| 2991 | modulo; |
| 2992 | |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 2993 | /* |
| 2994 | Compute the remainder of dividing offset by extent. It returns not only |
| 2995 | the quotient (tile the offset falls in) but also the positive remainer |
| 2996 | within that tile such that 0 <= remainder < extent. This method is |
| 2997 | essentially a ldiv() using a floored modulo division rather than the |
| 2998 | normal default truncated modulo division. |
| 2999 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3000 | modulo.quotient=offset/(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3001 | if (offset < 0L) |
| 3002 | modulo.quotient--; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3003 | modulo.remainder=offset-modulo.quotient*(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3004 | return(modulo); |
| 3005 | } |
| 3006 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 3007 | MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3008 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 3009 | const size_t columns,const size_t rows,NexusInfo *nexus_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3010 | ExceptionInfo *exception) |
| 3011 | { |
| 3012 | CacheInfo |
| 3013 | *cache_info; |
| 3014 | |
| 3015 | MagickOffsetType |
| 3016 | offset; |
| 3017 | |
| 3018 | MagickSizeType |
| 3019 | length, |
| 3020 | number_pixels; |
| 3021 | |
| 3022 | NexusInfo |
| 3023 | **virtual_nexus; |
| 3024 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3025 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3026 | *pixels, |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 3027 | virtual_pixel[CompositePixelChannel]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3028 | |
| 3029 | RectangleInfo |
| 3030 | region; |
| 3031 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3032 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3033 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3034 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3035 | register const void |
| 3036 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3037 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3038 | register Quantum |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3039 | *restrict q; |
| 3040 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3041 | register ssize_t |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3042 | i, |
| 3043 | u; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3044 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3045 | register unsigned char |
| 3046 | *restrict s; |
| 3047 | |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3048 | ssize_t |
| 3049 | v; |
| 3050 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3051 | void |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3052 | *virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3053 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3054 | /* |
| 3055 | Acquire pixels. |
| 3056 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3057 | assert(image != (const Image *) NULL); |
| 3058 | assert(image->signature == MagickSignature); |
| 3059 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3060 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3061 | assert(cache_info->signature == MagickSignature); |
cristy | 4cfbb3f | 2010-03-14 20:40:23 +0000 | [diff] [blame] | 3062 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3063 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3064 | region.x=x; |
| 3065 | region.y=y; |
| 3066 | region.width=columns; |
| 3067 | region.height=rows; |
| 3068 | pixels=SetPixelCacheNexusPixels(image,®ion,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3069 | if (pixels == (Quantum *) NULL) |
| 3070 | return((const Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3071 | q=pixels; |
cristy | df415c8 | 2010-03-11 16:47:50 +0000 | [diff] [blame] | 3072 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 3073 | nexus_info->region.x; |
| 3074 | length=(MagickSizeType) (nexus_info->region.height-1L)*cache_info->columns+ |
| 3075 | nexus_info->region.width-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3076 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 3077 | if ((offset >= 0) && (((MagickSizeType) offset+length) < number_pixels)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3078 | if ((x >= 0) && ((ssize_t) (x+columns) <= (ssize_t) cache_info->columns) && |
| 3079 | (y >= 0) && ((ssize_t) (y+rows) <= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3080 | { |
| 3081 | MagickBooleanType |
| 3082 | status; |
| 3083 | |
| 3084 | /* |
| 3085 | Pixel request is inside cache extents. |
| 3086 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3087 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3088 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3089 | status=ReadPixelCachePixels(cache_info,nexus_info,exception); |
| 3090 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3091 | return((const Quantum *) NULL); |
| 3092 | if (cache_info->metacontent_extent != 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3093 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3094 | status=ReadPixelCacheMetacontent(cache_info,nexus_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3095 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3096 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3097 | } |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3098 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3099 | } |
| 3100 | /* |
| 3101 | Pixel request is outside cache extents. |
| 3102 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3103 | s=(unsigned char *) GetPixelCacheNexusMetacontent(cache_info,nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3104 | virtual_nexus=AcquirePixelCacheNexus(1); |
| 3105 | if (virtual_nexus == (NexusInfo **) NULL) |
| 3106 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3107 | if (virtual_nexus != (NexusInfo **) NULL) |
| 3108 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3109 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 3110 | "UnableToGetCacheNexus","'%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3111 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3112 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3113 | (void) ResetMagickMemory(virtual_pixel,0,cache_info->number_channels* |
| 3114 | sizeof(*virtual_pixel)); |
| 3115 | virtual_metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3116 | switch (virtual_pixel_method) |
| 3117 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3118 | case BackgroundVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3119 | case BlackVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3120 | case GrayVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3121 | case TransparentVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3122 | case MaskVirtualPixelMethod: |
| 3123 | case WhiteVirtualPixelMethod: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3124 | case EdgeVirtualPixelMethod: |
| 3125 | case CheckerTileVirtualPixelMethod: |
| 3126 | case HorizontalTileVirtualPixelMethod: |
| 3127 | case VerticalTileVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3128 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3129 | if (cache_info->metacontent_extent != 0) |
| 3130 | { |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3131 | /* |
| 3132 | Acquire a metacontent buffer. |
| 3133 | */ |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3134 | virtual_metacontent=(void *) AcquireQuantumMemory(1, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3135 | cache_info->metacontent_extent); |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3136 | if (virtual_metacontent == (void *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3137 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3138 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3139 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 3140 | CacheError,"UnableToGetCacheNexus","'%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3141 | return((const Quantum *) NULL); |
| 3142 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3143 | (void) ResetMagickMemory(virtual_metacontent,0, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3144 | cache_info->metacontent_extent); |
| 3145 | } |
| 3146 | switch (virtual_pixel_method) |
| 3147 | { |
| 3148 | case BlackVirtualPixelMethod: |
| 3149 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3150 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3151 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3152 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3153 | break; |
| 3154 | } |
| 3155 | case GrayVirtualPixelMethod: |
| 3156 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3157 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 3158 | SetPixelChannel(image,(PixelChannel) i,QuantumRange/2, |
| 3159 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3160 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3161 | break; |
| 3162 | } |
| 3163 | case TransparentVirtualPixelMethod: |
| 3164 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3165 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3166 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3167 | SetPixelAlpha(image,TransparentAlpha,virtual_pixel); |
| 3168 | break; |
| 3169 | } |
| 3170 | case MaskVirtualPixelMethod: |
| 3171 | case WhiteVirtualPixelMethod: |
| 3172 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3173 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3174 | SetPixelChannel(image,(PixelChannel) i,QuantumRange,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3175 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3176 | break; |
| 3177 | } |
| 3178 | default: |
| 3179 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3180 | SetPixelRed(image,ClampToQuantum(image->background_color.red), |
| 3181 | virtual_pixel); |
| 3182 | SetPixelGreen(image,ClampToQuantum(image->background_color.green), |
| 3183 | virtual_pixel); |
| 3184 | SetPixelBlue(image,ClampToQuantum(image->background_color.blue), |
| 3185 | virtual_pixel); |
cristy | 6cff7ae | 2012-02-07 02:26:02 +0000 | [diff] [blame] | 3186 | SetPixelBlack(image,ClampToQuantum(image->background_color.black), |
| 3187 | virtual_pixel); |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3188 | SetPixelAlpha(image,ClampToQuantum(image->background_color.alpha), |
| 3189 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3190 | break; |
| 3191 | } |
| 3192 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3193 | break; |
| 3194 | } |
| 3195 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3196 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3197 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3198 | for (v=0; v < (ssize_t) rows; v++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3199 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3200 | for (u=0; u < (ssize_t) columns; u+=length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3201 | { |
| 3202 | length=(MagickSizeType) MagickMin(cache_info->columns-(x+u),columns-u); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3203 | if ((((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) || |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3204 | (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) || |
| 3205 | (length == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3206 | { |
| 3207 | MagickModulo |
| 3208 | x_modulo, |
| 3209 | y_modulo; |
| 3210 | |
| 3211 | /* |
| 3212 | Transfer a single pixel. |
| 3213 | */ |
| 3214 | length=(MagickSizeType) 1; |
| 3215 | switch (virtual_pixel_method) |
| 3216 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3217 | default: |
| 3218 | { |
| 3219 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3220 | EdgeX(x+u,cache_info->columns),EdgeY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3221 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3222 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3223 | break; |
| 3224 | } |
| 3225 | case RandomVirtualPixelMethod: |
| 3226 | { |
| 3227 | if (cache_info->random_info == (RandomInfo *) NULL) |
| 3228 | cache_info->random_info=AcquireRandomInfo(); |
| 3229 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3230 | RandomX(cache_info->random_info,cache_info->columns), |
| 3231 | RandomY(cache_info->random_info,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3232 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3233 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3234 | break; |
| 3235 | } |
| 3236 | case DitherVirtualPixelMethod: |
| 3237 | { |
| 3238 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3239 | DitherX(x+u,cache_info->columns),DitherY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3240 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3241 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3242 | break; |
| 3243 | } |
| 3244 | case TileVirtualPixelMethod: |
| 3245 | { |
| 3246 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3247 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3248 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3249 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3250 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3251 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3252 | break; |
| 3253 | } |
| 3254 | case MirrorVirtualPixelMethod: |
| 3255 | { |
| 3256 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3257 | if ((x_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3258 | x_modulo.remainder=(ssize_t) cache_info->columns- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3259 | x_modulo.remainder-1L; |
| 3260 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3261 | if ((y_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3262 | y_modulo.remainder=(ssize_t) cache_info->rows- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3263 | y_modulo.remainder-1L; |
| 3264 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3265 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3266 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3267 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3268 | break; |
| 3269 | } |
| 3270 | case HorizontalTileEdgeVirtualPixelMethod: |
| 3271 | { |
| 3272 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3273 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3274 | x_modulo.remainder,EdgeY(y+v,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3275 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3276 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3277 | break; |
| 3278 | } |
| 3279 | case VerticalTileEdgeVirtualPixelMethod: |
| 3280 | { |
| 3281 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3282 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3283 | EdgeX(x+u,cache_info->columns),y_modulo.remainder,1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3284 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3285 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3286 | break; |
| 3287 | } |
| 3288 | case BackgroundVirtualPixelMethod: |
| 3289 | case BlackVirtualPixelMethod: |
| 3290 | case GrayVirtualPixelMethod: |
| 3291 | case TransparentVirtualPixelMethod: |
| 3292 | case MaskVirtualPixelMethod: |
| 3293 | case WhiteVirtualPixelMethod: |
| 3294 | { |
| 3295 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3296 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3297 | break; |
| 3298 | } |
| 3299 | case EdgeVirtualPixelMethod: |
| 3300 | case CheckerTileVirtualPixelMethod: |
| 3301 | { |
| 3302 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3303 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3304 | if (((x_modulo.quotient ^ y_modulo.quotient) & 0x01) != 0L) |
| 3305 | { |
| 3306 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3307 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3308 | break; |
| 3309 | } |
| 3310 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3311 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3312 | exception); |
| 3313 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3314 | break; |
| 3315 | } |
| 3316 | case HorizontalTileVirtualPixelMethod: |
| 3317 | { |
| 3318 | if (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) |
| 3319 | { |
| 3320 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3321 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3322 | break; |
| 3323 | } |
| 3324 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3325 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3326 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3327 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3328 | exception); |
| 3329 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3330 | break; |
| 3331 | } |
| 3332 | case VerticalTileVirtualPixelMethod: |
| 3333 | { |
| 3334 | if (((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) |
| 3335 | { |
| 3336 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3337 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| 3340 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3341 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3342 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3343 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3344 | exception); |
| 3345 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3346 | break; |
| 3347 | } |
| 3348 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3349 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3350 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3351 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3352 | sizeof(*p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3353 | q+=cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3354 | if ((s != (void *) NULL) && (r != (const void *) NULL)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3355 | { |
| 3356 | (void) memcpy(s,r,(size_t) cache_info->metacontent_extent); |
| 3357 | s+=cache_info->metacontent_extent; |
| 3358 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3359 | continue; |
| 3360 | } |
| 3361 | /* |
| 3362 | Transfer a run of pixels. |
| 3363 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3364 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x+u,y+v,(size_t) |
| 3365 | length,1UL,*virtual_nexus,exception); |
| 3366 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3367 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3368 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3369 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels*sizeof(*p)); |
| 3370 | q+=length*cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3371 | if ((r != (void *) NULL) && (s != (const void *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3372 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3373 | (void) memcpy(s,r,(size_t) length); |
| 3374 | s+=length*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3378 | /* |
| 3379 | Free resources. |
| 3380 | */ |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3381 | if (virtual_metacontent != (void *) NULL) |
| 3382 | virtual_metacontent=(void *) RelinquishMagickMemory(virtual_metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3383 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3384 | return(pixels); |
| 3385 | } |
| 3386 | |
| 3387 | /* |
| 3388 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3389 | % % |
| 3390 | % % |
| 3391 | % % |
| 3392 | + G e t V i r t u a l P i x e l C a c h e % |
| 3393 | % % |
| 3394 | % % |
| 3395 | % % |
| 3396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3397 | % |
| 3398 | % GetVirtualPixelCache() get virtual pixels from the in-memory or disk pixel |
| 3399 | % cache as defined by the geometry parameters. A pointer to the pixels |
| 3400 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 3401 | % |
| 3402 | % The format of the GetVirtualPixelCache() method is: |
| 3403 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3404 | % const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3405 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 3406 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3407 | % ExceptionInfo *exception) |
| 3408 | % |
| 3409 | % A description of each parameter follows: |
| 3410 | % |
| 3411 | % o image: the image. |
| 3412 | % |
| 3413 | % o virtual_pixel_method: the virtual pixel method. |
| 3414 | % |
| 3415 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3416 | % pixels. |
| 3417 | % |
| 3418 | % o exception: return any errors or warnings in this structure. |
| 3419 | % |
| 3420 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3421 | static const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3422 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 3423 | const size_t columns,const size_t rows,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3424 | { |
| 3425 | CacheInfo |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3426 | *cache_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3427 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3428 | const int |
| 3429 | id = GetOpenMPThreadId(); |
| 3430 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3431 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3432 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3433 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3434 | assert(image != (const Image *) NULL); |
| 3435 | assert(image->signature == MagickSignature); |
| 3436 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3437 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3438 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3439 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3440 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3441 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3442 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | /* |
| 3446 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3447 | % % |
| 3448 | % % |
| 3449 | % % |
| 3450 | % G e t V i r t u a l P i x e l Q u e u e % |
| 3451 | % % |
| 3452 | % % |
| 3453 | % % |
| 3454 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3455 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3456 | % GetVirtualPixelQueue() returns the virtual pixels associated corresponding |
| 3457 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3458 | % |
| 3459 | % The format of the GetVirtualPixelQueue() method is: |
| 3460 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3461 | % const Quantum *GetVirtualPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3462 | % |
| 3463 | % A description of each parameter follows: |
| 3464 | % |
| 3465 | % o image: the image. |
| 3466 | % |
| 3467 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3468 | MagickExport const Quantum *GetVirtualPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3469 | { |
| 3470 | CacheInfo |
| 3471 | *cache_info; |
| 3472 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3473 | const int |
| 3474 | id = GetOpenMPThreadId(); |
| 3475 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3476 | assert(image != (const Image *) NULL); |
| 3477 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3478 | assert(image->cache != (Cache) NULL); |
| 3479 | cache_info=(CacheInfo *) image->cache; |
| 3480 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3481 | if (cache_info->methods.get_virtual_pixels_handler != |
| 3482 | (GetVirtualPixelsHandler) NULL) |
| 3483 | return(cache_info->methods.get_virtual_pixels_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3484 | assert(id < (int) cache_info->number_threads); |
| 3485 | return(GetVirtualPixelsNexus(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | /* |
| 3489 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3490 | % % |
| 3491 | % % |
| 3492 | % % |
| 3493 | % G e t V i r t u a l P i x e l s % |
| 3494 | % % |
| 3495 | % % |
| 3496 | % % |
| 3497 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3498 | % |
| 3499 | % GetVirtualPixels() returns an immutable pixel region. If the |
| 3500 | % region is successfully accessed, a pointer to it is returned, otherwise |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 3501 | % NULL is returned. The returned pointer may point to a temporary working |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3502 | % copy of the pixels or it may point to the original pixels in memory. |
| 3503 | % Performance is maximized if the selected region is part of one row, or one |
| 3504 | % or more full rows, since there is opportunity to access the pixels in-place |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 3505 | % (without a copy) if the image is in memory, or in a memory-mapped file. The |
| 3506 | % returned pointer must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3507 | % |
| 3508 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3509 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 3510 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 3511 | % access the meta-content (of type void) corresponding to the the |
| 3512 | % region. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3513 | % |
| 3514 | % If you plan to modify the pixels, use GetAuthenticPixels() instead. |
| 3515 | % |
| 3516 | % Note, the GetVirtualPixels() and GetAuthenticPixels() methods are not thread- |
| 3517 | % safe. In a threaded environment, use GetCacheViewVirtualPixels() or |
| 3518 | % GetCacheViewAuthenticPixels() instead. |
| 3519 | % |
| 3520 | % The format of the GetVirtualPixels() method is: |
| 3521 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3522 | % const Quantum *GetVirtualPixels(const Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3523 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3524 | % ExceptionInfo *exception) |
| 3525 | % |
| 3526 | % A description of each parameter follows: |
| 3527 | % |
| 3528 | % o image: the image. |
| 3529 | % |
| 3530 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3531 | % pixels. |
| 3532 | % |
| 3533 | % o exception: return any errors or warnings in this structure. |
| 3534 | % |
| 3535 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3536 | MagickExport const Quantum *GetVirtualPixels(const Image *image, |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3537 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
| 3538 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3539 | { |
| 3540 | CacheInfo |
| 3541 | *cache_info; |
| 3542 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3543 | const int |
| 3544 | id = GetOpenMPThreadId(); |
| 3545 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3546 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3547 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3548 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3549 | assert(image != (const Image *) NULL); |
| 3550 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3551 | assert(image->cache != (Cache) NULL); |
| 3552 | cache_info=(CacheInfo *) image->cache; |
| 3553 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3554 | if (cache_info->methods.get_virtual_pixel_handler != |
| 3555 | (GetVirtualPixelHandler) NULL) |
| 3556 | return(cache_info->methods.get_virtual_pixel_handler(image, |
| 3557 | GetPixelCacheVirtualMethod(image),x,y,columns,rows,exception)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3558 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3559 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3560 | columns,rows,cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3561 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | /* |
| 3565 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3566 | % % |
| 3567 | % % |
| 3568 | % % |
| 3569 | + G e t V i r t u a l P i x e l s F r o m C a c h e % |
| 3570 | % % |
| 3571 | % % |
| 3572 | % % |
| 3573 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3574 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3575 | % GetVirtualPixelsCache() returns the pixels associated corresponding with the |
| 3576 | % last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3577 | % |
| 3578 | % The format of the GetVirtualPixelsCache() method is: |
| 3579 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3580 | % Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3581 | % |
| 3582 | % A description of each parameter follows: |
| 3583 | % |
| 3584 | % o image: the image. |
| 3585 | % |
| 3586 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3587 | static const Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3588 | { |
| 3589 | CacheInfo |
| 3590 | *cache_info; |
| 3591 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3592 | const int |
| 3593 | id = GetOpenMPThreadId(); |
| 3594 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3595 | assert(image != (const Image *) NULL); |
| 3596 | assert(image->signature == MagickSignature); |
| 3597 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3598 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3599 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3600 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 3601 | return(GetVirtualPixelsNexus(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /* |
| 3605 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3606 | % % |
| 3607 | % % |
| 3608 | % % |
| 3609 | + G e t V i r t u a l P i x e l s N e x u s % |
| 3610 | % % |
| 3611 | % % |
| 3612 | % % |
| 3613 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3614 | % |
| 3615 | % GetVirtualPixelsNexus() returns the pixels associated with the specified |
| 3616 | % cache nexus. |
| 3617 | % |
| 3618 | % The format of the GetVirtualPixelsNexus() method is: |
| 3619 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3620 | % const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3621 | % NexusInfo *nexus_info) |
| 3622 | % |
| 3623 | % A description of each parameter follows: |
| 3624 | % |
| 3625 | % o cache: the pixel cache. |
| 3626 | % |
| 3627 | % o nexus_info: the cache nexus to return the colormap pixels. |
| 3628 | % |
| 3629 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 3630 | MagickPrivate const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3631 | NexusInfo *nexus_info) |
| 3632 | { |
| 3633 | CacheInfo |
| 3634 | *cache_info; |
| 3635 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3636 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3637 | cache_info=(CacheInfo *) cache; |
| 3638 | assert(cache_info->signature == MagickSignature); |
| 3639 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3640 | return((Quantum *) NULL); |
| 3641 | return((const Quantum *) nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | /* |
| 3645 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3646 | % % |
| 3647 | % % |
| 3648 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3649 | + O p e n P i x e l C a c h e % |
| 3650 | % % |
| 3651 | % % |
| 3652 | % % |
| 3653 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3654 | % |
| 3655 | % OpenPixelCache() allocates the pixel cache. This includes defining the cache |
| 3656 | % dimensions, allocating space for the image pixels and optionally the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3657 | % metacontent, and memory mapping the cache if it is disk based. The cache |
| 3658 | % nexus array is initialized as well. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3659 | % |
| 3660 | % The format of the OpenPixelCache() method is: |
| 3661 | % |
| 3662 | % MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 3663 | % ExceptionInfo *exception) |
| 3664 | % |
| 3665 | % A description of each parameter follows: |
| 3666 | % |
| 3667 | % o image: the image. |
| 3668 | % |
| 3669 | % o mode: ReadMode, WriteMode, or IOMode. |
| 3670 | % |
| 3671 | % o exception: return any errors or warnings in this structure. |
| 3672 | % |
| 3673 | */ |
| 3674 | |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 3675 | static inline void AllocatePixelCachePixels(CacheInfo *cache_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3676 | { |
| 3677 | cache_info->mapped=MagickFalse; |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3678 | cache_info->pixels=(Quantum *) AcquireQuantumMemory(1,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3679 | cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3680 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3681 | { |
| 3682 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3683 | cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3684 | cache_info->length); |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | static MagickBooleanType ExtendCache(Image *image,MagickSizeType length) |
| 3689 | { |
| 3690 | CacheInfo |
| 3691 | *cache_info; |
| 3692 | |
| 3693 | MagickOffsetType |
| 3694 | count, |
| 3695 | extent, |
| 3696 | offset; |
| 3697 | |
| 3698 | cache_info=(CacheInfo *) image->cache; |
| 3699 | if (image->debug != MagickFalse) |
| 3700 | { |
| 3701 | char |
| 3702 | format[MaxTextExtent], |
| 3703 | message[MaxTextExtent]; |
| 3704 | |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 3705 | (void) FormatMagickSize(length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3706 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | b37d4f2 | 2011-06-27 19:22:42 +0000 | [diff] [blame] | 3707 | "extend %s (%s[%d], disk, %s)",cache_info->filename, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3708 | cache_info->cache_filename,cache_info->file,format); |
| 3709 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 3710 | } |
| 3711 | if (length != (MagickSizeType) ((MagickOffsetType) length)) |
| 3712 | return(MagickFalse); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 3713 | extent=(MagickOffsetType) lseek(cache_info->file,0,SEEK_END); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3714 | if (extent < 0) |
| 3715 | return(MagickFalse); |
| 3716 | if ((MagickSizeType) extent >= length) |
| 3717 | return(MagickTrue); |
| 3718 | offset=(MagickOffsetType) length-1; |
| 3719 | count=WritePixelCacheRegion(cache_info,offset,1,(const unsigned char *) ""); |
| 3720 | return(count == (MagickOffsetType) 1 ? MagickTrue : MagickFalse); |
| 3721 | } |
| 3722 | |
| 3723 | static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 3724 | ExceptionInfo *exception) |
| 3725 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3726 | CacheInfo |
| 3727 | *cache_info, |
| 3728 | source_info; |
| 3729 | |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 3730 | char |
| 3731 | format[MaxTextExtent], |
| 3732 | message[MaxTextExtent]; |
| 3733 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3734 | MagickBooleanType |
| 3735 | status; |
| 3736 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3737 | MagickSizeType |
| 3738 | length, |
| 3739 | number_pixels; |
| 3740 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3741 | size_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3742 | columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3743 | packet_size; |
| 3744 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3745 | assert(image != (const Image *) NULL); |
| 3746 | assert(image->signature == MagickSignature); |
| 3747 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3748 | if (image->debug != MagickFalse) |
| 3749 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3750 | if ((image->columns == 0) || (image->rows == 0)) |
| 3751 | ThrowBinaryException(CacheError,"NoPixelsDefinedInCache",image->filename); |
| 3752 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3753 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3754 | source_info=(*cache_info); |
| 3755 | source_info.file=(-1); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3756 | (void) FormatLocaleString(cache_info->filename,MaxTextExtent,"%s[%.20g]", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3757 | image->filename,(double) GetImageIndexInList(image)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3758 | cache_info->storage_class=image->storage_class; |
| 3759 | cache_info->colorspace=image->colorspace; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3760 | cache_info->matte=image->matte; |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 3761 | cache_info->mask=image->mask; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3762 | cache_info->rows=image->rows; |
| 3763 | cache_info->columns=image->columns; |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3764 | InitializePixelChannelMap(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3765 | cache_info->number_channels=GetPixelChannels(image); |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 3766 | (void) memcpy(cache_info->channel_map,image->channel_map,MaxPixelChannels* |
| 3767 | sizeof(*image->channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3768 | cache_info->metacontent_extent=image->metacontent_extent; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3769 | cache_info->mode=mode; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3770 | if (image->ping != MagickFalse) |
| 3771 | { |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3772 | cache_info->type=PingCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3773 | cache_info->pixels=(Quantum *) NULL; |
| 3774 | cache_info->metacontent=(void *) NULL; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3775 | cache_info->length=0; |
| 3776 | return(MagickTrue); |
| 3777 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3778 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3779 | packet_size=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3780 | if (image->metacontent_extent != 0) |
| 3781 | packet_size+=cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3782 | length=number_pixels*packet_size; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3783 | columns=(size_t) (length/cache_info->rows/packet_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3784 | if (cache_info->columns != columns) |
| 3785 | ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed", |
| 3786 | image->filename); |
| 3787 | cache_info->length=length; |
| 3788 | status=AcquireMagickResource(AreaResource,cache_info->length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3789 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3790 | cache_info->metacontent_extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3791 | if ((status != MagickFalse) && (length == (MagickSizeType) ((size_t) length))) |
| 3792 | { |
| 3793 | status=AcquireMagickResource(MemoryResource,cache_info->length); |
| 3794 | if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) || |
| 3795 | (cache_info->type == MemoryCache)) |
| 3796 | { |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 3797 | AllocatePixelCachePixels(cache_info); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3798 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3799 | cache_info->pixels=source_info.pixels; |
| 3800 | else |
| 3801 | { |
| 3802 | /* |
| 3803 | Create memory pixel cache. |
| 3804 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3805 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3806 | if (image->debug != MagickFalse) |
| 3807 | { |
cristy | 32cacff | 2011-12-31 03:36:27 +0000 | [diff] [blame] | 3808 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3809 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3810 | "open %s (%s memory, %.20gx%.20gx%.20g %s)", |
| 3811 | cache_info->filename,cache_info->mapped != MagickFalse ? |
| 3812 | "anonymous" : "heap",(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3813 | cache_info->rows,(double) cache_info->number_channels, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3814 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3815 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 3816 | message); |
| 3817 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3818 | cache_info->type=MemoryCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3819 | cache_info->metacontent=(void *) NULL; |
| 3820 | if (cache_info->metacontent_extent != 0) |
| 3821 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3822 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3823 | if ((source_info.storage_class != UndefinedClass) && |
| 3824 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3825 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3826 | status=ClonePixelCachePixels(cache_info,&source_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3827 | exception); |
| 3828 | RelinquishPixelCachePixels(&source_info); |
| 3829 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3830 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 3834 | } |
| 3835 | /* |
| 3836 | Create pixel cache on disk. |
| 3837 | */ |
| 3838 | status=AcquireMagickResource(DiskResource,cache_info->length); |
| 3839 | if (status == MagickFalse) |
| 3840 | { |
| 3841 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 3842 | "CacheResourcesExhausted","'%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3843 | return(MagickFalse); |
| 3844 | } |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3845 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
| 3846 | { |
| 3847 | (void) ClosePixelCacheOnDisk(cache_info); |
| 3848 | *cache_info->cache_filename='\0'; |
| 3849 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3850 | if (OpenPixelCacheOnDisk(cache_info,mode) == MagickFalse) |
| 3851 | { |
| 3852 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 3853 | ThrowFileException(exception,CacheError,"UnableToOpenPixelCache", |
| 3854 | image->filename); |
| 3855 | return(MagickFalse); |
| 3856 | } |
| 3857 | status=ExtendCache(image,(MagickSizeType) cache_info->offset+ |
| 3858 | cache_info->length); |
| 3859 | if (status == MagickFalse) |
| 3860 | { |
| 3861 | ThrowFileException(exception,CacheError,"UnableToExtendCache", |
| 3862 | image->filename); |
| 3863 | return(MagickFalse); |
| 3864 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3865 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3866 | cache_info->metacontent_extent); |
cristy | a0b40ff | 2011-10-06 18:17:58 +0000 | [diff] [blame] | 3867 | if (length != (MagickSizeType) ((size_t) length)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3868 | cache_info->type=DiskCache; |
| 3869 | else |
| 3870 | { |
| 3871 | status=AcquireMagickResource(MapResource,cache_info->length); |
| 3872 | if ((status == MagickFalse) && (cache_info->type != MapCache) && |
| 3873 | (cache_info->type != MemoryCache)) |
| 3874 | cache_info->type=DiskCache; |
| 3875 | else |
| 3876 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3877 | cache_info->pixels=(Quantum *) MapBlob(cache_info->file,mode, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3878 | cache_info->offset,(size_t) cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3879 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3880 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3881 | cache_info->type=DiskCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3882 | cache_info->pixels=source_info.pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3883 | } |
| 3884 | else |
| 3885 | { |
| 3886 | /* |
| 3887 | Create file-backed memory-mapped pixel cache. |
| 3888 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3889 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3890 | (void) ClosePixelCacheOnDisk(cache_info); |
| 3891 | cache_info->type=MapCache; |
| 3892 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3893 | cache_info->metacontent=(void *) NULL; |
| 3894 | if (cache_info->metacontent_extent != 0) |
| 3895 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3896 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3897 | if ((source_info.storage_class != UndefinedClass) && |
| 3898 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3899 | { |
| 3900 | status=ClonePixelCachePixels(cache_info,&source_info, |
| 3901 | exception); |
| 3902 | RelinquishPixelCachePixels(&source_info); |
| 3903 | } |
| 3904 | if (image->debug != MagickFalse) |
| 3905 | { |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3906 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3907 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3908 | "open %s (%s[%d], memory-mapped, %.20gx%.20gx%.20g %s)", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3909 | cache_info->filename,cache_info->cache_filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3910 | cache_info->file,(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3911 | cache_info->rows,(double) cache_info->number_channels, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3912 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3913 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 3914 | message); |
| 3915 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3916 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3917 | } |
| 3918 | } |
| 3919 | RelinquishMagickResource(MapResource,cache_info->length); |
| 3920 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3921 | status=MagickTrue; |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3922 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3923 | { |
| 3924 | status=ClonePixelCachePixels(cache_info,&source_info,exception); |
| 3925 | RelinquishPixelCachePixels(&source_info); |
| 3926 | } |
| 3927 | if (image->debug != MagickFalse) |
| 3928 | { |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 3929 | (void) FormatMagickSize(cache_info->length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3930 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3931 | "open %s (%s[%d], disk, %.20gx%.20gx%.20g %s)",cache_info->filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3932 | cache_info->cache_filename,cache_info->file,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3933 | cache_info->columns,(double) cache_info->rows,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3934 | cache_info->number_channels,format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3935 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 3936 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3937 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | /* |
| 3941 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3942 | % % |
| 3943 | % % |
| 3944 | % % |
| 3945 | + P e r s i s t P i x e l C a c h e % |
| 3946 | % % |
| 3947 | % % |
| 3948 | % % |
| 3949 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3950 | % |
| 3951 | % PersistPixelCache() attaches to or initializes a persistent pixel cache. A |
| 3952 | % persistent pixel cache is one that resides on disk and is not destroyed |
| 3953 | % when the program exits. |
| 3954 | % |
| 3955 | % The format of the PersistPixelCache() method is: |
| 3956 | % |
| 3957 | % MagickBooleanType PersistPixelCache(Image *image,const char *filename, |
| 3958 | % const MagickBooleanType attach,MagickOffsetType *offset, |
| 3959 | % ExceptionInfo *exception) |
| 3960 | % |
| 3961 | % A description of each parameter follows: |
| 3962 | % |
| 3963 | % o image: the image. |
| 3964 | % |
| 3965 | % o filename: the persistent pixel cache filename. |
| 3966 | % |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 3967 | % o attach: A value other than zero initializes the persistent pixel cache. |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 3968 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3969 | % o initialize: A value other than zero initializes the persistent pixel |
| 3970 | % cache. |
| 3971 | % |
| 3972 | % o offset: the offset in the persistent cache to store pixels. |
| 3973 | % |
| 3974 | % o exception: return any errors or warnings in this structure. |
| 3975 | % |
| 3976 | */ |
| 3977 | MagickExport MagickBooleanType PersistPixelCache(Image *image, |
| 3978 | const char *filename,const MagickBooleanType attach,MagickOffsetType *offset, |
| 3979 | ExceptionInfo *exception) |
| 3980 | { |
| 3981 | CacheInfo |
| 3982 | *cache_info, |
| 3983 | *clone_info; |
| 3984 | |
| 3985 | Image |
| 3986 | clone_image; |
| 3987 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3988 | MagickBooleanType |
| 3989 | status; |
| 3990 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3991 | ssize_t |
| 3992 | page_size; |
| 3993 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3994 | assert(image != (Image *) NULL); |
| 3995 | assert(image->signature == MagickSignature); |
| 3996 | if (image->debug != MagickFalse) |
| 3997 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3998 | assert(image->cache != (void *) NULL); |
| 3999 | assert(filename != (const char *) NULL); |
| 4000 | assert(offset != (MagickOffsetType *) NULL); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4001 | page_size=GetMagickPageSize(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4002 | cache_info=(CacheInfo *) image->cache; |
| 4003 | assert(cache_info->signature == MagickSignature); |
| 4004 | if (attach != MagickFalse) |
| 4005 | { |
| 4006 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4007 | Attach existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4008 | */ |
| 4009 | if (image->debug != MagickFalse) |
| 4010 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4011 | "attach persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4012 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4013 | MaxTextExtent); |
| 4014 | cache_info->type=DiskCache; |
| 4015 | cache_info->offset=(*offset); |
cristy | de8c9c5 | 2010-09-20 18:56:24 +0000 | [diff] [blame] | 4016 | if (OpenPixelCache(image,ReadMode,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4017 | return(MagickFalse); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4018 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 8396771 | 2010-09-20 23:35:28 +0000 | [diff] [blame] | 4019 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4020 | } |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4021 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
| 4022 | (cache_info->reference_count == 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4023 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4024 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 4025 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4026 | (cache_info->reference_count == 1)) |
| 4027 | { |
| 4028 | int |
| 4029 | status; |
| 4030 | |
| 4031 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4032 | Usurp existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4033 | */ |
cristy | 320684d | 2011-09-23 14:55:47 +0000 | [diff] [blame] | 4034 | status=rename_utf8(cache_info->cache_filename,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4035 | if (status == 0) |
| 4036 | { |
| 4037 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4038 | MaxTextExtent); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4039 | *offset+=cache_info->length+page_size-(cache_info->length % |
| 4040 | page_size); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4041 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 4042 | cache_info=(CacheInfo *) ReferencePixelCache(cache_info); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4043 | if (image->debug != MagickFalse) |
| 4044 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
| 4045 | "Usurp resident persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4046 | return(MagickTrue); |
| 4047 | } |
| 4048 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4049 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4050 | } |
| 4051 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4052 | Clone persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4053 | */ |
| 4054 | clone_image=(*image); |
| 4055 | clone_info=(CacheInfo *) clone_image.cache; |
| 4056 | image->cache=ClonePixelCache(cache_info); |
| 4057 | cache_info=(CacheInfo *) ReferencePixelCache(image->cache); |
| 4058 | (void) CopyMagickString(cache_info->cache_filename,filename,MaxTextExtent); |
| 4059 | cache_info->type=DiskCache; |
| 4060 | cache_info->offset=(*offset); |
| 4061 | cache_info=(CacheInfo *) image->cache; |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4062 | status=OpenPixelCache(image,IOMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4063 | if (status != MagickFalse) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 4064 | status=ClonePixelCachePixels(cache_info,clone_info,exception); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4065 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4066 | clone_info=(CacheInfo *) DestroyPixelCache(clone_info); |
| 4067 | return(status); |
| 4068 | } |
| 4069 | |
| 4070 | /* |
| 4071 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4072 | % % |
| 4073 | % % |
| 4074 | % % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4075 | + Q u e u e A u t h e n t i c P i x e l C a c h e N e x u s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4076 | % % |
| 4077 | % % |
| 4078 | % % |
| 4079 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4080 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4081 | % QueueAuthenticPixelCacheNexus() allocates an region to store image pixels as |
| 4082 | % defined by the region rectangle and returns a pointer to the region. This |
| 4083 | % region is subsequently transferred from the pixel cache with |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4084 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4085 | % pixels are transferred, otherwise a NULL is returned. |
| 4086 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4087 | % The format of the QueueAuthenticPixelCacheNexus() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4088 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4089 | % Quantum *QueueAuthenticPixelCacheNexus(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4090 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4091 | % const MagickBooleanType clone,NexusInfo *nexus_info, |
| 4092 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4093 | % |
| 4094 | % A description of each parameter follows: |
| 4095 | % |
| 4096 | % o image: the image. |
| 4097 | % |
| 4098 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4099 | % pixels. |
| 4100 | % |
| 4101 | % o nexus_info: the cache nexus to set. |
| 4102 | % |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4103 | % o clone: clone the pixel cache. |
| 4104 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4105 | % o exception: return any errors or warnings in this structure. |
| 4106 | % |
| 4107 | */ |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4108 | MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image, |
| 4109 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4110 | const MagickBooleanType clone,NexusInfo *nexus_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4111 | { |
| 4112 | CacheInfo |
| 4113 | *cache_info; |
| 4114 | |
| 4115 | MagickOffsetType |
| 4116 | offset; |
| 4117 | |
| 4118 | MagickSizeType |
| 4119 | number_pixels; |
| 4120 | |
| 4121 | RectangleInfo |
| 4122 | region; |
| 4123 | |
| 4124 | /* |
| 4125 | Validate pixel cache geometry. |
| 4126 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4127 | assert(image != (const Image *) NULL); |
| 4128 | assert(image->signature == MagickSignature); |
| 4129 | assert(image->cache != (Cache) NULL); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4130 | cache_info=(CacheInfo *) GetImagePixelCache(image,clone,exception); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4131 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4132 | return((Quantum *) NULL); |
cristy | e27517a | 2011-09-04 23:02:10 +0000 | [diff] [blame] | 4133 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4134 | if ((cache_info->columns == 0) && (cache_info->rows == 0)) |
| 4135 | { |
| 4136 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 4137 | "NoPixelsDefinedInCache","'%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4138 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4139 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4140 | if ((x < 0) || (y < 0) || (x >= (ssize_t) cache_info->columns) || |
| 4141 | (y >= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4142 | { |
| 4143 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 4144 | "PixelsAreNotAuthentic","'%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4145 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4146 | } |
| 4147 | offset=(MagickOffsetType) y*cache_info->columns+x; |
| 4148 | if (offset < 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4149 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4150 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 4151 | offset+=(MagickOffsetType) (rows-1)*cache_info->columns+columns-1; |
| 4152 | if ((MagickSizeType) offset >= number_pixels) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4153 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4154 | /* |
| 4155 | Return pixel cache. |
| 4156 | */ |
| 4157 | region.x=x; |
| 4158 | region.y=y; |
| 4159 | region.width=columns; |
| 4160 | region.height=rows; |
| 4161 | return(SetPixelCacheNexusPixels(image,®ion,nexus_info,exception)); |
| 4162 | } |
| 4163 | |
| 4164 | /* |
| 4165 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4166 | % % |
| 4167 | % % |
| 4168 | % % |
| 4169 | + Q u e u e A u t h e n t i c P i x e l s C a c h e % |
| 4170 | % % |
| 4171 | % % |
| 4172 | % % |
| 4173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4174 | % |
| 4175 | % QueueAuthenticPixelsCache() allocates an region to store image pixels as |
| 4176 | % defined by the region rectangle and returns a pointer to the region. This |
| 4177 | % region is subsequently transferred from the pixel cache with |
| 4178 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4179 | % pixels are transferred, otherwise a NULL is returned. |
| 4180 | % |
| 4181 | % The format of the QueueAuthenticPixelsCache() method is: |
| 4182 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4183 | % Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4184 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4185 | % ExceptionInfo *exception) |
| 4186 | % |
| 4187 | % A description of each parameter follows: |
| 4188 | % |
| 4189 | % o image: the image. |
| 4190 | % |
| 4191 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4192 | % pixels. |
| 4193 | % |
| 4194 | % o exception: return any errors or warnings in this structure. |
| 4195 | % |
| 4196 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4197 | static Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4198 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4199 | ExceptionInfo *exception) |
| 4200 | { |
| 4201 | CacheInfo |
| 4202 | *cache_info; |
| 4203 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4204 | const int |
| 4205 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4206 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4207 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4208 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4209 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4210 | assert(image != (const Image *) NULL); |
| 4211 | assert(image->signature == MagickSignature); |
| 4212 | assert(image->cache != (Cache) NULL); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4213 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4214 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4215 | assert(id < (int) cache_info->number_threads); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4216 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4217 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4218 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /* |
| 4222 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4223 | % % |
| 4224 | % % |
| 4225 | % % |
| 4226 | % Q u e u e A u t h e n t i c P i x e l s % |
| 4227 | % % |
| 4228 | % % |
| 4229 | % % |
| 4230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4231 | % |
| 4232 | % QueueAuthenticPixels() queues a mutable pixel region. If the region is |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4233 | % successfully initialized a pointer to a Quantum array representing the |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4234 | % region is returned, otherwise NULL is returned. The returned pointer may |
| 4235 | % point to a temporary working buffer for the pixels or it may point to the |
| 4236 | % final location of the pixels in memory. |
| 4237 | % |
| 4238 | % Write-only access means that any existing pixel values corresponding to |
| 4239 | % the region are ignored. This is useful if the initial image is being |
| 4240 | % created from scratch, or if the existing pixel values are to be |
| 4241 | % completely replaced without need to refer to their pre-existing values. |
| 4242 | % The application is free to read and write the pixel buffer returned by |
| 4243 | % QueueAuthenticPixels() any way it pleases. QueueAuthenticPixels() does not |
| 4244 | % initialize the pixel array values. Initializing pixel array values is the |
| 4245 | % application's responsibility. |
| 4246 | % |
| 4247 | % Performance is maximized if the selected region is part of one row, or |
| 4248 | % one or more full rows, since then there is opportunity to access the |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 4249 | % pixels in-place (without a copy) if the image is in memory, or in a |
| 4250 | % memory-mapped file. The returned pointer must *never* be deallocated |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4251 | % by the user. |
| 4252 | % |
| 4253 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4254 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 4255 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 4256 | % obtain the meta-content (of type void) corresponding to the region. |
| 4257 | % Once the Quantum (and/or Quantum) array has been updated, the |
| 4258 | % changes must be saved back to the underlying image using |
| 4259 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4260 | % |
| 4261 | % The format of the QueueAuthenticPixels() method is: |
| 4262 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4263 | % Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4264 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4265 | % ExceptionInfo *exception) |
| 4266 | % |
| 4267 | % A description of each parameter follows: |
| 4268 | % |
| 4269 | % o image: the image. |
| 4270 | % |
| 4271 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4272 | % pixels. |
| 4273 | % |
| 4274 | % o exception: return any errors or warnings in this structure. |
| 4275 | % |
| 4276 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4277 | MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4278 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4279 | ExceptionInfo *exception) |
| 4280 | { |
| 4281 | CacheInfo |
| 4282 | *cache_info; |
| 4283 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4284 | const int |
| 4285 | id = GetOpenMPThreadId(); |
| 4286 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4287 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4288 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4289 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4290 | assert(image != (Image *) NULL); |
| 4291 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4292 | assert(image->cache != (Cache) NULL); |
| 4293 | cache_info=(CacheInfo *) image->cache; |
| 4294 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 4295 | if (cache_info->methods.queue_authentic_pixels_handler != |
cristy | c36c882 | 2012-02-14 14:02:36 +0000 | [diff] [blame] | 4296 | (QueueAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4297 | { |
cristy | c36c882 | 2012-02-14 14:02:36 +0000 | [diff] [blame] | 4298 | q=cache_info->methods.queue_authentic_pixels_handler(image,x,y,columns, |
| 4299 | rows,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4300 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4301 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4302 | assert(id < (int) cache_info->number_threads); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4303 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4304 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4305 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | /* |
| 4309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4310 | % % |
| 4311 | % % |
| 4312 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4313 | + R e a d P i x e l C a c h e M e t a c o n t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4314 | % % |
| 4315 | % % |
| 4316 | % % |
| 4317 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4318 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4319 | % ReadPixelCacheMetacontent() reads metacontent from the specified region of |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4320 | % the pixel cache. |
| 4321 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4322 | % The format of the ReadPixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4323 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4324 | % MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4325 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4326 | % |
| 4327 | % A description of each parameter follows: |
| 4328 | % |
| 4329 | % o cache_info: the pixel cache. |
| 4330 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4331 | % o nexus_info: the cache nexus to read the metacontent. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4332 | % |
| 4333 | % o exception: return any errors or warnings in this structure. |
| 4334 | % |
| 4335 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4336 | static MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4337 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4338 | { |
| 4339 | MagickOffsetType |
| 4340 | count, |
| 4341 | offset; |
| 4342 | |
| 4343 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4344 | extent, |
| 4345 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4346 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4347 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4348 | y; |
| 4349 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4350 | register unsigned char |
| 4351 | *restrict q; |
| 4352 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4353 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4354 | rows; |
| 4355 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4356 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4357 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4358 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4359 | return(MagickTrue); |
| 4360 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4361 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4362 | length=(MagickSizeType) nexus_info->region.width* |
| 4363 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4364 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4365 | extent=length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4366 | q=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4367 | switch (cache_info->type) |
| 4368 | { |
| 4369 | case MemoryCache: |
| 4370 | case MapCache: |
| 4371 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4372 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4373 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4374 | |
| 4375 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4376 | Read meta-content from memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4377 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4378 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4379 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4380 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4381 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4382 | rows=1UL; |
| 4383 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4384 | p=(unsigned char *) cache_info->metacontent+offset* |
| 4385 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4386 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4387 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4388 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4389 | p+=cache_info->metacontent_extent*cache_info->columns; |
| 4390 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4391 | } |
| 4392 | break; |
| 4393 | } |
| 4394 | case DiskCache: |
| 4395 | { |
| 4396 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4397 | Read meta content from disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4398 | */ |
| 4399 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4400 | { |
| 4401 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4402 | cache_info->cache_filename); |
| 4403 | return(MagickFalse); |
| 4404 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4405 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4406 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4407 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4408 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4409 | rows=1UL; |
| 4410 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4411 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4412 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4413 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4414 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4415 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4416 | cache_info->metacontent_extent,length,(unsigned char *) q); |
| 4417 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4418 | break; |
| 4419 | offset+=cache_info->columns; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4420 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4421 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4422 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 4423 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4424 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4425 | { |
| 4426 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4427 | cache_info->cache_filename); |
| 4428 | return(MagickFalse); |
| 4429 | } |
| 4430 | break; |
| 4431 | } |
| 4432 | default: |
| 4433 | break; |
| 4434 | } |
| 4435 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4436 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4437 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4438 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4439 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4440 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4441 | return(MagickTrue); |
| 4442 | } |
| 4443 | |
| 4444 | /* |
| 4445 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4446 | % % |
| 4447 | % % |
| 4448 | % % |
| 4449 | + R e a d P i x e l C a c h e P i x e l s % |
| 4450 | % % |
| 4451 | % % |
| 4452 | % % |
| 4453 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4454 | % |
| 4455 | % ReadPixelCachePixels() reads pixels from the specified region of the pixel |
| 4456 | % cache. |
| 4457 | % |
| 4458 | % The format of the ReadPixelCachePixels() method is: |
| 4459 | % |
| 4460 | % MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4461 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4462 | % |
| 4463 | % A description of each parameter follows: |
| 4464 | % |
| 4465 | % o cache_info: the pixel cache. |
| 4466 | % |
| 4467 | % o nexus_info: the cache nexus to read the pixels. |
| 4468 | % |
| 4469 | % o exception: return any errors or warnings in this structure. |
| 4470 | % |
| 4471 | */ |
| 4472 | static MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4473 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4474 | { |
| 4475 | MagickOffsetType |
| 4476 | count, |
| 4477 | offset; |
| 4478 | |
| 4479 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4480 | extent, |
| 4481 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4482 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4483 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4484 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4485 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4486 | register ssize_t |
| 4487 | y; |
| 4488 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4489 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4490 | rows; |
| 4491 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4492 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4493 | return(MagickTrue); |
| 4494 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4495 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4496 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4497 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4498 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4499 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4500 | q=nexus_info->pixels; |
| 4501 | switch (cache_info->type) |
| 4502 | { |
| 4503 | case MemoryCache: |
| 4504 | case MapCache: |
| 4505 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4506 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4507 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4508 | |
| 4509 | /* |
| 4510 | Read pixels from memory. |
| 4511 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4512 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4513 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4514 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4515 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4516 | rows=1UL; |
| 4517 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4518 | p=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4519 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4520 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4521 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4522 | p+=cache_info->number_channels*cache_info->columns; |
| 4523 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4524 | } |
| 4525 | break; |
| 4526 | } |
| 4527 | case DiskCache: |
| 4528 | { |
| 4529 | /* |
| 4530 | Read pixels from disk. |
| 4531 | */ |
| 4532 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4533 | { |
| 4534 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4535 | cache_info->cache_filename); |
| 4536 | return(MagickFalse); |
| 4537 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4538 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4539 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4540 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4541 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4542 | rows=1UL; |
| 4543 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4544 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4545 | { |
| 4546 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4547 | cache_info->number_channels*sizeof(*q),length,(unsigned char *) q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4548 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4549 | break; |
| 4550 | offset+=cache_info->columns; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4551 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4552 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4553 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 4554 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4555 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4556 | { |
| 4557 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4558 | cache_info->cache_filename); |
| 4559 | return(MagickFalse); |
| 4560 | } |
| 4561 | break; |
| 4562 | } |
| 4563 | default: |
| 4564 | break; |
| 4565 | } |
| 4566 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4567 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4568 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4569 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4570 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4571 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4572 | return(MagickTrue); |
| 4573 | } |
| 4574 | |
| 4575 | /* |
| 4576 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4577 | % % |
| 4578 | % % |
| 4579 | % % |
| 4580 | + R e f e r e n c e P i x e l C a c h e % |
| 4581 | % % |
| 4582 | % % |
| 4583 | % % |
| 4584 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4585 | % |
| 4586 | % ReferencePixelCache() increments the reference count associated with the |
| 4587 | % pixel cache returning a pointer to the cache. |
| 4588 | % |
| 4589 | % The format of the ReferencePixelCache method is: |
| 4590 | % |
| 4591 | % Cache ReferencePixelCache(Cache cache_info) |
| 4592 | % |
| 4593 | % A description of each parameter follows: |
| 4594 | % |
| 4595 | % o cache_info: the pixel cache. |
| 4596 | % |
| 4597 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4598 | MagickPrivate Cache ReferencePixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4599 | { |
| 4600 | CacheInfo |
| 4601 | *cache_info; |
| 4602 | |
| 4603 | assert(cache != (Cache *) NULL); |
| 4604 | cache_info=(CacheInfo *) cache; |
| 4605 | assert(cache_info->signature == MagickSignature); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4606 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4607 | cache_info->reference_count++; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4608 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4609 | return(cache_info); |
| 4610 | } |
| 4611 | |
| 4612 | /* |
| 4613 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4614 | % % |
| 4615 | % % |
| 4616 | % % |
| 4617 | + S e t P i x e l C a c h e M e t h o d s % |
| 4618 | % % |
| 4619 | % % |
| 4620 | % % |
| 4621 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4622 | % |
| 4623 | % SetPixelCacheMethods() sets the image pixel methods to the specified ones. |
| 4624 | % |
| 4625 | % The format of the SetPixelCacheMethods() method is: |
| 4626 | % |
| 4627 | % SetPixelCacheMethods(Cache *,CacheMethods *cache_methods) |
| 4628 | % |
| 4629 | % A description of each parameter follows: |
| 4630 | % |
| 4631 | % o cache: the pixel cache. |
| 4632 | % |
| 4633 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 4634 | % |
| 4635 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4636 | MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4637 | { |
| 4638 | CacheInfo |
| 4639 | *cache_info; |
| 4640 | |
| 4641 | GetOneAuthenticPixelFromHandler |
| 4642 | get_one_authentic_pixel_from_handler; |
| 4643 | |
| 4644 | GetOneVirtualPixelFromHandler |
| 4645 | get_one_virtual_pixel_from_handler; |
| 4646 | |
| 4647 | /* |
| 4648 | Set cache pixel methods. |
| 4649 | */ |
| 4650 | assert(cache != (Cache) NULL); |
| 4651 | assert(cache_methods != (CacheMethods *) NULL); |
| 4652 | cache_info=(CacheInfo *) cache; |
| 4653 | assert(cache_info->signature == MagickSignature); |
| 4654 | if (cache_info->debug != MagickFalse) |
| 4655 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4656 | cache_info->filename); |
| 4657 | if (cache_methods->get_virtual_pixel_handler != (GetVirtualPixelHandler) NULL) |
| 4658 | cache_info->methods.get_virtual_pixel_handler= |
| 4659 | cache_methods->get_virtual_pixel_handler; |
| 4660 | if (cache_methods->destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 4661 | cache_info->methods.destroy_pixel_handler= |
| 4662 | cache_methods->destroy_pixel_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4663 | if (cache_methods->get_virtual_metacontent_from_handler != |
| 4664 | (GetVirtualMetacontentFromHandler) NULL) |
| 4665 | cache_info->methods.get_virtual_metacontent_from_handler= |
| 4666 | cache_methods->get_virtual_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4667 | if (cache_methods->get_authentic_pixels_handler != |
| 4668 | (GetAuthenticPixelsHandler) NULL) |
| 4669 | cache_info->methods.get_authentic_pixels_handler= |
| 4670 | cache_methods->get_authentic_pixels_handler; |
| 4671 | if (cache_methods->queue_authentic_pixels_handler != |
| 4672 | (QueueAuthenticPixelsHandler) NULL) |
| 4673 | cache_info->methods.queue_authentic_pixels_handler= |
| 4674 | cache_methods->queue_authentic_pixels_handler; |
| 4675 | if (cache_methods->sync_authentic_pixels_handler != |
| 4676 | (SyncAuthenticPixelsHandler) NULL) |
| 4677 | cache_info->methods.sync_authentic_pixels_handler= |
| 4678 | cache_methods->sync_authentic_pixels_handler; |
| 4679 | if (cache_methods->get_authentic_pixels_from_handler != |
| 4680 | (GetAuthenticPixelsFromHandler) NULL) |
| 4681 | cache_info->methods.get_authentic_pixels_from_handler= |
| 4682 | cache_methods->get_authentic_pixels_from_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4683 | if (cache_methods->get_authentic_metacontent_from_handler != |
| 4684 | (GetAuthenticMetacontentFromHandler) NULL) |
| 4685 | cache_info->methods.get_authentic_metacontent_from_handler= |
| 4686 | cache_methods->get_authentic_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4687 | get_one_virtual_pixel_from_handler= |
| 4688 | cache_info->methods.get_one_virtual_pixel_from_handler; |
| 4689 | if (get_one_virtual_pixel_from_handler != |
| 4690 | (GetOneVirtualPixelFromHandler) NULL) |
| 4691 | cache_info->methods.get_one_virtual_pixel_from_handler= |
| 4692 | cache_methods->get_one_virtual_pixel_from_handler; |
| 4693 | get_one_authentic_pixel_from_handler= |
| 4694 | cache_methods->get_one_authentic_pixel_from_handler; |
| 4695 | if (get_one_authentic_pixel_from_handler != |
| 4696 | (GetOneAuthenticPixelFromHandler) NULL) |
| 4697 | cache_info->methods.get_one_authentic_pixel_from_handler= |
| 4698 | cache_methods->get_one_authentic_pixel_from_handler; |
| 4699 | } |
| 4700 | |
| 4701 | /* |
| 4702 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4703 | % % |
| 4704 | % % |
| 4705 | % % |
| 4706 | + S e t P i x e l C a c h e N e x u s P i x e l s % |
| 4707 | % % |
| 4708 | % % |
| 4709 | % % |
| 4710 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4711 | % |
| 4712 | % SetPixelCacheNexusPixels() defines the region of the cache for the |
| 4713 | % specified cache nexus. |
| 4714 | % |
| 4715 | % The format of the SetPixelCacheNexusPixels() method is: |
| 4716 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4717 | % Quantum SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4718 | % const RectangleInfo *region,NexusInfo *nexus_info, |
| 4719 | % ExceptionInfo *exception) |
| 4720 | % |
| 4721 | % A description of each parameter follows: |
| 4722 | % |
| 4723 | % o image: the image. |
| 4724 | % |
| 4725 | % o region: A pointer to the RectangleInfo structure that defines the |
| 4726 | % region of this particular cache nexus. |
| 4727 | % |
| 4728 | % o nexus_info: the cache nexus to set. |
| 4729 | % |
| 4730 | % o exception: return any errors or warnings in this structure. |
| 4731 | % |
| 4732 | */ |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4733 | |
| 4734 | static inline MagickBooleanType AcquireCacheNexusPixels(CacheInfo *cache_info, |
| 4735 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4736 | { |
| 4737 | if (nexus_info->length != (MagickSizeType) ((size_t) nexus_info->length)) |
| 4738 | return(MagickFalse); |
| 4739 | nexus_info->mapped=MagickFalse; |
cristy | 64c3edf | 2012-04-13 18:50:13 +0000 | [diff] [blame] | 4740 | nexus_info->cache=(Quantum *) AcquireMagickMemory((size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4741 | nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4742 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4743 | { |
| 4744 | nexus_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4745 | nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4746 | nexus_info->length); |
| 4747 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4748 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4749 | { |
| 4750 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 4751 | ResourceLimitError,"MemoryAllocationFailed","'%s'", |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4752 | cache_info->filename); |
| 4753 | return(MagickFalse); |
| 4754 | } |
| 4755 | return(MagickTrue); |
| 4756 | } |
| 4757 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4758 | static Quantum *SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4759 | const RectangleInfo *region,NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4760 | { |
| 4761 | CacheInfo |
| 4762 | *cache_info; |
| 4763 | |
| 4764 | MagickBooleanType |
| 4765 | status; |
| 4766 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4767 | MagickSizeType |
| 4768 | length, |
| 4769 | number_pixels; |
| 4770 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4771 | cache_info=(CacheInfo *) image->cache; |
| 4772 | assert(cache_info->signature == MagickSignature); |
| 4773 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4774 | return((Quantum *) NULL); |
cristy | dc8b63f | 2010-03-13 16:11:14 +0000 | [diff] [blame] | 4775 | nexus_info->region=(*region); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4776 | if ((cache_info->type != DiskCache) && (cache_info->type != PingCache)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4777 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4778 | ssize_t |
cristy | bad067a | 2010-02-15 17:20:55 +0000 | [diff] [blame] | 4779 | x, |
| 4780 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4781 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4782 | x=nexus_info->region.x+(ssize_t) nexus_info->region.width-1; |
| 4783 | y=nexus_info->region.y+(ssize_t) nexus_info->region.height-1; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4784 | if (((nexus_info->region.x >= 0) && (x < (ssize_t) cache_info->columns) && |
| 4785 | (nexus_info->region.y >= 0) && (y < (ssize_t) cache_info->rows)) && |
cristy | ed733b3 | 2010-09-17 16:27:34 +0000 | [diff] [blame] | 4786 | ((nexus_info->region.height == 1UL) || ((nexus_info->region.x == 0) && |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 4787 | ((nexus_info->region.width == cache_info->columns) || |
| 4788 | ((nexus_info->region.width % cache_info->columns) == 0))))) |
| 4789 | { |
| 4790 | MagickOffsetType |
| 4791 | offset; |
| 4792 | |
| 4793 | /* |
| 4794 | Pixels are accessed directly from memory. |
| 4795 | */ |
| 4796 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4797 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4798 | nexus_info->pixels=cache_info->pixels+cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4799 | offset; |
| 4800 | nexus_info->metacontent=(void *) NULL; |
| 4801 | if (cache_info->metacontent_extent != 0) |
| 4802 | nexus_info->metacontent=(unsigned char *) cache_info->metacontent+ |
| 4803 | offset*cache_info->metacontent_extent; |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 4804 | return(nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4805 | } |
| 4806 | } |
| 4807 | /* |
| 4808 | Pixels are stored in a cache region until they are synced to the cache. |
| 4809 | */ |
| 4810 | number_pixels=(MagickSizeType) nexus_info->region.width* |
| 4811 | nexus_info->region.height; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4812 | length=number_pixels*cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4813 | if (cache_info->metacontent_extent != 0) |
| 4814 | length+=number_pixels*cache_info->metacontent_extent; |
| 4815 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4816 | { |
| 4817 | nexus_info->length=length; |
| 4818 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 4819 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4820 | { |
| 4821 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4822 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4823 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4824 | } |
| 4825 | else |
| 4826 | if (nexus_info->length != length) |
| 4827 | { |
| 4828 | RelinquishCacheNexusPixels(nexus_info); |
| 4829 | nexus_info->length=length; |
| 4830 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 4831 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4832 | { |
| 4833 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4834 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4835 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4836 | } |
| 4837 | nexus_info->pixels=nexus_info->cache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4838 | nexus_info->metacontent=(void *) NULL; |
| 4839 | if (cache_info->metacontent_extent != 0) |
| 4840 | nexus_info->metacontent=(void *) (nexus_info->pixels+number_pixels* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4841 | cache_info->number_channels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4842 | return(nexus_info->pixels); |
| 4843 | } |
| 4844 | |
| 4845 | /* |
| 4846 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4847 | % % |
| 4848 | % % |
| 4849 | % % |
| 4850 | % S e t P i x e l C a c h e V i r t u a l M e t h o d % |
| 4851 | % % |
| 4852 | % % |
| 4853 | % % |
| 4854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4855 | % |
| 4856 | % SetPixelCacheVirtualMethod() sets the "virtual pixels" method for the |
| 4857 | % pixel cache and returns the previous setting. A virtual pixel is any pixel |
| 4858 | % access that is outside the boundaries of the image cache. |
| 4859 | % |
| 4860 | % The format of the SetPixelCacheVirtualMethod() method is: |
| 4861 | % |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4862 | % VirtualPixelMethod SetPixelCacheVirtualMethod(Image *image, |
| 4863 | % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4864 | % |
| 4865 | % A description of each parameter follows: |
| 4866 | % |
| 4867 | % o image: the image. |
| 4868 | % |
| 4869 | % o virtual_pixel_method: choose the type of virtual pixel. |
| 4870 | % |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4871 | % o exception: return any errors or warnings in this structure. |
| 4872 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4873 | */ |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4874 | |
| 4875 | static MagickBooleanType SetCacheAlphaChannel(Image *image,const Quantum alpha, |
| 4876 | ExceptionInfo *exception) |
| 4877 | { |
cristy | 23d198a | 2012-03-13 13:48:08 +0000 | [diff] [blame] | 4878 | CacheView |
| 4879 | *image_view; |
| 4880 | |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4881 | CacheInfo |
| 4882 | *cache_info; |
| 4883 | |
| 4884 | MagickBooleanType |
| 4885 | status; |
| 4886 | |
| 4887 | ssize_t |
| 4888 | y; |
| 4889 | |
| 4890 | assert(image != (Image *) NULL); |
| 4891 | assert(image->signature == MagickSignature); |
| 4892 | if (image->debug != MagickFalse) |
| 4893 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4894 | assert(image->cache != (Cache) NULL); |
| 4895 | cache_info=(CacheInfo *) image->cache; |
| 4896 | assert(cache_info->signature == MagickSignature); |
| 4897 | image->matte=MagickTrue; |
| 4898 | status=MagickTrue; |
cristy | a1022ad | 2012-05-02 13:01:59 +0000 | [diff] [blame] | 4899 | image_view=AcquireVirtualCacheView(image,exception); /* must be virtual */ |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4900 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 4901 | #pragma omp parallel for schedule(static) shared(status) |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4902 | #endif |
| 4903 | for (y=0; y < (ssize_t) image->rows; y++) |
| 4904 | { |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4905 | register Quantum |
| 4906 | *restrict q; |
| 4907 | |
| 4908 | register ssize_t |
| 4909 | x; |
| 4910 | |
| 4911 | if (status == MagickFalse) |
| 4912 | continue; |
cristy | 23d198a | 2012-03-13 13:48:08 +0000 | [diff] [blame] | 4913 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4914 | if (q == (Quantum *) NULL) |
| 4915 | { |
| 4916 | status=MagickFalse; |
| 4917 | continue; |
| 4918 | } |
| 4919 | for (x=0; x < (ssize_t) image->columns; x++) |
| 4920 | { |
| 4921 | SetPixelAlpha(image,alpha,q); |
| 4922 | q+=GetPixelChannels(image); |
| 4923 | } |
cristy | 23d198a | 2012-03-13 13:48:08 +0000 | [diff] [blame] | 4924 | status=SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4925 | } |
cristy | 23d198a | 2012-03-13 13:48:08 +0000 | [diff] [blame] | 4926 | image_view=DestroyCacheView(image_view); |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4927 | return(status); |
| 4928 | } |
| 4929 | |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4930 | MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(Image *image, |
| 4931 | const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4932 | { |
| 4933 | CacheInfo |
| 4934 | *cache_info; |
| 4935 | |
| 4936 | VirtualPixelMethod |
| 4937 | method; |
| 4938 | |
| 4939 | assert(image != (Image *) NULL); |
| 4940 | assert(image->signature == MagickSignature); |
| 4941 | if (image->debug != MagickFalse) |
| 4942 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4943 | assert(image->cache != (Cache) NULL); |
| 4944 | cache_info=(CacheInfo *) image->cache; |
| 4945 | assert(cache_info->signature == MagickSignature); |
| 4946 | method=cache_info->virtual_pixel_method; |
| 4947 | cache_info->virtual_pixel_method=virtual_pixel_method; |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4948 | switch (virtual_pixel_method) |
| 4949 | { |
| 4950 | case BackgroundVirtualPixelMethod: |
| 4951 | { |
| 4952 | if ((image->background_color.matte != MagickFalse) && |
| 4953 | (image->matte == MagickFalse)) |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4954 | (void) SetCacheAlphaChannel(image,OpaqueAlpha,exception); |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4955 | break; |
| 4956 | } |
| 4957 | case TransparentVirtualPixelMethod: |
| 4958 | { |
| 4959 | if (image->matte == MagickFalse) |
cristy | 3d4cb88 | 2012-02-07 19:11:26 +0000 | [diff] [blame] | 4960 | (void) SetCacheAlphaChannel(image,OpaqueAlpha,exception); |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4961 | break; |
| 4962 | } |
| 4963 | default: |
| 4964 | break; |
| 4965 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4966 | return(method); |
| 4967 | } |
| 4968 | |
| 4969 | /* |
| 4970 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4971 | % % |
| 4972 | % % |
| 4973 | % % |
| 4974 | + S y n c A u t h e n t i c P i x e l C a c h e N e x u s % |
| 4975 | % % |
| 4976 | % % |
| 4977 | % % |
| 4978 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4979 | % |
| 4980 | % SyncAuthenticPixelCacheNexus() saves the authentic image pixels to the |
| 4981 | % in-memory or disk cache. The method returns MagickTrue if the pixel region |
| 4982 | % is synced, otherwise MagickFalse. |
| 4983 | % |
| 4984 | % The format of the SyncAuthenticPixelCacheNexus() method is: |
| 4985 | % |
| 4986 | % MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
| 4987 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4988 | % |
| 4989 | % A description of each parameter follows: |
| 4990 | % |
| 4991 | % o image: the image. |
| 4992 | % |
| 4993 | % o nexus_info: the cache nexus to sync. |
| 4994 | % |
| 4995 | % o exception: return any errors or warnings in this structure. |
| 4996 | % |
| 4997 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4998 | MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4999 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5000 | { |
| 5001 | CacheInfo |
| 5002 | *cache_info; |
| 5003 | |
| 5004 | MagickBooleanType |
| 5005 | status; |
| 5006 | |
| 5007 | /* |
| 5008 | Transfer pixels to the cache. |
| 5009 | */ |
| 5010 | assert(image != (Image *) NULL); |
| 5011 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5012 | if (image->cache == (Cache) NULL) |
| 5013 | ThrowBinaryException(CacheError,"PixelCacheIsNotOpen",image->filename); |
| 5014 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5015 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5016 | if (cache_info->type == UndefinedCache) |
| 5017 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5018 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5019 | return(MagickTrue); |
| 5020 | assert(cache_info->signature == MagickSignature); |
| 5021 | status=WritePixelCachePixels(cache_info,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5022 | if ((cache_info->metacontent_extent != 0) && |
| 5023 | (WritePixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5024 | return(MagickFalse); |
| 5025 | return(status); |
| 5026 | } |
| 5027 | |
| 5028 | /* |
| 5029 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5030 | % % |
| 5031 | % % |
| 5032 | % % |
| 5033 | + S y n c A u t h e n t i c P i x e l C a c h e % |
| 5034 | % % |
| 5035 | % % |
| 5036 | % % |
| 5037 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5038 | % |
| 5039 | % SyncAuthenticPixelsCache() saves the authentic image pixels to the in-memory |
| 5040 | % or disk cache. The method returns MagickTrue if the pixel region is synced, |
| 5041 | % otherwise MagickFalse. |
| 5042 | % |
| 5043 | % The format of the SyncAuthenticPixelsCache() method is: |
| 5044 | % |
| 5045 | % MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 5046 | % ExceptionInfo *exception) |
| 5047 | % |
| 5048 | % A description of each parameter follows: |
| 5049 | % |
| 5050 | % o image: the image. |
| 5051 | % |
| 5052 | % o exception: return any errors or warnings in this structure. |
| 5053 | % |
| 5054 | */ |
| 5055 | static MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 5056 | ExceptionInfo *exception) |
| 5057 | { |
| 5058 | CacheInfo |
| 5059 | *cache_info; |
| 5060 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 5061 | const int |
| 5062 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5063 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5064 | MagickBooleanType |
| 5065 | status; |
| 5066 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5067 | assert(image != (Image *) NULL); |
| 5068 | assert(image->signature == MagickSignature); |
| 5069 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5070 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5071 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 5072 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5073 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5074 | exception); |
| 5075 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | /* |
| 5079 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5080 | % % |
| 5081 | % % |
| 5082 | % % |
| 5083 | % S y n c A u t h e n t i c P i x e l s % |
| 5084 | % % |
| 5085 | % % |
| 5086 | % % |
| 5087 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5088 | % |
| 5089 | % SyncAuthenticPixels() saves the image pixels to the in-memory or disk cache. |
| 5090 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5091 | % MagickFalse. |
| 5092 | % |
| 5093 | % The format of the SyncAuthenticPixels() method is: |
| 5094 | % |
| 5095 | % MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5096 | % ExceptionInfo *exception) |
| 5097 | % |
| 5098 | % A description of each parameter follows: |
| 5099 | % |
| 5100 | % o image: the image. |
| 5101 | % |
| 5102 | % o exception: return any errors or warnings in this structure. |
| 5103 | % |
| 5104 | */ |
| 5105 | MagickExport MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5106 | ExceptionInfo *exception) |
| 5107 | { |
| 5108 | CacheInfo |
| 5109 | *cache_info; |
| 5110 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5111 | const int |
| 5112 | id = GetOpenMPThreadId(); |
| 5113 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5114 | MagickBooleanType |
| 5115 | status; |
| 5116 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5117 | assert(image != (Image *) NULL); |
| 5118 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5119 | assert(image->cache != (Cache) NULL); |
| 5120 | cache_info=(CacheInfo *) image->cache; |
| 5121 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 5122 | if (cache_info->methods.sync_authentic_pixels_handler != |
| 5123 | (SyncAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5124 | { |
| 5125 | status=cache_info->methods.sync_authentic_pixels_handler(image, |
| 5126 | exception); |
| 5127 | return(status); |
| 5128 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5129 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5130 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5131 | exception); |
| 5132 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | /* |
| 5136 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5137 | % % |
| 5138 | % % |
| 5139 | % % |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5140 | + S y n c I m a g e P i x e l C a c h e % |
cristy | 6e43713 | 2011-08-12 13:02:19 +0000 | [diff] [blame] | 5141 | % % |
| 5142 | % % |
| 5143 | % % |
| 5144 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5145 | % |
| 5146 | % SyncImagePixelCache() saves the image pixels to the in-memory or disk cache. |
| 5147 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5148 | % MagickFalse. |
| 5149 | % |
| 5150 | % The format of the SyncImagePixelCache() method is: |
| 5151 | % |
| 5152 | % MagickBooleanType SyncImagePixelCache(Image *image, |
| 5153 | % ExceptionInfo *exception) |
| 5154 | % |
| 5155 | % A description of each parameter follows: |
| 5156 | % |
| 5157 | % o image: the image. |
| 5158 | % |
| 5159 | % o exception: return any errors or warnings in this structure. |
| 5160 | % |
| 5161 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5162 | MagickPrivate MagickBooleanType SyncImagePixelCache(Image *image, |
cristy | 6e43713 | 2011-08-12 13:02:19 +0000 | [diff] [blame] | 5163 | ExceptionInfo *exception) |
| 5164 | { |
| 5165 | CacheInfo |
| 5166 | *cache_info; |
| 5167 | |
| 5168 | assert(image != (Image *) NULL); |
| 5169 | assert(exception != (ExceptionInfo *) NULL); |
| 5170 | cache_info=(CacheInfo *) GetImagePixelCache(image,MagickTrue,exception); |
| 5171 | return(cache_info == (CacheInfo *) NULL ? MagickFalse : MagickTrue); |
| 5172 | } |
| 5173 | |
| 5174 | /* |
| 5175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5176 | % % |
| 5177 | % % |
| 5178 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5179 | + W r i t e P i x e l C a c h e M e t a c o n t e n t % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5180 | % % |
| 5181 | % % |
| 5182 | % % |
| 5183 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5184 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5185 | % WritePixelCacheMetacontent() writes the meta-content to the specified region |
| 5186 | % of the pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5187 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5188 | % The format of the WritePixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5189 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5190 | % MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5191 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5192 | % |
| 5193 | % A description of each parameter follows: |
| 5194 | % |
| 5195 | % o cache_info: the pixel cache. |
| 5196 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5197 | % o nexus_info: the cache nexus to write the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5198 | % |
| 5199 | % o exception: return any errors or warnings in this structure. |
| 5200 | % |
| 5201 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5202 | static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5203 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5204 | { |
| 5205 | MagickOffsetType |
| 5206 | count, |
| 5207 | offset; |
| 5208 | |
| 5209 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5210 | extent, |
| 5211 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5212 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5213 | register const unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5214 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5215 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5216 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5217 | y; |
| 5218 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5219 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5220 | rows; |
| 5221 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5222 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5223 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5224 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5225 | return(MagickTrue); |
| 5226 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5227 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5228 | length=(MagickSizeType) nexus_info->region.width* |
| 5229 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5230 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5231 | extent=(MagickSizeType) length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5232 | p=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5233 | switch (cache_info->type) |
| 5234 | { |
| 5235 | case MemoryCache: |
| 5236 | case MapCache: |
| 5237 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5238 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5239 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5240 | |
| 5241 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5242 | Write associated pixels to memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5243 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5244 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5245 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5246 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5247 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5248 | rows=1UL; |
| 5249 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5250 | q=(unsigned char *) cache_info->metacontent+offset* |
| 5251 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5252 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5253 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5254 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5255 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
| 5256 | q+=cache_info->columns*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5257 | } |
| 5258 | break; |
| 5259 | } |
| 5260 | case DiskCache: |
| 5261 | { |
| 5262 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5263 | Write associated pixels to disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5264 | */ |
| 5265 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5266 | { |
| 5267 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5268 | cache_info->cache_filename); |
| 5269 | return(MagickFalse); |
| 5270 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5271 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5272 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5273 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5274 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5275 | rows=1UL; |
| 5276 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5277 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5278 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5279 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5280 | count=WritePixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5281 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5282 | cache_info->metacontent_extent,length,(const unsigned char *) p); |
| 5283 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5284 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5285 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5286 | offset+=cache_info->columns; |
| 5287 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 5288 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 5289 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5290 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5291 | { |
| 5292 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5293 | cache_info->cache_filename); |
| 5294 | return(MagickFalse); |
| 5295 | } |
| 5296 | break; |
| 5297 | } |
| 5298 | default: |
| 5299 | break; |
| 5300 | } |
| 5301 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5302 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5303 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5304 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5305 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5306 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5307 | return(MagickTrue); |
| 5308 | } |
| 5309 | |
| 5310 | /* |
| 5311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5312 | % % |
| 5313 | % % |
| 5314 | % % |
| 5315 | + W r i t e C a c h e P i x e l s % |
| 5316 | % % |
| 5317 | % % |
| 5318 | % % |
| 5319 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5320 | % |
| 5321 | % WritePixelCachePixels() writes image pixels to the specified region of the |
| 5322 | % pixel cache. |
| 5323 | % |
| 5324 | % The format of the WritePixelCachePixels() method is: |
| 5325 | % |
| 5326 | % MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5327 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5328 | % |
| 5329 | % A description of each parameter follows: |
| 5330 | % |
| 5331 | % o cache_info: the pixel cache. |
| 5332 | % |
| 5333 | % o nexus_info: the cache nexus to write the pixels. |
| 5334 | % |
| 5335 | % o exception: return any errors or warnings in this structure. |
| 5336 | % |
| 5337 | */ |
| 5338 | static MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5339 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5340 | { |
| 5341 | MagickOffsetType |
| 5342 | count, |
| 5343 | offset; |
| 5344 | |
| 5345 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5346 | extent, |
| 5347 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5348 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5349 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5350 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5351 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5352 | register ssize_t |
cristy | 25ffffb | 2009-12-07 17:15:07 +0000 | [diff] [blame] | 5353 | y; |
| 5354 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5355 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5356 | rows; |
| 5357 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5358 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5359 | return(MagickTrue); |
| 5360 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5361 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5362 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5363 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5364 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5365 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5366 | p=nexus_info->pixels; |
| 5367 | switch (cache_info->type) |
| 5368 | { |
| 5369 | case MemoryCache: |
| 5370 | case MapCache: |
| 5371 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5372 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5373 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5374 | |
| 5375 | /* |
| 5376 | Write pixels to memory. |
| 5377 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5378 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5379 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5380 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5381 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5382 | rows=1UL; |
| 5383 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5384 | q=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5385 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5386 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5387 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5388 | p+=nexus_info->region.width*cache_info->number_channels; |
| 5389 | q+=cache_info->columns*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5390 | } |
| 5391 | break; |
| 5392 | } |
| 5393 | case DiskCache: |
| 5394 | { |
| 5395 | /* |
| 5396 | Write pixels to disk. |
| 5397 | */ |
| 5398 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5399 | { |
| 5400 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5401 | cache_info->cache_filename); |
| 5402 | return(MagickFalse); |
| 5403 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5404 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5405 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5406 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5407 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5408 | rows=1UL; |
| 5409 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5410 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5411 | { |
| 5412 | count=WritePixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5413 | cache_info->number_channels*sizeof(*p),length,(const unsigned char *) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5414 | p); |
| 5415 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5416 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5417 | p+=nexus_info->region.width*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5418 | offset+=cache_info->columns; |
| 5419 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 5420 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 5421 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5422 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5423 | { |
| 5424 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5425 | cache_info->cache_filename); |
| 5426 | return(MagickFalse); |
| 5427 | } |
| 5428 | break; |
| 5429 | } |
| 5430 | default: |
| 5431 | break; |
| 5432 | } |
| 5433 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5434 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5435 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5436 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5437 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5438 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5439 | return(MagickTrue); |
| 5440 | } |