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) |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 78 | #define IsFileDescriptorLimitExceeded() (GetMagickResource(FileResource) > \ |
| 79 | GetMagickResourceLimit(FileResource) ? MagickTrue : MagickFalse) |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 82 | Typedef declarations. |
| 83 | */ |
| 84 | typedef struct _MagickModulo |
| 85 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 86 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 87 | quotient, |
| 88 | remainder; |
| 89 | } MagickModulo; |
| 90 | |
| 91 | struct _NexusInfo |
| 92 | { |
| 93 | MagickBooleanType |
| 94 | mapped; |
| 95 | |
| 96 | RectangleInfo |
| 97 | region; |
| 98 | |
| 99 | MagickSizeType |
| 100 | length; |
| 101 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 102 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | *cache, |
| 104 | *pixels; |
| 105 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 106 | void |
| 107 | *metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 109 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | signature; |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | Forward declarations. |
| 115 | */ |
| 116 | #if defined(__cplusplus) || defined(c_plusplus) |
| 117 | extern "C" { |
| 118 | #endif |
| 119 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 120 | static const Quantum |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 121 | *GetVirtualPixelCache(const Image *,const VirtualPixelMethod,const ssize_t, |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 122 | const ssize_t,const size_t,const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | *GetVirtualPixelsCache(const Image *); |
| 124 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 125 | static const void |
| 126 | *GetVirtualMetacontentFromCache(const Image *); |
| 127 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | static MagickBooleanType |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 129 | GetOneAuthenticPixelFromCache(Image *,const ssize_t,const ssize_t, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 130 | Quantum *,ExceptionInfo *), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 131 | GetOneVirtualPixelFromCache(const Image *,const VirtualPixelMethod, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 132 | const ssize_t,const ssize_t,Quantum *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 133 | OpenPixelCache(Image *,const MapMode,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 134 | ReadPixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | ReadPixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *), |
| 136 | SyncAuthenticPixelsCache(Image *,ExceptionInfo *), |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 137 | WritePixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | WritePixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *); |
| 139 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 140 | static Quantum |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 141 | *GetAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 142 | const size_t,ExceptionInfo *), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 143 | *QueueAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t, |
| 144 | const size_t,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | *SetPixelCacheNexusPixels(const Image *,const RectangleInfo *,NexusInfo *, |
cristy | a4af2e3 | 2010-03-08 00:51:56 +0000 | [diff] [blame] | 146 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 147 | |
| 148 | #if defined(__cplusplus) || defined(c_plusplus) |
| 149 | } |
| 150 | #endif |
| 151 | |
| 152 | /* |
| 153 | Global declarations. |
| 154 | */ |
| 155 | static volatile MagickBooleanType |
| 156 | instantiate_cache = MagickFalse; |
| 157 | |
| 158 | static SemaphoreInfo |
| 159 | *cache_semaphore = (SemaphoreInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 163 | % % |
| 164 | % % |
| 165 | % % |
| 166 | + A c q u i r e P i x e l C a c h e % |
| 167 | % % |
| 168 | % % |
| 169 | % % |
| 170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 171 | % |
| 172 | % AcquirePixelCache() acquires a pixel cache. |
| 173 | % |
| 174 | % The format of the AcquirePixelCache() method is: |
| 175 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 176 | % Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | % |
| 178 | % A description of each parameter follows: |
| 179 | % |
| 180 | % o number_threads: the number of nexus threads. |
| 181 | % |
| 182 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 183 | MagickPrivate Cache AcquirePixelCache(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | { |
| 185 | CacheInfo |
| 186 | *cache_info; |
| 187 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 188 | cache_info=(CacheInfo *) AcquireQuantumMemory(1,sizeof(*cache_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | if (cache_info == (CacheInfo *) NULL) |
| 190 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 191 | (void) ResetMagickMemory(cache_info,0,sizeof(*cache_info)); |
| 192 | cache_info->type=UndefinedCache; |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 193 | cache_info->mode=IOMode; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 194 | cache_info->colorspace=RGBColorspace; |
| 195 | cache_info->file=(-1); |
| 196 | cache_info->id=GetMagickThreadId(); |
| 197 | cache_info->number_threads=number_threads; |
| 198 | if (number_threads == 0) |
| 199 | cache_info->number_threads=GetOpenMPMaximumThreads(); |
| 200 | cache_info->nexus_info=AcquirePixelCacheNexus(cache_info->number_threads); |
| 201 | if (cache_info->nexus_info == (NexusInfo **) NULL) |
| 202 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | cache_info->semaphore=AllocateSemaphoreInfo(); |
cristy | 93505cf | 2010-08-10 21:37:49 +0000 | [diff] [blame] | 204 | cache_info->reference_count=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 205 | cache_info->disk_semaphore=AllocateSemaphoreInfo(); |
| 206 | cache_info->debug=IsEventLogging(); |
| 207 | cache_info->signature=MagickSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | return((Cache ) cache_info); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 213 | % % |
| 214 | % % |
| 215 | % % |
| 216 | % A c q u i r e P i x e l C a c h e N e x u s % |
| 217 | % % |
| 218 | % % |
| 219 | % % |
| 220 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 221 | % |
| 222 | % AcquirePixelCacheNexus() allocates the NexusInfo structure. |
| 223 | % |
| 224 | % The format of the AcquirePixelCacheNexus method is: |
| 225 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 226 | % NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | % |
| 228 | % A description of each parameter follows: |
| 229 | % |
| 230 | % o number_threads: the number of nexus threads. |
| 231 | % |
| 232 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 233 | MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 235 | NexusInfo |
| 236 | **nexus_info; |
| 237 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 238 | register ssize_t |
| 239 | i; |
| 240 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 241 | nexus_info=(NexusInfo **) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 242 | sizeof(*nexus_info)); |
| 243 | if (nexus_info == (NexusInfo **) NULL) |
| 244 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 245 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 246 | { |
cristy | 7dc8ac5 | 2012-01-10 20:14:52 +0000 | [diff] [blame] | 247 | nexus_info[i]=(NexusInfo *) AcquireQuantumMemory(1,sizeof(**nexus_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | if (nexus_info[i] == (NexusInfo *) NULL) |
| 249 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 250 | (void) ResetMagickMemory(nexus_info[i],0,sizeof(*nexus_info[i])); |
| 251 | nexus_info[i]->signature=MagickSignature; |
| 252 | } |
| 253 | return(nexus_info); |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 258 | % % |
| 259 | % % |
| 260 | % % |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 261 | + A c q u i r e P i x e l C a c h e P i x e l s % |
| 262 | % % |
| 263 | % % |
| 264 | % % |
| 265 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 266 | % |
| 267 | % AcquirePixelCachePixels() returns the pixels associated with the specified |
| 268 | % image. |
| 269 | % |
| 270 | % The format of the AcquirePixelCachePixels() method is: |
| 271 | % |
| 272 | % const void *AcquirePixelCachePixels(const Image *image, |
| 273 | % MagickSizeType *length,ExceptionInfo *exception) |
| 274 | % |
| 275 | % A description of each parameter follows: |
| 276 | % |
| 277 | % o image: the image. |
| 278 | % |
| 279 | % o length: the pixel cache length. |
| 280 | % |
| 281 | % o exception: return any errors or warnings in this structure. |
| 282 | % |
| 283 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 284 | MagickPrivate const void *AcquirePixelCachePixels(const Image *image, |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 285 | MagickSizeType *length,ExceptionInfo *exception) |
| 286 | { |
| 287 | CacheInfo |
| 288 | *cache_info; |
| 289 | |
| 290 | assert(image != (const Image *) NULL); |
| 291 | assert(image->signature == MagickSignature); |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 292 | assert(exception != (ExceptionInfo *) NULL); |
| 293 | assert(exception->signature == MagickSignature); |
| 294 | assert(image->cache != (Cache) NULL); |
| 295 | cache_info=(CacheInfo *) image->cache; |
| 296 | assert(cache_info->signature == MagickSignature); |
| 297 | *length=0; |
| 298 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
| 299 | return((const void *) NULL); |
| 300 | *length=cache_info->length; |
| 301 | return((const void *) cache_info->pixels); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 306 | % % |
| 307 | % % |
| 308 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 309 | + C a c h e C o m p o n e n t G e n e s i s % |
| 310 | % % |
| 311 | % % |
| 312 | % % |
| 313 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 314 | % |
| 315 | % CacheComponentGenesis() instantiates the cache component. |
| 316 | % |
| 317 | % The format of the CacheComponentGenesis method is: |
| 318 | % |
| 319 | % MagickBooleanType CacheComponentGenesis(void) |
| 320 | % |
| 321 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 322 | MagickPrivate MagickBooleanType CacheComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 323 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 324 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 325 | return(MagickTrue); |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 330 | % % |
| 331 | % % |
| 332 | % % |
| 333 | + C a c h e C o m p o n e n t T e r m i n u s % |
| 334 | % % |
| 335 | % % |
| 336 | % % |
| 337 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 338 | % |
| 339 | % CacheComponentTerminus() destroys the cache component. |
| 340 | % |
| 341 | % The format of the CacheComponentTerminus() method is: |
| 342 | % |
| 343 | % CacheComponentTerminus(void) |
| 344 | % |
| 345 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 346 | MagickPrivate void CacheComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 347 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 348 | if (cache_semaphore == (SemaphoreInfo *) NULL) |
| 349 | AcquireSemaphoreInfo(&cache_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 350 | LockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 351 | instantiate_cache=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 352 | UnlockSemaphoreInfo(cache_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 353 | DestroySemaphoreInfo(&cache_semaphore); |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 358 | % % |
| 359 | % % |
| 360 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | + C l o n e P i x e l C a c h e % |
| 362 | % % |
| 363 | % % |
| 364 | % % |
| 365 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 366 | % |
| 367 | % ClonePixelCache() clones a pixel cache. |
| 368 | % |
| 369 | % The format of the ClonePixelCache() method is: |
| 370 | % |
| 371 | % Cache ClonePixelCache(const Cache cache) |
| 372 | % |
| 373 | % A description of each parameter follows: |
| 374 | % |
| 375 | % o cache: the pixel cache. |
| 376 | % |
| 377 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 378 | MagickPrivate Cache ClonePixelCache(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | { |
| 380 | CacheInfo |
| 381 | *clone_info; |
| 382 | |
| 383 | const CacheInfo |
| 384 | *cache_info; |
| 385 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 386 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 387 | cache_info=(const CacheInfo *) cache; |
| 388 | assert(cache_info->signature == MagickSignature); |
| 389 | if (cache_info->debug != MagickFalse) |
| 390 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 391 | cache_info->filename); |
| 392 | clone_info=(CacheInfo *) AcquirePixelCache(cache_info->number_threads); |
| 393 | if (clone_info == (Cache) NULL) |
| 394 | return((Cache) NULL); |
| 395 | clone_info->virtual_pixel_method=cache_info->virtual_pixel_method; |
| 396 | return((Cache ) clone_info); |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 401 | % % |
| 402 | % % |
| 403 | % % |
cristy | 60c44a8 | 2009-10-07 00:58:49 +0000 | [diff] [blame] | 404 | + 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] | 405 | % % |
| 406 | % % |
| 407 | % % |
| 408 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % |
| 409 | % ClonePixelCachePixels() clones the source pixel cache to the destination |
| 410 | % cache. |
| 411 | % |
| 412 | % The format of the ClonePixelCachePixels() method is: |
| 413 | % |
| 414 | % MagickBooleanType ClonePixelCachePixels(CacheInfo *cache_info, |
| 415 | % CacheInfo *source_info,ExceptionInfo *exception) |
| 416 | % |
| 417 | % A description of each parameter follows: |
| 418 | % |
| 419 | % o cache_info: the pixel cache. |
| 420 | % |
| 421 | % o source_info: the source pixel cache. |
| 422 | % |
| 423 | % o exception: return any errors or warnings in this structure. |
| 424 | % |
| 425 | */ |
| 426 | |
| 427 | static MagickBooleanType ClosePixelCacheOnDisk(CacheInfo *cache_info) |
| 428 | { |
| 429 | int |
| 430 | status; |
| 431 | |
cristy | 5ee247a | 2010-02-12 15:42:34 +0000 | [diff] [blame] | 432 | status=(-1); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 433 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 508d931 | 2010-02-10 21:10:30 +0000 | [diff] [blame] | 434 | if (cache_info->file != -1) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 435 | { |
| 436 | status=close(cache_info->file); |
| 437 | cache_info->file=(-1); |
| 438 | RelinquishMagickResource(FileResource,1); |
| 439 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 440 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 441 | return(status == -1 ? MagickFalse : MagickTrue); |
| 442 | } |
| 443 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 444 | static inline MagickSizeType MagickMax(const MagickSizeType x, |
| 445 | const MagickSizeType y) |
| 446 | { |
| 447 | if (x > y) |
| 448 | return(x); |
| 449 | return(y); |
| 450 | } |
| 451 | |
| 452 | static inline MagickSizeType MagickMin(const MagickSizeType x, |
| 453 | const MagickSizeType y) |
| 454 | { |
| 455 | if (x < y) |
| 456 | return(x); |
| 457 | return(y); |
| 458 | } |
| 459 | |
| 460 | static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info, |
| 461 | const MapMode mode) |
| 462 | { |
| 463 | int |
| 464 | file; |
| 465 | |
| 466 | /* |
| 467 | Open pixel cache on disk. |
| 468 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 469 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 470 | if (cache_info->file != -1) |
| 471 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 472 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | return(MagickTrue); /* cache already open */ |
| 474 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | if (*cache_info->cache_filename == '\0') |
| 476 | file=AcquireUniqueFileResource(cache_info->cache_filename); |
| 477 | else |
| 478 | switch (mode) |
| 479 | { |
| 480 | case ReadMode: |
| 481 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 482 | file=open_utf8(cache_info->cache_filename,O_RDONLY | O_BINARY,0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 483 | break; |
| 484 | } |
| 485 | case WriteMode: |
| 486 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 487 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_CREAT | |
| 488 | O_BINARY | O_EXCL,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 490 | file=open_utf8(cache_info->cache_filename,O_WRONLY | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | case IOMode: |
| 494 | default: |
| 495 | { |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 496 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_CREAT | O_BINARY | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | O_EXCL,S_MODE); |
| 498 | if (file == -1) |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 499 | file=open_utf8(cache_info->cache_filename,O_RDWR | O_BINARY,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 500 | break; |
| 501 | } |
| 502 | } |
| 503 | if (file == -1) |
| 504 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 505 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 506 | return(MagickFalse); |
| 507 | } |
| 508 | (void) AcquireMagickResource(FileResource,1); |
| 509 | cache_info->file=file; |
cristy | 4d9c192 | 2011-12-31 18:37:34 +0000 | [diff] [blame] | 510 | cache_info->mode=mode; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 511 | cache_info->timestamp=time(0); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 512 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 513 | return(MagickTrue); |
| 514 | } |
| 515 | |
| 516 | static inline MagickOffsetType ReadPixelCacheRegion(CacheInfo *cache_info, |
| 517 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 518 | unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | { |
| 520 | register MagickOffsetType |
| 521 | i; |
| 522 | |
| 523 | ssize_t |
| 524 | count; |
| 525 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 526 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 527 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 528 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 529 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 530 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 531 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | return((MagickOffsetType) -1); |
| 533 | } |
| 534 | #endif |
| 535 | count=0; |
| 536 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 537 | { |
| 538 | #if !defined(MAGICKCORE_HAVE_PREAD) |
| 539 | count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 540 | (MagickSizeType) SSIZE_MAX)); |
| 541 | #else |
| 542 | count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 543 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 544 | #endif |
| 545 | if (count > 0) |
| 546 | continue; |
| 547 | count=0; |
| 548 | if (errno != EINTR) |
| 549 | { |
| 550 | i=(-1); |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | #if !defined(MAGICKCORE_HAVE_PREAD) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 555 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 556 | #endif |
| 557 | return(i); |
| 558 | } |
| 559 | |
| 560 | static inline MagickOffsetType WritePixelCacheRegion(CacheInfo *cache_info, |
| 561 | const MagickOffsetType offset,const MagickSizeType length, |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 562 | const unsigned char *restrict buffer) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 563 | { |
| 564 | register MagickOffsetType |
| 565 | i; |
| 566 | |
| 567 | ssize_t |
| 568 | count; |
| 569 | |
cristy | 08a8820 | 2010-03-04 19:18:05 +0000 | [diff] [blame] | 570 | cache_info->timestamp=time(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 571 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 572 | LockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 573 | if (lseek(cache_info->file,offset,SEEK_SET) < 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 575 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 576 | return((MagickOffsetType) -1); |
| 577 | } |
| 578 | #endif |
| 579 | count=0; |
| 580 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 581 | { |
| 582 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
| 583 | count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
| 584 | (MagickSizeType) SSIZE_MAX)); |
| 585 | #else |
| 586 | count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-i, |
cristy | 94fc8fa | 2011-02-19 15:27:47 +0000 | [diff] [blame] | 587 | (MagickSizeType) SSIZE_MAX),(off_t) (offset+i)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | #endif |
| 589 | if (count > 0) |
| 590 | continue; |
| 591 | count=0; |
| 592 | if (errno != EINTR) |
| 593 | { |
| 594 | i=(-1); |
| 595 | break; |
| 596 | } |
| 597 | } |
| 598 | #if !defined(MAGICKCORE_HAVE_PWRITE) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 599 | UnlockSemaphoreInfo(cache_info->disk_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | #endif |
| 601 | return(i); |
| 602 | } |
| 603 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 604 | static MagickBooleanType DiskToDiskPixelCacheClone(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 606 | { |
| 607 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 608 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 609 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 610 | register MagickOffsetType |
| 611 | i; |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 612 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 613 | size_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 614 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 616 | unsigned char |
| 617 | *blob; |
| 618 | |
| 619 | /* |
| 620 | Clone pixel cache (both caches on disk). |
| 621 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 622 | if (cache_info->debug != MagickFalse) |
| 623 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 624 | blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 625 | sizeof(*blob)); |
| 626 | if (blob == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 627 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 628 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 629 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 630 | cache_info->filename); |
| 631 | return(MagickFalse); |
| 632 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 633 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 634 | { |
| 635 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 636 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 637 | cache_info->cache_filename); |
| 638 | return(MagickFalse); |
| 639 | } |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 640 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 641 | { |
| 642 | (void) ClosePixelCacheOnDisk(cache_info); |
| 643 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 645 | clone_info->cache_filename); |
| 646 | return(MagickFalse); |
| 647 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 648 | count=0; |
| 649 | for (i=0; i < (MagickOffsetType) cache_info->length; i+=count) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 650 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 651 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+i, |
| 652 | MagickMin(cache_info->length-i,(MagickSizeType) MagickMaxBufferExtent), |
| 653 | blob); |
| 654 | if (count <= 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 655 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 656 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 657 | cache_info->cache_filename); |
| 658 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 660 | length=(size_t) count; |
| 661 | count=WritePixelCacheRegion(clone_info,clone_info->offset+i,length,blob); |
| 662 | if ((MagickSizeType) count != length) |
| 663 | { |
| 664 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 665 | clone_info->cache_filename); |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | (void) ClosePixelCacheOnDisk(clone_info); |
| 670 | (void) ClosePixelCacheOnDisk(cache_info); |
| 671 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 672 | if (i < (MagickOffsetType) cache_info->length) |
| 673 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | return(MagickTrue); |
| 675 | } |
| 676 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 677 | static MagickBooleanType PixelCacheCloneOptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 678 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 679 | { |
| 680 | MagickOffsetType |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 681 | count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 682 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 683 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 684 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 685 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 686 | Clone pixel cache (both caches in memory). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 687 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 688 | if (cache_info->debug != MagickFalse) |
| 689 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 690 | (void) memcpy(clone_info->pixels,cache_info->pixels,(size_t) |
| 691 | cache_info->length); |
| 692 | return(MagickTrue); |
| 693 | } |
| 694 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 695 | { |
| 696 | /* |
| 697 | Clone pixel cache (one cache on disk, one in memory). |
| 698 | */ |
| 699 | if (cache_info->debug != MagickFalse) |
| 700 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 701 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 702 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 703 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | cache_info->cache_filename); |
| 705 | return(MagickFalse); |
| 706 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 707 | count=ReadPixelCacheRegion(cache_info,cache_info->offset, |
| 708 | cache_info->length,(unsigned char *) clone_info->pixels); |
| 709 | (void) ClosePixelCacheOnDisk(cache_info); |
| 710 | if ((MagickSizeType) count != cache_info->length) |
| 711 | { |
| 712 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 713 | cache_info->cache_filename); |
| 714 | return(MagickFalse); |
| 715 | } |
| 716 | return(MagickTrue); |
| 717 | } |
| 718 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 719 | { |
| 720 | /* |
| 721 | Clone pixel cache (one cache on disk, one in memory). |
| 722 | */ |
| 723 | if (clone_info->debug != MagickFalse) |
| 724 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 725 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
| 726 | { |
| 727 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 728 | clone_info->cache_filename); |
| 729 | return(MagickFalse); |
| 730 | } |
| 731 | count=WritePixelCacheRegion(clone_info,clone_info->offset, |
| 732 | clone_info->length,(unsigned char *) cache_info->pixels); |
| 733 | (void) ClosePixelCacheOnDisk(clone_info); |
| 734 | if ((MagickSizeType) count != clone_info->length) |
| 735 | { |
| 736 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 737 | clone_info->cache_filename); |
| 738 | return(MagickFalse); |
| 739 | } |
| 740 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | } |
| 742 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 743 | Clone pixel cache (both caches on disk). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 744 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 745 | return(DiskToDiskPixelCacheClone(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 746 | } |
| 747 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 748 | static MagickBooleanType PixelCacheCloneUnoptimized(CacheInfo *clone_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 749 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 750 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 751 | MagickBooleanType |
| 752 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 753 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 754 | MagickOffsetType |
| 755 | cache_offset, |
| 756 | clone_offset, |
| 757 | count; |
| 758 | |
| 759 | register ssize_t |
| 760 | x; |
| 761 | |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 762 | register unsigned char |
| 763 | *p; |
| 764 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 765 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 766 | length; |
| 767 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 768 | ssize_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 769 | y; |
| 770 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 771 | unsigned char |
| 772 | *blob; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 774 | /* |
| 775 | Clone pixel cache (unoptimized). |
| 776 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 777 | if (cache_info->debug != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 778 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 779 | if ((cache_info->type != DiskCache) && (clone_info->type != DiskCache)) |
| 780 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => memory"); |
| 781 | else |
| 782 | if ((clone_info->type != DiskCache) && (cache_info->type == DiskCache)) |
| 783 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => memory"); |
| 784 | else |
| 785 | if ((clone_info->type == DiskCache) && (cache_info->type != DiskCache)) |
| 786 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"memory => disk"); |
| 787 | else |
| 788 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"disk => disk"); |
| 789 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 790 | length=(size_t) MagickMax(MagickMax(cache_info->number_channels, |
| 791 | clone_info->number_channels)*sizeof(Quantum),MagickMax( |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 792 | cache_info->metacontent_extent,clone_info->metacontent_extent)); |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 793 | blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(*blob)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 794 | if (blob == (unsigned char *) NULL) |
| 795 | { |
| 796 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 797 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 798 | cache_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 799 | return(MagickFalse); |
| 800 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 801 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 802 | cache_offset=0; |
| 803 | clone_offset=0; |
| 804 | if (cache_info->type == DiskCache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 805 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 806 | if (OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 808 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 809 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 810 | cache_info->cache_filename); |
| 811 | return(MagickFalse); |
| 812 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 813 | cache_offset=cache_info->offset; |
| 814 | } |
| 815 | if (clone_info->type == DiskCache) |
| 816 | { |
cristy | 3dedf06 | 2011-07-02 14:07:40 +0000 | [diff] [blame] | 817 | if (OpenPixelCacheOnDisk(clone_info,WriteMode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 818 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 819 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 820 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 821 | clone_info->cache_filename); |
| 822 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 824 | clone_offset=clone_info->offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 825 | } |
| 826 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 827 | Clone pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 828 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 829 | status=MagickTrue; |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 830 | p=blob; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 831 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 832 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 833 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 834 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 835 | register ssize_t |
| 836 | i; |
| 837 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 838 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 839 | Read a set of pixel channels. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 840 | */ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 841 | length=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 842 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 843 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 844 | else |
| 845 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 846 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 847 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 848 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 849 | status=MagickFalse; |
| 850 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 851 | } |
| 852 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 853 | cache_offset+=length; |
| 854 | if ((y < (ssize_t) clone_info->rows) && |
| 855 | (x < (ssize_t) clone_info->columns)) |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 856 | for (i=0; i < (ssize_t) clone_info->number_channels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 857 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 858 | PixelChannel |
| 859 | channel; |
| 860 | |
| 861 | PixelTrait |
| 862 | traits; |
| 863 | |
| 864 | ssize_t |
| 865 | offset; |
| 866 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 867 | /* |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 868 | Write a set of pixel channels. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 869 | */ |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 870 | channel=clone_info->channel_map[i].channel; |
| 871 | traits=cache_info->channel_map[channel].traits; |
| 872 | if (traits == UndefinedPixelTrait) |
| 873 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 874 | clone_offset+=sizeof(Quantum); |
| 875 | continue; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 876 | } |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 877 | offset=cache_info->channel_map[channel].offset; |
| 878 | if (clone_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 879 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,p+ |
| 880 | offset*sizeof(Quantum),sizeof(Quantum)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 881 | else |
| 882 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 883 | count=WritePixelCacheRegion(clone_info,clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 884 | sizeof(Quantum),p+offset*sizeof(Quantum)); |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 885 | if ((MagickSizeType) count != sizeof(Quantum)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 886 | { |
cristy | 0f4425e | 2011-12-31 20:33:02 +0000 | [diff] [blame] | 887 | status=MagickFalse; |
| 888 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 891 | clone_offset+=sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 892 | } |
| 893 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 894 | length=clone_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 895 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 896 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 897 | { |
| 898 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 899 | Set remaining columns as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 900 | */ |
| 901 | if (clone_info->type != DiskCache) |
| 902 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,blob, |
| 903 | length); |
| 904 | else |
| 905 | { |
| 906 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 907 | if ((MagickSizeType) count != length) |
| 908 | { |
| 909 | status=MagickFalse; |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | clone_offset+=length; |
| 914 | } |
| 915 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 916 | length=clone_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 917 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 918 | for ( ; y < (ssize_t) clone_info->rows; y++) |
| 919 | { |
| 920 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 921 | Set remaining rows as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 922 | */ |
| 923 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 924 | { |
| 925 | if (clone_info->type != DiskCache) |
| 926 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset,blob, |
| 927 | length); |
| 928 | else |
| 929 | { |
| 930 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 931 | if ((MagickSizeType) count != length) |
| 932 | { |
| 933 | status=MagickFalse; |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | clone_offset+=length; |
| 938 | } |
| 939 | } |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 940 | if ((cache_info->metacontent_extent != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 941 | (clone_info->metacontent_extent != 0)) |
| 942 | { |
| 943 | /* |
| 944 | Clone metacontent. |
| 945 | */ |
| 946 | for (y=0; y < (ssize_t) cache_info->rows; y++) |
| 947 | { |
| 948 | for (x=0; x < (ssize_t) cache_info->columns; x++) |
| 949 | { |
| 950 | /* |
| 951 | Read a set of metacontent. |
| 952 | */ |
| 953 | length=cache_info->metacontent_extent; |
| 954 | if (cache_info->type != DiskCache) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 955 | p=(unsigned char *) cache_info->pixels+cache_offset; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 956 | else |
| 957 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 958 | count=ReadPixelCacheRegion(cache_info,cache_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 959 | if ((MagickSizeType) count != length) |
| 960 | { |
| 961 | status=MagickFalse; |
| 962 | break; |
| 963 | } |
| 964 | } |
| 965 | cache_offset+=length; |
| 966 | if ((y < (ssize_t) clone_info->rows) && |
| 967 | (x < (ssize_t) clone_info->columns)) |
| 968 | { |
| 969 | /* |
| 970 | Write a set of metacontent. |
| 971 | */ |
| 972 | length=clone_info->metacontent_extent; |
| 973 | if (clone_info->type != DiskCache) |
| 974 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 975 | p,length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 976 | else |
| 977 | { |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 978 | count=WritePixelCacheRegion(clone_info,clone_offset,length,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 979 | if ((MagickSizeType) count != length) |
| 980 | { |
| 981 | status=MagickFalse; |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | clone_offset+=length; |
| 986 | } |
| 987 | } |
| 988 | length=clone_info->metacontent_extent; |
| 989 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 990 | for ( ; x < (ssize_t) clone_info->columns; x++) |
| 991 | { |
| 992 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 993 | Set remaining columns as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 994 | */ |
| 995 | if (clone_info->type != DiskCache) |
| 996 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 997 | blob,length); |
| 998 | else |
| 999 | { |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1000 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1001 | if ((MagickSizeType) count != length) |
| 1002 | { |
| 1003 | status=MagickFalse; |
| 1004 | break; |
| 1005 | } |
| 1006 | } |
| 1007 | clone_offset+=length; |
| 1008 | } |
| 1009 | } |
| 1010 | length=clone_info->metacontent_extent; |
| 1011 | (void) ResetMagickMemory(blob,0,length*sizeof(*blob)); |
| 1012 | for ( ; y < (ssize_t) clone_info->rows; y++) |
| 1013 | { |
| 1014 | /* |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1015 | Set remaining rows as undefined. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1016 | */ |
| 1017 | for (x=0; x < (ssize_t) clone_info->columns; x++) |
| 1018 | { |
| 1019 | if (clone_info->type != DiskCache) |
| 1020 | (void) memcpy((unsigned char *) clone_info->pixels+clone_offset, |
| 1021 | blob,length); |
| 1022 | else |
| 1023 | { |
| 1024 | count=WritePixelCacheRegion(clone_info,clone_offset,length,blob); |
| 1025 | if ((MagickSizeType) count != length) |
| 1026 | { |
| 1027 | status=MagickFalse; |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
| 1031 | clone_offset+=length; |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | if (clone_info->type == DiskCache) |
| 1036 | (void) ClosePixelCacheOnDisk(clone_info); |
| 1037 | if (cache_info->type == DiskCache) |
| 1038 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1039 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 1040 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static MagickBooleanType ClonePixelCachePixels(CacheInfo *clone_info, |
| 1044 | CacheInfo *cache_info,ExceptionInfo *exception) |
| 1045 | { |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1046 | PixelChannelMap |
| 1047 | *p, |
| 1048 | *q; |
| 1049 | |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 1050 | if (cache_info->type == PingCache) |
| 1051 | return(MagickTrue); |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1052 | p=cache_info->channel_map; |
| 1053 | q=clone_info->channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1054 | if ((cache_info->columns == clone_info->columns) && |
| 1055 | (cache_info->rows == clone_info->rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1056 | (cache_info->number_channels == clone_info->number_channels) && |
cristy | 3dfccb2 | 2011-12-28 21:47:20 +0000 | [diff] [blame] | 1057 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1058 | (cache_info->metacontent_extent == clone_info->metacontent_extent)) |
cristy | fd24a06 | 2012-01-02 14:46:34 +0000 | [diff] [blame] | 1059 | return(PixelCacheCloneOptimized(clone_info,cache_info,exception)); |
| 1060 | return(PixelCacheCloneUnoptimized(clone_info,cache_info,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1065 | % % |
| 1066 | % % |
| 1067 | % % |
| 1068 | + C l o n e P i x e l C a c h e M e t h o d s % |
| 1069 | % % |
| 1070 | % % |
| 1071 | % % |
| 1072 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1073 | % |
| 1074 | % ClonePixelCacheMethods() clones the pixel cache methods from one cache to |
| 1075 | % another. |
| 1076 | % |
| 1077 | % The format of the ClonePixelCacheMethods() method is: |
| 1078 | % |
| 1079 | % void ClonePixelCacheMethods(Cache clone,const Cache cache) |
| 1080 | % |
| 1081 | % A description of each parameter follows: |
| 1082 | % |
| 1083 | % o clone: Specifies a pointer to a Cache structure. |
| 1084 | % |
| 1085 | % o cache: the pixel cache. |
| 1086 | % |
| 1087 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1088 | MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1089 | { |
| 1090 | CacheInfo |
| 1091 | *cache_info, |
| 1092 | *source_info; |
| 1093 | |
| 1094 | assert(clone != (Cache) NULL); |
| 1095 | source_info=(CacheInfo *) clone; |
| 1096 | assert(source_info->signature == MagickSignature); |
| 1097 | if (source_info->debug != MagickFalse) |
| 1098 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1099 | source_info->filename); |
| 1100 | assert(cache != (Cache) NULL); |
| 1101 | cache_info=(CacheInfo *) cache; |
| 1102 | assert(cache_info->signature == MagickSignature); |
| 1103 | source_info->methods=cache_info->methods; |
| 1104 | } |
| 1105 | |
| 1106 | /* |
| 1107 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1108 | % % |
| 1109 | % % |
| 1110 | % % |
| 1111 | + D e s t r o y I m a g e P i x e l C a c h e % |
| 1112 | % % |
| 1113 | % % |
| 1114 | % % |
| 1115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1116 | % |
| 1117 | % DestroyImagePixelCache() deallocates memory associated with the pixel cache. |
| 1118 | % |
| 1119 | % The format of the DestroyImagePixelCache() method is: |
| 1120 | % |
| 1121 | % void DestroyImagePixelCache(Image *image) |
| 1122 | % |
| 1123 | % A description of each parameter follows: |
| 1124 | % |
| 1125 | % o image: the image. |
| 1126 | % |
| 1127 | */ |
| 1128 | static void DestroyImagePixelCache(Image *image) |
| 1129 | { |
| 1130 | assert(image != (Image *) NULL); |
| 1131 | assert(image->signature == MagickSignature); |
| 1132 | if (image->debug != MagickFalse) |
| 1133 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1134 | if (image->cache == (void *) NULL) |
| 1135 | return; |
| 1136 | image->cache=DestroyPixelCache(image->cache); |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1141 | % % |
| 1142 | % % |
| 1143 | % % |
| 1144 | + D e s t r o y I m a g e P i x e l s % |
| 1145 | % % |
| 1146 | % % |
| 1147 | % % |
| 1148 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1149 | % |
| 1150 | % DestroyImagePixels() deallocates memory associated with the pixel cache. |
| 1151 | % |
| 1152 | % The format of the DestroyImagePixels() method is: |
| 1153 | % |
| 1154 | % void DestroyImagePixels(Image *image) |
| 1155 | % |
| 1156 | % A description of each parameter follows: |
| 1157 | % |
| 1158 | % o image: the image. |
| 1159 | % |
| 1160 | */ |
| 1161 | MagickExport void DestroyImagePixels(Image *image) |
| 1162 | { |
| 1163 | CacheInfo |
| 1164 | *cache_info; |
| 1165 | |
| 1166 | assert(image != (const Image *) NULL); |
| 1167 | assert(image->signature == MagickSignature); |
| 1168 | if (image->debug != MagickFalse) |
| 1169 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1170 | assert(image->cache != (Cache) NULL); |
| 1171 | cache_info=(CacheInfo *) image->cache; |
| 1172 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1173 | if (cache_info->methods.destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 1174 | { |
| 1175 | cache_info->methods.destroy_pixel_handler(image); |
| 1176 | return; |
| 1177 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1178 | image->cache=DestroyPixelCache(image->cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /* |
| 1182 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1183 | % % |
| 1184 | % % |
| 1185 | % % |
| 1186 | + D e s t r o y P i x e l C a c h e % |
| 1187 | % % |
| 1188 | % % |
| 1189 | % % |
| 1190 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1191 | % |
| 1192 | % DestroyPixelCache() deallocates memory associated with the pixel cache. |
| 1193 | % |
| 1194 | % The format of the DestroyPixelCache() method is: |
| 1195 | % |
| 1196 | % Cache DestroyPixelCache(Cache cache) |
| 1197 | % |
| 1198 | % A description of each parameter follows: |
| 1199 | % |
| 1200 | % o cache: the pixel cache. |
| 1201 | % |
| 1202 | */ |
| 1203 | |
| 1204 | static inline void RelinquishPixelCachePixels(CacheInfo *cache_info) |
| 1205 | { |
| 1206 | switch (cache_info->type) |
| 1207 | { |
| 1208 | case MemoryCache: |
| 1209 | { |
| 1210 | if (cache_info->mapped == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1211 | cache_info->pixels=(Quantum *) RelinquishMagickMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | cache_info->pixels); |
| 1213 | else |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1214 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1215 | (size_t) cache_info->length); |
| 1216 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 1217 | break; |
| 1218 | } |
| 1219 | case MapCache: |
| 1220 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1221 | cache_info->pixels=(Quantum *) UnmapBlob(cache_info->pixels,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1222 | cache_info->length); |
| 1223 | RelinquishMagickResource(MapResource,cache_info->length); |
| 1224 | } |
| 1225 | case DiskCache: |
| 1226 | { |
| 1227 | if (cache_info->file != -1) |
| 1228 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1229 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 1230 | break; |
| 1231 | } |
| 1232 | default: |
| 1233 | break; |
| 1234 | } |
| 1235 | cache_info->type=UndefinedCache; |
| 1236 | cache_info->mapped=MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1237 | cache_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1240 | MagickPrivate Cache DestroyPixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1241 | { |
| 1242 | CacheInfo |
| 1243 | *cache_info; |
| 1244 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1245 | assert(cache != (Cache) NULL); |
| 1246 | cache_info=(CacheInfo *) cache; |
| 1247 | assert(cache_info->signature == MagickSignature); |
| 1248 | if (cache_info->debug != MagickFalse) |
| 1249 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1250 | cache_info->filename); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1251 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1252 | cache_info->reference_count--; |
| 1253 | if (cache_info->reference_count != 0) |
| 1254 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1255 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1256 | return((Cache) NULL); |
| 1257 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1258 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1259 | if (cache_info->debug != MagickFalse) |
| 1260 | { |
| 1261 | char |
| 1262 | message[MaxTextExtent]; |
| 1263 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1264 | (void) FormatLocaleString(message,MaxTextExtent,"destroy %s", |
cristy | 5b8de73 | 2009-09-10 23:50:40 +0000 | [diff] [blame] | 1265 | cache_info->filename); |
| 1266 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 1267 | } |
cristy | c2e1bdd | 2009-09-10 23:43:34 +0000 | [diff] [blame] | 1268 | if ((cache_info->mode == ReadMode) || ((cache_info->type != MapCache) && |
| 1269 | (cache_info->type != DiskCache))) |
| 1270 | RelinquishPixelCachePixels(cache_info); |
| 1271 | else |
| 1272 | { |
| 1273 | RelinquishPixelCachePixels(cache_info); |
| 1274 | (void) RelinquishUniqueFileResource(cache_info->cache_filename); |
| 1275 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1276 | *cache_info->cache_filename='\0'; |
| 1277 | if (cache_info->nexus_info != (NexusInfo **) NULL) |
| 1278 | cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info, |
| 1279 | cache_info->number_threads); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1280 | if (cache_info->random_info != (RandomInfo *) NULL) |
| 1281 | cache_info->random_info=DestroyRandomInfo(cache_info->random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1282 | if (cache_info->disk_semaphore != (SemaphoreInfo *) NULL) |
| 1283 | DestroySemaphoreInfo(&cache_info->disk_semaphore); |
| 1284 | if (cache_info->semaphore != (SemaphoreInfo *) NULL) |
| 1285 | DestroySemaphoreInfo(&cache_info->semaphore); |
cristy | 154a1e2 | 2010-02-15 00:28:37 +0000 | [diff] [blame] | 1286 | cache_info->signature=(~MagickSignature); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 1287 | cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1288 | cache=(Cache) NULL; |
| 1289 | return(cache); |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1294 | % % |
| 1295 | % % |
| 1296 | % % |
| 1297 | + D e s t r o y P i x e l C a c h e N e x u s % |
| 1298 | % % |
| 1299 | % % |
| 1300 | % % |
| 1301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1302 | % |
| 1303 | % DestroyPixelCacheNexus() destroys a pixel cache nexus. |
| 1304 | % |
| 1305 | % The format of the DestroyPixelCacheNexus() method is: |
| 1306 | % |
| 1307 | % NexusInfo **DestroyPixelCacheNexus(NexusInfo *nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1308 | % const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1309 | % |
| 1310 | % A description of each parameter follows: |
| 1311 | % |
| 1312 | % o nexus_info: the nexus to destroy. |
| 1313 | % |
| 1314 | % o number_threads: the number of nexus threads. |
| 1315 | % |
| 1316 | */ |
| 1317 | |
| 1318 | static inline void RelinquishCacheNexusPixels(NexusInfo *nexus_info) |
| 1319 | { |
| 1320 | if (nexus_info->mapped == MagickFalse) |
cristy | 7dc8ac5 | 2012-01-10 20:14:52 +0000 | [diff] [blame] | 1321 | (void) RelinquishAlignedMemory(nexus_info->cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1322 | else |
| 1323 | (void) UnmapBlob(nexus_info->cache,(size_t) nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1324 | nexus_info->cache=(Quantum *) NULL; |
| 1325 | nexus_info->pixels=(Quantum *) NULL; |
| 1326 | nexus_info->metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1327 | nexus_info->length=0; |
| 1328 | nexus_info->mapped=MagickFalse; |
| 1329 | } |
| 1330 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1331 | MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1332 | const size_t number_threads) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1333 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1334 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1335 | i; |
| 1336 | |
| 1337 | assert(nexus_info != (NexusInfo **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1338 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1339 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1340 | if (nexus_info[i]->cache != (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1341 | RelinquishCacheNexusPixels(nexus_info[i]); |
| 1342 | nexus_info[i]->signature=(~MagickSignature); |
cristy | 7dc8ac5 | 2012-01-10 20:14:52 +0000 | [diff] [blame] | 1343 | nexus_info[i]=(NexusInfo *) RelinquishMagickMemory(nexus_info[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1344 | } |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 1345 | nexus_info=(NexusInfo **) RelinquishMagickMemory(nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1346 | return(nexus_info); |
| 1347 | } |
| 1348 | |
| 1349 | /* |
| 1350 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1351 | % % |
| 1352 | % % |
| 1353 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1354 | % 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] | 1355 | % % |
| 1356 | % % |
| 1357 | % % |
| 1358 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1359 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1360 | % GetAuthenticMetacontent() returns the authentic metacontent corresponding |
| 1361 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 1362 | % returned if the associated pixels are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1363 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1364 | % The format of the GetAuthenticMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1365 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1366 | % void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1367 | % |
| 1368 | % A description of each parameter follows: |
| 1369 | % |
| 1370 | % o image: the image. |
| 1371 | % |
| 1372 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1373 | MagickExport void *GetAuthenticMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1374 | { |
| 1375 | CacheInfo |
| 1376 | *cache_info; |
| 1377 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1378 | const int |
| 1379 | id = GetOpenMPThreadId(); |
| 1380 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1381 | void |
| 1382 | *metacontent; |
| 1383 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1384 | assert(image != (const Image *) NULL); |
| 1385 | assert(image->signature == MagickSignature); |
| 1386 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1387 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1388 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1389 | if (cache_info->methods.get_authentic_metacontent_from_handler != |
| 1390 | (GetAuthenticMetacontentFromHandler) NULL) |
| 1391 | { |
| 1392 | metacontent=cache_info->methods. |
| 1393 | get_authentic_metacontent_from_handler(image); |
| 1394 | return(metacontent); |
| 1395 | } |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1396 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1397 | metacontent=GetPixelCacheNexusMetacontent(cache_info, |
| 1398 | cache_info->nexus_info[id]); |
| 1399 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /* |
| 1403 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1404 | % % |
| 1405 | % % |
| 1406 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1407 | + 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] | 1408 | % % |
| 1409 | % % |
| 1410 | % % |
| 1411 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1412 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1413 | % GetAuthenticMetacontentFromCache() returns the meta-content corresponding |
| 1414 | % with the last call to QueueAuthenticPixelsCache() or |
| 1415 | % GetAuthenticPixelsCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1416 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1417 | % The format of the GetAuthenticMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1418 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1419 | % void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1420 | % |
| 1421 | % A description of each parameter follows: |
| 1422 | % |
| 1423 | % o image: the image. |
| 1424 | % |
| 1425 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1426 | static void *GetAuthenticMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | { |
| 1428 | CacheInfo |
| 1429 | *cache_info; |
| 1430 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1431 | const int |
| 1432 | id = GetOpenMPThreadId(); |
| 1433 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1434 | void |
| 1435 | *metacontent; |
| 1436 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1437 | assert(image != (const Image *) NULL); |
| 1438 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1439 | assert(image->cache != (Cache) NULL); |
| 1440 | cache_info=(CacheInfo *) image->cache; |
| 1441 | assert(cache_info->signature == MagickSignature); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1442 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1443 | metacontent=GetPixelCacheNexusMetacontent(image->cache, |
| 1444 | cache_info->nexus_info[id]); |
| 1445 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1450 | % % |
| 1451 | % % |
| 1452 | % % |
| 1453 | + 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 % |
| 1454 | % % |
| 1455 | % % |
| 1456 | % % |
| 1457 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1458 | % |
| 1459 | % GetAuthenticPixelCacheNexus() gets authentic pixels from the in-memory or |
| 1460 | % disk pixel cache as defined by the geometry parameters. A pointer to the |
| 1461 | % pixels is returned if the pixels are transferred, otherwise a NULL is |
| 1462 | % returned. |
| 1463 | % |
| 1464 | % The format of the GetAuthenticPixelCacheNexus() method is: |
| 1465 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1466 | % Quantum *GetAuthenticPixelCacheNexus(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1467 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1468 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1469 | % |
| 1470 | % A description of each parameter follows: |
| 1471 | % |
| 1472 | % o image: the image. |
| 1473 | % |
| 1474 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1475 | % pixels. |
| 1476 | % |
| 1477 | % o nexus_info: the cache nexus to return. |
| 1478 | % |
| 1479 | % o exception: return any errors or warnings in this structure. |
| 1480 | % |
| 1481 | */ |
| 1482 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1483 | static inline MagickBooleanType IsPixelAuthentic(const CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1484 | NexusInfo *nexus_info) |
| 1485 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1486 | MagickBooleanType |
| 1487 | status; |
| 1488 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1489 | MagickOffsetType |
| 1490 | offset; |
| 1491 | |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 1492 | if (cache_info->type == PingCache) |
| 1493 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1494 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 1495 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1496 | status=nexus_info->pixels == (cache_info->pixels+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1497 | cache_info->number_channels) ? MagickTrue : MagickFalse; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1498 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 1501 | MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image, |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 1502 | 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] | 1503 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 1504 | { |
| 1505 | CacheInfo |
| 1506 | *cache_info; |
| 1507 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1508 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1509 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1510 | |
| 1511 | /* |
| 1512 | Transfer pixels from the cache. |
| 1513 | */ |
| 1514 | assert(image != (Image *) NULL); |
| 1515 | assert(image->signature == MagickSignature); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 1516 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickTrue,nexus_info, |
| 1517 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1518 | if (q == (Quantum *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1519 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1520 | cache_info=(CacheInfo *) image->cache; |
| 1521 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1522 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1523 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1524 | if (ReadPixelCachePixels(cache_info,nexus_info,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1525 | return((Quantum *) NULL); |
| 1526 | if (cache_info->metacontent_extent != 0) |
| 1527 | if (ReadPixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse) |
| 1528 | return((Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1529 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /* |
| 1533 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1534 | % % |
| 1535 | % % |
| 1536 | % % |
| 1537 | + 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 % |
| 1538 | % % |
| 1539 | % % |
| 1540 | % % |
| 1541 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1542 | % |
| 1543 | % GetAuthenticPixelsFromCache() returns the pixels associated with the last |
| 1544 | % call to the QueueAuthenticPixelsCache() or GetAuthenticPixelsCache() methods. |
| 1545 | % |
| 1546 | % The format of the GetAuthenticPixelsFromCache() method is: |
| 1547 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1548 | % Quantum *GetAuthenticPixelsFromCache(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1549 | % |
| 1550 | % A description of each parameter follows: |
| 1551 | % |
| 1552 | % o image: the image. |
| 1553 | % |
| 1554 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1555 | static Quantum *GetAuthenticPixelsFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1556 | { |
| 1557 | CacheInfo |
| 1558 | *cache_info; |
| 1559 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1560 | const int |
| 1561 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1562 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1563 | assert(image != (const Image *) NULL); |
| 1564 | assert(image->signature == MagickSignature); |
| 1565 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1566 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1567 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1568 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 1569 | return(GetPixelCacheNexusPixels(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /* |
| 1573 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1574 | % % |
| 1575 | % % |
| 1576 | % % |
| 1577 | % G e t A u t h e n t i c P i x e l Q u e u e % |
| 1578 | % % |
| 1579 | % % |
| 1580 | % % |
| 1581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1582 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1583 | % GetAuthenticPixelQueue() returns the authentic pixels associated |
| 1584 | % corresponding with the last call to QueueAuthenticPixels() or |
| 1585 | % GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1586 | % |
| 1587 | % The format of the GetAuthenticPixelQueue() method is: |
| 1588 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1589 | % Quantum *GetAuthenticPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1590 | % |
| 1591 | % A description of each parameter follows: |
| 1592 | % |
| 1593 | % o image: the image. |
| 1594 | % |
| 1595 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1596 | MagickExport Quantum *GetAuthenticPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1597 | { |
| 1598 | CacheInfo |
| 1599 | *cache_info; |
| 1600 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1601 | const int |
| 1602 | id = GetOpenMPThreadId(); |
| 1603 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1604 | assert(image != (const Image *) NULL); |
| 1605 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1606 | assert(image->cache != (Cache) NULL); |
| 1607 | cache_info=(CacheInfo *) image->cache; |
| 1608 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1609 | if (cache_info->methods.get_authentic_pixels_from_handler != |
| 1610 | (GetAuthenticPixelsFromHandler) NULL) |
| 1611 | return(cache_info->methods.get_authentic_pixels_from_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1612 | assert(id < (int) cache_info->number_threads); |
| 1613 | return(GetPixelCacheNexusPixels(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1618 | % % |
| 1619 | % % |
| 1620 | % % |
| 1621 | % G e t A u t h e n t i c P i x e l s % |
| 1622 | % % |
| 1623 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1624 | % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1625 | % |
| 1626 | % GetAuthenticPixels() obtains a pixel region for read/write access. If the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1627 | % region is successfully accessed, a pointer to a Quantum array |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1628 | % representing the region is returned, otherwise NULL is returned. |
| 1629 | % |
| 1630 | % The returned pointer may point to a temporary working copy of the pixels |
| 1631 | % or it may point to the original pixels in memory. Performance is maximized |
| 1632 | % if the selected region is part of one row, or one or more full rows, since |
| 1633 | % then there is opportunity to access the pixels in-place (without a copy) |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 1634 | % if the image is in memory, or in a memory-mapped file. The returned pointer |
| 1635 | % must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1636 | % |
| 1637 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1638 | % Quantum. If the image has corresponding metacontent,call |
| 1639 | % GetAuthenticMetacontent() after invoking GetAuthenticPixels() to obtain the |
| 1640 | % meta-content corresponding to the region. Once the Quantum array has |
| 1641 | % been updated, the changes must be saved back to the underlying image using |
| 1642 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1643 | % |
| 1644 | % The format of the GetAuthenticPixels() method is: |
| 1645 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1646 | % Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 1647 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1648 | % ExceptionInfo *exception) |
| 1649 | % |
| 1650 | % A description of each parameter follows: |
| 1651 | % |
| 1652 | % o image: the image. |
| 1653 | % |
| 1654 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1655 | % pixels. |
| 1656 | % |
| 1657 | % o exception: return any errors or warnings in this structure. |
| 1658 | % |
| 1659 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1660 | MagickExport Quantum *GetAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1661 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | ExceptionInfo *exception) |
| 1663 | { |
| 1664 | CacheInfo |
| 1665 | *cache_info; |
| 1666 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1667 | const int |
| 1668 | id = GetOpenMPThreadId(); |
| 1669 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1670 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1671 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1672 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1673 | assert(image != (Image *) NULL); |
| 1674 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1675 | assert(image->cache != (Cache) NULL); |
| 1676 | cache_info=(CacheInfo *) image->cache; |
| 1677 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 1678 | if (cache_info->methods.get_authentic_pixels_handler != |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1679 | (GetAuthenticPixelsHandler) NULL) |
| 1680 | { |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1681 | q=cache_info->methods.get_authentic_pixels_handler(image,x,y,columns,rows, |
| 1682 | exception); |
| 1683 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1684 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1685 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1686 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1687 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1688 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | /* |
| 1692 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1693 | % % |
| 1694 | % % |
| 1695 | % % |
| 1696 | + G e t A u t h e n t i c P i x e l s C a c h e % |
| 1697 | % % |
| 1698 | % % |
| 1699 | % % |
| 1700 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1701 | % |
| 1702 | % GetAuthenticPixelsCache() gets pixels from the in-memory or disk pixel cache |
| 1703 | % as defined by the geometry parameters. A pointer to the pixels is returned |
| 1704 | % if the pixels are transferred, otherwise a NULL is returned. |
| 1705 | % |
| 1706 | % The format of the GetAuthenticPixelsCache() method is: |
| 1707 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1708 | % Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1709 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1710 | % ExceptionInfo *exception) |
| 1711 | % |
| 1712 | % A description of each parameter follows: |
| 1713 | % |
| 1714 | % o image: the image. |
| 1715 | % |
| 1716 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 1717 | % pixels. |
| 1718 | % |
| 1719 | % o exception: return any errors or warnings in this structure. |
| 1720 | % |
| 1721 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1722 | static Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1723 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1724 | ExceptionInfo *exception) |
| 1725 | { |
| 1726 | CacheInfo |
| 1727 | *cache_info; |
| 1728 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1729 | const int |
| 1730 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1731 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1732 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1733 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +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 | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 1738 | cache_info=(CacheInfo *) image->cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1739 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1740 | return((Quantum *) NULL); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 1741 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1742 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1743 | q=GetAuthenticPixelCacheNexus(image,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1744 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1745 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | /* |
| 1749 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1750 | % % |
| 1751 | % % |
| 1752 | % % |
| 1753 | + G e t I m a g e E x t e n t % |
| 1754 | % % |
| 1755 | % % |
| 1756 | % % |
| 1757 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1758 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1759 | % GetImageExtent() returns the extent of the pixels associated corresponding |
| 1760 | % with the last call to QueueAuthenticPixels() or GetAuthenticPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1761 | % |
| 1762 | % The format of the GetImageExtent() method is: |
| 1763 | % |
| 1764 | % MagickSizeType GetImageExtent(const Image *image) |
| 1765 | % |
| 1766 | % A description of each parameter follows: |
| 1767 | % |
| 1768 | % o image: the image. |
| 1769 | % |
| 1770 | */ |
| 1771 | MagickExport MagickSizeType GetImageExtent(const Image *image) |
| 1772 | { |
| 1773 | CacheInfo |
| 1774 | *cache_info; |
| 1775 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 1776 | const int |
| 1777 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1778 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1779 | assert(image != (Image *) NULL); |
| 1780 | assert(image->signature == MagickSignature); |
| 1781 | if (image->debug != MagickFalse) |
| 1782 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1783 | assert(image->cache != (Cache) NULL); |
| 1784 | cache_info=(CacheInfo *) image->cache; |
| 1785 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1786 | assert(id < (int) cache_info->number_threads); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 1787 | return(GetPixelCacheNexusExtent(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | /* |
| 1791 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1792 | % % |
| 1793 | % % |
| 1794 | % % |
| 1795 | + G e t I m a g e P i x e l C a c h e % |
| 1796 | % % |
| 1797 | % % |
| 1798 | % % |
| 1799 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1800 | % |
| 1801 | % GetImagePixelCache() ensures that there is only a single reference to the |
| 1802 | % pixel cache to be modified, updating the provided cache pointer to point to |
| 1803 | % a clone of the original pixel cache if necessary. |
| 1804 | % |
| 1805 | % The format of the GetImagePixelCache method is: |
| 1806 | % |
| 1807 | % Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 1808 | % ExceptionInfo *exception) |
| 1809 | % |
| 1810 | % A description of each parameter follows: |
| 1811 | % |
| 1812 | % o image: the image. |
| 1813 | % |
| 1814 | % o clone: any value other than MagickFalse clones the cache pixels. |
| 1815 | % |
| 1816 | % o exception: return any errors or warnings in this structure. |
| 1817 | % |
| 1818 | */ |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 1819 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1820 | static inline MagickBooleanType ValidatePixelCacheMorphology(const Image *image) |
| 1821 | { |
| 1822 | CacheInfo |
| 1823 | *cache_info; |
| 1824 | |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1825 | PixelChannelMap |
| 1826 | *p, |
| 1827 | *q; |
| 1828 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1829 | /* |
| 1830 | Does the image match the pixel cache morphology? |
| 1831 | */ |
| 1832 | cache_info=(CacheInfo *) image->cache; |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1833 | p=image->channel_map; |
| 1834 | q=cache_info->channel_map; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 | if ((image->storage_class != cache_info->storage_class) || |
| 1836 | (image->colorspace != cache_info->colorspace) || |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 1837 | (image->matte != cache_info->matte) || |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame^] | 1838 | (image->masky != cache_info->masky) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1839 | (image->columns != cache_info->columns) || |
| 1840 | (image->rows != cache_info->rows) || |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1841 | (image->number_channels != cache_info->number_channels) || |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 1842 | (memcmp(p,q,image->number_channels*sizeof(*p)) != 0) || |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1843 | (image->metacontent_extent != cache_info->metacontent_extent) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1844 | (cache_info->nexus_info == (NexusInfo **) NULL) || |
| 1845 | (cache_info->number_threads < GetOpenMPMaximumThreads())) |
| 1846 | return(MagickFalse); |
| 1847 | return(MagickTrue); |
| 1848 | } |
| 1849 | |
cristy | cd01fae | 2011-08-06 23:52:42 +0000 | [diff] [blame] | 1850 | static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, |
| 1851 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1852 | { |
| 1853 | CacheInfo |
| 1854 | *cache_info; |
| 1855 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1856 | MagickBooleanType |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1857 | destroy, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1858 | status; |
| 1859 | |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 1860 | static MagickSizeType |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1861 | cpu_throttle = 0, |
| 1862 | cycles = 0, |
cristy | 50a1092 | 2010-02-15 18:35:25 +0000 | [diff] [blame] | 1863 | time_limit = 0; |
| 1864 | |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1865 | static time_t |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1866 | cache_timestamp = 0; |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1867 | |
cristy | c4f9f13 | 2010-03-04 18:50:01 +0000 | [diff] [blame] | 1868 | status=MagickTrue; |
| 1869 | LockSemaphoreInfo(image->semaphore); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1870 | if (cpu_throttle == 0) |
| 1871 | { |
| 1872 | char |
| 1873 | *limit; |
| 1874 | |
| 1875 | /* |
| 1876 | Set CPU throttle in milleseconds. |
| 1877 | */ |
| 1878 | cpu_throttle=MagickResourceInfinity; |
| 1879 | limit=GetEnvironmentValue("MAGICK_THROTTLE"); |
| 1880 | if (limit == (char *) NULL) |
| 1881 | limit=GetPolicyValue("throttle"); |
| 1882 | if (limit != (char *) NULL) |
| 1883 | { |
| 1884 | cpu_throttle=(MagickSizeType) StringToInteger(limit); |
| 1885 | limit=DestroyString(limit); |
| 1886 | } |
| 1887 | } |
| 1888 | if ((cpu_throttle != MagickResourceInfinity) && ((cycles++ % 32) == 0)) |
| 1889 | MagickDelay(cpu_throttle); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1890 | if (time_limit == 0) |
| 1891 | { |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1892 | /* |
| 1893 | Set the exire time in seconds. |
| 1894 | */ |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1895 | time_limit=GetMagickResourceLimit(TimeResource); |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1896 | cache_timestamp=time((time_t *) NULL); |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1897 | } |
| 1898 | if ((time_limit != MagickResourceInfinity) && |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 1899 | ((MagickSizeType) (time((time_t *) NULL)-cache_timestamp) >= time_limit)) |
cristy | 1ea3496 | 2010-07-01 19:49:21 +0000 | [diff] [blame] | 1900 | ThrowFatalException(ResourceLimitFatalError,"TimeLimitExceeded"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1901 | assert(image->cache != (Cache) NULL); |
| 1902 | cache_info=(CacheInfo *) image->cache; |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1903 | destroy=MagickFalse; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1904 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1905 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1906 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 1907 | if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1908 | { |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1909 | Image |
| 1910 | clone_image; |
| 1911 | |
| 1912 | CacheInfo |
| 1913 | *clone_info; |
| 1914 | |
| 1915 | /* |
| 1916 | Clone pixel cache. |
| 1917 | */ |
| 1918 | clone_image=(*image); |
| 1919 | clone_image.semaphore=AllocateSemaphoreInfo(); |
| 1920 | clone_image.reference_count=1; |
| 1921 | clone_image.cache=ClonePixelCache(cache_info); |
| 1922 | clone_info=(CacheInfo *) clone_image.cache; |
| 1923 | status=OpenPixelCache(&clone_image,IOMode,exception); |
| 1924 | if (status != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1925 | { |
cristy | 5a7fbfb | 2010-11-06 16:10:59 +0000 | [diff] [blame] | 1926 | if (clone != MagickFalse) |
cristy | 4e6fa71 | 2010-11-06 16:06:12 +0000 | [diff] [blame] | 1927 | status=ClonePixelCachePixels(clone_info,cache_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1928 | if (status != MagickFalse) |
| 1929 | { |
cristy | 979bf77 | 2011-08-08 00:04:15 +0000 | [diff] [blame] | 1930 | if (cache_info->mode == ReadMode) |
| 1931 | cache_info->nexus_info=(NexusInfo **) NULL; |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1932 | destroy=MagickTrue; |
| 1933 | image->cache=clone_image.cache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1934 | } |
| 1935 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1936 | DestroySemaphoreInfo(&clone_image.semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1937 | } |
cristy | ceb55ee | 2010-11-06 16:05:49 +0000 | [diff] [blame] | 1938 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1939 | } |
cristy | 4320e0e | 2009-09-10 15:00:08 +0000 | [diff] [blame] | 1940 | if (destroy != MagickFalse) |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 1941 | cache_info=(CacheInfo *) DestroyPixelCache(cache_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1942 | if (status != MagickFalse) |
| 1943 | { |
| 1944 | /* |
| 1945 | Ensure the image matches the pixel cache morphology. |
| 1946 | */ |
| 1947 | image->taint=MagickTrue; |
cristy | 5f1c1ff | 2010-12-23 21:38:06 +0000 | [diff] [blame] | 1948 | image->type=UndefinedType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1949 | if (ValidatePixelCacheMorphology(image) == MagickFalse) |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 1950 | { |
| 1951 | status=OpenPixelCache(image,IOMode,exception); |
| 1952 | cache_info=(CacheInfo *) image->cache; |
| 1953 | if (cache_info->type == DiskCache) |
| 1954 | (void) ClosePixelCacheOnDisk(cache_info); |
| 1955 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1956 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1957 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1958 | if (status == MagickFalse) |
| 1959 | return((Cache) NULL); |
| 1960 | return(image->cache); |
| 1961 | } |
| 1962 | |
| 1963 | /* |
| 1964 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1965 | % % |
| 1966 | % % |
| 1967 | % % |
| 1968 | % G e t O n e A u t h e n t i c P i x e l % |
| 1969 | % % |
| 1970 | % % |
| 1971 | % % |
| 1972 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1973 | % |
| 1974 | % GetOneAuthenticPixel() returns a single pixel at the specified (x,y) |
| 1975 | % location. The image background color is returned if an error occurs. |
| 1976 | % |
| 1977 | % The format of the GetOneAuthenticPixel() method is: |
| 1978 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1979 | % MagickBooleanType GetOneAuthenticPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 1980 | % const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1981 | % |
| 1982 | % A description of each parameter follows: |
| 1983 | % |
| 1984 | % o image: the image. |
| 1985 | % |
| 1986 | % o x,y: These values define the location of the pixel to return. |
| 1987 | % |
| 1988 | % o pixel: return a pixel at the specified (x,y) location. |
| 1989 | % |
| 1990 | % o exception: return any errors or warnings in this structure. |
| 1991 | % |
| 1992 | */ |
cristy | acbbb7c | 2010-06-30 18:56:48 +0000 | [diff] [blame] | 1993 | MagickExport MagickBooleanType GetOneAuthenticPixel(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 1994 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1995 | { |
| 1996 | CacheInfo |
| 1997 | *cache_info; |
| 1998 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1999 | register Quantum |
| 2000 | *q; |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2001 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2002 | register ssize_t |
| 2003 | i; |
| 2004 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2005 | assert(image != (Image *) NULL); |
| 2006 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2007 | assert(image->cache != (Cache) NULL); |
| 2008 | cache_info=(CacheInfo *) image->cache; |
| 2009 | assert(cache_info->signature == MagickSignature); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2010 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 2011 | if (cache_info->methods.get_one_authentic_pixel_from_handler != |
| 2012 | (GetOneAuthenticPixelFromHandler) NULL) |
| 2013 | return(cache_info->methods.get_one_authentic_pixel_from_handler(image,x,y, |
| 2014 | pixel,exception)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2015 | q=GetAuthenticPixelsCache(image,x,y,1UL,1UL,exception); |
| 2016 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2017 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2018 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2019 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2020 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2021 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2022 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2023 | return(MagickFalse); |
| 2024 | } |
| 2025 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2026 | { |
| 2027 | PixelChannel |
| 2028 | channel; |
| 2029 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2030 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2031 | pixel[channel]=q[i]; |
| 2032 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2033 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2038 | % % |
| 2039 | % % |
| 2040 | % % |
| 2041 | + 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 % |
| 2042 | % % |
| 2043 | % % |
| 2044 | % % |
| 2045 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2046 | % |
| 2047 | % GetOneAuthenticPixelFromCache() returns a single pixel at the specified (x,y) |
| 2048 | % location. The image background color is returned if an error occurs. |
| 2049 | % |
| 2050 | % The format of the GetOneAuthenticPixelFromCache() method is: |
| 2051 | % |
| 2052 | % MagickBooleanType GetOneAuthenticPixelFromCache(const Image image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2053 | % const ssize_t x,const ssize_t y,Quantum *pixel, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 2054 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2055 | % |
| 2056 | % A description of each parameter follows: |
| 2057 | % |
| 2058 | % o image: the image. |
| 2059 | % |
| 2060 | % o x,y: These values define the location of the pixel to return. |
| 2061 | % |
| 2062 | % o pixel: return a pixel at the specified (x,y) location. |
| 2063 | % |
| 2064 | % o exception: return any errors or warnings in this structure. |
| 2065 | % |
| 2066 | */ |
| 2067 | static MagickBooleanType GetOneAuthenticPixelFromCache(Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2068 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2069 | { |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2070 | CacheInfo |
| 2071 | *cache_info; |
| 2072 | |
| 2073 | const int |
| 2074 | id = GetOpenMPThreadId(); |
| 2075 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2076 | register Quantum |
| 2077 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2078 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2079 | register ssize_t |
| 2080 | i; |
| 2081 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2082 | assert(image != (const Image *) NULL); |
| 2083 | assert(image->signature == MagickSignature); |
| 2084 | assert(image->cache != (Cache) NULL); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2085 | cache_info=(CacheInfo *) image->cache; |
| 2086 | assert(cache_info->signature == MagickSignature); |
cristy | 098f78c | 2010-09-23 17:28:44 +0000 | [diff] [blame] | 2087 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2088 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2089 | q=GetAuthenticPixelCacheNexus(image,x,y,1UL,1UL,cache_info->nexus_info[id], |
| 2090 | exception); |
| 2091 | if (q == (Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2092 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2093 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2094 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2095 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2096 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2097 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2098 | return(MagickFalse); |
| 2099 | } |
| 2100 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2101 | { |
| 2102 | PixelChannel |
| 2103 | channel; |
| 2104 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2105 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2106 | pixel[channel]=q[i]; |
| 2107 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2108 | return(MagickTrue); |
| 2109 | } |
| 2110 | |
| 2111 | /* |
| 2112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2113 | % % |
| 2114 | % % |
| 2115 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2116 | % G e t O n e V i r t u a l P i x e l % |
| 2117 | % % |
| 2118 | % % |
| 2119 | % % |
| 2120 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2121 | % |
| 2122 | % GetOneVirtualPixel() returns a single virtual pixel at the specified |
| 2123 | % (x,y) location. The image background color is returned if an error occurs. |
| 2124 | % If you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2125 | % |
| 2126 | % The format of the GetOneVirtualPixel() method is: |
| 2127 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2128 | % MagickBooleanType GetOneVirtualPixel(const Image image,const ssize_t x, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2129 | % const ssize_t y,Quantum *pixel,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2130 | % |
| 2131 | % A description of each parameter follows: |
| 2132 | % |
| 2133 | % o image: the image. |
| 2134 | % |
| 2135 | % o x,y: These values define the location of the pixel to return. |
| 2136 | % |
| 2137 | % o pixel: return a pixel at the specified (x,y) location. |
| 2138 | % |
| 2139 | % o exception: return any errors or warnings in this structure. |
| 2140 | % |
| 2141 | */ |
| 2142 | MagickExport MagickBooleanType GetOneVirtualPixel(const Image *image, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2143 | const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2144 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2145 | CacheInfo |
| 2146 | *cache_info; |
| 2147 | |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2148 | const int |
| 2149 | id = GetOpenMPThreadId(); |
| 2150 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2151 | const Quantum |
| 2152 | *p; |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2153 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2154 | register ssize_t |
| 2155 | i; |
| 2156 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2157 | assert(image != (const Image *) NULL); |
| 2158 | assert(image->signature == MagickSignature); |
| 2159 | assert(image->cache != (Cache) NULL); |
| 2160 | cache_info=(CacheInfo *) image->cache; |
| 2161 | assert(cache_info->signature == MagickSignature); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2162 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 2163 | if (cache_info->methods.get_one_virtual_pixel_from_handler != |
| 2164 | (GetOneVirtualPixelFromHandler) NULL) |
| 2165 | return(cache_info->methods.get_one_virtual_pixel_from_handler(image, |
| 2166 | GetPixelCacheVirtualMethod(image),x,y,pixel,exception)); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2167 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2168 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2169 | 1UL,1UL,cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2170 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2171 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2172 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2173 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2174 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2175 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2176 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2177 | return(MagickFalse); |
| 2178 | } |
| 2179 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2180 | { |
| 2181 | PixelChannel |
| 2182 | channel; |
| 2183 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2184 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2185 | pixel[channel]=p[i]; |
| 2186 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2187 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | /* |
| 2191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2192 | % % |
| 2193 | % % |
| 2194 | % % |
| 2195 | + 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 % |
| 2196 | % % |
| 2197 | % % |
| 2198 | % % |
| 2199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2200 | % |
| 2201 | % GetOneVirtualPixelFromCache() returns a single virtual pixel at the |
| 2202 | % specified (x,y) location. The image background color is returned if an |
| 2203 | % error occurs. |
| 2204 | % |
| 2205 | % The format of the GetOneVirtualPixelFromCache() method is: |
| 2206 | % |
| 2207 | % MagickBooleanType GetOneVirtualPixelFromCache(const Image image, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2208 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2209 | % Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2210 | % |
| 2211 | % A description of each parameter follows: |
| 2212 | % |
| 2213 | % o image: the image. |
| 2214 | % |
| 2215 | % o virtual_pixel_method: the virtual pixel method. |
| 2216 | % |
| 2217 | % o x,y: These values define the location of the pixel to return. |
| 2218 | % |
| 2219 | % o pixel: return a pixel at the specified (x,y) location. |
| 2220 | % |
| 2221 | % o exception: return any errors or warnings in this structure. |
| 2222 | % |
| 2223 | */ |
| 2224 | static MagickBooleanType GetOneVirtualPixelFromCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2225 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2226 | Quantum *pixel,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2227 | { |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2228 | CacheInfo |
| 2229 | *cache_info; |
| 2230 | |
| 2231 | const int |
| 2232 | id = GetOpenMPThreadId(); |
| 2233 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2234 | const Quantum |
| 2235 | *p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2236 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2237 | register ssize_t |
| 2238 | i; |
| 2239 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2240 | assert(image != (const Image *) NULL); |
| 2241 | assert(image->signature == MagickSignature); |
| 2242 | assert(image->cache != (Cache) NULL); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2243 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2244 | assert(cache_info->signature == MagickSignature); |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2245 | assert(id < (int) cache_info->number_threads); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2246 | (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2247 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
cristy | 0158a4b | 2010-09-20 13:59:45 +0000 | [diff] [blame] | 2248 | cache_info->nexus_info[id],exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2249 | if (p == (const Quantum *) NULL) |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2250 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 2251 | pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red); |
| 2252 | pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green); |
| 2253 | pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue); |
| 2254 | pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black); |
| 2255 | pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2256 | return(MagickFalse); |
| 2257 | } |
| 2258 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 2259 | { |
| 2260 | PixelChannel |
| 2261 | channel; |
| 2262 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 2263 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 2264 | pixel[channel]=p[i]; |
| 2265 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2266 | return(MagickTrue); |
| 2267 | } |
| 2268 | |
| 2269 | /* |
| 2270 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2271 | % % |
| 2272 | % % |
| 2273 | % % |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 2274 | % G e t O n e V i r t u a l P i x e l I n f o % |
| 2275 | % % |
| 2276 | % % |
| 2277 | % % |
| 2278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2279 | % |
| 2280 | % GetOneVirtualPixelInfo() returns a single pixel at the specified (x,y) |
| 2281 | % location. The image background color is returned if an error occurs. If |
| 2282 | % you plan to modify the pixel, use GetOneAuthenticPixel() instead. |
| 2283 | % |
| 2284 | % The format of the GetOneVirtualPixelInfo() method is: |
| 2285 | % |
| 2286 | % MagickBooleanType GetOneVirtualPixelInfo(const Image image, |
| 2287 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 2288 | % const ssize_t y,PixelInfo *pixel,ExceptionInfo exception) |
| 2289 | % |
| 2290 | % A description of each parameter follows: |
| 2291 | % |
| 2292 | % o image: the image. |
| 2293 | % |
| 2294 | % o virtual_pixel_method: the virtual pixel method. |
| 2295 | % |
| 2296 | % o x,y: these values define the location of the pixel to return. |
| 2297 | % |
| 2298 | % o pixel: return a pixel at the specified (x,y) location. |
| 2299 | % |
| 2300 | % o exception: return any errors or warnings in this structure. |
| 2301 | % |
| 2302 | */ |
| 2303 | MagickExport MagickBooleanType GetOneVirtualPixelInfo(const Image *image, |
| 2304 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 2305 | PixelInfo *pixel,ExceptionInfo *exception) |
| 2306 | { |
| 2307 | CacheInfo |
| 2308 | *cache_info; |
| 2309 | |
| 2310 | const int |
| 2311 | id = GetOpenMPThreadId(); |
| 2312 | |
| 2313 | register const Quantum |
| 2314 | *p; |
| 2315 | |
| 2316 | assert(image != (const Image *) NULL); |
| 2317 | assert(image->signature == MagickSignature); |
| 2318 | assert(image->cache != (Cache) NULL); |
| 2319 | cache_info=(CacheInfo *) image->cache; |
| 2320 | assert(cache_info->signature == MagickSignature); |
| 2321 | assert(id < (int) cache_info->number_threads); |
| 2322 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL, |
| 2323 | cache_info->nexus_info[id],exception); |
| 2324 | GetPixelInfo(image,pixel); |
| 2325 | if (p == (const Quantum *) NULL) |
| 2326 | return(MagickFalse); |
| 2327 | GetPixelInfoPixel(image,p,pixel); |
| 2328 | return(MagickTrue); |
| 2329 | } |
| 2330 | |
| 2331 | /* |
| 2332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2333 | % % |
| 2334 | % % |
| 2335 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2336 | + G e t P i x e l C a c h e C o l o r s p a c e % |
| 2337 | % % |
| 2338 | % % |
| 2339 | % % |
| 2340 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2341 | % |
| 2342 | % GetPixelCacheColorspace() returns the class type of the pixel cache. |
| 2343 | % |
| 2344 | % The format of the GetPixelCacheColorspace() method is: |
| 2345 | % |
| 2346 | % Colorspace GetPixelCacheColorspace(Cache cache) |
| 2347 | % |
| 2348 | % A description of each parameter follows: |
| 2349 | % |
| 2350 | % o cache: the pixel cache. |
| 2351 | % |
| 2352 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2353 | MagickPrivate ColorspaceType GetPixelCacheColorspace(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2354 | { |
| 2355 | CacheInfo |
| 2356 | *cache_info; |
| 2357 | |
| 2358 | assert(cache != (Cache) NULL); |
| 2359 | cache_info=(CacheInfo *) cache; |
| 2360 | assert(cache_info->signature == MagickSignature); |
| 2361 | if (cache_info->debug != MagickFalse) |
| 2362 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2363 | cache_info->filename); |
| 2364 | return(cache_info->colorspace); |
| 2365 | } |
| 2366 | |
| 2367 | /* |
| 2368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2369 | % % |
| 2370 | % % |
| 2371 | % % |
| 2372 | + G e t P i x e l C a c h e M e t h o d s % |
| 2373 | % % |
| 2374 | % % |
| 2375 | % % |
| 2376 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2377 | % |
| 2378 | % GetPixelCacheMethods() initializes the CacheMethods structure. |
| 2379 | % |
| 2380 | % The format of the GetPixelCacheMethods() method is: |
| 2381 | % |
| 2382 | % void GetPixelCacheMethods(CacheMethods *cache_methods) |
| 2383 | % |
| 2384 | % A description of each parameter follows: |
| 2385 | % |
| 2386 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 2387 | % |
| 2388 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2389 | MagickPrivate void GetPixelCacheMethods(CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2390 | { |
| 2391 | assert(cache_methods != (CacheMethods *) NULL); |
| 2392 | (void) ResetMagickMemory(cache_methods,0,sizeof(*cache_methods)); |
| 2393 | cache_methods->get_virtual_pixel_handler=GetVirtualPixelCache; |
| 2394 | cache_methods->get_virtual_pixels_handler=GetVirtualPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2395 | cache_methods->get_virtual_metacontent_from_handler= |
| 2396 | GetVirtualMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2397 | cache_methods->get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromCache; |
| 2398 | cache_methods->get_authentic_pixels_handler=GetAuthenticPixelsCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2399 | cache_methods->get_authentic_metacontent_from_handler= |
| 2400 | GetAuthenticMetacontentFromCache; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2401 | cache_methods->get_authentic_pixels_from_handler=GetAuthenticPixelsFromCache; |
| 2402 | cache_methods->get_one_authentic_pixel_from_handler= |
| 2403 | GetOneAuthenticPixelFromCache; |
| 2404 | cache_methods->queue_authentic_pixels_handler=QueueAuthenticPixelsCache; |
| 2405 | cache_methods->sync_authentic_pixels_handler=SyncAuthenticPixelsCache; |
| 2406 | cache_methods->destroy_pixel_handler=DestroyImagePixelCache; |
| 2407 | } |
| 2408 | |
| 2409 | /* |
| 2410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2411 | % % |
| 2412 | % % |
| 2413 | % % |
| 2414 | + G e t P i x e l C a c h e N e x u s E x t e n t % |
| 2415 | % % |
| 2416 | % % |
| 2417 | % % |
| 2418 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2419 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2420 | % GetPixelCacheNexusExtent() returns the extent of the pixels associated |
| 2421 | % corresponding with the last call to SetPixelCacheNexusPixels() or |
| 2422 | % GetPixelCacheNexusPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2423 | % |
| 2424 | % The format of the GetPixelCacheNexusExtent() method is: |
| 2425 | % |
| 2426 | % MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
| 2427 | % NexusInfo *nexus_info) |
| 2428 | % |
| 2429 | % A description of each parameter follows: |
| 2430 | % |
| 2431 | % o nexus_info: the nexus info. |
| 2432 | % |
| 2433 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2434 | MagickPrivate MagickSizeType GetPixelCacheNexusExtent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2435 | NexusInfo *nexus_info) |
| 2436 | { |
| 2437 | CacheInfo |
| 2438 | *cache_info; |
| 2439 | |
| 2440 | MagickSizeType |
| 2441 | extent; |
| 2442 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2443 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2444 | cache_info=(CacheInfo *) cache; |
| 2445 | assert(cache_info->signature == MagickSignature); |
| 2446 | extent=(MagickSizeType) nexus_info->region.width*nexus_info->region.height; |
| 2447 | if (extent == 0) |
| 2448 | return((MagickSizeType) cache_info->columns*cache_info->rows); |
| 2449 | return(extent); |
| 2450 | } |
| 2451 | |
| 2452 | /* |
| 2453 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2454 | % % |
| 2455 | % % |
| 2456 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2457 | + 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] | 2458 | % % |
| 2459 | % % |
| 2460 | % % |
| 2461 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2462 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2463 | % GetPixelCacheNexusMetacontent() returns the meta-content for the specified |
| 2464 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2465 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2466 | % The format of the GetPixelCacheNexusMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2467 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2468 | % void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2469 | % NexusInfo *nexus_info) |
| 2470 | % |
| 2471 | % A description of each parameter follows: |
| 2472 | % |
| 2473 | % o cache: the pixel cache. |
| 2474 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2475 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2476 | % |
| 2477 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2478 | MagickPrivate void *GetPixelCacheNexusMetacontent(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2479 | NexusInfo *nexus_info) |
| 2480 | { |
| 2481 | CacheInfo |
| 2482 | *cache_info; |
| 2483 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2484 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2485 | cache_info=(CacheInfo *) cache; |
| 2486 | assert(cache_info->signature == MagickSignature); |
| 2487 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2488 | return((void *) NULL); |
| 2489 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | /* |
| 2493 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2494 | % % |
| 2495 | % % |
| 2496 | % % |
| 2497 | + G e t P i x e l C a c h e N e x u s P i x e l s % |
| 2498 | % % |
| 2499 | % % |
| 2500 | % % |
| 2501 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2502 | % |
| 2503 | % GetPixelCacheNexusPixels() returns the pixels associated with the specified |
| 2504 | % cache nexus. |
| 2505 | % |
| 2506 | % The format of the GetPixelCacheNexusPixels() method is: |
| 2507 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2508 | % Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2509 | % NexusInfo *nexus_info) |
| 2510 | % |
| 2511 | % A description of each parameter follows: |
| 2512 | % |
| 2513 | % o cache: the pixel cache. |
| 2514 | % |
| 2515 | % o nexus_info: the cache nexus to return the pixels. |
| 2516 | % |
| 2517 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2518 | MagickPrivate Quantum *GetPixelCacheNexusPixels(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2519 | NexusInfo *nexus_info) |
| 2520 | { |
| 2521 | CacheInfo |
| 2522 | *cache_info; |
| 2523 | |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 2524 | assert(cache != NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2525 | cache_info=(CacheInfo *) cache; |
| 2526 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2527 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2528 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2529 | return(nexus_info->pixels); |
| 2530 | } |
| 2531 | |
| 2532 | /* |
| 2533 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2534 | % % |
| 2535 | % % |
| 2536 | % % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2537 | + G e t P i x e l C a c h e P i x e l s % |
| 2538 | % % |
| 2539 | % % |
| 2540 | % % |
| 2541 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2542 | % |
| 2543 | % GetPixelCachePixels() returns the pixels associated with the specified image. |
| 2544 | % |
| 2545 | % The format of the GetPixelCachePixels() method is: |
| 2546 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2547 | % void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
| 2548 | % ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2549 | % |
| 2550 | % A description of each parameter follows: |
| 2551 | % |
| 2552 | % o image: the image. |
| 2553 | % |
| 2554 | % o length: the pixel cache length. |
| 2555 | % |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2556 | % o exception: return any errors or warnings in this structure. |
| 2557 | % |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2558 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2559 | MagickPrivate void *GetPixelCachePixels(Image *image,MagickSizeType *length, |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2560 | ExceptionInfo *exception) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2561 | { |
| 2562 | CacheInfo |
| 2563 | *cache_info; |
| 2564 | |
| 2565 | assert(image != (const Image *) NULL); |
| 2566 | assert(image->signature == MagickSignature); |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2567 | assert(image->cache != (Cache) NULL); |
cristy | 654fdaf | 2011-02-24 15:24:33 +0000 | [diff] [blame] | 2568 | assert(length != (MagickSizeType *) NULL); |
| 2569 | assert(exception != (ExceptionInfo *) NULL); |
| 2570 | assert(exception->signature == MagickSignature); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 2571 | cache_info=(CacheInfo *) image->cache; |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2572 | assert(cache_info->signature == MagickSignature); |
| 2573 | *length=0; |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 2574 | if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache)) |
cristy | 056ba77 | 2010-01-02 23:33:54 +0000 | [diff] [blame] | 2575 | return((void *) NULL); |
| 2576 | *length=cache_info->length; |
| 2577 | return((void *) cache_info->pixels); |
| 2578 | } |
| 2579 | |
| 2580 | /* |
| 2581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2582 | % % |
| 2583 | % % |
| 2584 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2585 | + 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] | 2586 | % % |
| 2587 | % % |
| 2588 | % % |
| 2589 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2590 | % |
| 2591 | % GetPixelCacheStorageClass() returns the class type of the pixel cache. |
| 2592 | % |
| 2593 | % The format of the GetPixelCacheStorageClass() method is: |
| 2594 | % |
| 2595 | % ClassType GetPixelCacheStorageClass(Cache cache) |
| 2596 | % |
| 2597 | % A description of each parameter follows: |
| 2598 | % |
| 2599 | % o type: GetPixelCacheStorageClass returns DirectClass or PseudoClass. |
| 2600 | % |
| 2601 | % o cache: the pixel cache. |
| 2602 | % |
| 2603 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2604 | MagickPrivate ClassType GetPixelCacheStorageClass(const Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2605 | { |
| 2606 | CacheInfo |
| 2607 | *cache_info; |
| 2608 | |
| 2609 | assert(cache != (Cache) NULL); |
| 2610 | cache_info=(CacheInfo *) cache; |
| 2611 | assert(cache_info->signature == MagickSignature); |
| 2612 | if (cache_info->debug != MagickFalse) |
| 2613 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2614 | cache_info->filename); |
| 2615 | return(cache_info->storage_class); |
| 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2620 | % % |
| 2621 | % % |
| 2622 | % % |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2623 | + G e t P i x e l C a c h e T i l e S i z e % |
| 2624 | % % |
| 2625 | % % |
| 2626 | % % |
| 2627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2628 | % |
| 2629 | % GetPixelCacheTileSize() returns the pixel cache tile size. |
| 2630 | % |
| 2631 | % The format of the GetPixelCacheTileSize() method is: |
| 2632 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2633 | % void GetPixelCacheTileSize(const Image *image,size_t *width, |
| 2634 | % size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2635 | % |
| 2636 | % A description of each parameter follows: |
| 2637 | % |
| 2638 | % o image: the image. |
| 2639 | % |
| 2640 | % o width: the optimize cache tile width in pixels. |
| 2641 | % |
| 2642 | % o height: the optimize cache tile height in pixels. |
| 2643 | % |
| 2644 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2645 | MagickPrivate void GetPixelCacheTileSize(const Image *image,size_t *width, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2646 | size_t *height) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2647 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2648 | CacheInfo |
| 2649 | *cache_info; |
| 2650 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2651 | assert(image != (Image *) NULL); |
| 2652 | assert(image->signature == MagickSignature); |
| 2653 | if (image->debug != MagickFalse) |
| 2654 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2655 | cache_info=(CacheInfo *) image->cache; |
| 2656 | assert(cache_info->signature == MagickSignature); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2657 | *width=2048UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2658 | if (GetPixelCacheType(image) == DiskCache) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2659 | *width=8192UL/(cache_info->number_channels*sizeof(Quantum)); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2660 | *height=(*width); |
| 2661 | } |
| 2662 | |
| 2663 | /* |
| 2664 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2665 | % % |
| 2666 | % % |
| 2667 | % % |
| 2668 | + G e t P i x e l C a c h e T y p e % |
| 2669 | % % |
| 2670 | % % |
| 2671 | % % |
| 2672 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2673 | % |
| 2674 | % GetPixelCacheType() returns the pixel cache type (e.g. memory, disk, etc.). |
| 2675 | % |
| 2676 | % The format of the GetPixelCacheType() method is: |
| 2677 | % |
| 2678 | % CacheType GetPixelCacheType(const Image *image) |
| 2679 | % |
| 2680 | % A description of each parameter follows: |
| 2681 | % |
| 2682 | % o image: the image. |
| 2683 | % |
| 2684 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2685 | MagickPrivate CacheType GetPixelCacheType(const Image *image) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2686 | { |
| 2687 | CacheInfo |
| 2688 | *cache_info; |
| 2689 | |
| 2690 | assert(image != (Image *) NULL); |
| 2691 | assert(image->signature == MagickSignature); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2692 | assert(image->cache != (Cache) NULL); |
| 2693 | cache_info=(CacheInfo *) image->cache; |
| 2694 | assert(cache_info->signature == MagickSignature); |
| 2695 | return(cache_info->type); |
| 2696 | } |
| 2697 | |
| 2698 | /* |
| 2699 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2700 | % % |
| 2701 | % % |
| 2702 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2703 | + 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 % |
| 2704 | % % |
| 2705 | % % |
| 2706 | % % |
| 2707 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2708 | % |
| 2709 | % GetPixelCacheVirtualMethod() gets the "virtual pixels" method for the |
| 2710 | % pixel cache. A virtual pixel is any pixel access that is outside the |
| 2711 | % boundaries of the image cache. |
| 2712 | % |
| 2713 | % The format of the GetPixelCacheVirtualMethod() method is: |
| 2714 | % |
| 2715 | % VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
| 2716 | % |
| 2717 | % A description of each parameter follows: |
| 2718 | % |
| 2719 | % o image: the image. |
| 2720 | % |
| 2721 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 2722 | MagickPrivate VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2723 | { |
| 2724 | CacheInfo |
| 2725 | *cache_info; |
| 2726 | |
| 2727 | assert(image != (Image *) NULL); |
| 2728 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2729 | assert(image->cache != (Cache) NULL); |
| 2730 | cache_info=(CacheInfo *) image->cache; |
| 2731 | assert(cache_info->signature == MagickSignature); |
| 2732 | return(cache_info->virtual_pixel_method); |
| 2733 | } |
| 2734 | |
| 2735 | /* |
| 2736 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2737 | % % |
| 2738 | % % |
| 2739 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2740 | + 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] | 2741 | % % |
| 2742 | % % |
| 2743 | % % |
| 2744 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2745 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2746 | % GetVirtualMetacontentFromCache() returns the meta-content corresponding with |
| 2747 | % the last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2748 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2749 | % The format of the GetVirtualMetacontentFromCache() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2750 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2751 | % void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2752 | % |
| 2753 | % A description of each parameter follows: |
| 2754 | % |
| 2755 | % o image: the image. |
| 2756 | % |
| 2757 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2758 | static const void *GetVirtualMetacontentFromCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2759 | { |
| 2760 | CacheInfo |
| 2761 | *cache_info; |
| 2762 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 2763 | const int |
| 2764 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2765 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2766 | const void |
| 2767 | *metacontent; |
| 2768 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2769 | assert(image != (const Image *) NULL); |
| 2770 | assert(image->signature == MagickSignature); |
| 2771 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2772 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2773 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 2774 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2775 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 2776 | cache_info->nexus_info[id]); |
| 2777 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | /* |
| 2781 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2782 | % % |
| 2783 | % % |
| 2784 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2785 | + 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] | 2786 | % % |
| 2787 | % % |
| 2788 | % % |
| 2789 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2790 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2791 | % GetVirtualMetacontentFromNexus() returns the meta-content for the specified |
| 2792 | % cache nexus. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2793 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2794 | % The format of the GetVirtualMetacontentFromNexus() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2795 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2796 | % const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2797 | % NexusInfo *nexus_info) |
| 2798 | % |
| 2799 | % A description of each parameter follows: |
| 2800 | % |
| 2801 | % o cache: the pixel cache. |
| 2802 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2803 | % o nexus_info: the cache nexus to return the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2804 | % |
| 2805 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2806 | MagickPrivate const void *GetVirtualMetacontentFromNexus(const Cache cache, |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 2807 | NexusInfo *nexus_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2808 | { |
| 2809 | CacheInfo |
| 2810 | *cache_info; |
| 2811 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 2812 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2813 | cache_info=(CacheInfo *) cache; |
| 2814 | assert(cache_info->signature == MagickSignature); |
| 2815 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2816 | return((void *) NULL); |
| 2817 | return(nexus_info->metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | /* |
| 2821 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2822 | % % |
| 2823 | % % |
| 2824 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2825 | % 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] | 2826 | % % |
| 2827 | % % |
| 2828 | % % |
| 2829 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2830 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2831 | % GetVirtualMetacontent() returns the virtual metacontent corresponding with |
| 2832 | % the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is |
| 2833 | % returned if the meta-content are not available. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2834 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2835 | % The format of the GetVirtualMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2836 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2837 | % const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2838 | % |
| 2839 | % A description of each parameter follows: |
| 2840 | % |
| 2841 | % o image: the image. |
| 2842 | % |
| 2843 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2844 | MagickExport const void *GetVirtualMetacontent(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2845 | { |
| 2846 | CacheInfo |
| 2847 | *cache_info; |
| 2848 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2849 | const int |
| 2850 | id = GetOpenMPThreadId(); |
| 2851 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2852 | const void |
| 2853 | *metacontent; |
| 2854 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2855 | assert(image != (const Image *) NULL); |
| 2856 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2857 | assert(image->cache != (Cache) NULL); |
| 2858 | cache_info=(CacheInfo *) image->cache; |
| 2859 | assert(cache_info->signature == MagickSignature); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2860 | if (cache_info->methods.get_virtual_metacontent_from_handler != |
| 2861 | (GetVirtualMetacontentFromHandler) NULL) |
| 2862 | { |
| 2863 | metacontent=cache_info->methods. |
| 2864 | get_virtual_metacontent_from_handler(image); |
| 2865 | return(metacontent); |
| 2866 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 2867 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2868 | metacontent=GetVirtualMetacontentFromNexus(cache_info, |
| 2869 | cache_info->nexus_info[id]); |
| 2870 | return(metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | /* |
| 2874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2875 | % % |
| 2876 | % % |
| 2877 | % % |
| 2878 | + 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 % |
| 2879 | % % |
| 2880 | % % |
| 2881 | % % |
| 2882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2883 | % |
| 2884 | % GetVirtualPixelsFromNexus() gets virtual pixels from the in-memory or disk |
| 2885 | % pixel cache as defined by the geometry parameters. A pointer to the pixels |
| 2886 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 2887 | % |
| 2888 | % The format of the GetVirtualPixelsFromNexus() method is: |
| 2889 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2890 | % Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2891 | % const VirtualPixelMethod method,const ssize_t x,const ssize_t y, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 2892 | % const size_t columns,const size_t rows,NexusInfo *nexus_info, |
| 2893 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2894 | % |
| 2895 | % A description of each parameter follows: |
| 2896 | % |
| 2897 | % o image: the image. |
| 2898 | % |
| 2899 | % o virtual_pixel_method: the virtual pixel method. |
| 2900 | % |
| 2901 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 2902 | % pixels. |
| 2903 | % |
| 2904 | % o nexus_info: the cache nexus to acquire. |
| 2905 | % |
| 2906 | % o exception: return any errors or warnings in this structure. |
| 2907 | % |
| 2908 | */ |
| 2909 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2910 | static ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2911 | DitherMatrix[64] = |
| 2912 | { |
| 2913 | 0, 48, 12, 60, 3, 51, 15, 63, |
| 2914 | 32, 16, 44, 28, 35, 19, 47, 31, |
| 2915 | 8, 56, 4, 52, 11, 59, 7, 55, |
| 2916 | 40, 24, 36, 20, 43, 27, 39, 23, |
| 2917 | 2, 50, 14, 62, 1, 49, 13, 61, |
| 2918 | 34, 18, 46, 30, 33, 17, 45, 29, |
| 2919 | 10, 58, 6, 54, 9, 57, 5, 53, |
| 2920 | 42, 26, 38, 22, 41, 25, 37, 21 |
| 2921 | }; |
| 2922 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2923 | static inline ssize_t DitherX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2924 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2925 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2926 | index; |
| 2927 | |
| 2928 | index=x+DitherMatrix[x & 0x07]-32L; |
| 2929 | if (index < 0L) |
| 2930 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2931 | if (index >= (ssize_t) columns) |
| 2932 | return((ssize_t) columns-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2933 | return(index); |
| 2934 | } |
| 2935 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2936 | static inline ssize_t DitherY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2937 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2938 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2939 | index; |
| 2940 | |
| 2941 | index=y+DitherMatrix[y & 0x07]-32L; |
| 2942 | if (index < 0L) |
| 2943 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2944 | if (index >= (ssize_t) rows) |
| 2945 | return((ssize_t) rows-1L); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2946 | return(index); |
| 2947 | } |
| 2948 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2949 | static inline ssize_t EdgeX(const ssize_t x,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2950 | { |
| 2951 | if (x < 0L) |
| 2952 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2953 | if (x >= (ssize_t) columns) |
| 2954 | return((ssize_t) (columns-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2955 | return(x); |
| 2956 | } |
| 2957 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2958 | static inline ssize_t EdgeY(const ssize_t y,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2959 | { |
| 2960 | if (y < 0L) |
| 2961 | return(0L); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2962 | if (y >= (ssize_t) rows) |
| 2963 | return((ssize_t) (rows-1)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2964 | return(y); |
| 2965 | } |
| 2966 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2967 | static inline ssize_t RandomX(RandomInfo *random_info,const size_t columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2968 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2969 | return((ssize_t) (columns*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2972 | static inline ssize_t RandomY(RandomInfo *random_info,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2973 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2974 | return((ssize_t) (rows*GetPseudoRandomValue(random_info))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2977 | static inline MagickModulo VirtualPixelModulo(const ssize_t offset, |
| 2978 | const size_t extent) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2979 | { |
| 2980 | MagickModulo |
| 2981 | modulo; |
| 2982 | |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 2983 | /* |
| 2984 | Compute the remainder of dividing offset by extent. It returns not only |
| 2985 | the quotient (tile the offset falls in) but also the positive remainer |
| 2986 | within that tile such that 0 <= remainder < extent. This method is |
| 2987 | essentially a ldiv() using a floored modulo division rather than the |
| 2988 | normal default truncated modulo division. |
| 2989 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2990 | modulo.quotient=offset/(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2991 | if (offset < 0L) |
| 2992 | modulo.quotient--; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2993 | modulo.remainder=offset-modulo.quotient*(ssize_t) extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2994 | return(modulo); |
| 2995 | } |
| 2996 | |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 2997 | MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2998 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 2999 | const size_t columns,const size_t rows,NexusInfo *nexus_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3000 | ExceptionInfo *exception) |
| 3001 | { |
| 3002 | CacheInfo |
| 3003 | *cache_info; |
| 3004 | |
| 3005 | MagickOffsetType |
| 3006 | offset; |
| 3007 | |
| 3008 | MagickSizeType |
| 3009 | length, |
| 3010 | number_pixels; |
| 3011 | |
| 3012 | NexusInfo |
| 3013 | **virtual_nexus; |
| 3014 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3015 | Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3016 | *pixels, |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 3017 | virtual_pixel[CompositePixelChannel]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3018 | |
| 3019 | RectangleInfo |
| 3020 | region; |
| 3021 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3022 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3023 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3024 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3025 | register const void |
| 3026 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3027 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3028 | register Quantum |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3029 | *restrict q; |
| 3030 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3031 | register ssize_t |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3032 | i, |
| 3033 | u; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3034 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3035 | register unsigned char |
| 3036 | *restrict s; |
| 3037 | |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3038 | ssize_t |
| 3039 | v; |
| 3040 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3041 | void |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3042 | *virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3043 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3044 | /* |
| 3045 | Acquire pixels. |
| 3046 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3047 | assert(image != (const Image *) NULL); |
| 3048 | assert(image->signature == MagickSignature); |
| 3049 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3050 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3051 | assert(cache_info->signature == MagickSignature); |
cristy | 4cfbb3f | 2010-03-14 20:40:23 +0000 | [diff] [blame] | 3052 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3053 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3054 | region.x=x; |
| 3055 | region.y=y; |
| 3056 | region.width=columns; |
| 3057 | region.height=rows; |
| 3058 | pixels=SetPixelCacheNexusPixels(image,®ion,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3059 | if (pixels == (Quantum *) NULL) |
| 3060 | return((const Quantum *) NULL); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3061 | q=pixels; |
cristy | df415c8 | 2010-03-11 16:47:50 +0000 | [diff] [blame] | 3062 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 3063 | nexus_info->region.x; |
| 3064 | length=(MagickSizeType) (nexus_info->region.height-1L)*cache_info->columns+ |
| 3065 | nexus_info->region.width-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3066 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 3067 | if ((offset >= 0) && (((MagickSizeType) offset+length) < number_pixels)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3068 | if ((x >= 0) && ((ssize_t) (x+columns) <= (ssize_t) cache_info->columns) && |
| 3069 | (y >= 0) && ((ssize_t) (y+rows) <= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3070 | { |
| 3071 | MagickBooleanType |
| 3072 | status; |
| 3073 | |
| 3074 | /* |
| 3075 | Pixel request is inside cache extents. |
| 3076 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3077 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3078 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3079 | status=ReadPixelCachePixels(cache_info,nexus_info,exception); |
| 3080 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3081 | return((const Quantum *) NULL); |
| 3082 | if (cache_info->metacontent_extent != 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3083 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3084 | status=ReadPixelCacheMetacontent(cache_info,nexus_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3085 | if (status == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3086 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3087 | } |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3088 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3089 | } |
| 3090 | /* |
| 3091 | Pixel request is outside cache extents. |
| 3092 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3093 | s=(unsigned char *) GetPixelCacheNexusMetacontent(cache_info,nexus_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3094 | virtual_nexus=AcquirePixelCacheNexus(1); |
| 3095 | if (virtual_nexus == (NexusInfo **) NULL) |
| 3096 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3097 | if (virtual_nexus != (NexusInfo **) NULL) |
| 3098 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3099 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 3100 | "UnableToGetCacheNexus","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3101 | return((const Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3102 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3103 | (void) ResetMagickMemory(virtual_pixel,0,cache_info->number_channels* |
| 3104 | sizeof(*virtual_pixel)); |
| 3105 | virtual_metacontent=(void *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3106 | switch (virtual_pixel_method) |
| 3107 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3108 | case BackgroundVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3109 | case BlackVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3110 | case GrayVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3111 | case TransparentVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3112 | case MaskVirtualPixelMethod: |
| 3113 | case WhiteVirtualPixelMethod: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3114 | case EdgeVirtualPixelMethod: |
| 3115 | case CheckerTileVirtualPixelMethod: |
| 3116 | case HorizontalTileVirtualPixelMethod: |
| 3117 | case VerticalTileVirtualPixelMethod: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3118 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3119 | if (cache_info->metacontent_extent != 0) |
| 3120 | { |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3121 | /* |
| 3122 | Acquire a metacontent buffer. |
| 3123 | */ |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3124 | virtual_metacontent=(void *) AcquireQuantumMemory(1, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3125 | cache_info->metacontent_extent); |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3126 | if (virtual_metacontent == (void *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3127 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3128 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3129 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 3130 | CacheError,"UnableToGetCacheNexus","`%s'",image->filename); |
| 3131 | return((const Quantum *) NULL); |
| 3132 | } |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3133 | (void) ResetMagickMemory(virtual_metacontent,0, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3134 | cache_info->metacontent_extent); |
| 3135 | } |
| 3136 | switch (virtual_pixel_method) |
| 3137 | { |
| 3138 | case BlackVirtualPixelMethod: |
| 3139 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3140 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3141 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3142 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3143 | break; |
| 3144 | } |
| 3145 | case GrayVirtualPixelMethod: |
| 3146 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3147 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
cristy | 208b100 | 2011-08-07 18:51:50 +0000 | [diff] [blame] | 3148 | SetPixelChannel(image,(PixelChannel) i,QuantumRange/2, |
| 3149 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3150 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3151 | break; |
| 3152 | } |
| 3153 | case TransparentVirtualPixelMethod: |
| 3154 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3155 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3156 | SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3157 | SetPixelAlpha(image,TransparentAlpha,virtual_pixel); |
| 3158 | break; |
| 3159 | } |
| 3160 | case MaskVirtualPixelMethod: |
| 3161 | case WhiteVirtualPixelMethod: |
| 3162 | { |
cristy | 3030171 | 2011-07-18 15:06:51 +0000 | [diff] [blame] | 3163 | for (i=0; i < (ssize_t) cache_info->number_channels; i++) |
| 3164 | SetPixelChannel(image,(PixelChannel) i,QuantumRange,virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3165 | SetPixelAlpha(image,OpaqueAlpha,virtual_pixel); |
| 3166 | break; |
| 3167 | } |
| 3168 | default: |
| 3169 | { |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3170 | SetPixelRed(image,ClampToQuantum(image->background_color.red), |
| 3171 | virtual_pixel); |
| 3172 | SetPixelGreen(image,ClampToQuantum(image->background_color.green), |
| 3173 | virtual_pixel); |
| 3174 | SetPixelBlue(image,ClampToQuantum(image->background_color.blue), |
| 3175 | virtual_pixel); |
cristy | 6162bb4 | 2011-07-18 11:34:09 +0000 | [diff] [blame] | 3176 | if (image->colorspace == CMYKColorspace) |
cristy | 9e0719b | 2011-12-29 03:45:45 +0000 | [diff] [blame] | 3177 | SetPixelBlack(image,ClampToQuantum(image->background_color.black), |
| 3178 | virtual_pixel); |
| 3179 | SetPixelAlpha(image,ClampToQuantum(image->background_color.alpha), |
| 3180 | virtual_pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3181 | break; |
| 3182 | } |
| 3183 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3184 | break; |
| 3185 | } |
| 3186 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3187 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3188 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3189 | for (v=0; v < (ssize_t) rows; v++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3190 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3191 | for (u=0; u < (ssize_t) columns; u+=length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3192 | { |
| 3193 | length=(MagickSizeType) MagickMin(cache_info->columns-(x+u),columns-u); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3194 | if ((((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) || |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3195 | (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) || |
| 3196 | (length == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3197 | { |
| 3198 | MagickModulo |
| 3199 | x_modulo, |
| 3200 | y_modulo; |
| 3201 | |
| 3202 | /* |
| 3203 | Transfer a single pixel. |
| 3204 | */ |
| 3205 | length=(MagickSizeType) 1; |
| 3206 | switch (virtual_pixel_method) |
| 3207 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3208 | default: |
| 3209 | { |
| 3210 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3211 | EdgeX(x+u,cache_info->columns),EdgeY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3212 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3213 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3214 | break; |
| 3215 | } |
| 3216 | case RandomVirtualPixelMethod: |
| 3217 | { |
| 3218 | if (cache_info->random_info == (RandomInfo *) NULL) |
| 3219 | cache_info->random_info=AcquireRandomInfo(); |
| 3220 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3221 | RandomX(cache_info->random_info,cache_info->columns), |
| 3222 | RandomY(cache_info->random_info,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3223 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3224 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3225 | break; |
| 3226 | } |
| 3227 | case DitherVirtualPixelMethod: |
| 3228 | { |
| 3229 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3230 | DitherX(x+u,cache_info->columns),DitherY(y+v,cache_info->rows), |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3231 | 1UL,1UL,*virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3232 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | } |
| 3235 | case TileVirtualPixelMethod: |
| 3236 | { |
| 3237 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3238 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3239 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3240 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3241 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3242 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3243 | break; |
| 3244 | } |
| 3245 | case MirrorVirtualPixelMethod: |
| 3246 | { |
| 3247 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3248 | if ((x_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3249 | x_modulo.remainder=(ssize_t) cache_info->columns- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3250 | x_modulo.remainder-1L; |
| 3251 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3252 | if ((y_modulo.quotient & 0x01) == 1L) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3253 | y_modulo.remainder=(ssize_t) cache_info->rows- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3254 | y_modulo.remainder-1L; |
| 3255 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3256 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3257 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3258 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | } |
| 3261 | case HorizontalTileEdgeVirtualPixelMethod: |
| 3262 | { |
| 3263 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3264 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3265 | x_modulo.remainder,EdgeY(y+v,cache_info->rows),1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3266 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3267 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3268 | break; |
| 3269 | } |
| 3270 | case VerticalTileEdgeVirtualPixelMethod: |
| 3271 | { |
| 3272 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3273 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
cristy | 222528c | 2010-01-09 23:36:34 +0000 | [diff] [blame] | 3274 | EdgeX(x+u,cache_info->columns),y_modulo.remainder,1UL,1UL, |
cristy | 0a36c74 | 2010-10-03 02:10:53 +0000 | [diff] [blame] | 3275 | *virtual_nexus,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3276 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3277 | break; |
| 3278 | } |
| 3279 | case BackgroundVirtualPixelMethod: |
| 3280 | case BlackVirtualPixelMethod: |
| 3281 | case GrayVirtualPixelMethod: |
| 3282 | case TransparentVirtualPixelMethod: |
| 3283 | case MaskVirtualPixelMethod: |
| 3284 | case WhiteVirtualPixelMethod: |
| 3285 | { |
| 3286 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3287 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3288 | break; |
| 3289 | } |
| 3290 | case EdgeVirtualPixelMethod: |
| 3291 | case CheckerTileVirtualPixelMethod: |
| 3292 | { |
| 3293 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3294 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3295 | if (((x_modulo.quotient ^ y_modulo.quotient) & 0x01) != 0L) |
| 3296 | { |
| 3297 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3298 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3299 | break; |
| 3300 | } |
| 3301 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3302 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3303 | exception); |
| 3304 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3305 | break; |
| 3306 | } |
| 3307 | case HorizontalTileVirtualPixelMethod: |
| 3308 | { |
| 3309 | if (((y+v) < 0) || ((y+v) >= (ssize_t) cache_info->rows)) |
| 3310 | { |
| 3311 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3312 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3313 | break; |
| 3314 | } |
| 3315 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3316 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3317 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3318 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3319 | exception); |
| 3320 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
| 3321 | break; |
| 3322 | } |
| 3323 | case VerticalTileVirtualPixelMethod: |
| 3324 | { |
| 3325 | if (((x+u) < 0) || ((x+u) >= (ssize_t) cache_info->columns)) |
| 3326 | { |
| 3327 | p=virtual_pixel; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3328 | r=virtual_metacontent; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3329 | break; |
| 3330 | } |
| 3331 | x_modulo=VirtualPixelModulo(x+u,cache_info->columns); |
| 3332 | y_modulo=VirtualPixelModulo(y+v,cache_info->rows); |
| 3333 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method, |
| 3334 | x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, |
| 3335 | exception); |
| 3336 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | } |
| 3339 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3340 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3341 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3342 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3343 | sizeof(*p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3344 | q+=cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3345 | if ((s != (void *) NULL) && (r != (const void *) NULL)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3346 | { |
| 3347 | (void) memcpy(s,r,(size_t) cache_info->metacontent_extent); |
| 3348 | s+=cache_info->metacontent_extent; |
| 3349 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3350 | continue; |
| 3351 | } |
| 3352 | /* |
| 3353 | Transfer a run of pixels. |
| 3354 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3355 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x+u,y+v,(size_t) |
| 3356 | length,1UL,*virtual_nexus,exception); |
| 3357 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3358 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3359 | r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3360 | (void) memcpy(q,p,(size_t) length*cache_info->number_channels*sizeof(*p)); |
| 3361 | q+=length*cache_info->number_channels; |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3362 | if ((r != (void *) NULL) && (s != (const void *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3363 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3364 | (void) memcpy(s,r,(size_t) length); |
| 3365 | s+=length*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3369 | /* |
| 3370 | Free resources. |
| 3371 | */ |
cristy | 105ba3c | 2011-07-18 02:28:38 +0000 | [diff] [blame] | 3372 | if (virtual_metacontent != (void *) NULL) |
| 3373 | virtual_metacontent=(void *) RelinquishMagickMemory(virtual_metacontent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3374 | virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); |
| 3375 | return(pixels); |
| 3376 | } |
| 3377 | |
| 3378 | /* |
| 3379 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3380 | % % |
| 3381 | % % |
| 3382 | % % |
| 3383 | + G e t V i r t u a l P i x e l C a c h e % |
| 3384 | % % |
| 3385 | % % |
| 3386 | % % |
| 3387 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3388 | % |
| 3389 | % GetVirtualPixelCache() get virtual pixels from the in-memory or disk pixel |
| 3390 | % cache as defined by the geometry parameters. A pointer to the pixels |
| 3391 | % is returned if the pixels are transferred, otherwise a NULL is returned. |
| 3392 | % |
| 3393 | % The format of the GetVirtualPixelCache() method is: |
| 3394 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3395 | % const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3396 | % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, |
| 3397 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3398 | % ExceptionInfo *exception) |
| 3399 | % |
| 3400 | % A description of each parameter follows: |
| 3401 | % |
| 3402 | % o image: the image. |
| 3403 | % |
| 3404 | % o virtual_pixel_method: the virtual pixel method. |
| 3405 | % |
| 3406 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3407 | % pixels. |
| 3408 | % |
| 3409 | % o exception: return any errors or warnings in this structure. |
| 3410 | % |
| 3411 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3412 | static const Quantum *GetVirtualPixelCache(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3413 | const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, |
| 3414 | const size_t columns,const size_t rows,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3415 | { |
| 3416 | CacheInfo |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3417 | *cache_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3418 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3419 | const int |
| 3420 | id = GetOpenMPThreadId(); |
| 3421 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3422 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3423 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3424 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3425 | assert(image != (const Image *) NULL); |
| 3426 | assert(image->signature == MagickSignature); |
| 3427 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3428 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3429 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3430 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3431 | p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,columns,rows, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3432 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3433 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | /* |
| 3437 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3438 | % % |
| 3439 | % % |
| 3440 | % % |
| 3441 | % G e t V i r t u a l P i x e l Q u e u e % |
| 3442 | % % |
| 3443 | % % |
| 3444 | % % |
| 3445 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3446 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3447 | % GetVirtualPixelQueue() returns the virtual pixels associated corresponding |
| 3448 | % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3449 | % |
| 3450 | % The format of the GetVirtualPixelQueue() method is: |
| 3451 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3452 | % const Quantum *GetVirtualPixelQueue(const Image image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3453 | % |
| 3454 | % A description of each parameter follows: |
| 3455 | % |
| 3456 | % o image: the image. |
| 3457 | % |
| 3458 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3459 | MagickExport const Quantum *GetVirtualPixelQueue(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3460 | { |
| 3461 | CacheInfo |
| 3462 | *cache_info; |
| 3463 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3464 | const int |
| 3465 | id = GetOpenMPThreadId(); |
| 3466 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3467 | assert(image != (const Image *) NULL); |
| 3468 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3469 | assert(image->cache != (Cache) NULL); |
| 3470 | cache_info=(CacheInfo *) image->cache; |
| 3471 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3472 | if (cache_info->methods.get_virtual_pixels_handler != |
| 3473 | (GetVirtualPixelsHandler) NULL) |
| 3474 | return(cache_info->methods.get_virtual_pixels_handler(image)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3475 | assert(id < (int) cache_info->number_threads); |
| 3476 | return(GetVirtualPixelsNexus(cache_info,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | /* |
| 3480 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3481 | % % |
| 3482 | % % |
| 3483 | % % |
| 3484 | % G e t V i r t u a l P i x e l s % |
| 3485 | % % |
| 3486 | % % |
| 3487 | % % |
| 3488 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3489 | % |
| 3490 | % GetVirtualPixels() returns an immutable pixel region. If the |
| 3491 | % region is successfully accessed, a pointer to it is returned, otherwise |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 3492 | % NULL is returned. The returned pointer may point to a temporary working |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3493 | % copy of the pixels or it may point to the original pixels in memory. |
| 3494 | % Performance is maximized if the selected region is part of one row, or one |
| 3495 | % 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] | 3496 | % (without a copy) if the image is in memory, or in a memory-mapped file. The |
| 3497 | % returned pointer must *never* be deallocated by the user. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3498 | % |
| 3499 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3500 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 3501 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 3502 | % access the meta-content (of type void) corresponding to the the |
| 3503 | % region. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3504 | % |
| 3505 | % If you plan to modify the pixels, use GetAuthenticPixels() instead. |
| 3506 | % |
| 3507 | % Note, the GetVirtualPixels() and GetAuthenticPixels() methods are not thread- |
| 3508 | % safe. In a threaded environment, use GetCacheViewVirtualPixels() or |
| 3509 | % GetCacheViewAuthenticPixels() instead. |
| 3510 | % |
| 3511 | % The format of the GetVirtualPixels() method is: |
| 3512 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3513 | % const Quantum *GetVirtualPixels(const Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3514 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3515 | % ExceptionInfo *exception) |
| 3516 | % |
| 3517 | % A description of each parameter follows: |
| 3518 | % |
| 3519 | % o image: the image. |
| 3520 | % |
| 3521 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 3522 | % pixels. |
| 3523 | % |
| 3524 | % o exception: return any errors or warnings in this structure. |
| 3525 | % |
| 3526 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3527 | MagickExport const Quantum *GetVirtualPixels(const Image *image, |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 3528 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
| 3529 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3530 | { |
| 3531 | CacheInfo |
| 3532 | *cache_info; |
| 3533 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3534 | const int |
| 3535 | id = GetOpenMPThreadId(); |
| 3536 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3537 | const Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3538 | *p; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3539 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3540 | assert(image != (const Image *) NULL); |
| 3541 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3542 | assert(image->cache != (Cache) NULL); |
| 3543 | cache_info=(CacheInfo *) image->cache; |
| 3544 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 3545 | if (cache_info->methods.get_virtual_pixel_handler != |
| 3546 | (GetVirtualPixelHandler) NULL) |
| 3547 | return(cache_info->methods.get_virtual_pixel_handler(image, |
| 3548 | GetPixelCacheVirtualMethod(image),x,y,columns,rows,exception)); |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 3549 | assert(id < (int) cache_info->number_threads); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3550 | p=GetVirtualPixelsFromNexus(image,GetPixelCacheVirtualMethod(image),x,y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3551 | columns,rows,cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 3552 | return(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /* |
| 3556 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3557 | % % |
| 3558 | % % |
| 3559 | % % |
| 3560 | + 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 % |
| 3561 | % % |
| 3562 | % % |
| 3563 | % % |
| 3564 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3565 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3566 | % GetVirtualPixelsCache() returns the pixels associated corresponding with the |
| 3567 | % last call to QueueAuthenticPixelsCache() or GetVirtualPixelCache(). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3568 | % |
| 3569 | % The format of the GetVirtualPixelsCache() method is: |
| 3570 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3571 | % Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3572 | % |
| 3573 | % A description of each parameter follows: |
| 3574 | % |
| 3575 | % o image: the image. |
| 3576 | % |
| 3577 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3578 | static const Quantum *GetVirtualPixelsCache(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3579 | { |
| 3580 | CacheInfo |
| 3581 | *cache_info; |
| 3582 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3583 | const int |
| 3584 | id = GetOpenMPThreadId(); |
| 3585 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3586 | assert(image != (const Image *) NULL); |
| 3587 | assert(image->signature == MagickSignature); |
| 3588 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3589 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3590 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3591 | assert(id < (int) cache_info->number_threads); |
cristy | f54fb57 | 2010-09-17 20:08:14 +0000 | [diff] [blame] | 3592 | return(GetVirtualPixelsNexus(image->cache,cache_info->nexus_info[id])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | /* |
| 3596 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3597 | % % |
| 3598 | % % |
| 3599 | % % |
| 3600 | + G e t V i r t u a l P i x e l s N e x u s % |
| 3601 | % % |
| 3602 | % % |
| 3603 | % % |
| 3604 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3605 | % |
| 3606 | % GetVirtualPixelsNexus() returns the pixels associated with the specified |
| 3607 | % cache nexus. |
| 3608 | % |
| 3609 | % The format of the GetVirtualPixelsNexus() method is: |
| 3610 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3611 | % const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3612 | % NexusInfo *nexus_info) |
| 3613 | % |
| 3614 | % A description of each parameter follows: |
| 3615 | % |
| 3616 | % o cache: the pixel cache. |
| 3617 | % |
| 3618 | % o nexus_info: the cache nexus to return the colormap pixels. |
| 3619 | % |
| 3620 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 3621 | MagickPrivate const Quantum *GetVirtualPixelsNexus(const Cache cache, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3622 | NexusInfo *nexus_info) |
| 3623 | { |
| 3624 | CacheInfo |
| 3625 | *cache_info; |
| 3626 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3627 | assert(cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3628 | cache_info=(CacheInfo *) cache; |
| 3629 | assert(cache_info->signature == MagickSignature); |
| 3630 | if (cache_info->storage_class == UndefinedClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3631 | return((Quantum *) NULL); |
| 3632 | return((const Quantum *) nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | /* |
| 3636 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3637 | % % |
| 3638 | % % |
| 3639 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3640 | + O p e n P i x e l C a c h e % |
| 3641 | % % |
| 3642 | % % |
| 3643 | % % |
| 3644 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3645 | % |
| 3646 | % OpenPixelCache() allocates the pixel cache. This includes defining the cache |
| 3647 | % dimensions, allocating space for the image pixels and optionally the |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3648 | % metacontent, and memory mapping the cache if it is disk based. The cache |
| 3649 | % nexus array is initialized as well. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3650 | % |
| 3651 | % The format of the OpenPixelCache() method is: |
| 3652 | % |
| 3653 | % MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 3654 | % ExceptionInfo *exception) |
| 3655 | % |
| 3656 | % A description of each parameter follows: |
| 3657 | % |
| 3658 | % o image: the image. |
| 3659 | % |
| 3660 | % o mode: ReadMode, WriteMode, or IOMode. |
| 3661 | % |
| 3662 | % o exception: return any errors or warnings in this structure. |
| 3663 | % |
| 3664 | */ |
| 3665 | |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 3666 | static inline void AllocatePixelCachePixels(CacheInfo *cache_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3667 | { |
| 3668 | cache_info->mapped=MagickFalse; |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 3669 | cache_info->pixels=(Quantum *) AcquireQuantumMemory(1,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3670 | cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3671 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3672 | { |
| 3673 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3674 | cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3675 | cache_info->length); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | static MagickBooleanType ExtendCache(Image *image,MagickSizeType length) |
| 3680 | { |
| 3681 | CacheInfo |
| 3682 | *cache_info; |
| 3683 | |
| 3684 | MagickOffsetType |
| 3685 | count, |
| 3686 | extent, |
| 3687 | offset; |
| 3688 | |
| 3689 | cache_info=(CacheInfo *) image->cache; |
| 3690 | if (image->debug != MagickFalse) |
| 3691 | { |
| 3692 | char |
| 3693 | format[MaxTextExtent], |
| 3694 | message[MaxTextExtent]; |
| 3695 | |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 3696 | (void) FormatMagickSize(length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3697 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | b37d4f2 | 2011-06-27 19:22:42 +0000 | [diff] [blame] | 3698 | "extend %s (%s[%d], disk, %s)",cache_info->filename, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3699 | cache_info->cache_filename,cache_info->file,format); |
| 3700 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 3701 | } |
| 3702 | if (length != (MagickSizeType) ((MagickOffsetType) length)) |
| 3703 | return(MagickFalse); |
cristy | 7f31770 | 2011-02-18 20:40:28 +0000 | [diff] [blame] | 3704 | extent=(MagickOffsetType) lseek(cache_info->file,0,SEEK_END); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3705 | if (extent < 0) |
| 3706 | return(MagickFalse); |
| 3707 | if ((MagickSizeType) extent >= length) |
| 3708 | return(MagickTrue); |
| 3709 | offset=(MagickOffsetType) length-1; |
| 3710 | count=WritePixelCacheRegion(cache_info,offset,1,(const unsigned char *) ""); |
| 3711 | return(count == (MagickOffsetType) 1 ? MagickTrue : MagickFalse); |
| 3712 | } |
| 3713 | |
| 3714 | static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode, |
| 3715 | ExceptionInfo *exception) |
| 3716 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3717 | CacheInfo |
| 3718 | *cache_info, |
| 3719 | source_info; |
| 3720 | |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 3721 | char |
| 3722 | format[MaxTextExtent], |
| 3723 | message[MaxTextExtent]; |
| 3724 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3725 | MagickBooleanType |
| 3726 | status; |
| 3727 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3728 | MagickSizeType |
| 3729 | length, |
| 3730 | number_pixels; |
| 3731 | |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 3732 | PixelChannelMap |
| 3733 | *p, |
| 3734 | *q; |
| 3735 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3736 | size_t |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 3737 | columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3738 | packet_size; |
| 3739 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3740 | assert(image != (const Image *) NULL); |
| 3741 | assert(image->signature == MagickSignature); |
| 3742 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3743 | if (image->debug != MagickFalse) |
| 3744 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3745 | if ((image->columns == 0) || (image->rows == 0)) |
| 3746 | ThrowBinaryException(CacheError,"NoPixelsDefinedInCache",image->filename); |
| 3747 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 3748 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3749 | source_info=(*cache_info); |
| 3750 | source_info.file=(-1); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3751 | (void) FormatLocaleString(cache_info->filename,MaxTextExtent,"%s[%.20g]", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3752 | image->filename,(double) GetImageIndexInList(image)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3753 | cache_info->storage_class=image->storage_class; |
| 3754 | cache_info->colorspace=image->colorspace; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3755 | cache_info->matte=image->matte; |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame^] | 3756 | cache_info->masky=image->masky; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3757 | cache_info->rows=image->rows; |
| 3758 | cache_info->columns=image->columns; |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3759 | InitializePixelChannelMap(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3760 | cache_info->number_channels=GetPixelChannels(image); |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 3761 | (void) memcpy(cache_info->channel_map,image->channel_map,MaxPixelChannels* |
| 3762 | sizeof(*image->channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3763 | cache_info->metacontent_extent=image->metacontent_extent; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 3764 | cache_info->mode=mode; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3765 | if (image->ping != MagickFalse) |
| 3766 | { |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3767 | cache_info->type=PingCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3768 | cache_info->pixels=(Quantum *) NULL; |
| 3769 | cache_info->metacontent=(void *) NULL; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 3770 | cache_info->length=0; |
| 3771 | return(MagickTrue); |
| 3772 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3773 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3774 | packet_size=cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3775 | if (image->metacontent_extent != 0) |
| 3776 | packet_size+=cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3777 | length=number_pixels*packet_size; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3778 | columns=(size_t) (length/cache_info->rows/packet_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3779 | if (cache_info->columns != columns) |
| 3780 | ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed", |
| 3781 | image->filename); |
| 3782 | cache_info->length=length; |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 3783 | p=cache_info->channel_map; |
| 3784 | q=source_info.channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3785 | if ((cache_info->type != UndefinedCache) && |
| 3786 | (cache_info->columns <= source_info.columns) && |
| 3787 | (cache_info->rows <= source_info.rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3788 | (cache_info->number_channels <= source_info.number_channels) && |
cristy | 3b8fe92 | 2011-12-29 18:56:23 +0000 | [diff] [blame] | 3789 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3790 | (cache_info->metacontent_extent <= source_info.metacontent_extent)) |
| 3791 | { |
| 3792 | /* |
| 3793 | Inline pixel cache clone optimization. |
| 3794 | */ |
| 3795 | if ((cache_info->columns == source_info.columns) && |
| 3796 | (cache_info->rows == source_info.rows) && |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3797 | (cache_info->number_channels == source_info.number_channels) && |
cristy | 32cacff | 2011-12-31 03:36:27 +0000 | [diff] [blame] | 3798 | (memcmp(p,q,cache_info->number_channels*sizeof(*p)) == 0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3799 | (cache_info->metacontent_extent == source_info.metacontent_extent)) |
| 3800 | return(MagickTrue); |
| 3801 | return(ClonePixelCachePixels(cache_info,&source_info,exception)); |
| 3802 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3803 | status=AcquireMagickResource(AreaResource,cache_info->length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3804 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3805 | cache_info->metacontent_extent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3806 | if ((status != MagickFalse) && (length == (MagickSizeType) ((size_t) length))) |
| 3807 | { |
| 3808 | status=AcquireMagickResource(MemoryResource,cache_info->length); |
| 3809 | if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) || |
| 3810 | (cache_info->type == MemoryCache)) |
| 3811 | { |
cristy | d43a46b | 2010-01-21 02:13:41 +0000 | [diff] [blame] | 3812 | AllocatePixelCachePixels(cache_info); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3813 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3814 | cache_info->pixels=source_info.pixels; |
| 3815 | else |
| 3816 | { |
| 3817 | /* |
| 3818 | Create memory pixel cache. |
| 3819 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3820 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3821 | if (image->debug != MagickFalse) |
| 3822 | { |
cristy | 32cacff | 2011-12-31 03:36:27 +0000 | [diff] [blame] | 3823 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3824 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3825 | "open %s (%s memory, %.20gx%.20gx%.20g %s)", |
| 3826 | cache_info->filename,cache_info->mapped != MagickFalse ? |
| 3827 | "anonymous" : "heap",(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3828 | cache_info->rows,(double) cache_info->number_channels, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3829 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3830 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 3831 | message); |
| 3832 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3833 | cache_info->type=MemoryCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3834 | cache_info->metacontent=(void *) NULL; |
| 3835 | if (cache_info->metacontent_extent != 0) |
| 3836 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3837 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3838 | if ((source_info.storage_class != UndefinedClass) && |
| 3839 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3840 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3841 | status=ClonePixelCachePixels(cache_info,&source_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3842 | exception); |
| 3843 | RelinquishPixelCachePixels(&source_info); |
| 3844 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3845 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | RelinquishMagickResource(MemoryResource,cache_info->length); |
| 3849 | } |
| 3850 | /* |
| 3851 | Create pixel cache on disk. |
| 3852 | */ |
| 3853 | status=AcquireMagickResource(DiskResource,cache_info->length); |
| 3854 | if (status == MagickFalse) |
| 3855 | { |
| 3856 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 3857 | "CacheResourcesExhausted","`%s'",image->filename); |
| 3858 | return(MagickFalse); |
| 3859 | } |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3860 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
| 3861 | { |
| 3862 | (void) ClosePixelCacheOnDisk(cache_info); |
| 3863 | *cache_info->cache_filename='\0'; |
| 3864 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3865 | if (OpenPixelCacheOnDisk(cache_info,mode) == MagickFalse) |
| 3866 | { |
| 3867 | RelinquishMagickResource(DiskResource,cache_info->length); |
| 3868 | ThrowFileException(exception,CacheError,"UnableToOpenPixelCache", |
| 3869 | image->filename); |
| 3870 | return(MagickFalse); |
| 3871 | } |
| 3872 | status=ExtendCache(image,(MagickSizeType) cache_info->offset+ |
| 3873 | cache_info->length); |
| 3874 | if (status == MagickFalse) |
| 3875 | { |
| 3876 | ThrowFileException(exception,CacheError,"UnableToExtendCache", |
| 3877 | image->filename); |
| 3878 | return(MagickFalse); |
| 3879 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3880 | length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3881 | cache_info->metacontent_extent); |
cristy | a0b40ff | 2011-10-06 18:17:58 +0000 | [diff] [blame] | 3882 | if (length != (MagickSizeType) ((size_t) length)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3883 | cache_info->type=DiskCache; |
| 3884 | else |
| 3885 | { |
| 3886 | status=AcquireMagickResource(MapResource,cache_info->length); |
| 3887 | if ((status == MagickFalse) && (cache_info->type != MapCache) && |
| 3888 | (cache_info->type != MemoryCache)) |
| 3889 | cache_info->type=DiskCache; |
| 3890 | else |
| 3891 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3892 | cache_info->pixels=(Quantum *) MapBlob(cache_info->file,mode, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3893 | cache_info->offset,(size_t) cache_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3894 | if (cache_info->pixels == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3895 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3896 | cache_info->type=DiskCache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3897 | cache_info->pixels=source_info.pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3898 | } |
| 3899 | else |
| 3900 | { |
| 3901 | /* |
| 3902 | Create file-backed memory-mapped pixel cache. |
| 3903 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3904 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3905 | (void) ClosePixelCacheOnDisk(cache_info); |
| 3906 | cache_info->type=MapCache; |
| 3907 | cache_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3908 | cache_info->metacontent=(void *) NULL; |
| 3909 | if (cache_info->metacontent_extent != 0) |
| 3910 | cache_info->metacontent=(void *) (cache_info->pixels+ |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3911 | number_pixels*cache_info->number_channels); |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3912 | if ((source_info.storage_class != UndefinedClass) && |
| 3913 | (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3914 | { |
| 3915 | status=ClonePixelCachePixels(cache_info,&source_info, |
| 3916 | exception); |
| 3917 | RelinquishPixelCachePixels(&source_info); |
| 3918 | } |
| 3919 | if (image->debug != MagickFalse) |
| 3920 | { |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3921 | (void) FormatMagickSize(cache_info->length,MagickTrue,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3922 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3923 | "open %s (%s[%d], memory-mapped, %.20gx%.20gx%.20g %s)", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3924 | cache_info->filename,cache_info->cache_filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3925 | cache_info->file,(double) cache_info->columns,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3926 | cache_info->rows,(double) cache_info->number_channels, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3927 | format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3928 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s", |
| 3929 | message); |
| 3930 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3931 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | RelinquishMagickResource(MapResource,cache_info->length); |
| 3935 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3936 | status=MagickTrue; |
cristy | 413f130 | 2012-01-01 17:48:27 +0000 | [diff] [blame] | 3937 | if ((source_info.storage_class != UndefinedClass) && (mode != ReadMode)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3938 | { |
| 3939 | status=ClonePixelCachePixels(cache_info,&source_info,exception); |
| 3940 | RelinquishPixelCachePixels(&source_info); |
| 3941 | } |
| 3942 | if (image->debug != MagickFalse) |
| 3943 | { |
cristy | b9080c9 | 2009-12-01 20:13:26 +0000 | [diff] [blame] | 3944 | (void) FormatMagickSize(cache_info->length,MagickFalse,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3945 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3946 | "open %s (%s[%d], disk, %.20gx%.20gx%.20g %s)",cache_info->filename, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3947 | cache_info->cache_filename,cache_info->file,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3948 | cache_info->columns,(double) cache_info->rows,(double) |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3949 | cache_info->number_channels,format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3950 | (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message); |
| 3951 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3952 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /* |
| 3956 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3957 | % % |
| 3958 | % % |
| 3959 | % % |
| 3960 | + P e r s i s t P i x e l C a c h e % |
| 3961 | % % |
| 3962 | % % |
| 3963 | % % |
| 3964 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3965 | % |
| 3966 | % PersistPixelCache() attaches to or initializes a persistent pixel cache. A |
| 3967 | % persistent pixel cache is one that resides on disk and is not destroyed |
| 3968 | % when the program exits. |
| 3969 | % |
| 3970 | % The format of the PersistPixelCache() method is: |
| 3971 | % |
| 3972 | % MagickBooleanType PersistPixelCache(Image *image,const char *filename, |
| 3973 | % const MagickBooleanType attach,MagickOffsetType *offset, |
| 3974 | % ExceptionInfo *exception) |
| 3975 | % |
| 3976 | % A description of each parameter follows: |
| 3977 | % |
| 3978 | % o image: the image. |
| 3979 | % |
| 3980 | % o filename: the persistent pixel cache filename. |
| 3981 | % |
cristy | f3a6a9d | 2010-11-07 21:02:56 +0000 | [diff] [blame] | 3982 | % o attach: A value other than zero initializes the persistent pixel cache. |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 3983 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3984 | % o initialize: A value other than zero initializes the persistent pixel |
| 3985 | % cache. |
| 3986 | % |
| 3987 | % o offset: the offset in the persistent cache to store pixels. |
| 3988 | % |
| 3989 | % o exception: return any errors or warnings in this structure. |
| 3990 | % |
| 3991 | */ |
| 3992 | MagickExport MagickBooleanType PersistPixelCache(Image *image, |
| 3993 | const char *filename,const MagickBooleanType attach,MagickOffsetType *offset, |
| 3994 | ExceptionInfo *exception) |
| 3995 | { |
| 3996 | CacheInfo |
| 3997 | *cache_info, |
| 3998 | *clone_info; |
| 3999 | |
| 4000 | Image |
| 4001 | clone_image; |
| 4002 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4003 | MagickBooleanType |
| 4004 | status; |
| 4005 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4006 | ssize_t |
| 4007 | page_size; |
| 4008 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4009 | assert(image != (Image *) NULL); |
| 4010 | assert(image->signature == MagickSignature); |
| 4011 | if (image->debug != MagickFalse) |
| 4012 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4013 | assert(image->cache != (void *) NULL); |
| 4014 | assert(filename != (const char *) NULL); |
| 4015 | assert(offset != (MagickOffsetType *) NULL); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4016 | page_size=GetMagickPageSize(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4017 | cache_info=(CacheInfo *) image->cache; |
| 4018 | assert(cache_info->signature == MagickSignature); |
| 4019 | if (attach != MagickFalse) |
| 4020 | { |
| 4021 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4022 | Attach existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4023 | */ |
| 4024 | if (image->debug != MagickFalse) |
| 4025 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4026 | "attach persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4027 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4028 | MaxTextExtent); |
| 4029 | cache_info->type=DiskCache; |
| 4030 | cache_info->offset=(*offset); |
cristy | de8c9c5 | 2010-09-20 18:56:24 +0000 | [diff] [blame] | 4031 | if (OpenPixelCache(image,ReadMode,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4032 | return(MagickFalse); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4033 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 8396771 | 2010-09-20 23:35:28 +0000 | [diff] [blame] | 4034 | return(MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4035 | } |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4036 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
| 4037 | (cache_info->reference_count == 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4038 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4039 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | af894d7 | 2011-08-06 23:03:10 +0000 | [diff] [blame] | 4040 | if ((cache_info->mode != ReadMode) && (cache_info->type != MemoryCache) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4041 | (cache_info->reference_count == 1)) |
| 4042 | { |
| 4043 | int |
| 4044 | status; |
| 4045 | |
| 4046 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4047 | Usurp existing persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4048 | */ |
cristy | 320684d | 2011-09-23 14:55:47 +0000 | [diff] [blame] | 4049 | status=rename_utf8(cache_info->cache_filename,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4050 | if (status == 0) |
| 4051 | { |
| 4052 | (void) CopyMagickString(cache_info->cache_filename,filename, |
| 4053 | MaxTextExtent); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4054 | *offset+=cache_info->length+page_size-(cache_info->length % |
| 4055 | page_size); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4056 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 87528ea | 2009-09-10 14:53:56 +0000 | [diff] [blame] | 4057 | cache_info=(CacheInfo *) ReferencePixelCache(cache_info); |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4058 | if (image->debug != MagickFalse) |
| 4059 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
| 4060 | "Usurp resident persistent cache"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4061 | return(MagickTrue); |
| 4062 | } |
| 4063 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4064 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4065 | } |
| 4066 | /* |
cristy | 01b7eb0 | 2009-09-10 23:10:14 +0000 | [diff] [blame] | 4067 | Clone persistent pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4068 | */ |
| 4069 | clone_image=(*image); |
| 4070 | clone_info=(CacheInfo *) clone_image.cache; |
| 4071 | image->cache=ClonePixelCache(cache_info); |
| 4072 | cache_info=(CacheInfo *) ReferencePixelCache(image->cache); |
| 4073 | (void) CopyMagickString(cache_info->cache_filename,filename,MaxTextExtent); |
| 4074 | cache_info->type=DiskCache; |
| 4075 | cache_info->offset=(*offset); |
| 4076 | cache_info=(CacheInfo *) image->cache; |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4077 | status=OpenPixelCache(image,IOMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4078 | if (status != MagickFalse) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 4079 | status=ClonePixelCachePixels(cache_info,clone_info,exception); |
cristy | 688f07b | 2009-09-27 15:19:13 +0000 | [diff] [blame] | 4080 | *offset+=cache_info->length+page_size-(cache_info->length % page_size); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4081 | clone_info=(CacheInfo *) DestroyPixelCache(clone_info); |
| 4082 | return(status); |
| 4083 | } |
| 4084 | |
| 4085 | /* |
| 4086 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4087 | % % |
| 4088 | % % |
| 4089 | % % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4090 | + Q u e u e A u t h e n t i c P i x e l C a c h e N e x u s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4091 | % % |
| 4092 | % % |
| 4093 | % % |
| 4094 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4095 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4096 | % QueueAuthenticPixelCacheNexus() allocates an region to store image pixels as |
| 4097 | % defined by the region rectangle and returns a pointer to the region. This |
| 4098 | % region is subsequently transferred from the pixel cache with |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4099 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4100 | % pixels are transferred, otherwise a NULL is returned. |
| 4101 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4102 | % The format of the QueueAuthenticPixelCacheNexus() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4103 | % |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4104 | % Quantum *QueueAuthenticPixelCacheNexus(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4105 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4106 | % const MagickBooleanType clone,NexusInfo *nexus_info, |
| 4107 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4108 | % |
| 4109 | % A description of each parameter follows: |
| 4110 | % |
| 4111 | % o image: the image. |
| 4112 | % |
| 4113 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4114 | % pixels. |
| 4115 | % |
| 4116 | % o nexus_info: the cache nexus to set. |
| 4117 | % |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4118 | % o clone: clone the pixel cache. |
| 4119 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4120 | % o exception: return any errors or warnings in this structure. |
| 4121 | % |
| 4122 | */ |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4123 | MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image, |
| 4124 | const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4125 | const MagickBooleanType clone,NexusInfo *nexus_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4126 | { |
| 4127 | CacheInfo |
| 4128 | *cache_info; |
| 4129 | |
| 4130 | MagickOffsetType |
| 4131 | offset; |
| 4132 | |
| 4133 | MagickSizeType |
| 4134 | number_pixels; |
| 4135 | |
| 4136 | RectangleInfo |
| 4137 | region; |
| 4138 | |
| 4139 | /* |
| 4140 | Validate pixel cache geometry. |
| 4141 | */ |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4142 | assert(image != (const Image *) NULL); |
| 4143 | assert(image->signature == MagickSignature); |
| 4144 | assert(image->cache != (Cache) NULL); |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4145 | cache_info=(CacheInfo *) GetImagePixelCache(image,clone,exception); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4146 | if (cache_info == (Cache) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4147 | return((Quantum *) NULL); |
cristy | e27517a | 2011-09-04 23:02:10 +0000 | [diff] [blame] | 4148 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4149 | if ((cache_info->columns == 0) && (cache_info->rows == 0)) |
| 4150 | { |
| 4151 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 4152 | "NoPixelsDefinedInCache","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4153 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4154 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4155 | if ((x < 0) || (y < 0) || (x >= (ssize_t) cache_info->columns) || |
| 4156 | (y >= (ssize_t) cache_info->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4157 | { |
| 4158 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 4159 | "PixelsAreNotAuthentic","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4160 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4161 | } |
| 4162 | offset=(MagickOffsetType) y*cache_info->columns+x; |
| 4163 | if (offset < 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4164 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4165 | number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
| 4166 | offset+=(MagickOffsetType) (rows-1)*cache_info->columns+columns-1; |
| 4167 | if ((MagickSizeType) offset >= number_pixels) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4168 | return((Quantum *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4169 | /* |
| 4170 | Return pixel cache. |
| 4171 | */ |
| 4172 | region.x=x; |
| 4173 | region.y=y; |
| 4174 | region.width=columns; |
| 4175 | region.height=rows; |
| 4176 | return(SetPixelCacheNexusPixels(image,®ion,nexus_info,exception)); |
| 4177 | } |
| 4178 | |
| 4179 | /* |
| 4180 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4181 | % % |
| 4182 | % % |
| 4183 | % % |
| 4184 | + 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 % |
| 4185 | % % |
| 4186 | % % |
| 4187 | % % |
| 4188 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4189 | % |
| 4190 | % QueueAuthenticPixelsCache() allocates an region to store image pixels as |
| 4191 | % defined by the region rectangle and returns a pointer to the region. This |
| 4192 | % region is subsequently transferred from the pixel cache with |
| 4193 | % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the |
| 4194 | % pixels are transferred, otherwise a NULL is returned. |
| 4195 | % |
| 4196 | % The format of the QueueAuthenticPixelsCache() method is: |
| 4197 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4198 | % Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4199 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4200 | % ExceptionInfo *exception) |
| 4201 | % |
| 4202 | % A description of each parameter follows: |
| 4203 | % |
| 4204 | % o image: the image. |
| 4205 | % |
| 4206 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4207 | % pixels. |
| 4208 | % |
| 4209 | % o exception: return any errors or warnings in this structure. |
| 4210 | % |
| 4211 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4212 | static Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4213 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4214 | ExceptionInfo *exception) |
| 4215 | { |
| 4216 | CacheInfo |
| 4217 | *cache_info; |
| 4218 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4219 | const int |
| 4220 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4221 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4222 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4223 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4224 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4225 | assert(image != (const Image *) NULL); |
| 4226 | assert(image->signature == MagickSignature); |
| 4227 | assert(image->cache != (Cache) NULL); |
cristy | 77ff028 | 2010-09-13 00:51:10 +0000 | [diff] [blame] | 4228 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4229 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4230 | assert(id < (int) cache_info->number_threads); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4231 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4232 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4233 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | /* |
| 4237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4238 | % % |
| 4239 | % % |
| 4240 | % % |
| 4241 | % Q u e u e A u t h e n t i c P i x e l s % |
| 4242 | % % |
| 4243 | % % |
| 4244 | % % |
| 4245 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4246 | % |
| 4247 | % QueueAuthenticPixels() queues a mutable pixel region. If the region is |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4248 | % successfully initialized a pointer to a Quantum array representing the |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4249 | % region is returned, otherwise NULL is returned. The returned pointer may |
| 4250 | % point to a temporary working buffer for the pixels or it may point to the |
| 4251 | % final location of the pixels in memory. |
| 4252 | % |
| 4253 | % Write-only access means that any existing pixel values corresponding to |
| 4254 | % the region are ignored. This is useful if the initial image is being |
| 4255 | % created from scratch, or if the existing pixel values are to be |
| 4256 | % completely replaced without need to refer to their pre-existing values. |
| 4257 | % The application is free to read and write the pixel buffer returned by |
| 4258 | % QueueAuthenticPixels() any way it pleases. QueueAuthenticPixels() does not |
| 4259 | % initialize the pixel array values. Initializing pixel array values is the |
| 4260 | % application's responsibility. |
| 4261 | % |
| 4262 | % Performance is maximized if the selected region is part of one row, or |
| 4263 | % one or more full rows, since then there is opportunity to access the |
cristy | ad4e5b2 | 2010-01-10 00:04:19 +0000 | [diff] [blame] | 4264 | % pixels in-place (without a copy) if the image is in memory, or in a |
| 4265 | % memory-mapped file. The returned pointer must *never* be deallocated |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4266 | % by the user. |
| 4267 | % |
| 4268 | % Pixels accessed via the returned pointer represent a simple array of type |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4269 | % Quantum. If the image type is CMYK or the storage class is PseudoClass, |
| 4270 | % call GetAuthenticMetacontent() after invoking GetAuthenticPixels() to |
| 4271 | % obtain the meta-content (of type void) corresponding to the region. |
| 4272 | % Once the Quantum (and/or Quantum) array has been updated, the |
| 4273 | % changes must be saved back to the underlying image using |
| 4274 | % SyncAuthenticPixels() or they may be lost. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4275 | % |
| 4276 | % The format of the QueueAuthenticPixels() method is: |
| 4277 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4278 | % Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | 5f95947 | 2010-05-27 22:19:46 +0000 | [diff] [blame] | 4279 | % const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4280 | % ExceptionInfo *exception) |
| 4281 | % |
| 4282 | % A description of each parameter follows: |
| 4283 | % |
| 4284 | % o image: the image. |
| 4285 | % |
| 4286 | % o x,y,columns,rows: These values define the perimeter of a region of |
| 4287 | % pixels. |
| 4288 | % |
| 4289 | % o exception: return any errors or warnings in this structure. |
| 4290 | % |
| 4291 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4292 | MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4293 | const ssize_t y,const size_t columns,const size_t rows, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4294 | ExceptionInfo *exception) |
| 4295 | { |
| 4296 | CacheInfo |
| 4297 | *cache_info; |
| 4298 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4299 | const int |
| 4300 | id = GetOpenMPThreadId(); |
| 4301 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4302 | Quantum |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4303 | *q; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4304 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4305 | assert(image != (Image *) NULL); |
| 4306 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4307 | assert(image->cache != (Cache) NULL); |
| 4308 | cache_info=(CacheInfo *) image->cache; |
| 4309 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 4310 | if (cache_info->methods.queue_authentic_pixels_handler != |
| 4311 | (QueueAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4312 | { |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4313 | q=cache_info->methods.queue_authentic_pixels_handler(image,x,y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4314 | columns,rows,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4315 | return(q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4316 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 4317 | assert(id < (int) cache_info->number_threads); |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4318 | q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, |
cristy | 65dbf17 | 2011-10-06 17:32:04 +0000 | [diff] [blame] | 4319 | cache_info->nexus_info[id],exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4320 | return(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /* |
| 4324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4325 | % % |
| 4326 | % % |
| 4327 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4328 | + 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] | 4329 | % % |
| 4330 | % % |
| 4331 | % % |
| 4332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4333 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4334 | % ReadPixelCacheMetacontent() reads metacontent from the specified region of |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4335 | % the pixel cache. |
| 4336 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4337 | % The format of the ReadPixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4338 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4339 | % MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4340 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4341 | % |
| 4342 | % A description of each parameter follows: |
| 4343 | % |
| 4344 | % o cache_info: the pixel cache. |
| 4345 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4346 | % o nexus_info: the cache nexus to read the metacontent. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4347 | % |
| 4348 | % o exception: return any errors or warnings in this structure. |
| 4349 | % |
| 4350 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4351 | static MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4352 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4353 | { |
| 4354 | MagickOffsetType |
| 4355 | count, |
| 4356 | offset; |
| 4357 | |
| 4358 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4359 | extent, |
| 4360 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4361 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4362 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4363 | y; |
| 4364 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4365 | register unsigned char |
| 4366 | *restrict q; |
| 4367 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4368 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4369 | rows; |
| 4370 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4371 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4372 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4373 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4374 | return(MagickTrue); |
| 4375 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4376 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4377 | length=(MagickSizeType) nexus_info->region.width* |
| 4378 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4379 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4380 | extent=length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4381 | q=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4382 | switch (cache_info->type) |
| 4383 | { |
| 4384 | case MemoryCache: |
| 4385 | case MapCache: |
| 4386 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4387 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4388 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4389 | |
| 4390 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4391 | Read meta-content from memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4392 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4393 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4394 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4395 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4396 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4397 | rows=1UL; |
| 4398 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4399 | p=(unsigned char *) cache_info->metacontent+offset* |
| 4400 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4401 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4402 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4403 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4404 | p+=cache_info->metacontent_extent*cache_info->columns; |
| 4405 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4406 | } |
| 4407 | break; |
| 4408 | } |
| 4409 | case DiskCache: |
| 4410 | { |
| 4411 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4412 | Read meta content from disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4413 | */ |
| 4414 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4415 | { |
| 4416 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4417 | cache_info->cache_filename); |
| 4418 | return(MagickFalse); |
| 4419 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4420 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4421 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4422 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4423 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4424 | rows=1UL; |
| 4425 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4426 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4427 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4428 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4429 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4430 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4431 | cache_info->metacontent_extent,length,(unsigned char *) q); |
| 4432 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4433 | break; |
| 4434 | offset+=cache_info->columns; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4435 | q+=cache_info->metacontent_extent*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4436 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4437 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 4438 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4439 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4440 | { |
| 4441 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4442 | cache_info->cache_filename); |
| 4443 | return(MagickFalse); |
| 4444 | } |
| 4445 | break; |
| 4446 | } |
| 4447 | default: |
| 4448 | break; |
| 4449 | } |
| 4450 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4451 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4452 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4453 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4454 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4455 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4456 | return(MagickTrue); |
| 4457 | } |
| 4458 | |
| 4459 | /* |
| 4460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4461 | % % |
| 4462 | % % |
| 4463 | % % |
| 4464 | + R e a d P i x e l C a c h e P i x e l s % |
| 4465 | % % |
| 4466 | % % |
| 4467 | % % |
| 4468 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4469 | % |
| 4470 | % ReadPixelCachePixels() reads pixels from the specified region of the pixel |
| 4471 | % cache. |
| 4472 | % |
| 4473 | % The format of the ReadPixelCachePixels() method is: |
| 4474 | % |
| 4475 | % MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4476 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4477 | % |
| 4478 | % A description of each parameter follows: |
| 4479 | % |
| 4480 | % o cache_info: the pixel cache. |
| 4481 | % |
| 4482 | % o nexus_info: the cache nexus to read the pixels. |
| 4483 | % |
| 4484 | % o exception: return any errors or warnings in this structure. |
| 4485 | % |
| 4486 | */ |
| 4487 | static MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, |
| 4488 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4489 | { |
| 4490 | MagickOffsetType |
| 4491 | count, |
| 4492 | offset; |
| 4493 | |
| 4494 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4495 | extent, |
| 4496 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4497 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4498 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4499 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4500 | |
cristy | e076a6e | 2010-08-15 19:59:43 +0000 | [diff] [blame] | 4501 | register ssize_t |
| 4502 | y; |
| 4503 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4504 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4505 | rows; |
| 4506 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4507 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4508 | return(MagickTrue); |
| 4509 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4510 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4511 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4512 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4513 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4514 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4515 | q=nexus_info->pixels; |
| 4516 | switch (cache_info->type) |
| 4517 | { |
| 4518 | case MemoryCache: |
| 4519 | case MapCache: |
| 4520 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4521 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4522 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4523 | |
| 4524 | /* |
| 4525 | Read pixels from memory. |
| 4526 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4527 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4528 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4529 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4530 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4531 | rows=1UL; |
| 4532 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4533 | p=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4534 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4535 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 4536 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4537 | p+=cache_info->number_channels*cache_info->columns; |
| 4538 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4539 | } |
| 4540 | break; |
| 4541 | } |
| 4542 | case DiskCache: |
| 4543 | { |
| 4544 | /* |
| 4545 | Read pixels from disk. |
| 4546 | */ |
| 4547 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 4548 | { |
| 4549 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 4550 | cache_info->cache_filename); |
| 4551 | return(MagickFalse); |
| 4552 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4553 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4554 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4555 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 4556 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 4557 | rows=1UL; |
| 4558 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4559 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4560 | { |
| 4561 | count=ReadPixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4562 | cache_info->number_channels*sizeof(*q),length,(unsigned char *) q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4563 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4564 | break; |
| 4565 | offset+=cache_info->columns; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4566 | q+=cache_info->number_channels*nexus_info->region.width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4567 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 4568 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 4569 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4570 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4571 | { |
| 4572 | ThrowFileException(exception,CacheError,"UnableToReadPixelCache", |
| 4573 | cache_info->cache_filename); |
| 4574 | return(MagickFalse); |
| 4575 | } |
| 4576 | break; |
| 4577 | } |
| 4578 | default: |
| 4579 | break; |
| 4580 | } |
| 4581 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 4582 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4583 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4584 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4585 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 4586 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4587 | return(MagickTrue); |
| 4588 | } |
| 4589 | |
| 4590 | /* |
| 4591 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4592 | % % |
| 4593 | % % |
| 4594 | % % |
| 4595 | + R e f e r e n c e P i x e l C a c h e % |
| 4596 | % % |
| 4597 | % % |
| 4598 | % % |
| 4599 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4600 | % |
| 4601 | % ReferencePixelCache() increments the reference count associated with the |
| 4602 | % pixel cache returning a pointer to the cache. |
| 4603 | % |
| 4604 | % The format of the ReferencePixelCache method is: |
| 4605 | % |
| 4606 | % Cache ReferencePixelCache(Cache cache_info) |
| 4607 | % |
| 4608 | % A description of each parameter follows: |
| 4609 | % |
| 4610 | % o cache_info: the pixel cache. |
| 4611 | % |
| 4612 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4613 | MagickPrivate Cache ReferencePixelCache(Cache cache) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4614 | { |
| 4615 | CacheInfo |
| 4616 | *cache_info; |
| 4617 | |
| 4618 | assert(cache != (Cache *) NULL); |
| 4619 | cache_info=(CacheInfo *) cache; |
| 4620 | assert(cache_info->signature == MagickSignature); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4621 | LockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4622 | cache_info->reference_count++; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 4623 | UnlockSemaphoreInfo(cache_info->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4624 | return(cache_info); |
| 4625 | } |
| 4626 | |
| 4627 | /* |
| 4628 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4629 | % % |
| 4630 | % % |
| 4631 | % % |
| 4632 | + S e t P i x e l C a c h e M e t h o d s % |
| 4633 | % % |
| 4634 | % % |
| 4635 | % % |
| 4636 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4637 | % |
| 4638 | % SetPixelCacheMethods() sets the image pixel methods to the specified ones. |
| 4639 | % |
| 4640 | % The format of the SetPixelCacheMethods() method is: |
| 4641 | % |
| 4642 | % SetPixelCacheMethods(Cache *,CacheMethods *cache_methods) |
| 4643 | % |
| 4644 | % A description of each parameter follows: |
| 4645 | % |
| 4646 | % o cache: the pixel cache. |
| 4647 | % |
| 4648 | % o cache_methods: Specifies a pointer to a CacheMethods structure. |
| 4649 | % |
| 4650 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4651 | MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4652 | { |
| 4653 | CacheInfo |
| 4654 | *cache_info; |
| 4655 | |
| 4656 | GetOneAuthenticPixelFromHandler |
| 4657 | get_one_authentic_pixel_from_handler; |
| 4658 | |
| 4659 | GetOneVirtualPixelFromHandler |
| 4660 | get_one_virtual_pixel_from_handler; |
| 4661 | |
| 4662 | /* |
| 4663 | Set cache pixel methods. |
| 4664 | */ |
| 4665 | assert(cache != (Cache) NULL); |
| 4666 | assert(cache_methods != (CacheMethods *) NULL); |
| 4667 | cache_info=(CacheInfo *) cache; |
| 4668 | assert(cache_info->signature == MagickSignature); |
| 4669 | if (cache_info->debug != MagickFalse) |
| 4670 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4671 | cache_info->filename); |
| 4672 | if (cache_methods->get_virtual_pixel_handler != (GetVirtualPixelHandler) NULL) |
| 4673 | cache_info->methods.get_virtual_pixel_handler= |
| 4674 | cache_methods->get_virtual_pixel_handler; |
| 4675 | if (cache_methods->destroy_pixel_handler != (DestroyPixelHandler) NULL) |
| 4676 | cache_info->methods.destroy_pixel_handler= |
| 4677 | cache_methods->destroy_pixel_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4678 | if (cache_methods->get_virtual_metacontent_from_handler != |
| 4679 | (GetVirtualMetacontentFromHandler) NULL) |
| 4680 | cache_info->methods.get_virtual_metacontent_from_handler= |
| 4681 | cache_methods->get_virtual_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4682 | if (cache_methods->get_authentic_pixels_handler != |
| 4683 | (GetAuthenticPixelsHandler) NULL) |
| 4684 | cache_info->methods.get_authentic_pixels_handler= |
| 4685 | cache_methods->get_authentic_pixels_handler; |
| 4686 | if (cache_methods->queue_authentic_pixels_handler != |
| 4687 | (QueueAuthenticPixelsHandler) NULL) |
| 4688 | cache_info->methods.queue_authentic_pixels_handler= |
| 4689 | cache_methods->queue_authentic_pixels_handler; |
| 4690 | if (cache_methods->sync_authentic_pixels_handler != |
| 4691 | (SyncAuthenticPixelsHandler) NULL) |
| 4692 | cache_info->methods.sync_authentic_pixels_handler= |
| 4693 | cache_methods->sync_authentic_pixels_handler; |
| 4694 | if (cache_methods->get_authentic_pixels_from_handler != |
| 4695 | (GetAuthenticPixelsFromHandler) NULL) |
| 4696 | cache_info->methods.get_authentic_pixels_from_handler= |
| 4697 | cache_methods->get_authentic_pixels_from_handler; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4698 | if (cache_methods->get_authentic_metacontent_from_handler != |
| 4699 | (GetAuthenticMetacontentFromHandler) NULL) |
| 4700 | cache_info->methods.get_authentic_metacontent_from_handler= |
| 4701 | cache_methods->get_authentic_metacontent_from_handler; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4702 | get_one_virtual_pixel_from_handler= |
| 4703 | cache_info->methods.get_one_virtual_pixel_from_handler; |
| 4704 | if (get_one_virtual_pixel_from_handler != |
| 4705 | (GetOneVirtualPixelFromHandler) NULL) |
| 4706 | cache_info->methods.get_one_virtual_pixel_from_handler= |
| 4707 | cache_methods->get_one_virtual_pixel_from_handler; |
| 4708 | get_one_authentic_pixel_from_handler= |
| 4709 | cache_methods->get_one_authentic_pixel_from_handler; |
| 4710 | if (get_one_authentic_pixel_from_handler != |
| 4711 | (GetOneAuthenticPixelFromHandler) NULL) |
| 4712 | cache_info->methods.get_one_authentic_pixel_from_handler= |
| 4713 | cache_methods->get_one_authentic_pixel_from_handler; |
| 4714 | } |
| 4715 | |
| 4716 | /* |
| 4717 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4718 | % % |
| 4719 | % % |
| 4720 | % % |
| 4721 | + S e t P i x e l C a c h e N e x u s P i x e l s % |
| 4722 | % % |
| 4723 | % % |
| 4724 | % % |
| 4725 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4726 | % |
| 4727 | % SetPixelCacheNexusPixels() defines the region of the cache for the |
| 4728 | % specified cache nexus. |
| 4729 | % |
| 4730 | % The format of the SetPixelCacheNexusPixels() method is: |
| 4731 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4732 | % Quantum SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4733 | % const RectangleInfo *region,NexusInfo *nexus_info, |
| 4734 | % ExceptionInfo *exception) |
| 4735 | % |
| 4736 | % A description of each parameter follows: |
| 4737 | % |
| 4738 | % o image: the image. |
| 4739 | % |
| 4740 | % o region: A pointer to the RectangleInfo structure that defines the |
| 4741 | % region of this particular cache nexus. |
| 4742 | % |
| 4743 | % o nexus_info: the cache nexus to set. |
| 4744 | % |
| 4745 | % o exception: return any errors or warnings in this structure. |
| 4746 | % |
| 4747 | */ |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4748 | |
| 4749 | static inline MagickBooleanType AcquireCacheNexusPixels(CacheInfo *cache_info, |
| 4750 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4751 | { |
| 4752 | if (nexus_info->length != (MagickSizeType) ((size_t) nexus_info->length)) |
| 4753 | return(MagickFalse); |
| 4754 | nexus_info->mapped=MagickFalse; |
cristy | 7dc8ac5 | 2012-01-10 20:14:52 +0000 | [diff] [blame] | 4755 | nexus_info->cache=(Quantum *) AcquireAlignedMemory(1,(size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4756 | nexus_info->length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4757 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4758 | { |
| 4759 | nexus_info->mapped=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4760 | nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4761 | nexus_info->length); |
| 4762 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4763 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | abd6e37 | 2010-09-15 19:11:26 +0000 | [diff] [blame] | 4764 | { |
| 4765 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 4766 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 4767 | cache_info->filename); |
| 4768 | return(MagickFalse); |
| 4769 | } |
| 4770 | return(MagickTrue); |
| 4771 | } |
| 4772 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4773 | static Quantum *SetPixelCacheNexusPixels(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4774 | const RectangleInfo *region,NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4775 | { |
| 4776 | CacheInfo |
| 4777 | *cache_info; |
| 4778 | |
| 4779 | MagickBooleanType |
| 4780 | status; |
| 4781 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4782 | MagickSizeType |
| 4783 | length, |
| 4784 | number_pixels; |
| 4785 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4786 | cache_info=(CacheInfo *) image->cache; |
| 4787 | assert(cache_info->signature == MagickSignature); |
| 4788 | if (cache_info->type == UndefinedCache) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4789 | return((Quantum *) NULL); |
cristy | dc8b63f | 2010-03-13 16:11:14 +0000 | [diff] [blame] | 4790 | nexus_info->region=(*region); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame^] | 4791 | if ((cache_info->type != DiskCache) && (cache_info->type != PingCache)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4792 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4793 | ssize_t |
cristy | bad067a | 2010-02-15 17:20:55 +0000 | [diff] [blame] | 4794 | x, |
| 4795 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4796 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4797 | x=nexus_info->region.x+(ssize_t) nexus_info->region.width-1; |
| 4798 | y=nexus_info->region.y+(ssize_t) nexus_info->region.height-1; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4799 | if (((nexus_info->region.x >= 0) && (x < (ssize_t) cache_info->columns) && |
| 4800 | (nexus_info->region.y >= 0) && (y < (ssize_t) cache_info->rows)) && |
cristy | ed733b3 | 2010-09-17 16:27:34 +0000 | [diff] [blame] | 4801 | ((nexus_info->region.height == 1UL) || ((nexus_info->region.x == 0) && |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 4802 | ((nexus_info->region.width == cache_info->columns) || |
| 4803 | ((nexus_info->region.width % cache_info->columns) == 0))))) |
| 4804 | { |
| 4805 | MagickOffsetType |
| 4806 | offset; |
| 4807 | |
| 4808 | /* |
| 4809 | Pixels are accessed directly from memory. |
| 4810 | */ |
| 4811 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 4812 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4813 | nexus_info->pixels=cache_info->pixels+cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4814 | offset; |
| 4815 | nexus_info->metacontent=(void *) NULL; |
| 4816 | if (cache_info->metacontent_extent != 0) |
| 4817 | nexus_info->metacontent=(unsigned char *) cache_info->metacontent+ |
| 4818 | offset*cache_info->metacontent_extent; |
cristy | 731c353 | 2010-02-15 15:40:03 +0000 | [diff] [blame] | 4819 | return(nexus_info->pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4820 | } |
| 4821 | } |
| 4822 | /* |
| 4823 | Pixels are stored in a cache region until they are synced to the cache. |
| 4824 | */ |
| 4825 | number_pixels=(MagickSizeType) nexus_info->region.width* |
| 4826 | nexus_info->region.height; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4827 | length=number_pixels*cache_info->number_channels*sizeof(Quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4828 | if (cache_info->metacontent_extent != 0) |
| 4829 | length+=number_pixels*cache_info->metacontent_extent; |
| 4830 | if (nexus_info->cache == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4831 | { |
| 4832 | nexus_info->length=length; |
| 4833 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 4834 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4835 | { |
| 4836 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4837 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4838 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4839 | } |
| 4840 | else |
| 4841 | if (nexus_info->length != length) |
| 4842 | { |
| 4843 | RelinquishCacheNexusPixels(nexus_info); |
| 4844 | nexus_info->length=length; |
| 4845 | status=AcquireCacheNexusPixels(cache_info,nexus_info,exception); |
| 4846 | if (status == MagickFalse) |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4847 | { |
| 4848 | nexus_info->length=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4849 | return((Quantum *) NULL); |
cristy | 5485e37 | 2010-09-15 19:02:29 +0000 | [diff] [blame] | 4850 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4851 | } |
| 4852 | nexus_info->pixels=nexus_info->cache; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4853 | nexus_info->metacontent=(void *) NULL; |
| 4854 | if (cache_info->metacontent_extent != 0) |
| 4855 | nexus_info->metacontent=(void *) (nexus_info->pixels+number_pixels* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4856 | cache_info->number_channels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4857 | return(nexus_info->pixels); |
| 4858 | } |
| 4859 | |
| 4860 | /* |
| 4861 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4862 | % % |
| 4863 | % % |
| 4864 | % % |
| 4865 | % 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 % |
| 4866 | % % |
| 4867 | % % |
| 4868 | % % |
| 4869 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4870 | % |
| 4871 | % SetPixelCacheVirtualMethod() sets the "virtual pixels" method for the |
| 4872 | % pixel cache and returns the previous setting. A virtual pixel is any pixel |
| 4873 | % access that is outside the boundaries of the image cache. |
| 4874 | % |
| 4875 | % The format of the SetPixelCacheVirtualMethod() method is: |
| 4876 | % |
| 4877 | % VirtualPixelMethod SetPixelCacheVirtualMethod(const Image *image, |
| 4878 | % const VirtualPixelMethod virtual_pixel_method) |
| 4879 | % |
| 4880 | % A description of each parameter follows: |
| 4881 | % |
| 4882 | % o image: the image. |
| 4883 | % |
| 4884 | % o virtual_pixel_method: choose the type of virtual pixel. |
| 4885 | % |
| 4886 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 4887 | MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4888 | const VirtualPixelMethod virtual_pixel_method) |
| 4889 | { |
| 4890 | CacheInfo |
| 4891 | *cache_info; |
| 4892 | |
| 4893 | VirtualPixelMethod |
| 4894 | method; |
| 4895 | |
| 4896 | assert(image != (Image *) NULL); |
| 4897 | assert(image->signature == MagickSignature); |
| 4898 | if (image->debug != MagickFalse) |
| 4899 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4900 | assert(image->cache != (Cache) NULL); |
| 4901 | cache_info=(CacheInfo *) image->cache; |
| 4902 | assert(cache_info->signature == MagickSignature); |
| 4903 | method=cache_info->virtual_pixel_method; |
| 4904 | cache_info->virtual_pixel_method=virtual_pixel_method; |
| 4905 | return(method); |
| 4906 | } |
| 4907 | |
| 4908 | /* |
| 4909 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4910 | % % |
| 4911 | % % |
| 4912 | % % |
| 4913 | + 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 % |
| 4914 | % % |
| 4915 | % % |
| 4916 | % % |
| 4917 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4918 | % |
| 4919 | % SyncAuthenticPixelCacheNexus() saves the authentic image pixels to the |
| 4920 | % in-memory or disk cache. The method returns MagickTrue if the pixel region |
| 4921 | % is synced, otherwise MagickFalse. |
| 4922 | % |
| 4923 | % The format of the SyncAuthenticPixelCacheNexus() method is: |
| 4924 | % |
| 4925 | % MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
| 4926 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4927 | % |
| 4928 | % A description of each parameter follows: |
| 4929 | % |
| 4930 | % o image: the image. |
| 4931 | % |
| 4932 | % o nexus_info: the cache nexus to sync. |
| 4933 | % |
| 4934 | % o exception: return any errors or warnings in this structure. |
| 4935 | % |
| 4936 | */ |
cristy | a6577ff | 2011-09-02 19:54:26 +0000 | [diff] [blame] | 4937 | MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4938 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 4939 | { |
| 4940 | CacheInfo |
| 4941 | *cache_info; |
| 4942 | |
| 4943 | MagickBooleanType |
| 4944 | status; |
| 4945 | |
| 4946 | /* |
| 4947 | Transfer pixels to the cache. |
| 4948 | */ |
| 4949 | assert(image != (Image *) NULL); |
| 4950 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4951 | if (image->cache == (Cache) NULL) |
| 4952 | ThrowBinaryException(CacheError,"PixelCacheIsNotOpen",image->filename); |
| 4953 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 4954 | assert(cache_info->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4955 | if (cache_info->type == UndefinedCache) |
| 4956 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4957 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4958 | return(MagickTrue); |
| 4959 | assert(cache_info->signature == MagickSignature); |
| 4960 | status=WritePixelCachePixels(cache_info,nexus_info,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4961 | if ((cache_info->metacontent_extent != 0) && |
| 4962 | (WritePixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4963 | return(MagickFalse); |
| 4964 | return(status); |
| 4965 | } |
| 4966 | |
| 4967 | /* |
| 4968 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4969 | % % |
| 4970 | % % |
| 4971 | % % |
| 4972 | + S y n c A u t h e n t i c P i x e l C a c h e % |
| 4973 | % % |
| 4974 | % % |
| 4975 | % % |
| 4976 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4977 | % |
| 4978 | % SyncAuthenticPixelsCache() saves the authentic image pixels to the in-memory |
| 4979 | % or disk cache. The method returns MagickTrue if the pixel region is synced, |
| 4980 | % otherwise MagickFalse. |
| 4981 | % |
| 4982 | % The format of the SyncAuthenticPixelsCache() method is: |
| 4983 | % |
| 4984 | % MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 4985 | % ExceptionInfo *exception) |
| 4986 | % |
| 4987 | % A description of each parameter follows: |
| 4988 | % |
| 4989 | % o image: the image. |
| 4990 | % |
| 4991 | % o exception: return any errors or warnings in this structure. |
| 4992 | % |
| 4993 | */ |
| 4994 | static MagickBooleanType SyncAuthenticPixelsCache(Image *image, |
| 4995 | ExceptionInfo *exception) |
| 4996 | { |
| 4997 | CacheInfo |
| 4998 | *cache_info; |
| 4999 | |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 5000 | const int |
| 5001 | id = GetOpenMPThreadId(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5002 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5003 | MagickBooleanType |
| 5004 | status; |
| 5005 | |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5006 | assert(image != (Image *) NULL); |
| 5007 | assert(image->signature == MagickSignature); |
| 5008 | assert(image->cache != (Cache) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5009 | cache_info=(CacheInfo *) image->cache; |
cristy | e7cc7cf | 2010-09-21 13:26:47 +0000 | [diff] [blame] | 5010 | assert(cache_info->signature == MagickSignature); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 5011 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5012 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5013 | exception); |
| 5014 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | /* |
| 5018 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5019 | % % |
| 5020 | % % |
| 5021 | % % |
| 5022 | % S y n c A u t h e n t i c P i x e l s % |
| 5023 | % % |
| 5024 | % % |
| 5025 | % % |
| 5026 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5027 | % |
| 5028 | % SyncAuthenticPixels() saves the image pixels to the in-memory or disk cache. |
| 5029 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5030 | % MagickFalse. |
| 5031 | % |
| 5032 | % The format of the SyncAuthenticPixels() method is: |
| 5033 | % |
| 5034 | % MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5035 | % ExceptionInfo *exception) |
| 5036 | % |
| 5037 | % A description of each parameter follows: |
| 5038 | % |
| 5039 | % o image: the image. |
| 5040 | % |
| 5041 | % o exception: return any errors or warnings in this structure. |
| 5042 | % |
| 5043 | */ |
| 5044 | MagickExport MagickBooleanType SyncAuthenticPixels(Image *image, |
| 5045 | ExceptionInfo *exception) |
| 5046 | { |
| 5047 | CacheInfo |
| 5048 | *cache_info; |
| 5049 | |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5050 | const int |
| 5051 | id = GetOpenMPThreadId(); |
| 5052 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5053 | MagickBooleanType |
| 5054 | status; |
| 5055 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5056 | assert(image != (Image *) NULL); |
| 5057 | assert(image->signature == MagickSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5058 | assert(image->cache != (Cache) NULL); |
| 5059 | cache_info=(CacheInfo *) image->cache; |
| 5060 | assert(cache_info->signature == MagickSignature); |
cristy | d317f37 | 2010-09-18 01:42:20 +0000 | [diff] [blame] | 5061 | if (cache_info->methods.sync_authentic_pixels_handler != |
| 5062 | (SyncAuthenticPixelsHandler) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5063 | { |
| 5064 | status=cache_info->methods.sync_authentic_pixels_handler(image, |
| 5065 | exception); |
| 5066 | return(status); |
| 5067 | } |
cristy | 2036f5c | 2010-09-19 21:18:17 +0000 | [diff] [blame] | 5068 | assert(id < (int) cache_info->number_threads); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5069 | status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id], |
| 5070 | exception); |
| 5071 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /* |
| 5075 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5076 | % % |
| 5077 | % % |
| 5078 | % % |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5079 | + 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] | 5080 | % % |
| 5081 | % % |
| 5082 | % % |
| 5083 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5084 | % |
| 5085 | % SyncImagePixelCache() saves the image pixels to the in-memory or disk cache. |
| 5086 | % The method returns MagickTrue if the pixel region is flushed, otherwise |
| 5087 | % MagickFalse. |
| 5088 | % |
| 5089 | % The format of the SyncImagePixelCache() method is: |
| 5090 | % |
| 5091 | % MagickBooleanType SyncImagePixelCache(Image *image, |
| 5092 | % ExceptionInfo *exception) |
| 5093 | % |
| 5094 | % A description of each parameter follows: |
| 5095 | % |
| 5096 | % o image: the image. |
| 5097 | % |
| 5098 | % o exception: return any errors or warnings in this structure. |
| 5099 | % |
| 5100 | */ |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5101 | MagickPrivate MagickBooleanType SyncImagePixelCache(Image *image, |
cristy | 6e43713 | 2011-08-12 13:02:19 +0000 | [diff] [blame] | 5102 | ExceptionInfo *exception) |
| 5103 | { |
| 5104 | CacheInfo |
| 5105 | *cache_info; |
| 5106 | |
| 5107 | assert(image != (Image *) NULL); |
| 5108 | assert(exception != (ExceptionInfo *) NULL); |
| 5109 | cache_info=(CacheInfo *) GetImagePixelCache(image,MagickTrue,exception); |
| 5110 | return(cache_info == (CacheInfo *) NULL ? MagickFalse : MagickTrue); |
| 5111 | } |
| 5112 | |
| 5113 | /* |
| 5114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5115 | % % |
| 5116 | % % |
| 5117 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5118 | + 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] | 5119 | % % |
| 5120 | % % |
| 5121 | % % |
| 5122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5123 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5124 | % WritePixelCacheMetacontent() writes the meta-content to the specified region |
| 5125 | % of the pixel cache. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5126 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5127 | % The format of the WritePixelCacheMetacontent() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5128 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5129 | % MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5130 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5131 | % |
| 5132 | % A description of each parameter follows: |
| 5133 | % |
| 5134 | % o cache_info: the pixel cache. |
| 5135 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5136 | % o nexus_info: the cache nexus to write the meta-content. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5137 | % |
| 5138 | % o exception: return any errors or warnings in this structure. |
| 5139 | % |
| 5140 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5141 | static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5142 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5143 | { |
| 5144 | MagickOffsetType |
| 5145 | count, |
| 5146 | offset; |
| 5147 | |
| 5148 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5149 | extent, |
| 5150 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5151 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5152 | register const unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5153 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5154 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5155 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5156 | y; |
| 5157 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5158 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5159 | rows; |
| 5160 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5161 | if (cache_info->metacontent_extent == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5162 | return(MagickFalse); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5163 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5164 | return(MagickTrue); |
| 5165 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5166 | nexus_info->region.x; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5167 | length=(MagickSizeType) nexus_info->region.width* |
| 5168 | cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5169 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5170 | extent=(MagickSizeType) length*rows; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5171 | p=(unsigned char *) nexus_info->metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5172 | switch (cache_info->type) |
| 5173 | { |
| 5174 | case MemoryCache: |
| 5175 | case MapCache: |
| 5176 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5177 | register unsigned char |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5178 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5179 | |
| 5180 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5181 | Write associated pixels to memory. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5182 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5183 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5184 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5185 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5186 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5187 | rows=1UL; |
| 5188 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5189 | q=(unsigned char *) cache_info->metacontent+offset* |
| 5190 | cache_info->metacontent_extent; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5191 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5192 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5193 | (void) memcpy(q,p,(size_t) length); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5194 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
| 5195 | q+=cache_info->columns*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5196 | } |
| 5197 | break; |
| 5198 | } |
| 5199 | case DiskCache: |
| 5200 | { |
| 5201 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5202 | Write associated pixels to disk. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5203 | */ |
| 5204 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5205 | { |
| 5206 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5207 | cache_info->cache_filename); |
| 5208 | return(MagickFalse); |
| 5209 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5210 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5211 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5212 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5213 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5214 | rows=1UL; |
| 5215 | } |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5216 | extent=(MagickSizeType) cache_info->columns*cache_info->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5217 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5218 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5219 | count=WritePixelCacheRegion(cache_info,cache_info->offset+extent* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5220 | cache_info->number_channels*sizeof(Quantum)+offset* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5221 | cache_info->metacontent_extent,length,(const unsigned char *) p); |
| 5222 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5223 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5224 | p+=nexus_info->region.width*cache_info->metacontent_extent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5225 | offset+=cache_info->columns; |
| 5226 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 5227 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 5228 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5229 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5230 | { |
| 5231 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5232 | cache_info->cache_filename); |
| 5233 | return(MagickFalse); |
| 5234 | } |
| 5235 | break; |
| 5236 | } |
| 5237 | default: |
| 5238 | break; |
| 5239 | } |
| 5240 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5241 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5242 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5243 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5244 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5245 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5246 | return(MagickTrue); |
| 5247 | } |
| 5248 | |
| 5249 | /* |
| 5250 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5251 | % % |
| 5252 | % % |
| 5253 | % % |
| 5254 | + W r i t e C a c h e P i x e l s % |
| 5255 | % % |
| 5256 | % % |
| 5257 | % % |
| 5258 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5259 | % |
| 5260 | % WritePixelCachePixels() writes image pixels to the specified region of the |
| 5261 | % pixel cache. |
| 5262 | % |
| 5263 | % The format of the WritePixelCachePixels() method is: |
| 5264 | % |
| 5265 | % MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5266 | % NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5267 | % |
| 5268 | % A description of each parameter follows: |
| 5269 | % |
| 5270 | % o cache_info: the pixel cache. |
| 5271 | % |
| 5272 | % o nexus_info: the cache nexus to write the pixels. |
| 5273 | % |
| 5274 | % o exception: return any errors or warnings in this structure. |
| 5275 | % |
| 5276 | */ |
| 5277 | static MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, |
| 5278 | NexusInfo *nexus_info,ExceptionInfo *exception) |
| 5279 | { |
| 5280 | MagickOffsetType |
| 5281 | count, |
| 5282 | offset; |
| 5283 | |
| 5284 | MagickSizeType |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5285 | extent, |
| 5286 | length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5287 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5288 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5289 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5290 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5291 | register ssize_t |
cristy | 25ffffb | 2009-12-07 17:15:07 +0000 | [diff] [blame] | 5292 | y; |
| 5293 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5294 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5295 | rows; |
| 5296 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5297 | if (IsPixelAuthentic(cache_info,nexus_info) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5298 | return(MagickTrue); |
| 5299 | offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+ |
| 5300 | nexus_info->region.x; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5301 | length=(MagickSizeType) nexus_info->region.width*cache_info->number_channels* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5302 | sizeof(Quantum); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5303 | rows=nexus_info->region.height; |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5304 | extent=length*rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5305 | p=nexus_info->pixels; |
| 5306 | switch (cache_info->type) |
| 5307 | { |
| 5308 | case MemoryCache: |
| 5309 | case MapCache: |
| 5310 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5311 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5312 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5313 | |
| 5314 | /* |
| 5315 | Write pixels to memory. |
| 5316 | */ |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5317 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5318 | (extent == (MagickSizeType) ((size_t) extent))) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5319 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5320 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5321 | rows=1UL; |
| 5322 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5323 | q=cache_info->pixels+offset*cache_info->number_channels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5324 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5325 | { |
cristy | 8f036fe | 2010-09-18 02:02:00 +0000 | [diff] [blame] | 5326 | (void) memcpy(q,p,(size_t) length); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5327 | p+=nexus_info->region.width*cache_info->number_channels; |
| 5328 | q+=cache_info->columns*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5329 | } |
| 5330 | break; |
| 5331 | } |
| 5332 | case DiskCache: |
| 5333 | { |
| 5334 | /* |
| 5335 | Write pixels to disk. |
| 5336 | */ |
| 5337 | if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse) |
| 5338 | { |
| 5339 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 5340 | cache_info->cache_filename); |
| 5341 | return(MagickFalse); |
| 5342 | } |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5343 | if ((cache_info->columns == nexus_info->region.width) && |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5344 | (extent <= MagickMaxBufferExtent)) |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5345 | { |
cristy | 48078b1 | 2010-09-23 17:11:01 +0000 | [diff] [blame] | 5346 | length=extent; |
cristy | dd341db | 2010-03-04 19:06:38 +0000 | [diff] [blame] | 5347 | rows=1UL; |
| 5348 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5349 | for (y=0; y < (ssize_t) rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5350 | { |
| 5351 | count=WritePixelCacheRegion(cache_info,cache_info->offset+offset* |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5352 | cache_info->number_channels*sizeof(*p),length,(const unsigned char *) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5353 | p); |
| 5354 | if ((MagickSizeType) count != length) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5355 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5356 | p+=nexus_info->region.width*cache_info->number_channels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5357 | offset+=cache_info->columns; |
| 5358 | } |
cristy | c11dace | 2012-01-24 16:39:46 +0000 | [diff] [blame] | 5359 | if (IsFileDescriptorLimitExceeded() != MagickFalse) |
| 5360 | (void) ClosePixelCacheOnDisk(cache_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5361 | if (y < (ssize_t) rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5362 | { |
| 5363 | ThrowFileException(exception,CacheError,"UnableToWritePixelCache", |
| 5364 | cache_info->cache_filename); |
| 5365 | return(MagickFalse); |
| 5366 | } |
| 5367 | break; |
| 5368 | } |
| 5369 | default: |
| 5370 | break; |
| 5371 | } |
| 5372 | if ((cache_info->debug != MagickFalse) && |
cristy | 3009723 | 2010-07-01 02:16:30 +0000 | [diff] [blame] | 5373 | (CacheTick(nexus_info->region.y,cache_info->rows) != MagickFalse)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5374 | (void) LogMagickEvent(CacheEvent,GetMagickModule(), |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 5375 | "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 5376 | nexus_info->region.width,(double) nexus_info->region.height,(double) |
| 5377 | nexus_info->region.x,(double) nexus_info->region.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5378 | return(MagickTrue); |
| 5379 | } |