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" |
| 57 | #include "MagickCore/pixel.h" |
| 58 | #include "MagickCore/pixel-accessor.h" |
| 59 | #include "MagickCore/policy.h" |
| 60 | #include "MagickCore/quantum.h" |
| 61 | #include "MagickCore/random_.h" |
| 62 | #include "MagickCore/resource_.h" |
| 63 | #include "MagickCore/semaphore.h" |
| 64 | #include "MagickCore/splay-tree.h" |
| 65 | #include "MagickCore/string_.h" |
| 66 | #include "MagickCore/string-private.h" |
| 67 | #include "MagickCore/thread-private.h" |
| 68 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 69 | #include "MagickCore/utility-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | #if defined(MAGICKCORE_ZLIB_DELEGATE) |
| 71 | #include "zlib.h" |
| 72 | #endif |
| 73 | |
| 74 | /* |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 75 | Define declarations. |
| 76 | */ |
| 77 | #define CacheTick(offset,extent) QuantumTick((MagickOffsetType) offset,extent) |
| 78 | |
| 79 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | Typedef declarations. |
| 81 | */ |
| 82 | typedef struct _MagickModulo |
| 83 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 84 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | quotient, |
| 86 | remainder; |
| 87 | } MagickModulo; |
| 88 | |
| 89 | struct _NexusInfo |
| 90 | { |
| 91 | MagickBooleanType |
| 92 | mapped; |
| 93 | |
| 94 | RectangleInfo |
| 95 | region; |
| 96 | |
| 97 | MagickSizeType |
| 98 | length; |
| 99 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 100 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | *cache, |
| 102 | *pixels; |
| 103 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 104 | void |
| 105 | *metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 107 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | signature; |
| 109 | }; |
| 110 | |
| 111 | /* |
| 112 | Forward declarations. |
| 113 | */ |
| 114 | #if defined(__cplusplus) || defined(c_plusplus) |
| 115 | extern "C" { |
| 116 | #endif |
| 117 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 118 | static const Quantum |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 119 | *GetVirtualPixelCache(const Image *,const VirtualPixelMethod,const ssize_t, |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 120 | const ssize_t,const size_t,const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 121 | *GetVirtualPixelsCache(const Image *); |
| 122 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 123 | static const void |
| 124 | *GetVirtualMetacontentFromCache(const Image *); |
| 125 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 126 | static MagickBooleanType |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 127 | GetOneAuthenticPixelFromCache(Image *,const ssize_t,const ssize_t, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 128 | Quantum *,ExceptionInfo *), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 129 | GetOneVirtualPixelFromCache(const Image *,const VirtualPixelMethod, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 130 | const ssize_t,const ssize_t,Quantum *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | OpenPixelCache(Image *,const MapMode,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 132 | ReadPixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 133 | ReadPixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *), |
| 134 | SyncAuthenticPixelsCache(Image *,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 135 | WritePixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | WritePixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *); |
| 137 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 138 | static Quantum |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 139 | *GetAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 140 | const size_t,ExceptionInfo *), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 141 | *QueueAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 142 | const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | *SetPixelCacheNexusPixels(const Image *,const RectangleInfo *,NexusInfo *, |
cristy | a4af2e3 | 2010-03-08 00:51:56 +0000 | [diff] [blame] | 144 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | |
| 146 | #if defined(__cplusplus) || defined(c_plusplus) |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | /* |
| 151 | Global declarations. |
| 152 | */ |
| 153 | static volatile MagickBooleanType |
| 154 | instantiate_cache = MagickFalse; |
| 155 | |
| 156 | static SemaphoreInfo |
| 157 | *cache_semaphore = (SemaphoreInfo *) NULL; |
| 158 | |
| 159 | static SplayTreeInfo |
| 160 | *cache_resources = (SplayTreeInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 164 | % % |
| 165 | % % |
| 166 | % % |
| 167 | + A c q u i r e P i x e l C a c h e % |
| 168 | % % |
| 169 | % % |
| 170 | % % |
| 171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 172 | % |
| 173 | % AcquirePixelCache() acquires a pixel cache. |
| 174 | % |
| 175 | % The format of the AcquirePixelCache() method is: |
| 176 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 177 | % Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | % |
| 179 | % A description of each parameter follows: |
| 180 | % |
| 181 | % o number_threads: the number of nexus threads. |
| 182 | % |
| 183 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 184 | MagickPrivate Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | { |
| 186 | CacheInfo |
| 187 | *cache_info; |
| 188 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 189 | cache_info=(CacheInfo *) AcquireQuantumMemory(1,sizeof(*cache_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | if (cache_info == (CacheInfo *) NULL) |
| 191 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 192 | (void) ResetMagickMemory(cache_info,0,sizeof(*cache_info)); |
| 193 | cache_info->type=UndefinedCache; |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 194 | cache_info->mode=IOMode; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | cache_info->colorspace=RGBColorspace; |
| 196 | cache_info->file=(-1); |
| 197 | cache_info->id=GetMagickThreadId(); |
| 198 | cache_info->number_threads=number_threads; |
| 199 | if (number_threads == 0) |
| 200 | cache_info->number_threads=GetOpenMPMaximumThreads(); |
| 201 | cache_info->nexus_info=AcquirePixelCacheNexus(cache_info->number_threads); |
| 202 | if (cache_info->nexus_info == (NexusInfo **) NULL) |
| 203 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | cache_info->semaphore=AllocateSemaphoreInfo(); |
cristy | 93505cf | 2010-08-10 21:37:49 +0000 | [diff] [blame] | 205 | cache_info->reference_count=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | cache_info->disk_semaphore=AllocateSemaphoreInfo(); |
| 207 | cache_info->debug=IsEventLogging(); |
| 208 | cache_info->signature=MagickSignature; |
| 209 | if ((cache_resources == (SplayTreeInfo *) NULL) && |
| 210 | (instantiate_cache == MagickFalse)) |
| 211 | { |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 212 | if (cache_semaphore == (SemaphoreInfo *) NULL) |
| 213 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 214 | LockSemaphoreInfo(cache_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | if ((cache_resources == (SplayTreeInfo *) NULL) && |
| 216 | (instantiate_cache == MagickFalse)) |
| 217 | { |
| 218 | cache_resources=NewSplayTree((int (*)(const void *,const void *)) |
| 219 | NULL,(void *(*)(void *)) NULL,(void *(*)(void *)) NULL); |
| 220 | instantiate_cache=MagickTrue; |
| 221 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 222 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | } |
| 224 | (void) AddValueToSplayTree(cache_resources,cache_info,cache_info); |
| 225 | return((Cache ) cache_info); |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 230 | % % |
| 231 | % % |
| 232 | % % |
| 233 | % A c q u i r e P i x e l C a c h e N e x u s % |
| 234 | % % |
| 235 | % % |
| 236 | % % |
| 237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 238 | % |
| 239 | % AcquirePixelCacheNexus() allocates the NexusInfo structure. |
| 240 | % |
| 241 | % The format of the AcquirePixelCacheNexus method is: |
| 242 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 243 | % NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 244 | % |
| 245 | % A description of each parameter follows: |
| 246 | % |
| 247 | % o number_threads: the number of nexus threads. |
| 248 | % |
| 249 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 250 | MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | NexusInfo |
| 253 | **nexus_info; |
| 254 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 255 | register ssize_t |
| 256 | i; |
| 257 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 258 | nexus_info=(NexusInfo **) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 259 | sizeof(*nexus_info)); |
| 260 | if (nexus_info == (NexusInfo **) NULL) |
| 261 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 262 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | { |
cristy | 6a924af | 2010-09-23 14:02:54 +0000 | [diff] [blame] | 264 | nexus_info[i]=(NexusInfo *) AcquireAlignedMemory(1,sizeof(**nexus_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | if (nexus_info[i] == (NexusInfo *) NULL) |
| 266 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 267 | (void) ResetMagickMemory(nexus_info[i],0,sizeof(*nexus_info[i])); |
| 268 | nexus_info[i]->signature=MagickSignature; |
| 269 | } |
| 270 | return(nexus_info); |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 275 | % % |
| 276 | % % |
| 277 | % % |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 278 | + A c q u i r e P i x e l C a c h e P i x e l s % |
| 279 | % % |
| 280 | % % |
| 281 | % % |
| 282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 283 | % |
| 284 | % AcquirePixelCachePixels() returns the pixels associated with the specified |
| 285 | % image. |
| 286 | % |
| 287 | % The format of the AcquirePixelCachePixels() method is: |
| 288 | % |
| 289 | % const void *AcquirePixelCachePixels(const Image *image, |
| 290 | % MagickSizeType *length,ExceptionInfo *exception) |
| 291 | % |
| 292 | % A description of each parameter follows: |
| 293 | % |
| 294 | % o image: the image. |
| 295 | % |
| 296 | % o length: the pixel cache length. |
| 297 | % |
| 298 | % o exception: return any errors or warnings in this structure. |
| 299 | % |
| 300 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 301 | MagickPrivate const void *AcquirePixelCachePixels(const Image *image, |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 302 | MagickSizeType *length,ExceptionInfo *exception) |
| 303 | { |
| 304 | CacheInfo |
| 305 | *cache_info; |
| 306 | |
| 307 | assert(image != (const Image *) NULL); |
| 308 | assert(image->signature == MagickSignature); |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 309 | assert(exception != (ExceptionInfo *) NULL); |
| 310 | assert(exception->signature == MagickSignature); |
| 311 | assert(image->cache != (Cache) NULL); |
| 312 | cache_info=(CacheInfo *) image->cache; |
| 313 | assert(cache_info->signature == MagickSignature); |
| 314 | *length=0; |
| 315 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
| 316 | return((const void *) NULL); |
| 317 | *length=cache_info->length; |
| 318 | return((const void *) cache_info->pixels); |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 323 | % % |
| 324 | % % |
| 325 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 326 | + C a c h e C o m p o n e n t G e n e s i s % |
| 327 | % % |
| 328 | % % |
| 329 | % % |
| 330 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 331 | % |
| 332 | % CacheComponentGenesis() instantiates the cache component. |
| 333 | % |
| 334 | % The format of the CacheComponentGenesis method is: |
| 335 | % |
| 336 | % MagickBooleanType CacheComponentGenesis(void) |
| 337 | % |
| 338 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 339 | MagickPrivate MagickBooleanType CacheComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 340 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 341 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 342 | return(MagickTrue); |
| 343 | } |
| 344 | |
| 345 | /* |
| 346 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 347 | % % |
| 348 | % % |
| 349 | % % |
| 350 | + C a c h e C o m p o n e n t T e r m i n u s % |
| 351 | % % |
| 352 | % % |
| 353 | % % |
| 354 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 355 | % |
| 356 | % CacheComponentTerminus() destroys the cache component. |
| 357 | % |
| 358 | % The format of the CacheComponentTerminus() method is: |
| 359 | % |
| 360 | % CacheComponentTerminus(void) |
| 361 | % |
| 362 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 363 | MagickPrivate void CacheComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 364 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 365 | if (cache_semaphore == (SemaphoreInfo *) NULL) |
| 366 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 367 | LockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 368 | if (cache_resources != (SplayTreeInfo *) NULL) |
| 369 | cache_resources=DestroySplayTree(cache_resources); |
| 370 | instantiate_cache=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 371 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 372 | DestroySemaphoreInfo(&cache_semaphore); |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 377 | % % |
| 378 | % % |
| 379 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 380 | + C l i p P i x e l C a c h e N e x u s % |
| 381 | % % |
| 382 | % % |
| 383 | % % |
| 384 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 385 | % |
| 386 | % ClipPixelCacheNexus() clips the cache nexus as defined by the image clip |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 387 | % mask. It returns MagickTrue if the pixel region is clipped, otherwise |
| 388 | % MagickFalse. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 389 | % |
| 390 | % The format of the ClipPixelCacheNexus() method is: |
| 391 | % |
| 392 | % MagickBooleanType ClipPixelCacheNexus(Image *image,NexusInfo *nexus_info, |
| 393 | % ExceptionInfo *exception) |
| 394 | % |
| 395 | % A description of each parameter follows: |
| 396 | % |
| 397 | % o image: the image. |
| 398 | % |
| 399 | % o nexus_info: the cache nexus to clip. |
| 400 | % |
| 401 | % o exception: return any errors or warnings in this structure. |
| 402 | % |
| 403 | */ |
| 404 | static MagickBooleanType ClipPixelCacheNexus(Image *image, |
| 405 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 406 | { |
| 407 | CacheInfo |
| 408 | *cache_info; |
| 409 | |
| 410 | MagickSizeType |
| 411 | number_pixels; |
| 412 | |
| 413 | NexusInfo |
| 414 | **clip_nexus, |
| 415 | **image_nexus; |
| 416 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 417 | register const Quantum |
| 418 | *restrict p, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 419 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 420 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 421 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 422 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 423 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 424 | register ssize_t |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 425 | x; |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 426 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 427 | /* |
| 428 | Apply clip mask. |
| 429 | */ |
| 430 | if (image->debug != MagickFalse) |
| 431 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 432 | if (image->clip_mask == (Image *) NULL) |
| 433 | return(MagickFalse); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 434 | cache_info=(CacheInfo *) image->cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 435 | if (cache_info == (Cache) NULL) |
| 436 | return(MagickFalse); |
| 437 | image_nexus=AcquirePixelCacheNexus(1); |
| 438 | clip_nexus=AcquirePixelCacheNexus(1); |
| 439 | if ((image_nexus == (NexusInfo **) NULL) || |
| 440 | (clip_nexus == (NexusInfo **) NULL)) |
| 441 | ThrowBinaryException(CacheError,"UnableToGetCacheNexus",image->filename); |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 442 | p=(const Quantum *) GetAuthenticPixelCacheNexus(image,nexus_info->region.x, |
| 443 | nexus_info->region.y,nexus_info->region.width,nexus_info->region.height, |
| 444 | image_nexus[0],exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 445 | q=nexus_info->pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | r=GetVirtualPixelsFromNexus(image->clip_mask,MaskVirtualPixelMethod, |
| 447 | nexus_info->region.x,nexus_info->region.y,nexus_info->region.width, |
| 448 | nexus_info->region.height,clip_nexus[0],exception); |
| 449 | number_pixels=(MagickSizeType) nexus_info->region.width* |
| 450 | nexus_info->region.height; |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 451 | for (x=0; x < (ssize_t) number_pixels; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | { |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 453 | register ssize_t |
| 454 | i; |
| 455 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 456 | if ((p == (const Quantum *) NULL) || (r == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | break; |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 458 | if (GetPixelIntensity(image->clip_mask,r) > ((Quantum) QuantumRange/2)) |
| 459 | for (i=0; i < (ssize_t) image->number_channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | { |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 461 | PixelChannel |
| 462 | channel; |
| 463 | |
| 464 | PixelTrait |
| 465 | traits; |
| 466 | |
| 467 | channel=GetPixelChannelMapChannel(image,i); |
| 468 | traits=GetPixelChannelMapTraits(image,channel); |
| 469 | if (traits != UndefinedPixelTrait) |
| 470 | q[i]=p[i]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 471 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 472 | p+=GetPixelChannels(image); |
| 473 | q+=GetPixelChannels(image); |
| 474 | r+=GetPixelChannels(image->clip_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | } |
| 476 | clip_nexus=DestroyPixelCacheNexus(clip_nexus,1); |
| 477 | image_nexus=DestroyPixelCacheNexus(image_nexus,1); |
cristy | 1200611 | 2012-01-02 17:06:42 +0000 | [diff] [blame^] | 478 | if (x < (ssize_t) number_pixels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | return(MagickFalse); |
| 480 | return(MagickTrue); |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 485 | % % |
| 486 | % % |
| 487 | % % |
| 488 | + C l o n e P i x e l C a c h e % |
| 489 | % % |
| 490 | % % |
| 491 | % % |
| 492 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 493 | % |
| 494 | % ClonePixelCache() clones a pixel cache. |
| 495 | % |
| 496 | % The format of the ClonePixelCache() method is: |
| 497 | % |
| 498 | % Cache ClonePixelCache(const Cache cache) |
| 499 | % |
| 500 | % A description of each parameter follows: |
| 501 | % |
| 502 | % o cache: the pixel cache. |
| 503 | % |
| 504 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 505 | MagickPrivate Cache ClonePixelCache(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 506 | { |
| 507 | CacheInfo |
| 508 | *clone_info; |
| 509 | |
| 510 | const CacheInfo |
| 511 | *cache_info; |
| 512 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 513 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 514 | cache_info=(const CacheInfo *) cache; |
| 515 | assert(cache_info->signature == MagickSignature); |
| 516 | if (cache_info->debug != MagickFalse) |
| 517 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 518 | cache_info->filename); |
| 519 | clone_info=(CacheInfo *) AcquirePixelCache(cache_info->number_threads); |
| 520 | if (clone_info == (Cache) NULL) |
| 521 | return((Cache) NULL); |
| 522 | clone_info->virtual_pixel_method=cache_info->virtual_pixel_method; |
| 523 | return((Cache ) clone_info); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 528 | % % |
| 529 | % % |
| 530 | % % |
cristy | 60c44a8 | 2009-10-07 00:58:49 +0000 | [diff] [blame] | 531 | + 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] | 532 | % % |
| 533 | % % |
| 534 | % % |
| 535 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % |
| 536 | % ClonePixelCachePixels() clones the source pixel cache to the destination |
| 537 | % cache. |
| 538 | % |
| 539 | % The format of the ClonePixelCachePixels() method is: |
| 540 | % |
| 541 | % MagickBooleanType ClonePixelCachePixels(CacheInfo *cache_info, |
| 542 | % CacheInfo *source_info,ExceptionInfo *exception) |
| 543 | % |
| 544 | % A description of each parameter follows: |
| 545 | % |
| 546 | % o cache_info: the pixel cache. |
| 547 | % |
| 548 | % o source_info: the source pixel cache. |
| 549 | % |
| 550 | % o exception: return any errors or warnings in this structure. |
| 551 | % |
| 552 | */ |
| 553 | |
| 554 | static MagickBooleanType ClosePixelCacheOnDisk(CacheInfo *cache_info) |
| 555 | { |
| 556 | int |
| 557 | status; |
| 558 | |
cristy | 5ee247a | 2010-02-12 15:42:34 +0000 | [diff] [blame] | 559 | status=(-1); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 560 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 508d931 | 2010-02-10 21:10:30 +0000 | [diff] [blame] | 561 | if (cache_info->file != -1) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 562 | { |
| 563 | status=close(cache_info->file); |
| 564 | cache_info->file=(-1); |
| 565 | RelinquishMagickResource(FileResource,1); |
| 566 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 567 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | return(status == -1 ? MagickFalse : MagickTrue); |
| 569 | } |
| 570 | |
| 571 | static void LimitPixelCacheDescriptors(void) |
| 572 | { |
| 573 | register CacheInfo |
| 574 | *p, |
| 575 | *q; |
| 576 | |
| 577 | /* |
| 578 | Limit # of open file descriptors. |
| 579 | */ |
| 580 | if (GetMagickResource(FileResource) < GetMagickResourceLimit(FileResource)) |
| 581 | return; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 582 | LockSemaphoreInfo(cache_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 583 | if (cache_resources == (SplayTreeInfo *) NULL) |
| 584 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 585 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 586 | return; |
| 587 | } |
| 588 | ResetSplayTreeIterator(cache_resources); |
| 589 | p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); |
| 590 | while (p != (CacheInfo *) NULL) |
| 591 | { |
| 592 | if ((p->type == DiskCache) && (p->file != -1)) |
cristy | 508d931 | 2010-02-10 21:10:30 +0000 | [diff] [blame] | 593 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 594 | p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); |
| 595 | } |
| 596 | for (q=p; p != (CacheInfo *) NULL; ) |
| 597 | { |
| 598 | if ((p->type == DiskCache) && (p->file != -1) && |
| 599 | (p->timestamp < q->timestamp)) |
cristy | 508d931 | 2010-02-10 21:10:30 +0000 | [diff] [blame] | 600 | q=p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 601 | p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); |
| 602 | } |
| 603 | if (q != (CacheInfo *) NULL) |
cristy | 9e11692 | 2010-02-12 20:58:13 +0000 | [diff] [blame] | 604 | { |
| 605 | /* |
| 606 | Close least recently used cache. |
| 607 | */ |
| 608 | (void) close(q->file); |
| 609 | q->file=(-1); |
| 610 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 611 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static inline MagickSizeType MagickMax(const MagickSizeType x, |
| 615 | const MagickSizeType y) |
| 616 | { |
| 617 | if (x > y) |
| 618 | return(x); |
| 619 | return(y); |
| 620 | } |
| 621 | |
| 622 | static inline MagickSizeType MagickMin(const MagickSizeType x, |
| 623 | const MagickSizeType y) |
| 624 | { |
| 625 | if (x < y) |
| 626 | return(x); |
| 627 | return(y); |
| 628 | } |
| 629 | |
| 630 | static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info, |
| 631 | const MapMode mode) |
| 632 | { |
| 633 | int |
| 634 | file; |
| 635 | |
| 636 | /* |
| 637 | Open pixel cache on disk. |
| 638 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 639 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | if (cache_info->file != -1) |
| 641 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 642 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 643 | return(MagickTrue); /* cache already open */ |
| 644 | } |
| 645 | LimitPixelCacheDescriptors(); |
| 646 | if (*cache_info->cache_filename == '\0') |
| 647 | file=AcquireUniqueFileResource(cache_info->cache_filename); |
| 648 | else |
| 649 | switch (mode) |
| 650 | { |
| 651 | case ReadMode: |
| 652 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 653 | file=open_utf8(cache_info->cache_filename,O_RDONLY | O_BINARY,0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 654 | break; |
| 655 | } |
| 656 | case WriteMode: |
| 657 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 658 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_CREAT | |
| 659 | O_BINARY | O_EXCL,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 661 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | case IOMode: |
| 665 | default: |
| 666 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 667 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_CREAT | O_BINARY | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | O_EXCL,S_MODE); |
| 669 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 670 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 671 | break; |
| 672 | } |
| 673 | } |
| 674 | if (file == -1) |
| 675 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 676 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 677 | return(MagickFalse); |
| 678 | } |
| 679 | (void) AcquireMagickResource(FileResource,1); |
| 680 | cache_info->file=file; |
cristy | 4d9c192 | 2011-12-31 18:37:34 +0000 | [diff] [blame] | 681 | cache_info->mode=mode; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 682 | cache_info->timestamp=time(0); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 683 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 684 | return(MagickTrue); |
| 685 | } |
| 686 | |
| 687 | static inline MagickOffsetType ReadPixelCacheRegion(CacheInfo *cache_info, |
| 688 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 689 | unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 690 | { |
| 691 | register MagickOffsetType |
| 692 | i; |
| 693 | |
| 694 | ssize_t |
| 695 | count; |
| 696 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 697 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 698 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 699 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 700 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 701 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 702 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 703 | return((MagickOffsetType) -1); |
| 704 | } |
| 705 | #endif |
| 706 | count=0; |
| 707 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 708 | { |
| 709 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| 710 | count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 711 | (MagickSizeType) SSIZE_MAX)); |
| 712 | #else |
| 713 | count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 714 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 715 | #endif |
| 716 | if (count > 0) |
| 717 | continue; |
| 718 | count=0; |
| 719 | if (errno != EINTR) |
| 720 | { |
| 721 | i=(-1); |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 726 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 727 | #endif |
| 728 | return(i); |
| 729 | } |
| 730 | |
| 731 | static inline MagickOffsetType WritePixelCacheRegion(CacheInfo *cache_info, |
| 732 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 733 | const unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 734 | { |
| 735 | register MagickOffsetType |
| 736 | i; |
| 737 | |
| 738 | ssize_t |
| 739 | count; |
| 740 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 741 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 742 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 743 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 744 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 745 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 746 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | return((MagickOffsetType) -1); |
| 748 | } |
| 749 | #endif |
| 750 | count=0; |
| 751 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 752 | { |
| 753 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| 754 | count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 755 | (MagickSizeType) SSIZE_MAX)); |
| 756 | #else |
| 757 | count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 758 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 759 | #endif |
| 760 | if (count > 0) |
| 761 | continue; |
| 762 | count=0; |
| 763 | if (errno != EINTR) |
| 764 | { |
| 765 | i=(-1); |
| 766 | break; |
| 767 | } |
| 768 | } |
| 769 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 770 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 771 | #endif |
| 772 | return(i); |
| 773 | } |
| 774 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 775 | static MagickBooleanType DiskToDiskPixelCacheClone(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 776 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 777 | { |
| 778 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 779 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 780 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 781 | register MagickOffsetType |
| 782 | i; |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 783 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 784 | size_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 785 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 786 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 787 | unsigned char |
| 788 | *blob; |
| 789 | |
| 790 | /* |
| 791 | Clone pixel cache (both caches on disk). |
| 792 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 793 | if (cache_info->debug != MagickFalse) |
| 794 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 795 | blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 796 | sizeof(*blob)); |
| 797 | if (blob == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 798 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 799 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 800 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 801 | cache_info->filename); |
| 802 | return(MagickFalse); |
| 803 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 804 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 805 | { |
| 806 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 807 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 808 | cache_info->cache_filename); |
| 809 | return(MagickFalse); |
| 810 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 811 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 812 | { |
| 813 | (void) ClosePixelCacheOnDisk(cache_info); |
| 814 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 815 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 816 | clone_info->cache_filename); |
| 817 | return(MagickFalse); |
| 818 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 819 | count=0; |
| 820 | for (i=0; i < (MagickOffsetType) cache_info->length; i+=count) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 821 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 822 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+i, |
| 823 | MagickMin(cache_info->length-i,(MagickSizeType) MagickMaxBufferExtent), |
| 824 | blob); |
| 825 | if (count <= 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 826 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 827 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 828 | cache_info->cache_filename); |
| 829 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 830 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 831 | length=(size_t) count; |
| 832 | count=WritePixelCacheRegion(clone_info,clone_info->offset+i,length,blob); |
| 833 | if ((MagickSizeType) count != length) |
| 834 | { |
| 835 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 836 | clone_info->cache_filename); |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | (void) ClosePixelCacheOnDisk(clone_info); |
| 841 | (void) ClosePixelCacheOnDisk(cache_info); |
| 842 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 843 | if (i < (MagickOffsetType) cache_info->length) |
| 844 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | return(MagickTrue); |
| 846 | } |
| 847 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 848 | static MagickBooleanType PixelCacheCloneOptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 849 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 850 | { |
| 851 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 852 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 853 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 854 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 855 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 856 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 857 | Clone pixel cache (both caches in memory). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 859 | if (cache_info->debug != MagickFalse) |
| 860 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 861 | (void) memcpy(clone_info->pixels,cache_info->pixels,(size_t) |
| 862 | cache_info->length); |
| 863 | return(MagickTrue); |
| 864 | } |
| 865 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 866 | { |
| 867 | /* |
| 868 | Clone pixel cache (one cache on disk, one in memory). |
| 869 | */ |
| 870 | if (cache_info->debug != MagickFalse) |
| 871 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 872 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 873 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 874 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 875 | cache_info->cache_filename); |
| 876 | return(MagickFalse); |
| 877 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 878 | count=ReadPixelCacheRegion(cache_info,cache_info->offset, |
| 879 | cache_info->length,(unsigned char *) clone_info->pixels); |
| 880 | (void) ClosePixelCacheOnDisk(cache_info); |
| 881 | if ((MagickSizeType) count != cache_info->length) |
| 882 | { |
| 883 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 884 | cache_info->cache_filename); |
| 885 | return(MagickFalse); |
| 886 | } |
| 887 | return(MagickTrue); |
| 888 | } |
| 889 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 890 | { |
| 891 | /* |
| 892 | Clone pixel cache (one cache on disk, one in memory). |
| 893 | */ |
| 894 | if (clone_info->debug != MagickFalse) |
| 895 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 896 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
| 897 | { |
| 898 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 899 | clone_info->cache_filename); |
| 900 | return(MagickFalse); |
| 901 | } |
| 902 | count=WritePixelCacheRegion(clone_info,clone_info->offset, |
| 903 | clone_info->length,(unsigned char *) cache_info->pixels); |
| 904 | (void) ClosePixelCacheOnDisk(clone_info); |
| 905 | if ((MagickSizeType) count != clone_info->length) |
| 906 | { |
| 907 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 908 | clone_info->cache_filename); |
| 909 | return(MagickFalse); |
| 910 | } |
| 911 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 912 | } |
| 913 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 914 | Clone pixel cache (both caches on disk). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 915 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 916 | return(DiskToDiskPixelCacheClone(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 917 | } |
| 918 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 919 | static MagickBooleanType PixelCacheCloneUnoptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 920 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 921 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 922 | MagickBooleanType |
| 923 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 924 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 925 | MagickOffsetType |
| 926 | cache_offset, |
| 927 | clone_offset, |
| 928 | count; |
| 929 | |
| 930 | register ssize_t |
| 931 | x; |
| 932 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 933 | register unsigned char |
| 934 | *p; |
| 935 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 936 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 937 | length; |
| 938 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 939 | ssize_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 940 | y; |
| 941 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 942 | unsigned char |
| 943 | *blob; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 944 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 945 | /* |
| 946 | Clone pixel cache (unoptimized). |
| 947 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 948 | if (cache_info->debug != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 949 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 950 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
| 951 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 952 | else |
| 953 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 954 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 955 | else |
| 956 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 957 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 958 | else |
| 959 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
| 960 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 961 | length=(size_t) MagickMax(MagickMax(cache_info->number_channels, |
| 962 | clone_info->number_channels)*sizeof(Quantum),MagickMax( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 963 | cache_info->metacontent_extent,clone_info->metacontent_extent)); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 964 | blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(*blob)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 965 | if (blob == (unsigned char *) NULL) |
| 966 | { |
| 967 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 968 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 969 | cache_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 970 | return(MagickFalse); |
| 971 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 972 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 973 | cache_offset=0; |
| 974 | clone_offset=0; |
| 975 | if (cache_info->type == DiskCache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 976 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 977 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 978 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 979 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 980 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 981 | cache_info->cache_filename); |
| 982 | return(MagickFalse); |
| 983 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 984 | cache_offset=cache_info->offset; |
| 985 | } |
| 986 | if (clone_info->type == DiskCache) |
| 987 | { |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 988 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 989 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 990 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 991 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 992 | clone_info->cache_filename); |
| 993 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 994 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 995 | clone_offset=clone_info->offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 996 | } |
| 997 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 998 | Clone pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 999 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1000 | status=MagickTrue; |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1001 | p=blob; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1002 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1003 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1004 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1005 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1006 | register ssize_t |
| 1007 | i; |
| 1008 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1009 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1010 | Read a set of pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1011 | */ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1012 | length=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1013 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1014 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1015 | else |
| 1016 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1017 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1018 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1020 | status=MagickFalse; |
| 1021 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1022 | } |
| 1023 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1024 | cache_offset+=length; |
| 1025 | if ((y < (ssize_t) clone_info->rows) && |
| 1026 | (x < (ssize_t) clone_info->columns)) |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1027 | for (i=0; i < (ssize_t) clone_info->number_channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1028 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1029 | PixelChannel |
| 1030 | channel; |
| 1031 | |
| 1032 | PixelTrait |
| 1033 | traits; |
| 1034 | |
| 1035 | ssize_t |
| 1036 | offset; |
| 1037 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1038 | /* |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 1039 | Write a set of pixel channels. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1040 | */ |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1041 | channel=clone_info->channel_map[i].channel; |
| 1042 | traits=cache_info->channel_map[channel].traits; |
| 1043 | if (traits == UndefinedPixelTrait) |
| 1044 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 1045 | clone_offset+=sizeof(Quantum); |
| 1046 | continue; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1047 | } |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 1048 | offset=cache_info->channel_map[channel].offset; |
| 1049 | if (clone_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1050 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,p+ |
| 1051 | offset*sizeof(Quantum),sizeof(Quantum)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1052 | else |
| 1053 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 1054 | count=WritePixelCacheRegion(clone_info,clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1055 | sizeof(Quantum),p+offset*sizeof(Quantum)); |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 1056 | if ((MagickSizeType) count != sizeof(Quantum)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1057 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 1058 | status=MagickFalse; |
| 1059 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1062 | clone_offset+=sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1063 | } |
| 1064 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1065 | length=clone_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1066 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1067 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 1068 | { |
| 1069 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1070 | Set remaining columns as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1071 | */ |
| 1072 | if (clone_info->type != DiskCache) |
| 1073 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,blob, |
| 1074 | length); |
| 1075 | else |
| 1076 | { |
| 1077 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 1078 | if ((MagickSizeType) count != length) |
| 1079 | { |
| 1080 | status=MagickFalse; |
| 1081 | break; |
| 1082 | } |
| 1083 | } |
| 1084 | clone_offset+=length; |
| 1085 | } |
| 1086 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1087 | length=clone_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1088 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1089 | for ( ; y < (ssize_t) clone_info->rows; y++) |
| 1090 | { |
| 1091 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1092 | Set remaining rows as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1093 | */ |
| 1094 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 1095 | { |
| 1096 | if (clone_info->type != DiskCache) |
| 1097 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,blob, |
| 1098 | length); |
| 1099 | else |
| 1100 | { |
| 1101 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 1102 | if ((MagickSizeType) count != length) |
| 1103 | { |
| 1104 | status=MagickFalse; |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | clone_offset+=length; |
| 1109 | } |
| 1110 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1111 | if ((cache_info->metacontent_extent != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1112 | (clone_info->metacontent_extent != 0)) |
| 1113 | { |
| 1114 | /* |
| 1115 | Clone metacontent. |
| 1116 | */ |
| 1117 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
| 1118 | { |
| 1119 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
| 1120 | { |
| 1121 | /* |
| 1122 | Read a set of metacontent. |
| 1123 | */ |
| 1124 | length=cache_info->metacontent_extent; |
| 1125 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1126 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1127 | else |
| 1128 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1129 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1130 | if ((MagickSizeType) count != length) |
| 1131 | { |
| 1132 | status=MagickFalse; |
| 1133 | break; |
| 1134 | } |
| 1135 | } |
| 1136 | cache_offset+=length; |
| 1137 | if ((y < (ssize_t) clone_info->rows) && |
| 1138 | (x < (ssize_t) clone_info->columns)) |
| 1139 | { |
| 1140 | /* |
| 1141 | Write a set of metacontent. |
| 1142 | */ |
| 1143 | length=clone_info->metacontent_extent; |
| 1144 | if (clone_info->type != DiskCache) |
| 1145 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1146 | p,length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1147 | else |
| 1148 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1149 | count=WritePixelCacheRegion(clone_info,clone_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1150 | if ((MagickSizeType) count != length) |
| 1151 | { |
| 1152 | status=MagickFalse; |
| 1153 | break; |
| 1154 | } |
| 1155 | } |
| 1156 | clone_offset+=length; |
| 1157 | } |
| 1158 | } |
| 1159 | length=clone_info->metacontent_extent; |
| 1160 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1161 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 1162 | { |
| 1163 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1164 | Set remaining columns as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1165 | */ |
| 1166 | if (clone_info->type != DiskCache) |
| 1167 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 1168 | blob,length); |
| 1169 | else |
| 1170 | { |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1171 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1172 | if ((MagickSizeType) count != length) |
| 1173 | { |
| 1174 | status=MagickFalse; |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | clone_offset+=length; |
| 1179 | } |
| 1180 | } |
| 1181 | length=clone_info->metacontent_extent; |
| 1182 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1183 | for ( ; y < (ssize_t) clone_info->rows; y++) |
| 1184 | { |
| 1185 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1186 | Set remaining rows as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1187 | */ |
| 1188 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 1189 | { |
| 1190 | if (clone_info->type != DiskCache) |
| 1191 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 1192 | blob,length); |
| 1193 | else |
| 1194 | { |
| 1195 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 1196 | if ((MagickSizeType) count != length) |
| 1197 | { |
| 1198 | status=MagickFalse; |
| 1199 | break; |
| 1200 | } |
| 1201 | } |
| 1202 | clone_offset+=length; |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | if (clone_info->type == DiskCache) |
| 1207 | (void) ClosePixelCacheOnDisk(clone_info); |
| 1208 | if (cache_info->type == DiskCache) |
| 1209 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1210 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 1211 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | static MagickBooleanType ClonePixelCachePixels(CacheInfo *clone_info, |
| 1215 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 1216 | { |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1217 | PixelChannelMap |
| 1218 | *p, |
| 1219 | *q; |
| 1220 | |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 1221 | if (cache_info->type == PingCache) |
| 1222 | return(MagickTrue); |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1223 | p=cache_info->channel_map; |
| 1224 | q=clone_info->channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1225 | if ((cache_info->columns == clone_info->columns) && |
| 1226 | (cache_info->rows == clone_info->rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1227 | (cache_info->number_channels == clone_info->number_channels) && |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1228 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1229 | (cache_info->metacontent_extent == clone_info->metacontent_extent)) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1230 | return(PixelCacheCloneOptimized(clone_info,cache_info,exception)); |
| 1231 | return(PixelCacheCloneUnoptimized(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | /* |
| 1235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1236 | % % |
| 1237 | % % |
| 1238 | % % |
| 1239 | + C l o n e P i x e l C a c h e M e t h o d s % |
| 1240 | % % |
| 1241 | % % |
| 1242 | % % |
| 1243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1244 | % |
| 1245 | % ClonePixelCacheMethods() clones the pixel cache methods from one cache to |
| 1246 | % another. |
| 1247 | % |
| 1248 | % The format of the ClonePixelCacheMethods() method is: |
| 1249 | % |
| 1250 | % void ClonePixelCacheMethods(Cache clone,const Cache cache) |
| 1251 | % |
| 1252 | % A description of each parameter follows: |
| 1253 | % |
| 1254 | % o clone: Specifies a pointer to a Cache structure. |
| 1255 | % |
| 1256 | % o cache: the pixel cache. |
| 1257 | % |
| 1258 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1259 | MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1260 | { |
| 1261 | CacheInfo |
| 1262 | *cache_info, |
| 1263 | *source_info; |
| 1264 | |
| 1265 | assert(clone != (Cache) NULL); |
| 1266 | source_info=(CacheInfo *) clone; |
| 1267 | assert(source_info->signature == MagickSignature); |
| 1268 | if (source_info->debug != MagickFalse) |
| 1269 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1270 | source_info->filename); |
| 1271 | assert(cache != (Cache) NULL); |
| 1272 | cache_info=(CacheInfo *) cache; |
| 1273 | assert(cache_info->signature == MagickSignature); |
| 1274 | source_info->methods=cache_info->methods; |
| 1275 | } |
| 1276 | |
| 1277 | /* |
| 1278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1279 | % % |
| 1280 | % % |
| 1281 | % % |
| 1282 | + D e s t r o y I m a g e P i x e l C a c h e % |
| 1283 | % % |
| 1284 | % % |
| 1285 | % % |
| 1286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1287 | % |
| 1288 | % DestroyImagePixelCache() deallocates memory associated with the pixel cache. |
| 1289 | % |
| 1290 | % The format of the DestroyImagePixelCache() method is: |
| 1291 | % |
| 1292 | % void DestroyImagePixelCache(Image *image) |
| 1293 | % |
| 1294 | % A description of each parameter follows: |
| 1295 | % |
| 1296 | % o image: the image. |
| 1297 | % |
| 1298 | */ |
| 1299 | static void DestroyImagePixelCache(Image *image) |
| 1300 | { |
| 1301 | assert(image != (Image *) NULL); |
| 1302 | assert(image->signature == MagickSignature); |
| 1303 | if (image->debug != MagickFalse) |
| 1304 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1305 | if (image->cache == (void *) NULL) |
| 1306 | return; |
| 1307 | image->cache=DestroyPixelCache(image->cache); |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1312 | % % |
| 1313 | % % |
| 1314 | % % |
| 1315 | + D e s t r o y I m a g e P i x e l s % |
| 1316 | % % |
| 1317 | % % |
| 1318 | % % |
| 1319 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1320 | % |
| 1321 | % DestroyImagePixels() deallocates memory associated with the pixel cache. |
| 1322 | % |
| 1323 | % The format of the DestroyImagePixels() method is: |
| 1324 | % |
| 1325 | % void DestroyImagePixels(Image *image) |
| 1326 | % |
| 1327 | % A description of each parameter follows: |
| 1328 | % |
| 1329 | % o image: the image. |
| 1330 | % |
| 1331 | */ |
| 1332 | MagickExport void DestroyImagePixels(Image *image) |
| 1333 | { |
| 1334 | CacheInfo |
| 1335 | *cache_info; |
| 1336 | |
| 1337 | assert(image != (const Image *) NULL); |
| 1338 | assert(image->signature == MagickSignature); |
| 1339 | if (image->debug != MagickFalse) |
| 1340 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1341 | assert(image->cache != (Cache) NULL); |
| 1342 | cache_info=(CacheInfo *) image->cache; |
| 1343 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1344 | if (cache_info->methods.destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 1345 | { |
| 1346 | cache_info->methods.destroy_pixel_handler(image); |
| 1347 | return; |
| 1348 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1349 | image->cache=DestroyPixelCache(image->cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | /* |
| 1353 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1354 | % % |
| 1355 | % % |
| 1356 | % % |
| 1357 | + D e s t r o y P i x e l C a c h e % |
| 1358 | % % |
| 1359 | % % |
| 1360 | % % |
| 1361 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1362 | % |
| 1363 | % DestroyPixelCache() deallocates memory associated with the pixel cache. |
| 1364 | % |
| 1365 | % The format of the DestroyPixelCache() method is: |
| 1366 | % |
| 1367 | % Cache DestroyPixelCache(Cache cache) |
| 1368 | % |
| 1369 | % A description of each parameter follows: |
| 1370 | % |
| 1371 | % o cache: the pixel cache. |
| 1372 | % |
| 1373 | */ |
| 1374 | |
| 1375 | static inline void RelinquishPixelCachePixels(CacheInfo *cache_info) |
| 1376 | { |
| 1377 | switch (cache_info->type) |
| 1378 | { |
| 1379 | case MemoryCache: |
| 1380 | { |
| 1381 | if (cache_info->mapped == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1382 | cache_info->pixels=(Quantum *) RelinquishMagickMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1383 | cache_info->pixels); |
| 1384 | else |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1385 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1386 | (size_t) cache_info->length); |
| 1387 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 1388 | break; |
| 1389 | } |
| 1390 | case MapCache: |
| 1391 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1392 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1393 | cache_info->length); |
| 1394 | RelinquishMagickResource(MapResource,cache_info->length); |
| 1395 | } |
| 1396 | case DiskCache: |
| 1397 | { |
| 1398 | if (cache_info->file != -1) |
| 1399 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1400 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 1401 | break; |
| 1402 | } |
| 1403 | default: |
| 1404 | break; |
| 1405 | } |
| 1406 | cache_info->type=UndefinedCache; |
| 1407 | cache_info->mapped=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1408 | cache_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1411 | MagickPrivate Cache DestroyPixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1412 | { |
| 1413 | CacheInfo |
| 1414 | *cache_info; |
| 1415 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1416 | assert(cache != (Cache) NULL); |
| 1417 | cache_info=(CacheInfo *) cache; |
| 1418 | assert(cache_info->signature == MagickSignature); |
| 1419 | if (cache_info->debug != MagickFalse) |
| 1420 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1421 | cache_info->filename); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1422 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1423 | cache_info->reference_count--; |
| 1424 | if (cache_info->reference_count != 0) |
| 1425 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1426 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | return((Cache) NULL); |
| 1428 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1429 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1430 | if (cache_resources != (SplayTreeInfo *) NULL) |
| 1431 | (void) DeleteNodeByValueFromSplayTree(cache_resources,cache_info); |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1432 | if (cache_info->debug != MagickFalse) |
| 1433 | { |
| 1434 | char |
| 1435 | message[MaxTextExtent]; |
| 1436 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1437 | (void) FormatLocaleString(message,MaxTextExtent,"destroy %s", |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1438 | cache_info->filename); |
| 1439 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 1440 | } |
cristy | c2e1bdd | 2009-09-10 23:43:34 +0000 | [diff] [blame] | 1441 | if ((cache_info->mode == ReadMode) || ((cache_info->type != MapCache) && |
| 1442 | (cache_info->type != DiskCache))) |
| 1443 | RelinquishPixelCachePixels(cache_info); |
| 1444 | else |
| 1445 | { |
| 1446 | RelinquishPixelCachePixels(cache_info); |
| 1447 | (void) RelinquishUniqueFileResource(cache_info->cache_filename); |
| 1448 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1449 | *cache_info->cache_filename='\0'; |
| 1450 | if (cache_info->nexus_info != (NexusInfo **) NULL) |
| 1451 | cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info, |
| 1452 | cache_info->number_threads); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1453 | if (cache_info->random_info != (RandomInfo *) NULL) |
| 1454 | cache_info->random_info=DestroyRandomInfo(cache_info->random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1455 | if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL) |
| 1456 | DestroySemaphoreInfo(&cache_info->disk_semaphore); |
| 1457 | if (cache_info->semaphore != (SemaphoreInfo *) NULL) |
| 1458 | DestroySemaphoreInfo(&cache_info->semaphore); |
cristy | 154a1e2 | 2010-02-15 00:28:37 +0000 | [diff] [blame] | 1459 | cache_info->signature=(~MagickSignature); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 1460 | cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1461 | cache=(Cache) NULL; |
| 1462 | return(cache); |
| 1463 | } |
| 1464 | |
| 1465 | /* |
| 1466 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1467 | % % |
| 1468 | % % |
| 1469 | % % |
| 1470 | + D e s t r o y P i x e l C a c h e N e x u s % |
| 1471 | % % |
| 1472 | % % |
| 1473 | % % |
| 1474 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1475 | % |
| 1476 | % DestroyPixelCacheNexus() destroys a pixel cache nexus. |
| 1477 | % |
| 1478 | % The format of the DestroyPixelCacheNexus() method is: |
| 1479 | % |
| 1480 | % NexusInfo **DestroyPixelCacheNexus(NexusInfo *nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1481 | % const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | % |
| 1483 | % A description of each parameter follows: |
| 1484 | % |
| 1485 | % o nexus_info: the nexus to destroy. |
| 1486 | % |
| 1487 | % o number_threads: the number of nexus threads. |
| 1488 | % |
| 1489 | */ |
| 1490 | |
| 1491 | static inline void RelinquishCacheNexusPixels(NexusInfo *nexus_info) |
| 1492 | { |
| 1493 | if (nexus_info->mapped == MagickFalse) |
| 1494 | (void) RelinquishMagickMemory(nexus_info->cache); |
| 1495 | else |
| 1496 | (void) UnmapBlob(nexus_info->cache,(size_t) nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1497 | nexus_info->cache=(Quantum *) NULL; |
| 1498 | nexus_info->pixels=(Quantum *) NULL; |
| 1499 | nexus_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | nexus_info->length=0; |
| 1501 | nexus_info->mapped=MagickFalse; |
| 1502 | } |
| 1503 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1504 | MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1505 | const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1506 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1507 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1508 | i; |
| 1509 | |
| 1510 | assert(nexus_info != (NexusInfo **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1511 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1513 | if (nexus_info[i]->cache != (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1514 | RelinquishCacheNexusPixels(nexus_info[i]); |
| 1515 | nexus_info[i]->signature=(~MagickSignature); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 1516 | nexus_info[i]=(NexusInfo *) RelinquishAlignedMemory(nexus_info[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1517 | } |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 1518 | nexus_info=(NexusInfo **) RelinquishMagickMemory(nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1519 | return(nexus_info); |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1524 | % % |
| 1525 | % % |
| 1526 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1527 | % 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] | 1528 | % % |
| 1529 | % % |
| 1530 | % % |
| 1531 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1532 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1533 | % GetAuthenticMetacontent() returns the authentic metacontent corresponding |
| 1534 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 1535 | % returned if the associated pixels are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1536 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1537 | % The format of the GetAuthenticMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1538 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1539 | % void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1540 | % |
| 1541 | % A description of each parameter follows: |
| 1542 | % |
| 1543 | % o image: the image. |
| 1544 | % |
| 1545 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1546 | MagickExport void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1547 | { |
| 1548 | CacheInfo |
| 1549 | *cache_info; |
| 1550 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1551 | const int |
| 1552 | id = GetOpenMPThreadId(); |
| 1553 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1554 | void |
| 1555 | *metacontent; |
| 1556 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1557 | assert(image != (const Image *) NULL); |
| 1558 | assert(image->signature == MagickSignature); |
| 1559 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1560 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1561 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1562 | if (cache_info->methods.get_authentic_metacontent_from_handler != |
| 1563 | (GetAuthenticMetacontentFromHandler) NULL) |
| 1564 | { |
| 1565 | metacontent=cache_info->methods. |
| 1566 | get_authentic_metacontent_from_handler(image); |
| 1567 | return(metacontent); |
| 1568 | } |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1569 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1570 | metacontent=GetPixelCacheNexusMetacontent(cache_info, |
| 1571 | cache_info->nexus_info[id]); |
| 1572 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1577 | % % |
| 1578 | % % |
| 1579 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1580 | + 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] | 1581 | % % |
| 1582 | % % |
| 1583 | % % |
| 1584 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1585 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1586 | % GetAuthenticMetacontentFromCache() returns the meta-content corresponding |
| 1587 | % with the last call to QueueAuthenticPixelsCache() or |
| 1588 | % GetAuthenticPixelsCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1589 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1590 | % The format of the GetAuthenticMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1591 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1592 | % void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1593 | % |
| 1594 | % A description of each parameter follows: |
| 1595 | % |
| 1596 | % o image: the image. |
| 1597 | % |
| 1598 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1599 | static void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1600 | { |
| 1601 | CacheInfo |
| 1602 | *cache_info; |
| 1603 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1604 | const int |
| 1605 | id = GetOpenMPThreadId(); |
| 1606 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1607 | void |
| 1608 | *metacontent; |
| 1609 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | assert(image != (const Image *) NULL); |
| 1611 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | assert(image->cache != (Cache) NULL); |
| 1613 | cache_info=(CacheInfo *) image->cache; |
| 1614 | assert(cache_info->signature == MagickSignature); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1615 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1616 | metacontent=GetPixelCacheNexusMetacontent(image->cache, |
| 1617 | cache_info->nexus_info[id]); |
| 1618 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1623 | % % |
| 1624 | % % |
| 1625 | % % |
| 1626 | + 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 % |
| 1627 | % % |
| 1628 | % % |
| 1629 | % % |
| 1630 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1631 | % |
| 1632 | % GetAuthenticPixelCacheNexus() gets authentic pixels from the in-memory or |
| 1633 | % disk pixel cache as defined by the geometry parameters. A pointer to the |
| 1634 | % pixels is returned if the pixels are transferred, otherwise a NULL is |
| 1635 | % returned. |
| 1636 | % |
| 1637 | % The format of the GetAuthenticPixelCacheNexus() method is: |
| 1638 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1639 | % Quantum *GetAuthenticPixelCacheNexus(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1640 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1641 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1642 | % |
| 1643 | % A description of each parameter follows: |
| 1644 | % |
| 1645 | % o image: the image. |
| 1646 | % |
| 1647 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1648 | % pixels. |
| 1649 | % |
| 1650 | % o nexus_info: the cache nexus to return. |
| 1651 | % |
| 1652 | % o exception: return any errors or warnings in this structure. |
| 1653 | % |
| 1654 | */ |
| 1655 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1656 | static inline MagickBooleanType IsPixelAuthentic(const CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1657 | NexusInfo *nexus_info) |
| 1658 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1659 | MagickBooleanType |
| 1660 | status; |
| 1661 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | MagickOffsetType |
| 1663 | offset; |
| 1664 | |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 1665 | if (cache_info->type == PingCache) |
| 1666 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1667 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 1668 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1669 | status=nexus_info->pixels == (cache_info->pixels+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1670 | cache_info->number_channels) ? MagickTrue : MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1671 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1674 | MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image, |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 1675 | 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] | 1676 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1677 | { |
| 1678 | CacheInfo |
| 1679 | *cache_info; |
| 1680 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1681 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1682 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1683 | |
| 1684 | /* |
| 1685 | Transfer pixels from the cache. |
| 1686 | */ |
| 1687 | assert(image != (Image *) NULL); |
| 1688 | assert(image->signature == MagickSignature); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 1689 | q=QueueAuthenticNexus(image,x,y,columns,rows,MagickTrue,nexus_info,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1690 | if (q == (Quantum *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1691 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1692 | cache_info=(CacheInfo *) image->cache; |
| 1693 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1694 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1695 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1696 | if (ReadPixelCachePixels(cache_info,nexus_info,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1697 | return((Quantum *) NULL); |
| 1698 | if (cache_info->metacontent_extent != 0) |
| 1699 | if (ReadPixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse) |
| 1700 | return((Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1701 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | /* |
| 1705 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1706 | % % |
| 1707 | % % |
| 1708 | % % |
| 1709 | + 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 % |
| 1710 | % % |
| 1711 | % % |
| 1712 | % % |
| 1713 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1714 | % |
| 1715 | % GetAuthenticPixelsFromCache() returns the pixels associated with the last |
| 1716 | % call to the QueueAuthenticPixelsCache() or GetAuthenticPixelsCache() methods. |
| 1717 | % |
| 1718 | % The format of the GetAuthenticPixelsFromCache() method is: |
| 1719 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1720 | % Quantum *GetAuthenticPixelsFromCache(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1721 | % |
| 1722 | % A description of each parameter follows: |
| 1723 | % |
| 1724 | % o image: the image. |
| 1725 | % |
| 1726 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1727 | static Quantum *GetAuthenticPixelsFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1728 | { |
| 1729 | CacheInfo |
| 1730 | *cache_info; |
| 1731 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1732 | const int |
| 1733 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1734 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1735 | assert(image != (const Image *) NULL); |
| 1736 | assert(image->signature == MagickSignature); |
| 1737 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1738 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1739 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1740 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 1741 | return(GetPixelCacheNexusPixels(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | /* |
| 1745 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1746 | % % |
| 1747 | % % |
| 1748 | % % |
| 1749 | % G e t A u t h e n t i c P i x e l Q u e u e % |
| 1750 | % % |
| 1751 | % % |
| 1752 | % % |
| 1753 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1754 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1755 | % GetAuthenticPixelQueue() returns the authentic pixels associated |
| 1756 | % corresponding with the last call to QueueAuthenticPixels() or |
| 1757 | % GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1758 | % |
| 1759 | % The format of the GetAuthenticPixelQueue() method is: |
| 1760 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1761 | % Quantum *GetAuthenticPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1762 | % |
| 1763 | % A description of each parameter follows: |
| 1764 | % |
| 1765 | % o image: the image. |
| 1766 | % |
| 1767 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1768 | MagickExport Quantum *GetAuthenticPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1769 | { |
| 1770 | CacheInfo |
| 1771 | *cache_info; |
| 1772 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1773 | const int |
| 1774 | id = GetOpenMPThreadId(); |
| 1775 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1776 | assert(image != (const Image *) NULL); |
| 1777 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1778 | assert(image->cache != (Cache) NULL); |
| 1779 | cache_info=(CacheInfo *) image->cache; |
| 1780 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1781 | if (cache_info->methods.get_authentic_pixels_from_handler != |
| 1782 | (GetAuthenticPixelsFromHandler) NULL) |
| 1783 | return(cache_info->methods.get_authentic_pixels_from_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1784 | assert(id < (int) cache_info->number_threads); |
| 1785 | return(GetPixelCacheNexusPixels(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /* |
| 1789 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1790 | % % |
| 1791 | % % |
| 1792 | % % |
| 1793 | % G e t A u t h e n t i c P i x e l s % |
| 1794 | % % |
| 1795 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1796 | % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1797 | % |
| 1798 | % GetAuthenticPixels() obtains a pixel region for read/write access. If the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1799 | % region is successfully accessed, a pointer to a Quantum array |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1800 | % representing the region is returned, otherwise NULL is returned. |
| 1801 | % |
| 1802 | % The returned pointer may point to a temporary working copy of the pixels |
| 1803 | % or it may point to the original pixels in memory. Performance is maximized |
| 1804 | % if the selected region is part of one row, or one or more full rows, since |
| 1805 | % then there is opportunity to access the pixels in-place (without a copy) |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 1806 | % if the image is in memory, or in a memory-mapped file. The returned pointer |
| 1807 | % must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1808 | % |
| 1809 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1810 | % Quantum. If the image has corresponding metacontent,call |
| 1811 | % GetAuthenticMetacontent() after invoking GetAuthenticPixels() to obtain the |
| 1812 | % meta-content corresponding to the region. Once the Quantum array has |
| 1813 | % been updated, the changes must be saved back to the underlying image using |
| 1814 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1815 | % |
| 1816 | % The format of the GetAuthenticPixels() method is: |
| 1817 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1818 | % Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 1819 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1820 | % ExceptionInfo *exception) |
| 1821 | % |
| 1822 | % A description of each parameter follows: |
| 1823 | % |
| 1824 | % o image: the image. |
| 1825 | % |
| 1826 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1827 | % pixels. |
| 1828 | % |
| 1829 | % o exception: return any errors or warnings in this structure. |
| 1830 | % |
| 1831 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1832 | MagickExport Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1833 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1834 | ExceptionInfo *exception) |
| 1835 | { |
| 1836 | CacheInfo |
| 1837 | *cache_info; |
| 1838 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1839 | const int |
| 1840 | id = GetOpenMPThreadId(); |
| 1841 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1842 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1843 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1844 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1845 | assert(image != (Image *) NULL); |
| 1846 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1847 | assert(image->cache != (Cache) NULL); |
| 1848 | cache_info=(CacheInfo *) image->cache; |
| 1849 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1850 | if (cache_info->methods.get_authentic_pixels_handler != |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1851 | (GetAuthenticPixelsHandler) NULL) |
| 1852 | { |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1853 | q=cache_info->methods.get_authentic_pixels_handler(image,x,y,columns,rows, |
| 1854 | exception); |
| 1855 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1856 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1857 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1858 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1859 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1860 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /* |
| 1864 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1865 | % % |
| 1866 | % % |
| 1867 | % % |
| 1868 | + G e t A u t h e n t i c P i x e l s C a c h e % |
| 1869 | % % |
| 1870 | % % |
| 1871 | % % |
| 1872 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1873 | % |
| 1874 | % GetAuthenticPixelsCache() gets pixels from the in-memory or disk pixel cache |
| 1875 | % as defined by the geometry parameters. A pointer to the pixels is returned |
| 1876 | % if the pixels are transferred, otherwise a NULL is returned. |
| 1877 | % |
| 1878 | % The format of the GetAuthenticPixelsCache() method is: |
| 1879 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1880 | % Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1881 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1882 | % ExceptionInfo *exception) |
| 1883 | % |
| 1884 | % A description of each parameter follows: |
| 1885 | % |
| 1886 | % o image: the image. |
| 1887 | % |
| 1888 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1889 | % pixels. |
| 1890 | % |
| 1891 | % o exception: return any errors or warnings in this structure. |
| 1892 | % |
| 1893 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1894 | static Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1895 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1896 | ExceptionInfo *exception) |
| 1897 | { |
| 1898 | CacheInfo |
| 1899 | *cache_info; |
| 1900 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1901 | const int |
| 1902 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1903 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1904 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1905 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1906 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1907 | assert(image != (const Image *) NULL); |
| 1908 | assert(image->signature == MagickSignature); |
| 1909 | assert(image->cache != (Cache) NULL); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 1910 | cache_info=(CacheInfo *) image->cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1911 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1912 | return((Quantum *) NULL); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1913 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1914 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1915 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1916 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1917 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /* |
| 1921 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1922 | % % |
| 1923 | % % |
| 1924 | % % |
| 1925 | + G e t I m a g e E x t e n t % |
| 1926 | % % |
| 1927 | % % |
| 1928 | % % |
| 1929 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1930 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1931 | % GetImageExtent() returns the extent of the pixels associated corresponding |
| 1932 | % with the last call to QueueAuthenticPixels() or GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1933 | % |
| 1934 | % The format of the GetImageExtent() method is: |
| 1935 | % |
| 1936 | % MagickSizeType GetImageExtent(const Image *image) |
| 1937 | % |
| 1938 | % A description of each parameter follows: |
| 1939 | % |
| 1940 | % o image: the image. |
| 1941 | % |
| 1942 | */ |
| 1943 | MagickExport MagickSizeType GetImageExtent(const Image *image) |
| 1944 | { |
| 1945 | CacheInfo |
| 1946 | *cache_info; |
| 1947 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1948 | const int |
| 1949 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1950 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1951 | assert(image != (Image *) NULL); |
| 1952 | assert(image->signature == MagickSignature); |
| 1953 | if (image->debug != MagickFalse) |
| 1954 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1955 | assert(image->cache != (Cache) NULL); |
| 1956 | cache_info=(CacheInfo *) image->cache; |
| 1957 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1958 | assert(id < (int) cache_info->number_threads); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1959 | return(GetPixelCacheNexusExtent(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /* |
| 1963 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1964 | % % |
| 1965 | % % |
| 1966 | % % |
| 1967 | + G e t I m a g e P i x e l C a c h e % |
| 1968 | % % |
| 1969 | % % |
| 1970 | % % |
| 1971 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1972 | % |
| 1973 | % GetImagePixelCache() ensures that there is only a single reference to the |
| 1974 | % pixel cache to be modified, updating the provided cache pointer to point to |
| 1975 | % a clone of the original pixel cache if necessary. |
| 1976 | % |
| 1977 | % The format of the GetImagePixelCache method is: |
| 1978 | % |
| 1979 | % Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 1980 | % ExceptionInfo *exception) |
| 1981 | % |
| 1982 | % A description of each parameter follows: |
| 1983 | % |
| 1984 | % o image: the image. |
| 1985 | % |
| 1986 | % o clone: any value other than MagickFalse clones the cache pixels. |
| 1987 | % |
| 1988 | % o exception: return any errors or warnings in this structure. |
| 1989 | % |
| 1990 | */ |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 1991 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1992 | static inline MagickBooleanType ValidatePixelCacheMorphology(const Image *image) |
| 1993 | { |
| 1994 | CacheInfo |
| 1995 | *cache_info; |
| 1996 | |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1997 | PixelChannelMap |
| 1998 | *p, |
| 1999 | *q; |
| 2000 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2001 | /* |
| 2002 | Does the image match the pixel cache morphology? |
| 2003 | */ |
| 2004 | cache_info=(CacheInfo *) image->cache; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2005 | p=image->channel_map; |
| 2006 | q=cache_info->channel_map; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2007 | if ((image->storage_class != cache_info->storage_class) || |
| 2008 | (image->colorspace != cache_info->colorspace) || |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 2009 | (image->matte != cache_info->matte) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2010 | (image->columns != cache_info->columns) || |
| 2011 | (image->rows != cache_info->rows) || |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2012 | (image->number_channels != cache_info->number_channels) || |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2013 | (memcmp(p,q,image->number_channels*sizeof(*p)) != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2014 | (image->metacontent_extent != cache_info->metacontent_extent) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2015 | (cache_info->nexus_info == (NexusInfo **) NULL) || |
| 2016 | (cache_info->number_threads < GetOpenMPMaximumThreads())) |
| 2017 | return(MagickFalse); |
| 2018 | return(MagickTrue); |
| 2019 | } |
| 2020 | |
cristy | cd01fae | 2011-08-06 23:52:42 +0000 | [diff] [blame] | 2021 | static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 2022 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2023 | { |
| 2024 | CacheInfo |
| 2025 | *cache_info; |
| 2026 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2027 | MagickBooleanType |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 2028 | destroy, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2029 | status; |
| 2030 | |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 2031 | static MagickSizeType |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2032 | cpu_throttle = 0, |
| 2033 | cycles = 0, |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 2034 | time_limit = 0; |
| 2035 | |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2036 | static time_t |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 2037 | cache_timestamp = 0; |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2038 | |
cristy | c4f9f13 | 2010-03-04 18:50:01 +0000 | [diff] [blame] | 2039 | status=MagickTrue; |
| 2040 | LockSemaphoreInfo(image->semaphore); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2041 | if (cpu_throttle == 0) |
| 2042 | { |
| 2043 | char |
| 2044 | *limit; |
| 2045 | |
| 2046 | /* |
| 2047 | Set CPU throttle in milleseconds. |
| 2048 | */ |
| 2049 | cpu_throttle=MagickResourceInfinity; |
| 2050 | limit=GetEnvironmentValue("MAGICK_THROTTLE"); |
| 2051 | if (limit == (char *) NULL) |
| 2052 | limit=GetPolicyValue("throttle"); |
| 2053 | if (limit != (char *) NULL) |
| 2054 | { |
| 2055 | cpu_throttle=(MagickSizeType) StringToInteger(limit); |
| 2056 | limit=DestroyString(limit); |
| 2057 | } |
| 2058 | } |
| 2059 | if ((cpu_throttle != MagickResourceInfinity) && ((cycles++ % 32) == 0)) |
| 2060 | MagickDelay(cpu_throttle); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2061 | if (time_limit == 0) |
| 2062 | { |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2063 | /* |
| 2064 | Set the exire time in seconds. |
| 2065 | */ |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2066 | time_limit=GetMagickResourceLimit(TimeResource); |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 2067 | cache_timestamp=time((time_t *) NULL); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2068 | } |
| 2069 | if ((time_limit != MagickResourceInfinity) && |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 2070 | ((MagickSizeType) (time((time_t *) NULL)-cache_timestamp) >= time_limit)) |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 2071 | ThrowFatalException(ResourceLimitFatalError,"TimeLimitExceeded"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2072 | assert(image->cache != (Cache) NULL); |
| 2073 | cache_info=(CacheInfo *) image->cache; |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 2074 | destroy=MagickFalse; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2075 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2076 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2077 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 2078 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2079 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2080 | Image |
| 2081 | clone_image; |
| 2082 | |
| 2083 | CacheInfo |
| 2084 | *clone_info; |
| 2085 | |
| 2086 | /* |
| 2087 | Clone pixel cache. |
| 2088 | */ |
| 2089 | clone_image=(*image); |
| 2090 | clone_image.semaphore=AllocateSemaphoreInfo(); |
| 2091 | clone_image.reference_count=1; |
| 2092 | clone_image.cache=ClonePixelCache(cache_info); |
| 2093 | clone_info=(CacheInfo *) clone_image.cache; |
| 2094 | status=OpenPixelCache(&clone_image,IOMode,exception); |
| 2095 | if (status != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2096 | { |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 2097 | if (clone != MagickFalse) |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 2098 | status=ClonePixelCachePixels(clone_info,cache_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2099 | if (status != MagickFalse) |
| 2100 | { |
cristy | 979bf77 | 2011-08-08 00:04:15 +0000 | [diff] [blame] | 2101 | if (cache_info->mode == ReadMode) |
| 2102 | cache_info->nexus_info=(NexusInfo **) NULL; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2103 | destroy=MagickTrue; |
| 2104 | image->cache=clone_image.cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2105 | } |
| 2106 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2107 | DestroySemaphoreInfo(&clone_image.semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2108 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 2109 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2110 | } |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 2111 | if (destroy != MagickFalse) |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 2112 | cache_info=(CacheInfo *) DestroyPixelCache(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2113 | if (status != MagickFalse) |
| 2114 | { |
| 2115 | /* |
| 2116 | Ensure the image matches the pixel cache morphology. |
| 2117 | */ |
| 2118 | image->taint=MagickTrue; |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 2119 | image->type=UndefinedType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2120 | if (ValidatePixelCacheMorphology(image) == MagickFalse) |
| 2121 | status=OpenPixelCache(image,IOMode,exception); |
| 2122 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2123 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2124 | if (status == MagickFalse) |
| 2125 | return((Cache) NULL); |
| 2126 | return(image->cache); |
| 2127 | } |
| 2128 | |
| 2129 | /* |
| 2130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2131 | % % |
| 2132 | % % |
| 2133 | % % |
| 2134 | % G e t O n e A u t h e n t i c P i x e l % |
| 2135 | % % |
| 2136 | % % |
| 2137 | % % |
| 2138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2139 | % |
| 2140 | % GetOneAuthenticPixel() returns a single pixel at the specified (x,y) |
| 2141 | % location. The image background color is returned if an error occurs. |
| 2142 | % |
| 2143 | % The format of the GetOneAuthenticPixel() method is: |
| 2144 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2145 | % MagickBooleanType GetOneAuthenticPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2146 | % const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2147 | % |
| 2148 | % A description of each parameter follows: |
| 2149 | % |
| 2150 | % o image: the image. |
| 2151 | % |
| 2152 | % o x,y: These values define the location of the pixel to return. |
| 2153 | % |
| 2154 | % o pixel: return a pixel at the specified (x,y) location. |
| 2155 | % |
| 2156 | % o exception: return any errors or warnings in this structure. |
| 2157 | % |
| 2158 | */ |
cristy | acbbb7c | 2010-06-30 18:56:48 +0000 | [diff] [blame] | 2159 | MagickExport MagickBooleanType GetOneAuthenticPixel(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2160 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2161 | { |
| 2162 | CacheInfo |
| 2163 | *cache_info; |
| 2164 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2165 | register Quantum |
| 2166 | *q; |
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 != (Image *) NULL); |
| 2172 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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_authentic_pixel_from_handler != |
| 2178 | (GetOneAuthenticPixelFromHandler) NULL) |
| 2179 | return(cache_info->methods.get_one_authentic_pixel_from_handler(image,x,y, |
| 2180 | pixel,exception)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2181 | q=GetAuthenticPixelsCache(image,x,y,1UL,1UL,exception); |
| 2182 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2183 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2184 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2185 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2186 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2187 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2188 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2189 | return(MagickFalse); |
| 2190 | } |
| 2191 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2192 | { |
| 2193 | PixelChannel |
| 2194 | channel; |
| 2195 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2196 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2197 | pixel[channel]=q[i]; |
| 2198 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2199 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | /* |
| 2203 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2204 | % % |
| 2205 | % % |
| 2206 | % % |
| 2207 | + 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 % |
| 2208 | % % |
| 2209 | % % |
| 2210 | % % |
| 2211 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2212 | % |
| 2213 | % GetOneAuthenticPixelFromCache() returns a single pixel at the specified (x,y) |
| 2214 | % location. The image background color is returned if an error occurs. |
| 2215 | % |
| 2216 | % The format of the GetOneAuthenticPixelFromCache() method is: |
| 2217 | % |
| 2218 | % MagickBooleanType GetOneAuthenticPixelFromCache(const Image image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2219 | % const ssize_t x,const ssize_t y,Quantum *pixel, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 2220 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2221 | % |
| 2222 | % A description of each parameter follows: |
| 2223 | % |
| 2224 | % o image: the image. |
| 2225 | % |
| 2226 | % o x,y: These values define the location of the pixel to return. |
| 2227 | % |
| 2228 | % o pixel: return a pixel at the specified (x,y) location. |
| 2229 | % |
| 2230 | % o exception: return any errors or warnings in this structure. |
| 2231 | % |
| 2232 | */ |
| 2233 | static MagickBooleanType GetOneAuthenticPixelFromCache(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2234 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2235 | { |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2236 | CacheInfo |
| 2237 | *cache_info; |
| 2238 | |
| 2239 | const int |
| 2240 | id = GetOpenMPThreadId(); |
| 2241 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2242 | register Quantum |
| 2243 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2244 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2245 | register ssize_t |
| 2246 | i; |
| 2247 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2248 | assert(image != (const Image *) NULL); |
| 2249 | assert(image->signature == MagickSignature); |
| 2250 | assert(image->cache != (Cache) NULL); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2251 | cache_info=(CacheInfo *) image->cache; |
| 2252 | assert(cache_info->signature == MagickSignature); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2253 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2254 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2255 | q=GetAuthenticPixelCacheNexus(image,x,y,1UL,1UL,cache_info->nexus_info[id], |
| 2256 | exception); |
| 2257 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2258 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2259 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2260 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2261 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2262 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2263 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2264 | return(MagickFalse); |
| 2265 | } |
| 2266 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2267 | { |
| 2268 | PixelChannel |
| 2269 | channel; |
| 2270 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2271 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2272 | pixel[channel]=q[i]; |
| 2273 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2274 | return(MagickTrue); |
| 2275 | } |
| 2276 | |
| 2277 | /* |
| 2278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2279 | % % |
| 2280 | % % |
| 2281 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2282 | % G e t O n e V i r t u a l P i x e l % |
| 2283 | % % |
| 2284 | % % |
| 2285 | % % |
| 2286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2287 | % |
| 2288 | % GetOneVirtualPixel() returns a single virtual pixel at the specified |
| 2289 | % (x,y) location. The image background color is returned if an error occurs. |
| 2290 | % If you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2291 | % |
| 2292 | % The format of the GetOneVirtualPixel() method is: |
| 2293 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2294 | % MagickBooleanType GetOneVirtualPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2295 | % const ssize_t y,Quantum *pixel,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2296 | % |
| 2297 | % A description of each parameter follows: |
| 2298 | % |
| 2299 | % o image: the image. |
| 2300 | % |
| 2301 | % o x,y: These values define the location of the pixel to return. |
| 2302 | % |
| 2303 | % o pixel: return a pixel at the specified (x,y) location. |
| 2304 | % |
| 2305 | % o exception: return any errors or warnings in this structure. |
| 2306 | % |
| 2307 | */ |
| 2308 | MagickExport MagickBooleanType GetOneVirtualPixel(const Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2309 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2310 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2311 | CacheInfo |
| 2312 | *cache_info; |
| 2313 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2314 | const int |
| 2315 | id = GetOpenMPThreadId(); |
| 2316 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2317 | const Quantum |
| 2318 | *p; |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2319 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2320 | register ssize_t |
| 2321 | i; |
| 2322 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2323 | assert(image != (const Image *) NULL); |
| 2324 | assert(image->signature == MagickSignature); |
| 2325 | assert(image->cache != (Cache) NULL); |
| 2326 | cache_info=(CacheInfo *) image->cache; |
| 2327 | assert(cache_info->signature == MagickSignature); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2328 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 2329 | if (cache_info->methods.get_one_virtual_pixel_from_handler != |
| 2330 | (GetOneVirtualPixelFromHandler) NULL) |
| 2331 | return(cache_info->methods.get_one_virtual_pixel_from_handler(image, |
| 2332 | GetPixelCacheVirtualMethod(image),x,y,pixel,exception)); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2333 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2334 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2335 | 1UL,1UL,cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2336 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2337 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2338 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2339 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2340 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2341 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2342 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2343 | return(MagickFalse); |
| 2344 | } |
| 2345 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2346 | { |
| 2347 | PixelChannel |
| 2348 | channel; |
| 2349 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2350 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2351 | pixel[channel]=p[i]; |
| 2352 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2353 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /* |
| 2357 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2358 | % % |
| 2359 | % % |
| 2360 | % % |
| 2361 | + 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 % |
| 2362 | % % |
| 2363 | % % |
| 2364 | % % |
| 2365 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2366 | % |
| 2367 | % GetOneVirtualPixelFromCache() returns a single virtual pixel at the |
| 2368 | % specified (x,y) location. The image background color is returned if an |
| 2369 | % error occurs. |
| 2370 | % |
| 2371 | % The format of the GetOneVirtualPixelFromCache() method is: |
| 2372 | % |
| 2373 | % MagickBooleanType GetOneVirtualPixelFromCache(const Image image, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2374 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2375 | % Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2376 | % |
| 2377 | % A description of each parameter follows: |
| 2378 | % |
| 2379 | % o image: the image. |
| 2380 | % |
| 2381 | % o virtual_pixel_method: the virtual pixel method. |
| 2382 | % |
| 2383 | % o x,y: These values define the location of the pixel to return. |
| 2384 | % |
| 2385 | % o pixel: return a pixel at the specified (x,y) location. |
| 2386 | % |
| 2387 | % o exception: return any errors or warnings in this structure. |
| 2388 | % |
| 2389 | */ |
| 2390 | static MagickBooleanType GetOneVirtualPixelFromCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2391 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2392 | Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2393 | { |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2394 | CacheInfo |
| 2395 | *cache_info; |
| 2396 | |
| 2397 | const int |
| 2398 | id = GetOpenMPThreadId(); |
| 2399 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2400 | const Quantum |
| 2401 | *p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2402 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2403 | register ssize_t |
| 2404 | i; |
| 2405 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2406 | assert(image != (const Image *) NULL); |
| 2407 | assert(image->signature == MagickSignature); |
| 2408 | assert(image->cache != (Cache) NULL); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2409 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2410 | assert(cache_info->signature == MagickSignature); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2411 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2412 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2413 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2414 | cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2415 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2416 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2417 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2418 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2419 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2420 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2421 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2422 | return(MagickFalse); |
| 2423 | } |
| 2424 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2425 | { |
| 2426 | PixelChannel |
| 2427 | channel; |
| 2428 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2429 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2430 | pixel[channel]=p[i]; |
| 2431 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2432 | return(MagickTrue); |
| 2433 | } |
| 2434 | |
| 2435 | /* |
| 2436 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2437 | % % |
| 2438 | % % |
| 2439 | % % |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 2440 | % G e t O n e V i r t u a l P i x e l I n f o % |
| 2441 | % % |
| 2442 | % % |
| 2443 | % % |
| 2444 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2445 | % |
| 2446 | % GetOneVirtualPixelInfo() returns a single pixel at the specified (x,y) |
| 2447 | % location. The image background color is returned if an error occurs. If |
| 2448 | % you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2449 | % |
| 2450 | % The format of the GetOneVirtualPixelInfo() method is: |
| 2451 | % |
| 2452 | % MagickBooleanType GetOneVirtualPixelInfo(const Image image, |
| 2453 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 2454 | % const ssize_t y,PixelInfo *pixel,ExceptionInfo exception) |
| 2455 | % |
| 2456 | % A description of each parameter follows: |
| 2457 | % |
| 2458 | % o image: the image. |
| 2459 | % |
| 2460 | % o virtual_pixel_method: the virtual pixel method. |
| 2461 | % |
| 2462 | % o x,y: these values define the location of the pixel to return. |
| 2463 | % |
| 2464 | % o pixel: return a pixel at the specified (x,y) location. |
| 2465 | % |
| 2466 | % o exception: return any errors or warnings in this structure. |
| 2467 | % |
| 2468 | */ |
| 2469 | MagickExport MagickBooleanType GetOneVirtualPixelInfo(const Image *image, |
| 2470 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 2471 | PixelInfo *pixel,ExceptionInfo *exception) |
| 2472 | { |
| 2473 | CacheInfo |
| 2474 | *cache_info; |
| 2475 | |
| 2476 | const int |
| 2477 | id = GetOpenMPThreadId(); |
| 2478 | |
| 2479 | register const Quantum |
| 2480 | *p; |
| 2481 | |
| 2482 | assert(image != (const Image *) NULL); |
| 2483 | assert(image->signature == MagickSignature); |
| 2484 | assert(image->cache != (Cache) NULL); |
| 2485 | cache_info=(CacheInfo *) image->cache; |
| 2486 | assert(cache_info->signature == MagickSignature); |
| 2487 | assert(id < (int) cache_info->number_threads); |
| 2488 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
| 2489 | cache_info->nexus_info[id],exception); |
| 2490 | GetPixelInfo(image,pixel); |
| 2491 | if (p == (const Quantum *) NULL) |
| 2492 | return(MagickFalse); |
| 2493 | GetPixelInfoPixel(image,p,pixel); |
| 2494 | return(MagickTrue); |
| 2495 | } |
| 2496 | |
| 2497 | /* |
| 2498 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2499 | % % |
| 2500 | % % |
| 2501 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2502 | + G e t P i x e l C a c h e C o l o r s p a c e % |
| 2503 | % % |
| 2504 | % % |
| 2505 | % % |
| 2506 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2507 | % |
| 2508 | % GetPixelCacheColorspace() returns the class type of the pixel cache. |
| 2509 | % |
| 2510 | % The format of the GetPixelCacheColorspace() method is: |
| 2511 | % |
| 2512 | % Colorspace GetPixelCacheColorspace(Cache cache) |
| 2513 | % |
| 2514 | % A description of each parameter follows: |
| 2515 | % |
| 2516 | % o cache: the pixel cache. |
| 2517 | % |
| 2518 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2519 | MagickPrivate ColorspaceType GetPixelCacheColorspace(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2520 | { |
| 2521 | CacheInfo |
| 2522 | *cache_info; |
| 2523 | |
| 2524 | assert(cache != (Cache) NULL); |
| 2525 | cache_info=(CacheInfo *) cache; |
| 2526 | assert(cache_info->signature == MagickSignature); |
| 2527 | if (cache_info->debug != MagickFalse) |
| 2528 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2529 | cache_info->filename); |
| 2530 | return(cache_info->colorspace); |
| 2531 | } |
| 2532 | |
| 2533 | /* |
| 2534 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2535 | % % |
| 2536 | % % |
| 2537 | % % |
| 2538 | + G e t P i x e l C a c h e M e t h o d s % |
| 2539 | % % |
| 2540 | % % |
| 2541 | % % |
| 2542 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2543 | % |
| 2544 | % GetPixelCacheMethods() initializes the CacheMethods structure. |
| 2545 | % |
| 2546 | % The format of the GetPixelCacheMethods() method is: |
| 2547 | % |
| 2548 | % void GetPixelCacheMethods(CacheMethods *cache_methods) |
| 2549 | % |
| 2550 | % A description of each parameter follows: |
| 2551 | % |
| 2552 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 2553 | % |
| 2554 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2555 | MagickPrivate void GetPixelCacheMethods(CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2556 | { |
| 2557 | assert(cache_methods != (CacheMethods *) NULL); |
| 2558 | (void) ResetMagickMemory(cache_methods,0,sizeof(*cache_methods)); |
| 2559 | cache_methods->get_virtual_pixel_handler=GetVirtualPixelCache; |
| 2560 | cache_methods->get_virtual_pixels_handler=GetVirtualPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2561 | cache_methods->get_virtual_metacontent_from_handler= |
| 2562 | GetVirtualMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2563 | cache_methods->get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromCache; |
| 2564 | cache_methods->get_authentic_pixels_handler=GetAuthenticPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2565 | cache_methods->get_authentic_metacontent_from_handler= |
| 2566 | GetAuthenticMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2567 | cache_methods->get_authentic_pixels_from_handler=GetAuthenticPixelsFromCache; |
| 2568 | cache_methods->get_one_authentic_pixel_from_handler= |
| 2569 | GetOneAuthenticPixelFromCache; |
| 2570 | cache_methods->queue_authentic_pixels_handler=QueueAuthenticPixelsCache; |
| 2571 | cache_methods->sync_authentic_pixels_handler=SyncAuthenticPixelsCache; |
| 2572 | cache_methods->destroy_pixel_handler=DestroyImagePixelCache; |
| 2573 | } |
| 2574 | |
| 2575 | /* |
| 2576 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2577 | % % |
| 2578 | % % |
| 2579 | % % |
| 2580 | + G e t P i x e l C a c h e N e x u s E x t e n t % |
| 2581 | % % |
| 2582 | % % |
| 2583 | % % |
| 2584 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2585 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2586 | % GetPixelCacheNexusExtent() returns the extent of the pixels associated |
| 2587 | % corresponding with the last call to SetPixelCacheNexusPixels() or |
| 2588 | % GetPixelCacheNexusPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2589 | % |
| 2590 | % The format of the GetPixelCacheNexusExtent() method is: |
| 2591 | % |
| 2592 | % MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
| 2593 | % NexusInfo *nexus_info) |
| 2594 | % |
| 2595 | % A description of each parameter follows: |
| 2596 | % |
| 2597 | % o nexus_info: the nexus info. |
| 2598 | % |
| 2599 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2600 | MagickPrivate MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2601 | NexusInfo *nexus_info) |
| 2602 | { |
| 2603 | CacheInfo |
| 2604 | *cache_info; |
| 2605 | |
| 2606 | MagickSizeType |
| 2607 | extent; |
| 2608 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2609 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2610 | cache_info=(CacheInfo *) cache; |
| 2611 | assert(cache_info->signature == MagickSignature); |
| 2612 | extent=(MagickSizeType) nexus_info->region.width*nexus_info->region.height; |
| 2613 | if (extent == 0) |
| 2614 | return((MagickSizeType) cache_info->columns*cache_info->rows); |
| 2615 | return(extent); |
| 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2620 | % % |
| 2621 | % % |
| 2622 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2623 | + 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] | 2624 | % % |
| 2625 | % % |
| 2626 | % % |
| 2627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2628 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2629 | % GetPixelCacheNexusMetacontent() returns the meta-content for the specified |
| 2630 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2631 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2632 | % The format of the GetPixelCacheNexusMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2633 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2634 | % void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2635 | % NexusInfo *nexus_info) |
| 2636 | % |
| 2637 | % A description of each parameter follows: |
| 2638 | % |
| 2639 | % o cache: the pixel cache. |
| 2640 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2641 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2642 | % |
| 2643 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2644 | MagickPrivate void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2645 | NexusInfo *nexus_info) |
| 2646 | { |
| 2647 | CacheInfo |
| 2648 | *cache_info; |
| 2649 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2650 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2651 | cache_info=(CacheInfo *) cache; |
| 2652 | assert(cache_info->signature == MagickSignature); |
| 2653 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2654 | return((void *) NULL); |
| 2655 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /* |
| 2659 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2660 | % % |
| 2661 | % % |
| 2662 | % % |
| 2663 | + G e t P i x e l C a c h e N e x u s P i x e l s % |
| 2664 | % % |
| 2665 | % % |
| 2666 | % % |
| 2667 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2668 | % |
| 2669 | % GetPixelCacheNexusPixels() returns the pixels associated with the specified |
| 2670 | % cache nexus. |
| 2671 | % |
| 2672 | % The format of the GetPixelCacheNexusPixels() method is: |
| 2673 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2674 | % Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2675 | % NexusInfo *nexus_info) |
| 2676 | % |
| 2677 | % A description of each parameter follows: |
| 2678 | % |
| 2679 | % o cache: the pixel cache. |
| 2680 | % |
| 2681 | % o nexus_info: the cache nexus to return the pixels. |
| 2682 | % |
| 2683 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2684 | MagickPrivate Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2685 | NexusInfo *nexus_info) |
| 2686 | { |
| 2687 | CacheInfo |
| 2688 | *cache_info; |
| 2689 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2690 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2691 | cache_info=(CacheInfo *) cache; |
| 2692 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2693 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2694 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2695 | return(nexus_info->pixels); |
| 2696 | } |
| 2697 | |
| 2698 | /* |
| 2699 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2700 | % % |
| 2701 | % % |
| 2702 | % % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2703 | + G e t P i x e l C a c h e P i x e l s % |
| 2704 | % % |
| 2705 | % % |
| 2706 | % % |
| 2707 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2708 | % |
| 2709 | % GetPixelCachePixels() returns the pixels associated with the specified image. |
| 2710 | % |
| 2711 | % The format of the GetPixelCachePixels() method is: |
| 2712 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2713 | % void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
| 2714 | % ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2715 | % |
| 2716 | % A description of each parameter follows: |
| 2717 | % |
| 2718 | % o image: the image. |
| 2719 | % |
| 2720 | % o length: the pixel cache length. |
| 2721 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2722 | % o exception: return any errors or warnings in this structure. |
| 2723 | % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2724 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2725 | MagickPrivate void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2726 | ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2727 | { |
| 2728 | CacheInfo |
| 2729 | *cache_info; |
| 2730 | |
| 2731 | assert(image != (const Image *) NULL); |
| 2732 | assert(image->signature == MagickSignature); |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2733 | assert(image->cache != (Cache) NULL); |
cristy | 654fdaf | 2011-02-24 15:24:33 +0000 | [diff] [blame] | 2734 | assert(length != (MagickSizeType *) NULL); |
| 2735 | assert(exception != (ExceptionInfo *) NULL); |
| 2736 | assert(exception->signature == MagickSignature); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 2737 | cache_info=(CacheInfo *) image->cache; |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2738 | assert(cache_info->signature == MagickSignature); |
| 2739 | *length=0; |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 2740 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2741 | return((void *) NULL); |
| 2742 | *length=cache_info->length; |
| 2743 | return((void *) cache_info->pixels); |
| 2744 | } |
| 2745 | |
| 2746 | /* |
| 2747 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2748 | % % |
| 2749 | % % |
| 2750 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2751 | + 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] | 2752 | % % |
| 2753 | % % |
| 2754 | % % |
| 2755 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2756 | % |
| 2757 | % GetPixelCacheStorageClass() returns the class type of the pixel cache. |
| 2758 | % |
| 2759 | % The format of the GetPixelCacheStorageClass() method is: |
| 2760 | % |
| 2761 | % ClassType GetPixelCacheStorageClass(Cache cache) |
| 2762 | % |
| 2763 | % A description of each parameter follows: |
| 2764 | % |
| 2765 | % o type: GetPixelCacheStorageClass returns DirectClass or PseudoClass. |
| 2766 | % |
| 2767 | % o cache: the pixel cache. |
| 2768 | % |
| 2769 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2770 | MagickPrivate ClassType GetPixelCacheStorageClass(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2771 | { |
| 2772 | CacheInfo |
| 2773 | *cache_info; |
| 2774 | |
| 2775 | assert(cache != (Cache) NULL); |
| 2776 | cache_info=(CacheInfo *) cache; |
| 2777 | assert(cache_info->signature == MagickSignature); |
| 2778 | if (cache_info->debug != MagickFalse) |
| 2779 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2780 | cache_info->filename); |
| 2781 | return(cache_info->storage_class); |
| 2782 | } |
| 2783 | |
| 2784 | /* |
| 2785 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2786 | % % |
| 2787 | % % |
| 2788 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2789 | + G e t P i x e l C a c h e T i l e S i z e % |
| 2790 | % % |
| 2791 | % % |
| 2792 | % % |
| 2793 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2794 | % |
| 2795 | % GetPixelCacheTileSize() returns the pixel cache tile size. |
| 2796 | % |
| 2797 | % The format of the GetPixelCacheTileSize() method is: |
| 2798 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2799 | % void GetPixelCacheTileSize(const Image *image,size_t *width, |
| 2800 | % size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2801 | % |
| 2802 | % A description of each parameter follows: |
| 2803 | % |
| 2804 | % o image: the image. |
| 2805 | % |
| 2806 | % o width: the optimize cache tile width in pixels. |
| 2807 | % |
| 2808 | % o height: the optimize cache tile height in pixels. |
| 2809 | % |
| 2810 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2811 | MagickPrivate void GetPixelCacheTileSize(const Image *image,size_t *width, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2812 | size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2813 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2814 | CacheInfo |
| 2815 | *cache_info; |
| 2816 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2817 | assert(image != (Image *) NULL); |
| 2818 | assert(image->signature == MagickSignature); |
| 2819 | if (image->debug != MagickFalse) |
| 2820 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2821 | cache_info=(CacheInfo *) image->cache; |
| 2822 | assert(cache_info->signature == MagickSignature); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2823 | *width=2048UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2824 | if (GetPixelCacheType(image) == DiskCache) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2825 | *width=8192UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2826 | *height=(*width); |
| 2827 | } |
| 2828 | |
| 2829 | /* |
| 2830 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2831 | % % |
| 2832 | % % |
| 2833 | % % |
| 2834 | + G e t P i x e l C a c h e T y p e % |
| 2835 | % % |
| 2836 | % % |
| 2837 | % % |
| 2838 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2839 | % |
| 2840 | % GetPixelCacheType() returns the pixel cache type (e.g. memory, disk, etc.). |
| 2841 | % |
| 2842 | % The format of the GetPixelCacheType() method is: |
| 2843 | % |
| 2844 | % CacheType GetPixelCacheType(const Image *image) |
| 2845 | % |
| 2846 | % A description of each parameter follows: |
| 2847 | % |
| 2848 | % o image: the image. |
| 2849 | % |
| 2850 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2851 | MagickPrivate CacheType GetPixelCacheType(const Image *image) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2852 | { |
| 2853 | CacheInfo |
| 2854 | *cache_info; |
| 2855 | |
| 2856 | assert(image != (Image *) NULL); |
| 2857 | assert(image->signature == MagickSignature); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2858 | assert(image->cache != (Cache) NULL); |
| 2859 | cache_info=(CacheInfo *) image->cache; |
| 2860 | assert(cache_info->signature == MagickSignature); |
| 2861 | return(cache_info->type); |
| 2862 | } |
| 2863 | |
| 2864 | /* |
| 2865 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2866 | % % |
| 2867 | % % |
| 2868 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2869 | + 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 % |
| 2870 | % % |
| 2871 | % % |
| 2872 | % % |
| 2873 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2874 | % |
| 2875 | % GetPixelCacheVirtualMethod() gets the "virtual pixels" method for the |
| 2876 | % pixel cache. A virtual pixel is any pixel access that is outside the |
| 2877 | % boundaries of the image cache. |
| 2878 | % |
| 2879 | % The format of the GetPixelCacheVirtualMethod() method is: |
| 2880 | % |
| 2881 | % VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
| 2882 | % |
| 2883 | % A description of each parameter follows: |
| 2884 | % |
| 2885 | % o image: the image. |
| 2886 | % |
| 2887 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2888 | MagickPrivate VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2889 | { |
| 2890 | CacheInfo |
| 2891 | *cache_info; |
| 2892 | |
| 2893 | assert(image != (Image *) NULL); |
| 2894 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2895 | assert(image->cache != (Cache) NULL); |
| 2896 | cache_info=(CacheInfo *) image->cache; |
| 2897 | assert(cache_info->signature == MagickSignature); |
| 2898 | return(cache_info->virtual_pixel_method); |
| 2899 | } |
| 2900 | |
| 2901 | /* |
| 2902 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2903 | % % |
| 2904 | % % |
| 2905 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2906 | + 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] | 2907 | % % |
| 2908 | % % |
| 2909 | % % |
| 2910 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2911 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2912 | % GetVirtualMetacontentFromCache() returns the meta-content corresponding with |
| 2913 | % the last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2914 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2915 | % The format of the GetVirtualMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2916 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2917 | % void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2918 | % |
| 2919 | % A description of each parameter follows: |
| 2920 | % |
| 2921 | % o image: the image. |
| 2922 | % |
| 2923 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2924 | static const void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2925 | { |
| 2926 | CacheInfo |
| 2927 | *cache_info; |
| 2928 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 2929 | const int |
| 2930 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2931 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2932 | const void |
| 2933 | *metacontent; |
| 2934 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2935 | assert(image != (const Image *) NULL); |
| 2936 | assert(image->signature == MagickSignature); |
| 2937 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2938 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2939 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2940 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2941 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 2942 | cache_info->nexus_info[id]); |
| 2943 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | /* |
| 2947 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2948 | % % |
| 2949 | % % |
| 2950 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2951 | + 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] | 2952 | % % |
| 2953 | % % |
| 2954 | % % |
| 2955 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2956 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2957 | % GetVirtualMetacontentFromNexus() returns the meta-content for the specified |
| 2958 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2959 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2960 | % The format of the GetVirtualMetacontentFromNexus() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2961 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2962 | % const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2963 | % NexusInfo *nexus_info) |
| 2964 | % |
| 2965 | % A description of each parameter follows: |
| 2966 | % |
| 2967 | % o cache: the pixel cache. |
| 2968 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2969 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2970 | % |
| 2971 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2972 | MagickPrivate const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 2973 | NexusInfo *nexus_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2974 | { |
| 2975 | CacheInfo |
| 2976 | *cache_info; |
| 2977 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2978 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2979 | cache_info=(CacheInfo *) cache; |
| 2980 | assert(cache_info->signature == MagickSignature); |
| 2981 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2982 | return((void *) NULL); |
| 2983 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | /* |
| 2987 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2988 | % % |
| 2989 | % % |
| 2990 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2991 | % 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] | 2992 | % % |
| 2993 | % % |
| 2994 | % % |
| 2995 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2996 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2997 | % GetVirtualMetacontent() returns the virtual metacontent corresponding with |
| 2998 | % the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 2999 | % returned if the meta-content are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3000 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3001 | % The format of the GetVirtualMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3002 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3003 | % const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3004 | % |
| 3005 | % A description of each parameter follows: |
| 3006 | % |
| 3007 | % o image: the image. |
| 3008 | % |
| 3009 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3010 | MagickExport const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3011 | { |
| 3012 | CacheInfo |
| 3013 | *cache_info; |
| 3014 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3015 | const int |
| 3016 | id = GetOpenMPThreadId(); |
| 3017 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3018 | const void |
| 3019 | *metacontent; |
| 3020 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3021 | assert(image != (const Image *) NULL); |
| 3022 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3023 | assert(image->cache != (Cache) NULL); |
| 3024 | cache_info=(CacheInfo *) image->cache; |
| 3025 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3026 | if (cache_info->methods.get_virtual_metacontent_from_handler != |
| 3027 | (GetVirtualMetacontentFromHandler) NULL) |
| 3028 | { |
| 3029 | metacontent=cache_info->methods. |
| 3030 | get_virtual_metacontent_from_handler(image); |
| 3031 | return(metacontent); |
| 3032 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3033 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3034 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 3035 | cache_info->nexus_info[id]); |
| 3036 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | /* |
| 3040 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3041 | % % |
| 3042 | % % |
| 3043 | % % |
| 3044 | + 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 % |
| 3045 | % % |
| 3046 | % % |
| 3047 | % % |
| 3048 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3049 | % |
| 3050 | % GetVirtualPixelsFromNexus() gets virtual pixels from the in-memory or disk |
| 3051 | % pixel cache as defined by the geometry parameters. A pointer to the pixels |
| 3052 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 3053 | % |
| 3054 | % The format of the GetVirtualPixelsFromNexus() method is: |
| 3055 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3056 | % Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3057 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 3058 | % const size_t columns,const size_t rows,NexusInfo *nexus_info, |
| 3059 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3060 | % |
| 3061 | % A description of each parameter follows: |
| 3062 | % |
| 3063 | % o image: the image. |
| 3064 | % |
| 3065 | % o virtual_pixel_method: the virtual pixel method. |
| 3066 | % |
| 3067 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3068 | % pixels. |
| 3069 | % |
| 3070 | % o nexus_info: the cache nexus to acquire. |
| 3071 | % |
| 3072 | % o exception: return any errors or warnings in this structure. |
| 3073 | % |
| 3074 | */ |
| 3075 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3076 | static ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3077 | DitherMatrix[64] = |
| 3078 | { |
| 3079 | 0, 48, 12, 60, 3, 51, 15, 63, |
| 3080 | 32, 16, 44, 28, 35, 19, 47, 31, |
| 3081 | 8, 56, 4, 52, 11, 59, 7, 55, |
| 3082 | 40, 24, 36, 20, 43, 27, 39, 23, |
| 3083 | 2, 50, 14, 62, 1, 49, 13, 61, |
| 3084 | 34, 18, 46, 30, 33, 17, 45, 29, |
| 3085 | 10, 58, 6, 54, 9, 57, 5, 53, |
| 3086 | 42, 26, 38, 22, 41, 25, 37, 21 |
| 3087 | }; |
| 3088 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3089 | static inline ssize_t DitherX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3090 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3091 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3092 | index; |
| 3093 | |
| 3094 | index=x+DitherMatrix[x & 0x07]-32L; |
| 3095 | if (index < 0L) |
| 3096 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3097 | if (index >= (ssize_t) columns) |
| 3098 | return((ssize_t) columns-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3099 | return(index); |
| 3100 | } |
| 3101 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3102 | static inline ssize_t DitherY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3103 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3104 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3105 | index; |
| 3106 | |
| 3107 | index=y+DitherMatrix[y & 0x07]-32L; |
| 3108 | if (index < 0L) |
| 3109 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3110 | if (index >= (ssize_t) rows) |
| 3111 | return((ssize_t) rows-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3112 | return(index); |
| 3113 | } |
| 3114 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3115 | static inline ssize_t EdgeX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3116 | { |
| 3117 | if (x < 0L) |
| 3118 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3119 | if (x >= (ssize_t) columns) |
| 3120 | return((ssize_t) (columns-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3121 | return(x); |
| 3122 | } |
| 3123 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3124 | static inline ssize_t EdgeY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3125 | { |
| 3126 | if (y < 0L) |
| 3127 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3128 | if (y >= (ssize_t) rows) |
| 3129 | return((ssize_t) (rows-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3130 | return(y); |
| 3131 | } |
| 3132 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3133 | static inline ssize_t RandomX(RandomInfo *random_info,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3134 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3135 | return((ssize_t) (columns*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3138 | static inline ssize_t RandomY(RandomInfo *random_info,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3139 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3140 | return((ssize_t) (rows*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3143 | static inline MagickModulo VirtualPixelModulo(const ssize_t offset, |
| 3144 | const size_t extent) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3145 | { |
| 3146 | MagickModulo |
| 3147 | modulo; |
| 3148 | |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3149 | /* |
| 3150 | Compute the remainder of dividing offset by extent. It returns not only |
| 3151 | the quotient (tile the offset falls in) but also the positive remainer |
| 3152 | within that tile such that 0 <= remainder < extent. This method is |
| 3153 | essentially a ldiv() using a floored modulo division rather than the |
| 3154 | normal default truncated modulo division. |
| 3155 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3156 | modulo.quotient=offset/(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3157 | if (offset < 0L) |
| 3158 | modulo.quotient--; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3159 | modulo.remainder=offset-modulo.quotient*(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3160 | return(modulo); |
| 3161 | } |
| 3162 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 3163 | MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3164 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 3165 | const size_t columns,const size_t rows,NexusInfo *nexus_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3166 | ExceptionInfo *exception) |
| 3167 | { |
| 3168 | CacheInfo |
| 3169 | *cache_info; |
| 3170 | |
| 3171 | MagickOffsetType |
| 3172 | offset; |
| 3173 | |
| 3174 | MagickSizeType |
| 3175 | length, |
| 3176 | number_pixels; |
| 3177 | |
| 3178 | NexusInfo |
| 3179 | **virtual_nexus; |
| 3180 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3181 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3182 | *pixels, |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 3183 | virtual_pixel[CompositePixelChannel]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3184 | |
| 3185 | RectangleInfo |
| 3186 | region; |
| 3187 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3188 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3189 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3190 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3191 | register const void |
| 3192 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3193 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3194 | register Quantum |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3195 | *restrict q; |
| 3196 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3197 | register ssize_t |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3198 | i, |
| 3199 | u; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3200 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3201 | register unsigned char |
| 3202 | *restrict s; |
| 3203 | |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3204 | ssize_t |
| 3205 | v; |
| 3206 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3207 | void |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3208 | *virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3209 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3210 | /* |
| 3211 | Acquire pixels. |
| 3212 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3213 | assert(image != (const Image *) NULL); |
| 3214 | assert(image->signature == MagickSignature); |
| 3215 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3216 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3217 | assert(cache_info->signature == MagickSignature); |
cristy | 4cfbb3f | 2010-03-14 20:40:23 +0000 | [diff] [blame] | 3218 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3219 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3220 | region.x=x; |
| 3221 | region.y=y; |
| 3222 | region.width=columns; |
| 3223 | region.height=rows; |
| 3224 | pixels=SetPixelCacheNexusPixels(image,®ion,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3225 | if (pixels == (Quantum *) NULL) |
| 3226 | return((const Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3227 | q=pixels; |
cristy | df415c8 | 2010-03-11 16:47:50 +0000 | [diff] [blame] | 3228 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 3229 | nexus_info->region.x; |
| 3230 | length=(MagickSizeType) (nexus_info->region.height-1L)*cache_info->columns+ |
| 3231 | nexus_info->region.width-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3232 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 3233 | if ((offset >= 0) && (((MagickSizeType) offset+length) < number_pixels)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3234 | if ((x >= 0) && ((ssize_t) (x+columns) <= (ssize_t) cache_info->columns) && |
| 3235 | (y >= 0) && ((ssize_t) (y+rows) <= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3236 | { |
| 3237 | MagickBooleanType |
| 3238 | status; |
| 3239 | |
| 3240 | /* |
| 3241 | Pixel request is inside cache extents. |
| 3242 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3243 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3244 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3245 | status=ReadPixelCachePixels(cache_info,nexus_info,exception); |
| 3246 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3247 | return((const Quantum *) NULL); |
| 3248 | if (cache_info->metacontent_extent != 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3249 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3250 | status=ReadPixelCacheMetacontent(cache_info,nexus_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3251 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3252 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3253 | } |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3254 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3255 | } |
| 3256 | /* |
| 3257 | Pixel request is outside cache extents. |
| 3258 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3259 | s=(unsigned char *) GetPixelCacheNexusMetacontent(cache_info,nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3260 | virtual_nexus=AcquirePixelCacheNexus(1); |
| 3261 | if (virtual_nexus == (NexusInfo **) NULL) |
| 3262 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3263 | if (virtual_nexus != (NexusInfo **) NULL) |
| 3264 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3265 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 3266 | "UnableToGetCacheNexus","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3267 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3268 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3269 | (void) ResetMagickMemory(virtual_pixel,0,cache_info->number_channels* |
| 3270 | sizeof(*virtual_pixel)); |
| 3271 | virtual_metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3272 | switch (virtual_pixel_method) |
| 3273 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3274 | case BackgroundVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3275 | case BlackVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3276 | case GrayVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3277 | case TransparentVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3278 | case MaskVirtualPixelMethod: |
| 3279 | case WhiteVirtualPixelMethod: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3280 | case EdgeVirtualPixelMethod: |
| 3281 | case CheckerTileVirtualPixelMethod: |
| 3282 | case HorizontalTileVirtualPixelMethod: |
| 3283 | case VerticalTileVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3284 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3285 | if (cache_info->metacontent_extent != 0) |
| 3286 | { |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3287 | /* |
| 3288 | Acquire a metacontent buffer. |
| 3289 | */ |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3290 | virtual_metacontent=(void *) AcquireQuantumMemory(1, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3291 | cache_info->metacontent_extent); |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3292 | if (virtual_metacontent == (void *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3293 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3294 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3295 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 3296 | CacheError,"UnableToGetCacheNexus","`%s'",image->filename); |
| 3297 | return((const Quantum *) NULL); |
| 3298 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3299 | (void) ResetMagickMemory(virtual_metacontent,0, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3300 | cache_info->metacontent_extent); |
| 3301 | } |
| 3302 | switch (virtual_pixel_method) |
| 3303 | { |
| 3304 | case BlackVirtualPixelMethod: |
| 3305 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3306 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3307 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3308 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3309 | break; |
| 3310 | } |
| 3311 | case GrayVirtualPixelMethod: |
| 3312 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3313 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 3314 | SetPixelChannel(image,(PixelChannel) i,QuantumRange/2, |
| 3315 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3316 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3317 | break; |
| 3318 | } |
| 3319 | case TransparentVirtualPixelMethod: |
| 3320 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3321 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3322 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3323 | SetPixelAlpha(image,TransparentAlpha,virtual_pixel); |
| 3324 | break; |
| 3325 | } |
| 3326 | case MaskVirtualPixelMethod: |
| 3327 | case WhiteVirtualPixelMethod: |
| 3328 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3329 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3330 | SetPixelChannel(image,(PixelChannel) i,QuantumRange,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3331 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3332 | break; |
| 3333 | } |
| 3334 | default: |
| 3335 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3336 | SetPixelRed(image,ClampToQuantum(image->background_color.red), |
| 3337 | virtual_pixel); |
| 3338 | SetPixelGreen(image,ClampToQuantum(image->background_color.green), |
| 3339 | virtual_pixel); |
| 3340 | SetPixelBlue(image,ClampToQuantum(image->background_color.blue), |
| 3341 | virtual_pixel); |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3342 | if (image->colorspace == CMYKColorspace) |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3343 | SetPixelBlack(image,ClampToQuantum(image->background_color.black), |
| 3344 | virtual_pixel); |
| 3345 | SetPixelAlpha(image,ClampToQuantum(image->background_color.alpha), |
| 3346 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3347 | break; |
| 3348 | } |
| 3349 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3350 | break; |
| 3351 | } |
| 3352 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3353 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3354 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3355 | for (v=0; v < (ssize_t) rows; v++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3356 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3357 | for (u=0; u < (ssize_t) columns; u+=length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3358 | { |
| 3359 | length=(MagickSizeType) MagickMin(cache_info->columns-(x+u),columns-u); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3360 | if ((((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) || |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3361 | (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) || |
| 3362 | (length == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3363 | { |
| 3364 | MagickModulo |
| 3365 | x_modulo, |
| 3366 | y_modulo; |
| 3367 | |
| 3368 | /* |
| 3369 | Transfer a single pixel. |
| 3370 | */ |
| 3371 | length=(MagickSizeType) 1; |
| 3372 | switch (virtual_pixel_method) |
| 3373 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3374 | default: |
| 3375 | { |
| 3376 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3377 | EdgeX(x+u,cache_info->columns),EdgeY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3378 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3379 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3380 | break; |
| 3381 | } |
| 3382 | case RandomVirtualPixelMethod: |
| 3383 | { |
| 3384 | if (cache_info->random_info == (RandomInfo *) NULL) |
| 3385 | cache_info->random_info=AcquireRandomInfo(); |
| 3386 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3387 | RandomX(cache_info->random_info,cache_info->columns), |
| 3388 | RandomY(cache_info->random_info,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3389 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3390 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3391 | break; |
| 3392 | } |
| 3393 | case DitherVirtualPixelMethod: |
| 3394 | { |
| 3395 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3396 | DitherX(x+u,cache_info->columns),DitherY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3397 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3398 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3399 | break; |
| 3400 | } |
| 3401 | case TileVirtualPixelMethod: |
| 3402 | { |
| 3403 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3404 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3405 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3406 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3407 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3408 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3409 | break; |
| 3410 | } |
| 3411 | case MirrorVirtualPixelMethod: |
| 3412 | { |
| 3413 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3414 | if ((x_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3415 | x_modulo.remainder=(ssize_t) cache_info->columns- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3416 | x_modulo.remainder-1L; |
| 3417 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3418 | if ((y_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3419 | y_modulo.remainder=(ssize_t) cache_info->rows- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3420 | y_modulo.remainder-1L; |
| 3421 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3422 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3423 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3424 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3425 | break; |
| 3426 | } |
| 3427 | case HorizontalTileEdgeVirtualPixelMethod: |
| 3428 | { |
| 3429 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3430 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3431 | x_modulo.remainder,EdgeY(y+v,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3432 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3433 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3434 | break; |
| 3435 | } |
| 3436 | case VerticalTileEdgeVirtualPixelMethod: |
| 3437 | { |
| 3438 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3439 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3440 | EdgeX(x+u,cache_info->columns),y_modulo.remainder,1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3441 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3442 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3443 | break; |
| 3444 | } |
| 3445 | case BackgroundVirtualPixelMethod: |
| 3446 | case BlackVirtualPixelMethod: |
| 3447 | case GrayVirtualPixelMethod: |
| 3448 | case TransparentVirtualPixelMethod: |
| 3449 | case MaskVirtualPixelMethod: |
| 3450 | case WhiteVirtualPixelMethod: |
| 3451 | { |
| 3452 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3453 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3454 | break; |
| 3455 | } |
| 3456 | case EdgeVirtualPixelMethod: |
| 3457 | case CheckerTileVirtualPixelMethod: |
| 3458 | { |
| 3459 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3460 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3461 | if (((x_modulo.quotient ^ y_modulo.quotient) & 0x01) != 0L) |
| 3462 | { |
| 3463 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3464 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3465 | break; |
| 3466 | } |
| 3467 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3468 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3469 | exception); |
| 3470 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3471 | break; |
| 3472 | } |
| 3473 | case HorizontalTileVirtualPixelMethod: |
| 3474 | { |
| 3475 | if (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) |
| 3476 | { |
| 3477 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3478 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3479 | break; |
| 3480 | } |
| 3481 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3482 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3483 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3484 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3485 | exception); |
| 3486 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3487 | break; |
| 3488 | } |
| 3489 | case VerticalTileVirtualPixelMethod: |
| 3490 | { |
| 3491 | if (((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) |
| 3492 | { |
| 3493 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3494 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3495 | break; |
| 3496 | } |
| 3497 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3498 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3499 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3500 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3501 | exception); |
| 3502 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3503 | break; |
| 3504 | } |
| 3505 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3506 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3507 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3508 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3509 | sizeof(*p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3510 | q+=cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3511 | if ((s != (void *) NULL) && (r != (const void *) NULL)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3512 | { |
| 3513 | (void) memcpy(s,r,(size_t) cache_info->metacontent_extent); |
| 3514 | s+=cache_info->metacontent_extent; |
| 3515 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3516 | continue; |
| 3517 | } |
| 3518 | /* |
| 3519 | Transfer a run of pixels. |
| 3520 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3521 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x+u,y+v,(size_t) |
| 3522 | length,1UL,*virtual_nexus,exception); |
| 3523 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3524 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3525 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3526 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels*sizeof(*p)); |
| 3527 | q+=length*cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3528 | if ((r != (void *) NULL) && (s != (const void *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3529 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3530 | (void) memcpy(s,r,(size_t) length); |
| 3531 | s+=length*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3532 | } |
| 3533 | } |
| 3534 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3535 | /* |
| 3536 | Free resources. |
| 3537 | */ |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3538 | if (virtual_metacontent != (void *) NULL) |
| 3539 | virtual_metacontent=(void *) RelinquishMagickMemory(virtual_metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3540 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3541 | return(pixels); |
| 3542 | } |
| 3543 | |
| 3544 | /* |
| 3545 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3546 | % % |
| 3547 | % % |
| 3548 | % % |
| 3549 | + G e t V i r t u a l P i x e l C a c h e % |
| 3550 | % % |
| 3551 | % % |
| 3552 | % % |
| 3553 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3554 | % |
| 3555 | % GetVirtualPixelCache() get virtual pixels from the in-memory or disk pixel |
| 3556 | % cache as defined by the geometry parameters. A pointer to the pixels |
| 3557 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 3558 | % |
| 3559 | % The format of the GetVirtualPixelCache() method is: |
| 3560 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3561 | % const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3562 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 3563 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3564 | % ExceptionInfo *exception) |
| 3565 | % |
| 3566 | % A description of each parameter follows: |
| 3567 | % |
| 3568 | % o image: the image. |
| 3569 | % |
| 3570 | % o virtual_pixel_method: the virtual pixel method. |
| 3571 | % |
| 3572 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3573 | % pixels. |
| 3574 | % |
| 3575 | % o exception: return any errors or warnings in this structure. |
| 3576 | % |
| 3577 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3578 | static const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3579 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 3580 | const size_t columns,const size_t rows,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3581 | { |
| 3582 | CacheInfo |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3583 | *cache_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3584 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3585 | const int |
| 3586 | id = GetOpenMPThreadId(); |
| 3587 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3588 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3589 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3590 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3591 | assert(image != (const Image *) NULL); |
| 3592 | assert(image->signature == MagickSignature); |
| 3593 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3594 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3595 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3596 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3597 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3598 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3599 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | /* |
| 3603 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3604 | % % |
| 3605 | % % |
| 3606 | % % |
| 3607 | % G e t V i r t u a l P i x e l Q u e u e % |
| 3608 | % % |
| 3609 | % % |
| 3610 | % % |
| 3611 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3612 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3613 | % GetVirtualPixelQueue() returns the virtual pixels associated corresponding |
| 3614 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3615 | % |
| 3616 | % The format of the GetVirtualPixelQueue() method is: |
| 3617 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3618 | % const Quantum *GetVirtualPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3619 | % |
| 3620 | % A description of each parameter follows: |
| 3621 | % |
| 3622 | % o image: the image. |
| 3623 | % |
| 3624 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3625 | MagickExport const Quantum *GetVirtualPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3626 | { |
| 3627 | CacheInfo |
| 3628 | *cache_info; |
| 3629 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3630 | const int |
| 3631 | id = GetOpenMPThreadId(); |
| 3632 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3633 | assert(image != (const Image *) NULL); |
| 3634 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3635 | assert(image->cache != (Cache) NULL); |
| 3636 | cache_info=(CacheInfo *) image->cache; |
| 3637 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3638 | if (cache_info->methods.get_virtual_pixels_handler != |
| 3639 | (GetVirtualPixelsHandler) NULL) |
| 3640 | return(cache_info->methods.get_virtual_pixels_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3641 | assert(id < (int) cache_info->number_threads); |
| 3642 | return(GetVirtualPixelsNexus(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /* |
| 3646 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3647 | % % |
| 3648 | % % |
| 3649 | % % |
| 3650 | % G e t V i r t u a l P i x e l s % |
| 3651 | % % |
| 3652 | % % |
| 3653 | % % |
| 3654 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3655 | % |
| 3656 | % GetVirtualPixels() returns an immutable pixel region. If the |
| 3657 | % region is successfully accessed, a pointer to it is returned, otherwise |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 3658 | % NULL is returned. The returned pointer may point to a temporary working |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3659 | % copy of the pixels or it may point to the original pixels in memory. |
| 3660 | % Performance is maximized if the selected region is part of one row, or one |
| 3661 | % 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] | 3662 | % (without a copy) if the image is in memory, or in a memory-mapped file. The |
| 3663 | % returned pointer must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3664 | % |
| 3665 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3666 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 3667 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 3668 | % access the meta-content (of type void) corresponding to the the |
| 3669 | % region. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3670 | % |
| 3671 | % If you plan to modify the pixels, use GetAuthenticPixels() instead. |
| 3672 | % |
| 3673 | % Note, the GetVirtualPixels() and GetAuthenticPixels() methods are not thread- |
| 3674 | % safe. In a threaded environment, use GetCacheViewVirtualPixels() or |
| 3675 | % GetCacheViewAuthenticPixels() instead. |
| 3676 | % |
| 3677 | % The format of the GetVirtualPixels() method is: |
| 3678 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3679 | % const Quantum *GetVirtualPixels(const Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3680 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3681 | % ExceptionInfo *exception) |
| 3682 | % |
| 3683 | % A description of each parameter follows: |
| 3684 | % |
| 3685 | % o image: the image. |
| 3686 | % |
| 3687 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3688 | % pixels. |
| 3689 | % |
| 3690 | % o exception: return any errors or warnings in this structure. |
| 3691 | % |
| 3692 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3693 | MagickExport const Quantum *GetVirtualPixels(const Image *image, |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3694 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
| 3695 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3696 | { |
| 3697 | CacheInfo |
| 3698 | *cache_info; |
| 3699 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3700 | const int |
| 3701 | id = GetOpenMPThreadId(); |
| 3702 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3703 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3704 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3705 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3706 | assert(image != (const Image *) NULL); |
| 3707 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3708 | assert(image->cache != (Cache) NULL); |
| 3709 | cache_info=(CacheInfo *) image->cache; |
| 3710 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3711 | if (cache_info->methods.get_virtual_pixel_handler != |
| 3712 | (GetVirtualPixelHandler) NULL) |
| 3713 | return(cache_info->methods.get_virtual_pixel_handler(image, |
| 3714 | GetPixelCacheVirtualMethod(image),x,y,columns,rows,exception)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3715 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3716 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3717 | columns,rows,cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3718 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | /* |
| 3722 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3723 | % % |
| 3724 | % % |
| 3725 | % % |
| 3726 | + 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 % |
| 3727 | % % |
| 3728 | % % |
| 3729 | % % |
| 3730 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3731 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3732 | % GetVirtualPixelsCache() returns the pixels associated corresponding with the |
| 3733 | % last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3734 | % |
| 3735 | % The format of the GetVirtualPixelsCache() method is: |
| 3736 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3737 | % Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3738 | % |
| 3739 | % A description of each parameter follows: |
| 3740 | % |
| 3741 | % o image: the image. |
| 3742 | % |
| 3743 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3744 | static const Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3745 | { |
| 3746 | CacheInfo |
| 3747 | *cache_info; |
| 3748 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3749 | const int |
| 3750 | id = GetOpenMPThreadId(); |
| 3751 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3752 | assert(image != (const Image *) NULL); |
| 3753 | assert(image->signature == MagickSignature); |
| 3754 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3755 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3756 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3757 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 3758 | return(GetVirtualPixelsNexus(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | /* |
| 3762 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3763 | % % |
| 3764 | % % |
| 3765 | % % |
| 3766 | + G e t V i r t u a l P i x e l s N e x u s % |
| 3767 | % % |
| 3768 | % % |
| 3769 | % % |
| 3770 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3771 | % |
| 3772 | % GetVirtualPixelsNexus() returns the pixels associated with the specified |
| 3773 | % cache nexus. |
| 3774 | % |
| 3775 | % The format of the GetVirtualPixelsNexus() method is: |
| 3776 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3777 | % const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3778 | % NexusInfo *nexus_info) |
| 3779 | % |
| 3780 | % A description of each parameter follows: |
| 3781 | % |
| 3782 | % o cache: the pixel cache. |
| 3783 | % |
| 3784 | % o nexus_info: the cache nexus to return the colormap pixels. |
| 3785 | % |
| 3786 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 3787 | MagickPrivate const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3788 | NexusInfo *nexus_info) |
| 3789 | { |
| 3790 | CacheInfo |
| 3791 | *cache_info; |
| 3792 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3793 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3794 | cache_info=(CacheInfo *) cache; |
| 3795 | assert(cache_info->signature == MagickSignature); |
| 3796 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3797 | return((Quantum *) NULL); |
| 3798 | return((const Quantum *) nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /* |
| 3802 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3803 | % % |
| 3804 | % % |
| 3805 | % % |
| 3806 | + M a s k P i x e l C a c h e N e x u s % |
| 3807 | % % |
| 3808 | % % |
| 3809 | % % |
| 3810 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3811 | % |
| 3812 | % MaskPixelCacheNexus() masks the cache nexus as defined by the image mask. |
| 3813 | % The method returns MagickTrue if the pixel region is masked, otherwise |
| 3814 | % MagickFalse. |
| 3815 | % |
| 3816 | % The format of the MaskPixelCacheNexus() method is: |
| 3817 | % |
| 3818 | % MagickBooleanType MaskPixelCacheNexus(Image *image, |
| 3819 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 3820 | % |
| 3821 | % A description of each parameter follows: |
| 3822 | % |
| 3823 | % o image: the image. |
| 3824 | % |
| 3825 | % o nexus_info: the cache nexus to clip. |
| 3826 | % |
| 3827 | % o exception: return any errors or warnings in this structure. |
| 3828 | % |
| 3829 | */ |
| 3830 | |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 3831 | static inline void MaskPixelOver(const PixelInfo *p,const MagickRealType alpha, |
| 3832 | const PixelInfo *q,const MagickRealType beta,PixelInfo *composite) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3833 | { |
| 3834 | MagickRealType |
| 3835 | gamma; |
| 3836 | |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 3837 | if (fabs(alpha-TransparentAlpha) < MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3838 | { |
| 3839 | *composite=(*q); |
| 3840 | return; |
| 3841 | } |
| 3842 | gamma=1.0-QuantumScale*QuantumScale*alpha*beta; |
| 3843 | gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma); |
cristy | b40bd89 | 2011-04-23 00:52:38 +0000 | [diff] [blame] | 3844 | composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta); |
| 3845 | composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta); |
| 3846 | composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3847 | if ((p->colorspace == CMYKColorspace) && (q->colorspace == CMYKColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3848 | composite->black=gamma*MagickOver_(p->black,alpha,q->black,beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | static MagickBooleanType MaskPixelCacheNexus(Image *image,NexusInfo *nexus_info, |
| 3852 | ExceptionInfo *exception) |
| 3853 | { |
| 3854 | CacheInfo |
| 3855 | *cache_info; |
| 3856 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3857 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3858 | alpha, |
| 3859 | beta; |
| 3860 | |
| 3861 | MagickSizeType |
| 3862 | number_pixels; |
| 3863 | |
| 3864 | NexusInfo |
| 3865 | **clip_nexus, |
| 3866 | **image_nexus; |
| 3867 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3868 | register const Quantum |
| 3869 | *restrict p, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3870 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3871 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3872 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3873 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3874 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3875 | register ssize_t |
| 3876 | i; |
| 3877 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3878 | /* |
| 3879 | Apply clip mask. |
| 3880 | */ |
| 3881 | if (image->debug != MagickFalse) |
| 3882 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3883 | if (image->mask == (Image *) NULL) |
| 3884 | return(MagickFalse); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 3885 | cache_info=(CacheInfo *) image->cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3886 | if (cache_info == (Cache) NULL) |
| 3887 | return(MagickFalse); |
| 3888 | image_nexus=AcquirePixelCacheNexus(1); |
| 3889 | clip_nexus=AcquirePixelCacheNexus(1); |
| 3890 | if ((image_nexus == (NexusInfo **) NULL) || |
| 3891 | (clip_nexus == (NexusInfo **) NULL)) |
| 3892 | ThrowBinaryException(CacheError,"UnableToGetCacheNexus",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3893 | p=(const Quantum *) GetAuthenticPixelCacheNexus(image, |
| 3894 | nexus_info->region.x,nexus_info->region.y,nexus_info->region.width, |
| 3895 | nexus_info->region.height,image_nexus[0],exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3896 | q=nexus_info->pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3897 | r=GetVirtualPixelsFromNexus(image->mask,MaskVirtualPixelMethod, |
| 3898 | nexus_info->region.x,nexus_info->region.y,nexus_info->region.width, |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3899 | nexus_info->region.height,clip_nexus[0],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3900 | GetPixelInfo(image,&alpha); |
| 3901 | GetPixelInfo(image,&beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3902 | number_pixels=(MagickSizeType) nexus_info->region.width* |
| 3903 | nexus_info->region.height; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3904 | for (i=0; i < (ssize_t) number_pixels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3905 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3906 | if ((p == (const Quantum *) NULL) || (r == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3907 | break; |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 3908 | GetPixelInfoPixel(image,p,&alpha); |
| 3909 | GetPixelInfoPixel(image,q,&beta); |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 3910 | MaskPixelOver(&beta,(MagickRealType) GetPixelIntensity(image,r), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3911 | &alpha,alpha.alpha,&beta); |
| 3912 | SetPixelRed(image,ClampToQuantum(beta.red),q); |
| 3913 | SetPixelGreen(image,ClampToQuantum(beta.green),q); |
| 3914 | SetPixelBlue(image,ClampToQuantum(beta.blue),q); |
| 3915 | if (cache_info->colorspace == CMYKColorspace) |
| 3916 | SetPixelBlack(image,ClampToQuantum(beta.black),q); |
| 3917 | SetPixelAlpha(image,ClampToQuantum(beta.alpha),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3918 | p++; |
| 3919 | q++; |
| 3920 | r++; |
| 3921 | } |
| 3922 | clip_nexus=DestroyPixelCacheNexus(clip_nexus,1); |
| 3923 | image_nexus=DestroyPixelCacheNexus(image_nexus,1); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3924 | if (i < (ssize_t) number_pixels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3925 | return(MagickFalse); |
| 3926 | return(MagickTrue); |
| 3927 | } |
| 3928 | |
| 3929 | /* |
| 3930 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3931 | % % |
| 3932 | % % |
| 3933 | % % |
| 3934 | + O p e n P i x e l C a c h e % |
| 3935 | % % |
| 3936 | % % |
| 3937 | % % |
| 3938 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3939 | % |
| 3940 | % OpenPixelCache() allocates the pixel cache. This includes defining the cache |
| 3941 | % dimensions, allocating space for the image pixels and optionally the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3942 | % metacontent, and memory mapping the cache if it is disk based. The cache |
| 3943 | % nexus array is initialized as well. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3944 | % |
| 3945 | % The format of the OpenPixelCache() method is: |
| 3946 | % |
| 3947 | % MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 3948 | % ExceptionInfo *exception) |
| 3949 | % |
| 3950 | % A description of each parameter follows: |
| 3951 | % |
| 3952 | % o image: the image. |
| 3953 | % |
| 3954 | % o mode: ReadMode, WriteMode, or IOMode. |
| 3955 | % |
| 3956 | % o exception: return any errors or warnings in this structure. |
| 3957 | % |
| 3958 | */ |
| 3959 | |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 3960 | static inline void AllocatePixelCachePixels(CacheInfo *cache_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3961 | { |
| 3962 | cache_info->mapped=MagickFalse; |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3963 | cache_info->pixels=(Quantum *) AcquireQuantumMemory(1,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3964 | cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3965 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3966 | { |
| 3967 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3968 | cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3969 | cache_info->length); |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | static MagickBooleanType ExtendCache(Image *image,MagickSizeType length) |
| 3974 | { |
| 3975 | CacheInfo |
| 3976 | *cache_info; |
| 3977 | |
| 3978 | MagickOffsetType |
| 3979 | count, |
| 3980 | extent, |
| 3981 | offset; |
| 3982 | |
| 3983 | cache_info=(CacheInfo *) image->cache; |
| 3984 | if (image->debug != MagickFalse) |
| 3985 | { |
| 3986 | char |
| 3987 | format[MaxTextExtent], |
| 3988 | message[MaxTextExtent]; |
| 3989 | |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 3990 | (void) FormatMagickSize(length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3991 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | b37d4f2 | 2011-06-27 19:22:42 +0000 | [diff] [blame] | 3992 | "extend %s (%s[%d], disk, %s)",cache_info->filename, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3993 | cache_info->cache_filename,cache_info->file,format); |
| 3994 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 3995 | } |
| 3996 | if (length != (MagickSizeType) ((MagickOffsetType) length)) |
| 3997 | return(MagickFalse); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 3998 | extent=(MagickOffsetType) lseek(cache_info->file,0,SEEK_END); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3999 | if (extent < 0) |
| 4000 | return(MagickFalse); |
| 4001 | if ((MagickSizeType) extent >= length) |
| 4002 | return(MagickTrue); |
| 4003 | offset=(MagickOffsetType) length-1; |
| 4004 | count=WritePixelCacheRegion(cache_info,offset,1,(const unsigned char *) ""); |
| 4005 | return(count == (MagickOffsetType) 1 ? MagickTrue : MagickFalse); |
| 4006 | } |
| 4007 | |
| 4008 | static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 4009 | ExceptionInfo *exception) |
| 4010 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4011 | CacheInfo |
| 4012 | *cache_info, |
| 4013 | source_info; |
| 4014 | |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 4015 | char |
| 4016 | format[MaxTextExtent], |
| 4017 | message[MaxTextExtent]; |
| 4018 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4019 | MagickBooleanType |
| 4020 | status; |
| 4021 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4022 | MagickSizeType |
| 4023 | length, |
| 4024 | number_pixels; |
| 4025 | |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 4026 | PixelChannelMap |
| 4027 | *p, |
| 4028 | *q; |
| 4029 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4030 | size_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4031 | columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4032 | packet_size; |
| 4033 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4034 | assert(image != (const Image *) NULL); |
| 4035 | assert(image->signature == MagickSignature); |
| 4036 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4037 | if (image->debug != MagickFalse) |
| 4038 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4039 | if ((image->columns == 0) || (image->rows == 0)) |
| 4040 | ThrowBinaryException(CacheError,"NoPixelsDefinedInCache",image->filename); |
| 4041 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4042 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4043 | source_info=(*cache_info); |
| 4044 | source_info.file=(-1); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4045 | (void) FormatLocaleString(cache_info->filename,MaxTextExtent,"%s[%.20g]", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4046 | image->filename,(double) GetImageIndexInList(image)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4047 | cache_info->storage_class=image->storage_class; |
| 4048 | cache_info->colorspace=image->colorspace; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4049 | cache_info->matte=image->matte; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4050 | cache_info->rows=image->rows; |
| 4051 | cache_info->columns=image->columns; |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4052 | InitializePixelChannelMap(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4053 | cache_info->number_channels=GetPixelChannels(image); |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 4054 | (void) memcpy(cache_info->channel_map,image->channel_map,MaxPixelChannels* |
| 4055 | sizeof(*image->channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4056 | cache_info->metacontent_extent=image->metacontent_extent; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4057 | cache_info->mode=mode; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 4058 | if (image->ping != MagickFalse) |
| 4059 | { |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 4060 | cache_info->type=PingCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4061 | cache_info->pixels=(Quantum *) NULL; |
| 4062 | cache_info->metacontent=(void *) NULL; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 4063 | cache_info->length=0; |
| 4064 | return(MagickTrue); |
| 4065 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4066 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4067 | packet_size=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4068 | if (image->metacontent_extent != 0) |
| 4069 | packet_size+=cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4070 | length=number_pixels*packet_size; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4071 | columns=(size_t) (length/cache_info->rows/packet_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4072 | if (cache_info->columns != columns) |
| 4073 | ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed", |
| 4074 | image->filename); |
| 4075 | cache_info->length=length; |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 4076 | p=cache_info->channel_map; |
| 4077 | q=source_info.channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4078 | if ((cache_info->type != UndefinedCache) && |
| 4079 | (cache_info->columns <= source_info.columns) && |
| 4080 | (cache_info->rows <= source_info.rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4081 | (cache_info->number_channels <= source_info.number_channels) && |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 4082 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4083 | (cache_info->metacontent_extent <= source_info.metacontent_extent)) |
| 4084 | { |
| 4085 | /* |
| 4086 | Inline pixel cache clone optimization. |
| 4087 | */ |
| 4088 | if ((cache_info->columns == source_info.columns) && |
| 4089 | (cache_info->rows == source_info.rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4090 | (cache_info->number_channels == source_info.number_channels) && |
cristy | 32cacff | 2011-12-31 03:36:27 +0000 | [diff] [blame] | 4091 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4092 | (cache_info->metacontent_extent == source_info.metacontent_extent)) |
| 4093 | return(MagickTrue); |
| 4094 | return(ClonePixelCachePixels(cache_info,&source_info,exception)); |
| 4095 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4096 | status=AcquireMagickResource(AreaResource,cache_info->length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4097 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4098 | cache_info->metacontent_extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4099 | if ((status != MagickFalse) && (length == (MagickSizeType) ((size_t) length))) |
| 4100 | { |
| 4101 | status=AcquireMagickResource(MemoryResource,cache_info->length); |
| 4102 | if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) || |
| 4103 | (cache_info->type == MemoryCache)) |
| 4104 | { |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 4105 | AllocatePixelCachePixels(cache_info); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4106 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4107 | cache_info->pixels=source_info.pixels; |
| 4108 | else |
| 4109 | { |
| 4110 | /* |
| 4111 | Create memory pixel cache. |
| 4112 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4113 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4114 | if (image->debug != MagickFalse) |
| 4115 | { |
cristy | 32cacff | 2011-12-31 03:36:27 +0000 | [diff] [blame] | 4116 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4117 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4118 | "open %s (%s memory, %.20gx%.20gx%.20g %s)", |
| 4119 | cache_info->filename,cache_info->mapped != MagickFalse ? |
| 4120 | "anonymous" : "heap",(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4121 | cache_info->rows,(double) cache_info->number_channels, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4122 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4123 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 4124 | message); |
| 4125 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4126 | cache_info->type=MemoryCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4127 | cache_info->metacontent=(void *) NULL; |
| 4128 | if (cache_info->metacontent_extent != 0) |
| 4129 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4130 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 4131 | if ((source_info.storage_class != UndefinedClass) && |
| 4132 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4133 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4134 | status=ClonePixelCachePixels(cache_info,&source_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4135 | exception); |
| 4136 | RelinquishPixelCachePixels(&source_info); |
| 4137 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4138 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 4142 | } |
| 4143 | /* |
| 4144 | Create pixel cache on disk. |
| 4145 | */ |
| 4146 | status=AcquireMagickResource(DiskResource,cache_info->length); |
| 4147 | if (status == MagickFalse) |
| 4148 | { |
| 4149 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 4150 | "CacheResourcesExhausted","`%s'",image->filename); |
| 4151 | return(MagickFalse); |
| 4152 | } |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 4153 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
| 4154 | { |
| 4155 | (void) ClosePixelCacheOnDisk(cache_info); |
| 4156 | *cache_info->cache_filename='\0'; |
| 4157 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4158 | if (OpenPixelCacheOnDisk(cache_info,mode) == MagickFalse) |
| 4159 | { |
| 4160 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 4161 | ThrowFileException(exception,CacheError,"UnableToOpenPixelCache", |
| 4162 | image->filename); |
| 4163 | return(MagickFalse); |
| 4164 | } |
| 4165 | status=ExtendCache(image,(MagickSizeType) cache_info->offset+ |
| 4166 | cache_info->length); |
| 4167 | if (status == MagickFalse) |
| 4168 | { |
| 4169 | ThrowFileException(exception,CacheError,"UnableToExtendCache", |
| 4170 | image->filename); |
| 4171 | return(MagickFalse); |
| 4172 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4173 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4174 | cache_info->metacontent_extent); |
cristy | a0b40ff | 2011-10-06 18:17:58 +0000 | [diff] [blame] | 4175 | if (length != (MagickSizeType) ((size_t) length)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4176 | cache_info->type=DiskCache; |
| 4177 | else |
| 4178 | { |
| 4179 | status=AcquireMagickResource(MapResource,cache_info->length); |
| 4180 | if ((status == MagickFalse) && (cache_info->type != MapCache) && |
| 4181 | (cache_info->type != MemoryCache)) |
| 4182 | cache_info->type=DiskCache; |
| 4183 | else |
| 4184 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4185 | cache_info->pixels=(Quantum *) MapBlob(cache_info->file,mode, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4186 | cache_info->offset,(size_t) cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4187 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4188 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4189 | cache_info->type=DiskCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4190 | cache_info->pixels=source_info.pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4191 | } |
| 4192 | else |
| 4193 | { |
| 4194 | /* |
| 4195 | Create file-backed memory-mapped pixel cache. |
| 4196 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4197 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4198 | (void) ClosePixelCacheOnDisk(cache_info); |
| 4199 | cache_info->type=MapCache; |
| 4200 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4201 | cache_info->metacontent=(void *) NULL; |
| 4202 | if (cache_info->metacontent_extent != 0) |
| 4203 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4204 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 4205 | if ((source_info.storage_class != UndefinedClass) && |
| 4206 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4207 | { |
| 4208 | status=ClonePixelCachePixels(cache_info,&source_info, |
| 4209 | exception); |
| 4210 | RelinquishPixelCachePixels(&source_info); |
| 4211 | } |
| 4212 | if (image->debug != MagickFalse) |
| 4213 | { |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 4214 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4215 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4216 | "open %s (%s[%d], memory-mapped, %.20gx%.20gx%.20g %s)", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4217 | cache_info->filename,cache_info->cache_filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4218 | cache_info->file,(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4219 | cache_info->rows,(double) cache_info->number_channels, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4220 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4221 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 4222 | message); |
| 4223 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4224 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | RelinquishMagickResource(MapResource,cache_info->length); |
| 4228 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4229 | status=MagickTrue; |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 4230 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4231 | { |
| 4232 | status=ClonePixelCachePixels(cache_info,&source_info,exception); |
| 4233 | RelinquishPixelCachePixels(&source_info); |
| 4234 | } |
| 4235 | if (image->debug != MagickFalse) |
| 4236 | { |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 4237 | (void) FormatMagickSize(cache_info->length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4238 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4239 | "open %s (%s[%d], disk, %.20gx%.20gx%.20g %s)",cache_info->filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4240 | cache_info->cache_filename,cache_info->file,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4241 | cache_info->columns,(double) cache_info->rows,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4242 | cache_info->number_channels,format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4243 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 4244 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4245 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | /* |
| 4249 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4250 | % % |
| 4251 | % % |
| 4252 | % % |
| 4253 | + P e r s i s t P i x e l C a c h e % |
| 4254 | % % |
| 4255 | % % |
| 4256 | % % |
| 4257 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4258 | % |
| 4259 | % PersistPixelCache() attaches to or initializes a persistent pixel cache. A |
| 4260 | % persistent pixel cache is one that resides on disk and is not destroyed |
| 4261 | % when the program exits. |
| 4262 | % |
| 4263 | % The format of the PersistPixelCache() method is: |
| 4264 | % |
| 4265 | % MagickBooleanType PersistPixelCache(Image *image,const char *filename, |
| 4266 | % const MagickBooleanType attach,MagickOffsetType *offset, |
| 4267 | % ExceptionInfo *exception) |
| 4268 | % |
| 4269 | % A description of each parameter follows: |
| 4270 | % |
| 4271 | % o image: the image. |
| 4272 | % |
| 4273 | % o filename: the persistent pixel cache filename. |
| 4274 | % |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 4275 | % o attach: A value other than zero initializes the persistent pixel cache. |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4276 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4277 | % o initialize: A value other than zero initializes the persistent pixel |
| 4278 | % cache. |
| 4279 | % |
| 4280 | % o offset: the offset in the persistent cache to store pixels. |
| 4281 | % |
| 4282 | % o exception: return any errors or warnings in this structure. |
| 4283 | % |
| 4284 | */ |
| 4285 | MagickExport MagickBooleanType PersistPixelCache(Image *image, |
| 4286 | const char *filename,const MagickBooleanType attach,MagickOffsetType *offset, |
| 4287 | ExceptionInfo *exception) |
| 4288 | { |
| 4289 | CacheInfo |
| 4290 | *cache_info, |
| 4291 | *clone_info; |
| 4292 | |
| 4293 | Image |
| 4294 | clone_image; |
| 4295 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4296 | MagickBooleanType |
| 4297 | status; |
| 4298 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4299 | ssize_t |
| 4300 | page_size; |
| 4301 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4302 | assert(image != (Image *) NULL); |
| 4303 | assert(image->signature == MagickSignature); |
| 4304 | if (image->debug != MagickFalse) |
| 4305 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4306 | assert(image->cache != (void *) NULL); |
| 4307 | assert(filename != (const char *) NULL); |
| 4308 | assert(offset != (MagickOffsetType *) NULL); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4309 | page_size=GetMagickPageSize(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4310 | cache_info=(CacheInfo *) image->cache; |
| 4311 | assert(cache_info->signature == MagickSignature); |
| 4312 | if (attach != MagickFalse) |
| 4313 | { |
| 4314 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4315 | Attach existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4316 | */ |
| 4317 | if (image->debug != MagickFalse) |
| 4318 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4319 | "attach persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4320 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4321 | MaxTextExtent); |
| 4322 | cache_info->type=DiskCache; |
| 4323 | cache_info->offset=(*offset); |
cristy | de8c9c5 | 2010-09-20 18:56:24 +0000 | [diff] [blame] | 4324 | if (OpenPixelCache(image,ReadMode,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4325 | return(MagickFalse); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4326 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 8396771 | 2010-09-20 23:35:28 +0000 | [diff] [blame] | 4327 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4328 | } |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4329 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
| 4330 | (cache_info->reference_count == 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4331 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4332 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 4333 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4334 | (cache_info->reference_count == 1)) |
| 4335 | { |
| 4336 | int |
| 4337 | status; |
| 4338 | |
| 4339 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4340 | Usurp existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4341 | */ |
cristy | 320684d | 2011-09-23 14:55:47 +0000 | [diff] [blame] | 4342 | status=rename_utf8(cache_info->cache_filename,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4343 | if (status == 0) |
| 4344 | { |
| 4345 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4346 | MaxTextExtent); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4347 | *offset+=cache_info->length+page_size-(cache_info->length % |
| 4348 | page_size); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4349 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 4350 | cache_info=(CacheInfo *) ReferencePixelCache(cache_info); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4351 | if (image->debug != MagickFalse) |
| 4352 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
| 4353 | "Usurp resident persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4354 | return(MagickTrue); |
| 4355 | } |
| 4356 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4357 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4358 | } |
| 4359 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4360 | Clone persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4361 | */ |
| 4362 | clone_image=(*image); |
| 4363 | clone_info=(CacheInfo *) clone_image.cache; |
| 4364 | image->cache=ClonePixelCache(cache_info); |
| 4365 | cache_info=(CacheInfo *) ReferencePixelCache(image->cache); |
| 4366 | (void) CopyMagickString(cache_info->cache_filename,filename,MaxTextExtent); |
| 4367 | cache_info->type=DiskCache; |
| 4368 | cache_info->offset=(*offset); |
| 4369 | cache_info=(CacheInfo *) image->cache; |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4370 | status=OpenPixelCache(image,IOMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4371 | if (status != MagickFalse) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 4372 | status=ClonePixelCachePixels(cache_info,clone_info,exception); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4373 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4374 | clone_info=(CacheInfo *) DestroyPixelCache(clone_info); |
| 4375 | return(status); |
| 4376 | } |
| 4377 | |
| 4378 | /* |
| 4379 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4380 | % % |
| 4381 | % % |
| 4382 | % % |
| 4383 | + Q u e u e A u t h e n t i c N e x u s % |
| 4384 | % % |
| 4385 | % % |
| 4386 | % % |
| 4387 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4388 | % |
| 4389 | % QueueAuthenticNexus() allocates an region to store image pixels as defined |
| 4390 | % by the region rectangle and returns a pointer to the region. This region is |
| 4391 | % subsequently transferred from the pixel cache with |
| 4392 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4393 | % pixels are transferred, otherwise a NULL is returned. |
| 4394 | % |
| 4395 | % The format of the QueueAuthenticNexus() method is: |
| 4396 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4397 | % Quantum *QueueAuthenticNexus(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4398 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4399 | % const MagickBooleanType clone,NexusInfo *nexus_info, |
| 4400 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4401 | % |
| 4402 | % A description of each parameter follows: |
| 4403 | % |
| 4404 | % o image: the image. |
| 4405 | % |
| 4406 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4407 | % pixels. |
| 4408 | % |
| 4409 | % o nexus_info: the cache nexus to set. |
| 4410 | % |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4411 | % o clone: clone the pixel cache. |
| 4412 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4413 | % o exception: return any errors or warnings in this structure. |
| 4414 | % |
| 4415 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4416 | MagickPrivate Quantum *QueueAuthenticNexus(Image *image,const ssize_t x, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4417 | const ssize_t y,const size_t columns,const size_t rows, |
| 4418 | const MagickBooleanType clone,NexusInfo *nexus_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4419 | { |
| 4420 | CacheInfo |
| 4421 | *cache_info; |
| 4422 | |
| 4423 | MagickOffsetType |
| 4424 | offset; |
| 4425 | |
| 4426 | MagickSizeType |
| 4427 | number_pixels; |
| 4428 | |
| 4429 | RectangleInfo |
| 4430 | region; |
| 4431 | |
| 4432 | /* |
| 4433 | Validate pixel cache geometry. |
| 4434 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4435 | assert(image != (const Image *) NULL); |
| 4436 | assert(image->signature == MagickSignature); |
| 4437 | assert(image->cache != (Cache) NULL); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4438 | cache_info=(CacheInfo *) GetImagePixelCache(image,clone,exception); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4439 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4440 | return((Quantum *) NULL); |
cristy | e27517a | 2011-09-04 23:02:10 +0000 | [diff] [blame] | 4441 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4442 | if ((cache_info->columns == 0) && (cache_info->rows == 0)) |
| 4443 | { |
| 4444 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 4445 | "NoPixelsDefinedInCache","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4446 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4447 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4448 | if ((x < 0) || (y < 0) || (x >= (ssize_t) cache_info->columns) || |
| 4449 | (y >= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4450 | { |
| 4451 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 4452 | "PixelsAreNotAuthentic","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4453 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4454 | } |
| 4455 | offset=(MagickOffsetType) y*cache_info->columns+x; |
| 4456 | if (offset < 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4457 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4458 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 4459 | offset+=(MagickOffsetType) (rows-1)*cache_info->columns+columns-1; |
| 4460 | if ((MagickSizeType) offset >= number_pixels) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4461 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4462 | /* |
| 4463 | Return pixel cache. |
| 4464 | */ |
| 4465 | region.x=x; |
| 4466 | region.y=y; |
| 4467 | region.width=columns; |
| 4468 | region.height=rows; |
| 4469 | return(SetPixelCacheNexusPixels(image,®ion,nexus_info,exception)); |
| 4470 | } |
| 4471 | |
| 4472 | /* |
| 4473 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4474 | % % |
| 4475 | % % |
| 4476 | % % |
| 4477 | + 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 % |
| 4478 | % % |
| 4479 | % % |
| 4480 | % % |
| 4481 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4482 | % |
| 4483 | % QueueAuthenticPixelsCache() allocates an region to store image pixels as |
| 4484 | % defined by the region rectangle and returns a pointer to the region. This |
| 4485 | % region is subsequently transferred from the pixel cache with |
| 4486 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4487 | % pixels are transferred, otherwise a NULL is returned. |
| 4488 | % |
| 4489 | % The format of the QueueAuthenticPixelsCache() method is: |
| 4490 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4491 | % Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4492 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4493 | % ExceptionInfo *exception) |
| 4494 | % |
| 4495 | % A description of each parameter follows: |
| 4496 | % |
| 4497 | % o image: the image. |
| 4498 | % |
| 4499 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4500 | % pixels. |
| 4501 | % |
| 4502 | % o exception: return any errors or warnings in this structure. |
| 4503 | % |
| 4504 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4505 | static Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4506 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4507 | ExceptionInfo *exception) |
| 4508 | { |
| 4509 | CacheInfo |
| 4510 | *cache_info; |
| 4511 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4512 | const int |
| 4513 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4514 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4515 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4516 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4517 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4518 | assert(image != (const Image *) NULL); |
| 4519 | assert(image->signature == MagickSignature); |
| 4520 | assert(image->cache != (Cache) NULL); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4521 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4522 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4523 | assert(id < (int) cache_info->number_threads); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4524 | q=QueueAuthenticNexus(image,x,y,columns,rows,MagickFalse, |
| 4525 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4526 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /* |
| 4530 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4531 | % % |
| 4532 | % % |
| 4533 | % % |
| 4534 | % Q u e u e A u t h e n t i c P i x e l s % |
| 4535 | % % |
| 4536 | % % |
| 4537 | % % |
| 4538 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4539 | % |
| 4540 | % QueueAuthenticPixels() queues a mutable pixel region. If the region is |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4541 | % successfully initialized a pointer to a Quantum array representing the |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4542 | % region is returned, otherwise NULL is returned. The returned pointer may |
| 4543 | % point to a temporary working buffer for the pixels or it may point to the |
| 4544 | % final location of the pixels in memory. |
| 4545 | % |
| 4546 | % Write-only access means that any existing pixel values corresponding to |
| 4547 | % the region are ignored. This is useful if the initial image is being |
| 4548 | % created from scratch, or if the existing pixel values are to be |
| 4549 | % completely replaced without need to refer to their pre-existing values. |
| 4550 | % The application is free to read and write the pixel buffer returned by |
| 4551 | % QueueAuthenticPixels() any way it pleases. QueueAuthenticPixels() does not |
| 4552 | % initialize the pixel array values. Initializing pixel array values is the |
| 4553 | % application's responsibility. |
| 4554 | % |
| 4555 | % Performance is maximized if the selected region is part of one row, or |
| 4556 | % one or more full rows, since then there is opportunity to access the |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 4557 | % pixels in-place (without a copy) if the image is in memory, or in a |
| 4558 | % memory-mapped file. The returned pointer must *never* be deallocated |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4559 | % by the user. |
| 4560 | % |
| 4561 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4562 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 4563 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 4564 | % obtain the meta-content (of type void) corresponding to the region. |
| 4565 | % Once the Quantum (and/or Quantum) array has been updated, the |
| 4566 | % changes must be saved back to the underlying image using |
| 4567 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4568 | % |
| 4569 | % The format of the QueueAuthenticPixels() method is: |
| 4570 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4571 | % Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4572 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4573 | % ExceptionInfo *exception) |
| 4574 | % |
| 4575 | % A description of each parameter follows: |
| 4576 | % |
| 4577 | % o image: the image. |
| 4578 | % |
| 4579 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4580 | % pixels. |
| 4581 | % |
| 4582 | % o exception: return any errors or warnings in this structure. |
| 4583 | % |
| 4584 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4585 | MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4586 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4587 | ExceptionInfo *exception) |
| 4588 | { |
| 4589 | CacheInfo |
| 4590 | *cache_info; |
| 4591 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4592 | const int |
| 4593 | id = GetOpenMPThreadId(); |
| 4594 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4595 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4596 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4597 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4598 | assert(image != (Image *) NULL); |
| 4599 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4600 | assert(image->cache != (Cache) NULL); |
| 4601 | cache_info=(CacheInfo *) image->cache; |
| 4602 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 4603 | if (cache_info->methods.queue_authentic_pixels_handler != |
| 4604 | (QueueAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4605 | { |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4606 | q=cache_info->methods.queue_authentic_pixels_handler(image,x,y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4607 | columns,rows,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4608 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4609 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4610 | assert(id < (int) cache_info->number_threads); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4611 | q=QueueAuthenticNexus(image,x,y,columns,rows,MagickFalse, |
| 4612 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4613 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | /* |
| 4617 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4618 | % % |
| 4619 | % % |
| 4620 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4621 | + 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] | 4622 | % % |
| 4623 | % % |
| 4624 | % % |
| 4625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4626 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4627 | % ReadPixelCacheMetacontent() reads metacontent from the specified region of |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4628 | % the pixel cache. |
| 4629 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4630 | % The format of the ReadPixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4631 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4632 | % MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4633 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4634 | % |
| 4635 | % A description of each parameter follows: |
| 4636 | % |
| 4637 | % o cache_info: the pixel cache. |
| 4638 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4639 | % o nexus_info: the cache nexus to read the metacontent. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4640 | % |
| 4641 | % o exception: return any errors or warnings in this structure. |
| 4642 | % |
| 4643 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4644 | static MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4645 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4646 | { |
| 4647 | MagickOffsetType |
| 4648 | count, |
| 4649 | offset; |
| 4650 | |
| 4651 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4652 | extent, |
| 4653 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4654 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4655 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4656 | y; |
| 4657 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4658 | register unsigned char |
| 4659 | *restrict q; |
| 4660 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4661 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4662 | rows; |
| 4663 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4664 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4665 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4666 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4667 | return(MagickTrue); |
| 4668 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4669 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4670 | length=(MagickSizeType) nexus_info->region.width* |
| 4671 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4672 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4673 | extent=length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4674 | q=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4675 | switch (cache_info->type) |
| 4676 | { |
| 4677 | case MemoryCache: |
| 4678 | case MapCache: |
| 4679 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4680 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4681 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4682 | |
| 4683 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4684 | Read meta-content from memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4685 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4686 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4687 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4688 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4689 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4690 | rows=1UL; |
| 4691 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4692 | p=(unsigned char *) cache_info->metacontent+offset* |
| 4693 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4694 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4695 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4696 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4697 | p+=cache_info->metacontent_extent*cache_info->columns; |
| 4698 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4699 | } |
| 4700 | break; |
| 4701 | } |
| 4702 | case DiskCache: |
| 4703 | { |
| 4704 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4705 | Read meta content from disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4706 | */ |
| 4707 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4708 | { |
| 4709 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4710 | cache_info->cache_filename); |
| 4711 | return(MagickFalse); |
| 4712 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4713 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4714 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4715 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4716 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4717 | rows=1UL; |
| 4718 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4719 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4720 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4721 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4722 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4723 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4724 | cache_info->metacontent_extent,length,(unsigned char *) q); |
| 4725 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4726 | break; |
| 4727 | offset+=cache_info->columns; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4728 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4729 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4730 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4731 | { |
| 4732 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4733 | cache_info->cache_filename); |
| 4734 | return(MagickFalse); |
| 4735 | } |
| 4736 | break; |
| 4737 | } |
| 4738 | default: |
| 4739 | break; |
| 4740 | } |
| 4741 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4742 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4743 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4744 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4745 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4746 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4747 | return(MagickTrue); |
| 4748 | } |
| 4749 | |
| 4750 | /* |
| 4751 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4752 | % % |
| 4753 | % % |
| 4754 | % % |
| 4755 | + R e a d P i x e l C a c h e P i x e l s % |
| 4756 | % % |
| 4757 | % % |
| 4758 | % % |
| 4759 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4760 | % |
| 4761 | % ReadPixelCachePixels() reads pixels from the specified region of the pixel |
| 4762 | % cache. |
| 4763 | % |
| 4764 | % The format of the ReadPixelCachePixels() method is: |
| 4765 | % |
| 4766 | % MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4767 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4768 | % |
| 4769 | % A description of each parameter follows: |
| 4770 | % |
| 4771 | % o cache_info: the pixel cache. |
| 4772 | % |
| 4773 | % o nexus_info: the cache nexus to read the pixels. |
| 4774 | % |
| 4775 | % o exception: return any errors or warnings in this structure. |
| 4776 | % |
| 4777 | */ |
| 4778 | static MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4779 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4780 | { |
| 4781 | MagickOffsetType |
| 4782 | count, |
| 4783 | offset; |
| 4784 | |
| 4785 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4786 | extent, |
| 4787 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4788 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4789 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4790 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4791 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4792 | register ssize_t |
| 4793 | y; |
| 4794 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4795 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4796 | rows; |
| 4797 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4798 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4799 | return(MagickTrue); |
| 4800 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4801 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4802 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4803 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4804 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4805 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4806 | q=nexus_info->pixels; |
| 4807 | switch (cache_info->type) |
| 4808 | { |
| 4809 | case MemoryCache: |
| 4810 | case MapCache: |
| 4811 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4812 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4813 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4814 | |
| 4815 | /* |
| 4816 | Read pixels from memory. |
| 4817 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4818 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4819 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4820 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4821 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4822 | rows=1UL; |
| 4823 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4824 | p=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4825 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4826 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4827 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4828 | p+=cache_info->number_channels*cache_info->columns; |
| 4829 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4830 | } |
| 4831 | break; |
| 4832 | } |
| 4833 | case DiskCache: |
| 4834 | { |
| 4835 | /* |
| 4836 | Read pixels from disk. |
| 4837 | */ |
| 4838 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4839 | { |
| 4840 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4841 | cache_info->cache_filename); |
| 4842 | return(MagickFalse); |
| 4843 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4844 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4845 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4846 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4847 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4848 | rows=1UL; |
| 4849 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4850 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4851 | { |
| 4852 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4853 | cache_info->number_channels*sizeof(*q),length,(unsigned char *) q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4854 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4855 | break; |
| 4856 | offset+=cache_info->columns; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4857 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4858 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4859 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4860 | { |
| 4861 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4862 | cache_info->cache_filename); |
| 4863 | return(MagickFalse); |
| 4864 | } |
| 4865 | break; |
| 4866 | } |
| 4867 | default: |
| 4868 | break; |
| 4869 | } |
| 4870 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4871 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4872 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4873 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4874 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4875 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4876 | return(MagickTrue); |
| 4877 | } |
| 4878 | |
| 4879 | /* |
| 4880 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4881 | % % |
| 4882 | % % |
| 4883 | % % |
| 4884 | + R e f e r e n c e P i x e l C a c h e % |
| 4885 | % % |
| 4886 | % % |
| 4887 | % % |
| 4888 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4889 | % |
| 4890 | % ReferencePixelCache() increments the reference count associated with the |
| 4891 | % pixel cache returning a pointer to the cache. |
| 4892 | % |
| 4893 | % The format of the ReferencePixelCache method is: |
| 4894 | % |
| 4895 | % Cache ReferencePixelCache(Cache cache_info) |
| 4896 | % |
| 4897 | % A description of each parameter follows: |
| 4898 | % |
| 4899 | % o cache_info: the pixel cache. |
| 4900 | % |
| 4901 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4902 | MagickPrivate Cache ReferencePixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4903 | { |
| 4904 | CacheInfo |
| 4905 | *cache_info; |
| 4906 | |
| 4907 | assert(cache != (Cache *) NULL); |
| 4908 | cache_info=(CacheInfo *) cache; |
| 4909 | assert(cache_info->signature == MagickSignature); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4910 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4911 | cache_info->reference_count++; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4912 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4913 | return(cache_info); |
| 4914 | } |
| 4915 | |
| 4916 | /* |
| 4917 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4918 | % % |
| 4919 | % % |
| 4920 | % % |
| 4921 | + S e t P i x e l C a c h e M e t h o d s % |
| 4922 | % % |
| 4923 | % % |
| 4924 | % % |
| 4925 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4926 | % |
| 4927 | % SetPixelCacheMethods() sets the image pixel methods to the specified ones. |
| 4928 | % |
| 4929 | % The format of the SetPixelCacheMethods() method is: |
| 4930 | % |
| 4931 | % SetPixelCacheMethods(Cache *,CacheMethods *cache_methods) |
| 4932 | % |
| 4933 | % A description of each parameter follows: |
| 4934 | % |
| 4935 | % o cache: the pixel cache. |
| 4936 | % |
| 4937 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 4938 | % |
| 4939 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4940 | MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4941 | { |
| 4942 | CacheInfo |
| 4943 | *cache_info; |
| 4944 | |
| 4945 | GetOneAuthenticPixelFromHandler |
| 4946 | get_one_authentic_pixel_from_handler; |
| 4947 | |
| 4948 | GetOneVirtualPixelFromHandler |
| 4949 | get_one_virtual_pixel_from_handler; |
| 4950 | |
| 4951 | /* |
| 4952 | Set cache pixel methods. |
| 4953 | */ |
| 4954 | assert(cache != (Cache) NULL); |
| 4955 | assert(cache_methods != (CacheMethods *) NULL); |
| 4956 | cache_info=(CacheInfo *) cache; |
| 4957 | assert(cache_info->signature == MagickSignature); |
| 4958 | if (cache_info->debug != MagickFalse) |
| 4959 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4960 | cache_info->filename); |
| 4961 | if (cache_methods->get_virtual_pixel_handler != (GetVirtualPixelHandler) NULL) |
| 4962 | cache_info->methods.get_virtual_pixel_handler= |
| 4963 | cache_methods->get_virtual_pixel_handler; |
| 4964 | if (cache_methods->destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 4965 | cache_info->methods.destroy_pixel_handler= |
| 4966 | cache_methods->destroy_pixel_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4967 | if (cache_methods->get_virtual_metacontent_from_handler != |
| 4968 | (GetVirtualMetacontentFromHandler) NULL) |
| 4969 | cache_info->methods.get_virtual_metacontent_from_handler= |
| 4970 | cache_methods->get_virtual_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4971 | if (cache_methods->get_authentic_pixels_handler != |
| 4972 | (GetAuthenticPixelsHandler) NULL) |
| 4973 | cache_info->methods.get_authentic_pixels_handler= |
| 4974 | cache_methods->get_authentic_pixels_handler; |
| 4975 | if (cache_methods->queue_authentic_pixels_handler != |
| 4976 | (QueueAuthenticPixelsHandler) NULL) |
| 4977 | cache_info->methods.queue_authentic_pixels_handler= |
| 4978 | cache_methods->queue_authentic_pixels_handler; |
| 4979 | if (cache_methods->sync_authentic_pixels_handler != |
| 4980 | (SyncAuthenticPixelsHandler) NULL) |
| 4981 | cache_info->methods.sync_authentic_pixels_handler= |
| 4982 | cache_methods->sync_authentic_pixels_handler; |
| 4983 | if (cache_methods->get_authentic_pixels_from_handler != |
| 4984 | (GetAuthenticPixelsFromHandler) NULL) |
| 4985 | cache_info->methods.get_authentic_pixels_from_handler= |
| 4986 | cache_methods->get_authentic_pixels_from_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4987 | if (cache_methods->get_authentic_metacontent_from_handler != |
| 4988 | (GetAuthenticMetacontentFromHandler) NULL) |
| 4989 | cache_info->methods.get_authentic_metacontent_from_handler= |
| 4990 | cache_methods->get_authentic_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4991 | get_one_virtual_pixel_from_handler= |
| 4992 | cache_info->methods.get_one_virtual_pixel_from_handler; |
| 4993 | if (get_one_virtual_pixel_from_handler != |
| 4994 | (GetOneVirtualPixelFromHandler) NULL) |
| 4995 | cache_info->methods.get_one_virtual_pixel_from_handler= |
| 4996 | cache_methods->get_one_virtual_pixel_from_handler; |
| 4997 | get_one_authentic_pixel_from_handler= |
| 4998 | cache_methods->get_one_authentic_pixel_from_handler; |
| 4999 | if (get_one_authentic_pixel_from_handler != |
| 5000 | (GetOneAuthenticPixelFromHandler) NULL) |
| 5001 | cache_info->methods.get_one_authentic_pixel_from_handler= |
| 5002 | cache_methods->get_one_authentic_pixel_from_handler; |
| 5003 | } |
| 5004 | |
| 5005 | /* |
| 5006 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5007 | % % |
| 5008 | % % |
| 5009 | % % |
| 5010 | + S e t P i x e l C a c h e N e x u s P i x e l s % |
| 5011 | % % |
| 5012 | % % |
| 5013 | % % |
| 5014 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5015 | % |
| 5016 | % SetPixelCacheNexusPixels() defines the region of the cache for the |
| 5017 | % specified cache nexus. |
| 5018 | % |
| 5019 | % The format of the SetPixelCacheNexusPixels() method is: |
| 5020 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5021 | % Quantum SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5022 | % const RectangleInfo *region,NexusInfo *nexus_info, |
| 5023 | % ExceptionInfo *exception) |
| 5024 | % |
| 5025 | % A description of each parameter follows: |
| 5026 | % |
| 5027 | % o image: the image. |
| 5028 | % |
| 5029 | % o region: A pointer to the RectangleInfo structure that defines the |
| 5030 | % region of this particular cache nexus. |
| 5031 | % |
| 5032 | % o nexus_info: the cache nexus to set. |
| 5033 | % |
| 5034 | % o exception: return any errors or warnings in this structure. |
| 5035 | % |
| 5036 | */ |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 5037 | |
| 5038 | static inline MagickBooleanType AcquireCacheNexusPixels(CacheInfo *cache_info, |
| 5039 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5040 | { |
| 5041 | if (nexus_info->length != (MagickSizeType) ((size_t) nexus_info->length)) |
| 5042 | return(MagickFalse); |
| 5043 | nexus_info->mapped=MagickFalse; |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 5044 | nexus_info->cache=(Quantum *) AcquireQuantumMemory(1,(size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 5045 | nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5046 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 5047 | { |
| 5048 | nexus_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5049 | nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 5050 | nexus_info->length); |
| 5051 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5052 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 5053 | { |
| 5054 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 5055 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 5056 | cache_info->filename); |
| 5057 | return(MagickFalse); |
| 5058 | } |
| 5059 | return(MagickTrue); |
| 5060 | } |
| 5061 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5062 | static Quantum *SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5063 | const RectangleInfo *region,NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5064 | { |
| 5065 | CacheInfo |
| 5066 | *cache_info; |
| 5067 | |
| 5068 | MagickBooleanType |
| 5069 | status; |
| 5070 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5071 | MagickSizeType |
| 5072 | length, |
| 5073 | number_pixels; |
| 5074 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5075 | cache_info=(CacheInfo *) image->cache; |
| 5076 | assert(cache_info->signature == MagickSignature); |
| 5077 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5078 | return((Quantum *) NULL); |
cristy | dc8b63f | 2010-03-13 16:11:14 +0000 | [diff] [blame] | 5079 | nexus_info->region=(*region); |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 5080 | if ((cache_info->type != DiskCache) && (cache_info->type != PingCache) && |
| 5081 | (image->clip_mask == (Image *) NULL) && (image->mask == (Image *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5082 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5083 | ssize_t |
cristy | bad067a | 2010-02-15 17:20:55 +0000 | [diff] [blame] | 5084 | x, |
| 5085 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5086 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 5087 | x=nexus_info->region.x+(ssize_t) nexus_info->region.width-1; |
| 5088 | y=nexus_info->region.y+(ssize_t) nexus_info->region.height-1; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5089 | if (((nexus_info->region.x >= 0) && (x < (ssize_t) cache_info->columns) && |
| 5090 | (nexus_info->region.y >= 0) && (y < (ssize_t) cache_info->rows)) && |
cristy | ed733b3 | 2010-09-17 16:27:34 +0000 | [diff] [blame] | 5091 | ((nexus_info->region.height == 1UL) || ((nexus_info->region.x == 0) && |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 5092 | ((nexus_info->region.width == cache_info->columns) || |
| 5093 | ((nexus_info->region.width % cache_info->columns) == 0))))) |
| 5094 | { |
| 5095 | MagickOffsetType |
| 5096 | offset; |
| 5097 | |
| 5098 | /* |
| 5099 | Pixels are accessed directly from memory. |
| 5100 | */ |
| 5101 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5102 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5103 | nexus_info->pixels=cache_info->pixels+cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5104 | offset; |
| 5105 | nexus_info->metacontent=(void *) NULL; |
| 5106 | if (cache_info->metacontent_extent != 0) |
| 5107 | nexus_info->metacontent=(unsigned char *) cache_info->metacontent+ |
| 5108 | offset*cache_info->metacontent_extent; |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 5109 | return(nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5110 | } |
| 5111 | } |
| 5112 | /* |
| 5113 | Pixels are stored in a cache region until they are synced to the cache. |
| 5114 | */ |
| 5115 | number_pixels=(MagickSizeType) nexus_info->region.width* |
| 5116 | nexus_info->region.height; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5117 | length=number_pixels*cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5118 | if (cache_info->metacontent_extent != 0) |
| 5119 | length+=number_pixels*cache_info->metacontent_extent; |
| 5120 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5121 | { |
| 5122 | nexus_info->length=length; |
| 5123 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 5124 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 5125 | { |
| 5126 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5127 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 5128 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5129 | } |
| 5130 | else |
| 5131 | if (nexus_info->length != length) |
| 5132 | { |
| 5133 | RelinquishCacheNexusPixels(nexus_info); |
| 5134 | nexus_info->length=length; |
| 5135 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 5136 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 5137 | { |
| 5138 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5139 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 5140 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5141 | } |
| 5142 | nexus_info->pixels=nexus_info->cache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5143 | nexus_info->metacontent=(void *) NULL; |
| 5144 | if (cache_info->metacontent_extent != 0) |
| 5145 | nexus_info->metacontent=(void *) (nexus_info->pixels+number_pixels* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5146 | cache_info->number_channels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5147 | return(nexus_info->pixels); |
| 5148 | } |
| 5149 | |
| 5150 | /* |
| 5151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5152 | % % |
| 5153 | % % |
| 5154 | % % |
| 5155 | % 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 % |
| 5156 | % % |
| 5157 | % % |
| 5158 | % % |
| 5159 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5160 | % |
| 5161 | % SetPixelCacheVirtualMethod() sets the "virtual pixels" method for the |
| 5162 | % pixel cache and returns the previous setting. A virtual pixel is any pixel |
| 5163 | % access that is outside the boundaries of the image cache. |
| 5164 | % |
| 5165 | % The format of the SetPixelCacheVirtualMethod() method is: |
| 5166 | % |
| 5167 | % VirtualPixelMethod SetPixelCacheVirtualMethod(const Image *image, |
| 5168 | % const VirtualPixelMethod virtual_pixel_method) |
| 5169 | % |
| 5170 | % A description of each parameter follows: |
| 5171 | % |
| 5172 | % o image: the image. |
| 5173 | % |
| 5174 | % o virtual_pixel_method: choose the type of virtual pixel. |
| 5175 | % |
| 5176 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5177 | MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5178 | const VirtualPixelMethod virtual_pixel_method) |
| 5179 | { |
| 5180 | CacheInfo |
| 5181 | *cache_info; |
| 5182 | |
| 5183 | VirtualPixelMethod |
| 5184 | method; |
| 5185 | |
| 5186 | assert(image != (Image *) NULL); |
| 5187 | assert(image->signature == MagickSignature); |
| 5188 | if (image->debug != MagickFalse) |
| 5189 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5190 | assert(image->cache != (Cache) NULL); |
| 5191 | cache_info=(CacheInfo *) image->cache; |
| 5192 | assert(cache_info->signature == MagickSignature); |
| 5193 | method=cache_info->virtual_pixel_method; |
| 5194 | cache_info->virtual_pixel_method=virtual_pixel_method; |
| 5195 | return(method); |
| 5196 | } |
| 5197 | |
| 5198 | /* |
| 5199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5200 | % % |
| 5201 | % % |
| 5202 | % % |
| 5203 | + 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 % |
| 5204 | % % |
| 5205 | % % |
| 5206 | % % |
| 5207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5208 | % |
| 5209 | % SyncAuthenticPixelCacheNexus() saves the authentic image pixels to the |
| 5210 | % in-memory or disk cache. The method returns MagickTrue if the pixel region |
| 5211 | % is synced, otherwise MagickFalse. |
| 5212 | % |
| 5213 | % The format of the SyncAuthenticPixelCacheNexus() method is: |
| 5214 | % |
| 5215 | % MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
| 5216 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5217 | % |
| 5218 | % A description of each parameter follows: |
| 5219 | % |
| 5220 | % o image: the image. |
| 5221 | % |
| 5222 | % o nexus_info: the cache nexus to sync. |
| 5223 | % |
| 5224 | % o exception: return any errors or warnings in this structure. |
| 5225 | % |
| 5226 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 5227 | MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5228 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5229 | { |
| 5230 | CacheInfo |
| 5231 | *cache_info; |
| 5232 | |
| 5233 | MagickBooleanType |
| 5234 | status; |
| 5235 | |
| 5236 | /* |
| 5237 | Transfer pixels to the cache. |
| 5238 | */ |
| 5239 | assert(image != (Image *) NULL); |
| 5240 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5241 | if (image->cache == (Cache) NULL) |
| 5242 | ThrowBinaryException(CacheError,"PixelCacheIsNotOpen",image->filename); |
| 5243 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5244 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5245 | if (cache_info->type == UndefinedCache) |
| 5246 | return(MagickFalse); |
| 5247 | if ((image->clip_mask != (Image *) NULL) && |
| 5248 | (ClipPixelCacheNexus(image,nexus_info,exception) == MagickFalse)) |
| 5249 | return(MagickFalse); |
| 5250 | if ((image->mask != (Image *) NULL) && |
| 5251 | (MaskPixelCacheNexus(image,nexus_info,exception) == MagickFalse)) |
| 5252 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5253 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5254 | return(MagickTrue); |
| 5255 | assert(cache_info->signature == MagickSignature); |
| 5256 | status=WritePixelCachePixels(cache_info,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5257 | if ((cache_info->metacontent_extent != 0) && |
| 5258 | (WritePixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5259 | return(MagickFalse); |
| 5260 | return(status); |
| 5261 | } |
| 5262 | |
| 5263 | /* |
| 5264 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5265 | % % |
| 5266 | % % |
| 5267 | % % |
| 5268 | + S y n c A u t h e n t i c P i x e l C a c h e % |
| 5269 | % % |
| 5270 | % % |
| 5271 | % % |
| 5272 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5273 | % |
| 5274 | % SyncAuthenticPixelsCache() saves the authentic image pixels to the in-memory |
| 5275 | % or disk cache. The method returns MagickTrue if the pixel region is synced, |
| 5276 | % otherwise MagickFalse. |
| 5277 | % |
| 5278 | % The format of the SyncAuthenticPixelsCache() method is: |
| 5279 | % |
| 5280 | % MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 5281 | % ExceptionInfo *exception) |
| 5282 | % |
| 5283 | % A description of each parameter follows: |
| 5284 | % |
| 5285 | % o image: the image. |
| 5286 | % |
| 5287 | % o exception: return any errors or warnings in this structure. |
| 5288 | % |
| 5289 | */ |
| 5290 | static MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 5291 | ExceptionInfo *exception) |
| 5292 | { |
| 5293 | CacheInfo |
| 5294 | *cache_info; |
| 5295 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 5296 | const int |
| 5297 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5298 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5299 | MagickBooleanType |
| 5300 | status; |
| 5301 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5302 | assert(image != (Image *) NULL); |
| 5303 | assert(image->signature == MagickSignature); |
| 5304 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5305 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5306 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 5307 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5308 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5309 | exception); |
| 5310 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | /* |
| 5314 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5315 | % % |
| 5316 | % % |
| 5317 | % % |
| 5318 | % S y n c A u t h e n t i c P i x e l s % |
| 5319 | % % |
| 5320 | % % |
| 5321 | % % |
| 5322 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5323 | % |
| 5324 | % SyncAuthenticPixels() saves the image pixels to the in-memory or disk cache. |
| 5325 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5326 | % MagickFalse. |
| 5327 | % |
| 5328 | % The format of the SyncAuthenticPixels() method is: |
| 5329 | % |
| 5330 | % MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5331 | % ExceptionInfo *exception) |
| 5332 | % |
| 5333 | % A description of each parameter follows: |
| 5334 | % |
| 5335 | % o image: the image. |
| 5336 | % |
| 5337 | % o exception: return any errors or warnings in this structure. |
| 5338 | % |
| 5339 | */ |
| 5340 | MagickExport MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5341 | ExceptionInfo *exception) |
| 5342 | { |
| 5343 | CacheInfo |
| 5344 | *cache_info; |
| 5345 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5346 | const int |
| 5347 | id = GetOpenMPThreadId(); |
| 5348 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5349 | MagickBooleanType |
| 5350 | status; |
| 5351 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5352 | assert(image != (Image *) NULL); |
| 5353 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5354 | assert(image->cache != (Cache) NULL); |
| 5355 | cache_info=(CacheInfo *) image->cache; |
| 5356 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 5357 | if (cache_info->methods.sync_authentic_pixels_handler != |
| 5358 | (SyncAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5359 | { |
| 5360 | status=cache_info->methods.sync_authentic_pixels_handler(image, |
| 5361 | exception); |
| 5362 | return(status); |
| 5363 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5364 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5365 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5366 | exception); |
| 5367 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | /* |
| 5371 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5372 | % % |
| 5373 | % % |
| 5374 | % % |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5375 | + 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] | 5376 | % % |
| 5377 | % % |
| 5378 | % % |
| 5379 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5380 | % |
| 5381 | % SyncImagePixelCache() saves the image pixels to the in-memory or disk cache. |
| 5382 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5383 | % MagickFalse. |
| 5384 | % |
| 5385 | % The format of the SyncImagePixelCache() method is: |
| 5386 | % |
| 5387 | % MagickBooleanType SyncImagePixelCache(Image *image, |
| 5388 | % ExceptionInfo *exception) |
| 5389 | % |
| 5390 | % A description of each parameter follows: |
| 5391 | % |
| 5392 | % o image: the image. |
| 5393 | % |
| 5394 | % o exception: return any errors or warnings in this structure. |
| 5395 | % |
| 5396 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5397 | MagickPrivate MagickBooleanType SyncImagePixelCache(Image *image, |
cristy | 6e43713 | 2011-08-12 13:02:19 +0000 | [diff] [blame] | 5398 | ExceptionInfo *exception) |
| 5399 | { |
| 5400 | CacheInfo |
| 5401 | *cache_info; |
| 5402 | |
| 5403 | assert(image != (Image *) NULL); |
| 5404 | assert(exception != (ExceptionInfo *) NULL); |
| 5405 | cache_info=(CacheInfo *) GetImagePixelCache(image,MagickTrue,exception); |
| 5406 | return(cache_info == (CacheInfo *) NULL ? MagickFalse : MagickTrue); |
| 5407 | } |
| 5408 | |
| 5409 | /* |
| 5410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5411 | % % |
| 5412 | % % |
| 5413 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5414 | + 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] | 5415 | % % |
| 5416 | % % |
| 5417 | % % |
| 5418 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5419 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5420 | % WritePixelCacheMetacontent() writes the meta-content to the specified region |
| 5421 | % of the pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5422 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5423 | % The format of the WritePixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5424 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5425 | % MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5426 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5427 | % |
| 5428 | % A description of each parameter follows: |
| 5429 | % |
| 5430 | % o cache_info: the pixel cache. |
| 5431 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5432 | % o nexus_info: the cache nexus to write the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5433 | % |
| 5434 | % o exception: return any errors or warnings in this structure. |
| 5435 | % |
| 5436 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5437 | static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5438 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5439 | { |
| 5440 | MagickOffsetType |
| 5441 | count, |
| 5442 | offset; |
| 5443 | |
| 5444 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5445 | extent, |
| 5446 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5447 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5448 | register const unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5449 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5450 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5451 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5452 | y; |
| 5453 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5454 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5455 | rows; |
| 5456 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5457 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5458 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5459 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5460 | return(MagickTrue); |
| 5461 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5462 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5463 | length=(MagickSizeType) nexus_info->region.width* |
| 5464 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5465 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5466 | extent=(MagickSizeType) length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5467 | p=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5468 | switch (cache_info->type) |
| 5469 | { |
| 5470 | case MemoryCache: |
| 5471 | case MapCache: |
| 5472 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5473 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5474 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5475 | |
| 5476 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5477 | Write associated pixels to memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5478 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5479 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5480 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5481 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5482 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5483 | rows=1UL; |
| 5484 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5485 | q=(unsigned char *) cache_info->metacontent+offset* |
| 5486 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5487 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5488 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5489 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5490 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
| 5491 | q+=cache_info->columns*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5492 | } |
| 5493 | break; |
| 5494 | } |
| 5495 | case DiskCache: |
| 5496 | { |
| 5497 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5498 | Write associated pixels to disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5499 | */ |
| 5500 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5501 | { |
| 5502 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5503 | cache_info->cache_filename); |
| 5504 | return(MagickFalse); |
| 5505 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5506 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5507 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5508 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5509 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5510 | rows=1UL; |
| 5511 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5512 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5513 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5514 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5515 | count=WritePixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5516 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5517 | cache_info->metacontent_extent,length,(const unsigned char *) p); |
| 5518 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5519 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5520 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5521 | offset+=cache_info->columns; |
| 5522 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5523 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5524 | { |
| 5525 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5526 | cache_info->cache_filename); |
| 5527 | return(MagickFalse); |
| 5528 | } |
| 5529 | break; |
| 5530 | } |
| 5531 | default: |
| 5532 | break; |
| 5533 | } |
| 5534 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5535 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5536 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5537 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5538 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5539 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5540 | return(MagickTrue); |
| 5541 | } |
| 5542 | |
| 5543 | /* |
| 5544 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5545 | % % |
| 5546 | % % |
| 5547 | % % |
| 5548 | + W r i t e C a c h e P i x e l s % |
| 5549 | % % |
| 5550 | % % |
| 5551 | % % |
| 5552 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5553 | % |
| 5554 | % WritePixelCachePixels() writes image pixels to the specified region of the |
| 5555 | % pixel cache. |
| 5556 | % |
| 5557 | % The format of the WritePixelCachePixels() method is: |
| 5558 | % |
| 5559 | % MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5560 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5561 | % |
| 5562 | % A description of each parameter follows: |
| 5563 | % |
| 5564 | % o cache_info: the pixel cache. |
| 5565 | % |
| 5566 | % o nexus_info: the cache nexus to write the pixels. |
| 5567 | % |
| 5568 | % o exception: return any errors or warnings in this structure. |
| 5569 | % |
| 5570 | */ |
| 5571 | static MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5572 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5573 | { |
| 5574 | MagickOffsetType |
| 5575 | count, |
| 5576 | offset; |
| 5577 | |
| 5578 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5579 | extent, |
| 5580 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5581 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5582 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5583 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5584 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5585 | register ssize_t |
cristy | 25ffffb | 2009-12-07 17:15:07 +0000 | [diff] [blame] | 5586 | y; |
| 5587 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5588 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5589 | rows; |
| 5590 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5591 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5592 | return(MagickTrue); |
| 5593 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5594 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5595 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5596 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5597 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5598 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5599 | p=nexus_info->pixels; |
| 5600 | switch (cache_info->type) |
| 5601 | { |
| 5602 | case MemoryCache: |
| 5603 | case MapCache: |
| 5604 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5605 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5606 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5607 | |
| 5608 | /* |
| 5609 | Write pixels to memory. |
| 5610 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5611 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5612 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5613 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5614 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5615 | rows=1UL; |
| 5616 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5617 | q=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5618 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5619 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5620 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5621 | p+=nexus_info->region.width*cache_info->number_channels; |
| 5622 | q+=cache_info->columns*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5623 | } |
| 5624 | break; |
| 5625 | } |
| 5626 | case DiskCache: |
| 5627 | { |
| 5628 | /* |
| 5629 | Write pixels to disk. |
| 5630 | */ |
| 5631 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5632 | { |
| 5633 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5634 | cache_info->cache_filename); |
| 5635 | return(MagickFalse); |
| 5636 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5637 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5638 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5639 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5640 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5641 | rows=1UL; |
| 5642 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5643 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5644 | { |
| 5645 | count=WritePixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5646 | cache_info->number_channels*sizeof(*p),length,(const unsigned char *) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5647 | p); |
| 5648 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5649 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5650 | p+=nexus_info->region.width*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5651 | offset+=cache_info->columns; |
| 5652 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5653 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5654 | { |
| 5655 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5656 | cache_info->cache_filename); |
| 5657 | return(MagickFalse); |
| 5658 | } |
| 5659 | break; |
| 5660 | } |
| 5661 | default: |
| 5662 | break; |
| 5663 | } |
| 5664 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5665 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5666 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5667 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5668 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5669 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5670 | return(MagickTrue); |
| 5671 | } |