]> granicus.if.org Git - imagemagick/blob - MagickCore/cache-view.c
(no commit message)
[imagemagick] / MagickCore / cache-view.c
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 %                        V   V  IIIII  EEEEE  W   W                           %
13 %                        V   V    I    E      W   W                           %
14 %                        V   V    I    EEE    W W W                           %
15 %                         V V     I    E      WW WW                           %
16 %                          V    IIIII  EEEEE  W   W                           %
17 %                                                                             %
18 %                                                                             %
19 %                        MagickCore Cache View Methods                        %
20 %                                                                             %
21 %                              Software Design                                %
22 %                                John Cristy                                  %
23 %                               February 2000                                 %
24 %                                                                             %
25 %                                                                             %
26 %  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
27 %  dedicated to making software imaging solutions freely available.           %
28 %                                                                             %
29 %  You may not use this file except in compliance with the License.  You may  %
30 %  obtain a copy of the License at                                            %
31 %                                                                             %
32 %    http://www.imagemagick.org/script/license.php                            %
33 %                                                                             %
34 %  Unless required by applicable law or agreed to in writing, software        %
35 %  distributed under the License is distributed on an "AS IS" BASIS,          %
36 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
37 %  See the License for the specific language governing permissions and        %
38 %  limitations under the License.                                             %
39 %                                                                             %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %
42 %
43 %
44 */
45 \f
46 /*
47   Include declarations.
48 */
49 #include "MagickCore/studio.h"
50 #include "MagickCore/cache.h"
51 #include "MagickCore/cache-private.h"
52 #include "MagickCore/cache-view.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/memory-private.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/resource_.h"
59 #include "MagickCore/string_.h"
60 #include "MagickCore/thread-private.h"
61 \f
62 /*
63   Typedef declarations.
64 */
65 struct _CacheView
66 {
67   Image
68     *image;
69
70   VirtualPixelMethod
71     virtual_pixel_method;
72
73   size_t
74     number_threads;
75
76   NexusInfo
77     **nexus_info;
78
79   MagickBooleanType
80     debug;
81
82   size_t
83     signature;
84 };
85 \f
86 /*
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 %                                                                             %
89 %                                                                             %
90 %                                                                             %
91 %   A c q u i r e A u t h e n t i c C a c h e V i e w                         %
92 %                                                                             %
93 %                                                                             %
94 %                                                                             %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 %  AcquireAuthenticCacheView() acquires an authentic view into the pixel cache.
98 %
99 %  The format of the AcquireAuthenticCacheView method is:
100 %
101 %      CacheView *AcquireAuthenticCacheView(const Image *image,
102 %        ExceptionInfo *exception)
103 %
104 %  A description of each parameter follows:
105 %
106 %    o image: the image.
107 %
108 %    o exception: return any errors or warnings in this structure.
109 %
110 */
111 MagickExport CacheView *AcquireAuthenticCacheView(const Image *image,
112   ExceptionInfo *exception)
113 {
114   CacheView
115     *cache_view;
116
117   MagickBooleanType
118     status;
119
120   cache_view=AcquireVirtualCacheView(image,exception);
121   status=SyncImagePixelCache(cache_view->image,exception);
122   if (status == MagickFalse)
123     ThrowFatalException(CacheFatalError,"UnableToAcquireCacheView");
124   return(cache_view);
125 }
126 \f
127 /*
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %                                                                             %
130 %                                                                             %
131 %                                                                             %
132 %   A c q u i r e V i r t u a l C a c h e V i e w                             %
133 %                                                                             %
134 %                                                                             %
135 %                                                                             %
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 %
138 %  AcquireVirtualCacheView() acquires a virtual view into the pixel cache,
139 %  using the VirtualPixelMethod that is defined within the given image itself.
140 %
141 %  The format of the AcquireVirtualCacheView method is:
142 %
143 %      CacheView *AcquireVirtualCacheView(const Image *image,
144 %        ExceptionInfo *exception)
145 %
146 %  A description of each parameter follows:
147 %
148 %    o image: the image.
149 %
150 %    o exception: return any errors or warnings in this structure.
151 %
152 */
153 MagickExport CacheView *AcquireVirtualCacheView(const Image *image,
154   ExceptionInfo *exception)
155 {
156   CacheView
157     *cache_view;
158
159   assert(image != (Image *) NULL);
160   assert(image->signature == MagickSignature);
161   if (image->debug != MagickFalse)
162     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
163   (void) exception;
164   cache_view=(CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
165     sizeof(*cache_view)));
166   if (cache_view == (CacheView *) NULL)
167     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168   (void) ResetMagickMemory(cache_view,0,sizeof(*cache_view));
169   cache_view->image=ReferenceImage((Image *) image);
170   cache_view->number_threads=GetOpenMPMaximumThreads();
171   if (GetMagickResourceLimit(ThreadResource) > cache_view->number_threads)
172     cache_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
173   if (cache_view->number_threads == 0)
174     cache_view->number_threads=1;
175   cache_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
176   cache_view->virtual_pixel_method=GetImageVirtualPixelMethod(image);
177   cache_view->debug=IsEventLogging();
178   cache_view->signature=MagickSignature;
179   if (cache_view->nexus_info == (NexusInfo **) NULL)
180     ThrowFatalException(CacheFatalError,"UnableToAcquireCacheView");
181   return(cache_view);
182 }
183 \f
184 /*
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 %                                                                             %
187 %                                                                             %
188 %                                                                             %
189 %   C l o n e C a c h e V i e w                                               %
190 %                                                                             %
191 %                                                                             %
192 %                                                                             %
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 %
195 %  CloneCacheView()  makes an exact copy of the specified cache view.
196 %
197 %  The format of the CloneCacheView method is:
198 %
199 %      CacheView *CloneCacheView(const CacheView *cache_view)
200 %
201 %  A description of each parameter follows:
202 %
203 %    o cache_view: the cache view.
204 %
205 */
206 MagickExport CacheView *CloneCacheView(const CacheView *cache_view)
207 {
208   CacheView
209     *clone_view;
210
211   assert(cache_view != (CacheView *) NULL);
212   assert(cache_view->signature == MagickSignature);
213   if (cache_view->debug != MagickFalse)
214     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
215       cache_view->image->filename);
216   clone_view=(CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
217     sizeof(*clone_view)));
218   if (clone_view == (CacheView *) NULL)
219     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
220   (void) ResetMagickMemory(clone_view,0,sizeof(*clone_view));
221   clone_view->image=ReferenceImage(cache_view->image);
222   clone_view->number_threads=cache_view->number_threads;
223   clone_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
224   clone_view->virtual_pixel_method=cache_view->virtual_pixel_method;
225   clone_view->debug=cache_view->debug;
226   clone_view->signature=MagickSignature;
227   return(clone_view);
228 }
229 \f
230 /*
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 %                                                                             %
233 %                                                                             %
234 %                                                                             %
235 %   D e s t r o y C a c h e V i e w                                           %
236 %                                                                             %
237 %                                                                             %
238 %                                                                             %
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 %
241 %  DestroyCacheView() destroys the specified view returned by a previous call
242 %  to AcquireCacheView().
243 %
244 %  The format of the DestroyCacheView method is:
245 %
246 %      CacheView *DestroyCacheView(CacheView *cache_view)
247 %
248 %  A description of each parameter follows:
249 %
250 %    o cache_view: the cache view.
251 %
252 */
253 MagickExport CacheView *DestroyCacheView(CacheView *cache_view)
254 {
255   assert(cache_view != (CacheView *) NULL);
256   assert(cache_view->signature == MagickSignature);
257   if (cache_view->debug != MagickFalse)
258     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
259       cache_view->image->filename);
260   if (cache_view->nexus_info != (NexusInfo **) NULL)
261     cache_view->nexus_info=DestroyPixelCacheNexus(cache_view->nexus_info,
262       cache_view->number_threads);
263   cache_view->image=DestroyImage(cache_view->image);
264   cache_view->signature=(~MagickSignature);
265   cache_view=(CacheView *) RelinquishAlignedMemory(cache_view);
266   return(cache_view);
267 }
268 \f
269 /*
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 %                                                                             %
272 %                                                                             %
273 %                                                                             %
274 %   G e t C a c h e V i e w A u t h e n t i c P i x e l s                     %
275 %                                                                             %
276 %                                                                             %
277 %                                                                             %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 %
280 %  GetCacheViewAuthenticPixels() gets pixels from the in-memory or disk pixel
281 %  cache as defined by the geometry parameters.   A pointer to the pixels is
282 %  returned if the pixels are transferred, otherwise a NULL is returned.
283 %
284 %  The format of the GetCacheViewAuthenticPixels method is:
285 %
286 %      Quantum *GetCacheViewAuthenticPixels(CacheView *cache_view,
287 %        const ssize_t x,const ssize_t y,const size_t columns,
288 %        const size_t rows,ExceptionInfo *exception)
289 %
290 %  A description of each parameter follows:
291 %
292 %    o cache_view: the cache view.
293 %
294 %    o x,y,columns,rows:  These values define the perimeter of a region of
295 %      pixels.
296 %
297 %    o exception: return any errors or warnings in this structure.
298 %
299 */
300 MagickExport Quantum *GetCacheViewAuthenticPixels(CacheView *cache_view,
301   const ssize_t x,const ssize_t y,const size_t columns,const size_t rows,
302   ExceptionInfo *exception)
303 {
304   const int
305     id = GetOpenMPThreadId();
306
307   Quantum
308     *pixels;
309
310   assert(cache_view != (CacheView *) NULL);
311   assert(cache_view->signature == MagickSignature);
312   assert(id < (int) cache_view->number_threads);
313   pixels=GetAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
314     cache_view->nexus_info[id],exception);
315   return(pixels);
316 }
317 \f
318 /*
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 %                                                                             %
321 %                                                                             %
322 %                                                                             %
323 %   G e t C a c h e V i e w A u t h e n t i c M e t a c o n t e n t           %
324 %                                                                             %
325 %                                                                             %
326 %                                                                             %
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 %
329 %  GetCacheViewAuthenticMetacontent() returns the meta-content corresponding
330 %  with the last call to SetCacheViewIndexes() or
331 %  GetCacheViewAuthenticMetacontent().  The meta-content are authentic and can
332 %  be updated.
333 %
334 %  The format of the GetCacheViewAuthenticMetacontent() method is:
335 %
336 %      void *GetCacheViewAuthenticMetacontent(CacheView *cache_view)
337 %
338 %  A description of each parameter follows:
339 %
340 %    o cache_view: the cache view.
341 %
342 */
343 MagickExport void *GetCacheViewAuthenticMetacontent(CacheView *cache_view)
344 {
345   const int
346     id = GetOpenMPThreadId();
347
348   void
349     *metacontent;
350
351   assert(cache_view != (CacheView *) NULL);
352   assert(cache_view->signature == MagickSignature);
353   assert(cache_view->image->cache != (Cache) NULL);
354   assert(id < (int) cache_view->number_threads);
355   metacontent=GetPixelCacheNexusMetacontent(cache_view->image->cache,
356     cache_view->nexus_info[id]);
357   return(metacontent);
358 }
359 \f
360 /*
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362 %                                                                             %
363 %                                                                             %
364 %                                                                             %
365 %   G e t C a c h e V i e w A u t h e n t i c P i x e l Q u e u e             %
366 %                                                                             %
367 %                                                                             %
368 %                                                                             %
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370 %
371 %  GetCacheViewAuthenticPixelQueue() returns the pixels associated with the
372 %  last call to QueueCacheViewAuthenticPixels() or
373 %  GetCacheViewAuthenticPixels().  The pixels are authentic and therefore can be
374 %  updated.
375 %
376 %  The format of the GetCacheViewAuthenticPixelQueue() method is:
377 %
378 %      Quantum *GetCacheViewAuthenticPixelQueue(CacheView *cache_view)
379 %
380 %  A description of each parameter follows:
381 %
382 %    o cache_view: the cache view.
383 %
384 */
385 MagickExport Quantum *GetCacheViewAuthenticPixelQueue(CacheView *cache_view)
386 {
387   const int
388     id = GetOpenMPThreadId();
389
390   Quantum
391     *pixels;
392
393   assert(cache_view != (CacheView *) NULL);
394   assert(cache_view->signature == MagickSignature);
395   assert(cache_view->image->cache != (Cache) NULL);
396   assert(id < (int) cache_view->number_threads);
397   pixels=GetPixelCacheNexusPixels(cache_view->image->cache,
398     cache_view->nexus_info[id]);
399   return(pixels);
400 }
401 \f
402 /*
403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 %                                                                             %
405 %                                                                             %
406 %                                                                             %
407 %   G e t C a c h e V i e w C o l o r s p a c e                               %
408 %                                                                             %
409 %                                                                             %
410 %                                                                             %
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 %
413 %  GetCacheViewColorspace() returns the image colorspace associated with the
414 %  specified view.
415 %
416 %  The format of the GetCacheViewColorspace method is:
417 %
418 %      ColorspaceType GetCacheViewColorspace(const CacheView *cache_view)
419 %
420 %  A description of each parameter follows:
421 %
422 %    o cache_view: the cache view.
423 %
424 */
425 MagickExport ColorspaceType GetCacheViewColorspace(const CacheView *cache_view)
426 {
427   assert(cache_view != (CacheView *) NULL);
428   assert(cache_view->signature == MagickSignature);
429   if (cache_view->debug != MagickFalse)
430     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
431       cache_view->image->filename);
432   return(GetPixelCacheColorspace(cache_view->image->cache));
433 }
434 \f
435 /*
436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 %                                                                             %
438 %                                                                             %
439 %                                                                             %
440 +   G e t C a c h e V i e w E x t e n t                                       %
441 %                                                                             %
442 %                                                                             %
443 %                                                                             %
444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445 %
446 %  GetCacheViewExtent() returns the extent of the pixels associated with the
447 %  last call to QueueCacheViewAuthenticPixels() or
448 %  GetCacheViewAuthenticPixels().
449 %
450 %  The format of the GetCacheViewExtent() method is:
451 %
452 %      MagickSizeType GetCacheViewExtent(const CacheView *cache_view)
453 %
454 %  A description of each parameter follows:
455 %
456 %    o cache_view: the cache view.
457 %
458 */
459 MagickExport MagickSizeType GetCacheViewExtent(const CacheView *cache_view)
460 {
461   const int
462     id = GetOpenMPThreadId();
463
464   MagickSizeType
465     extent;
466
467   assert(cache_view != (CacheView *) NULL);
468   assert(cache_view->signature == MagickSignature);
469   if (cache_view->debug != MagickFalse)
470     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
471       cache_view->image->filename);
472   assert(cache_view->image->cache != (Cache) NULL);
473   assert(id < (int) cache_view->number_threads);
474   extent=GetPixelCacheNexusExtent(cache_view->image->cache,
475     cache_view->nexus_info[id]);
476   return(extent);
477 }
478 \f
479 /*
480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
481 %                                                                             %
482 %                                                                             %
483 %                                                                             %
484 %   G e t C a c h e V i e w I m a g e                                         %
485 %                                                                             %
486 %                                                                             %
487 %                                                                             %
488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 %
490 %  GetCacheViewImage() returns the image associated with the specified view.
491 %
492 %  The format of the GetCacheViewImage method is:
493 %
494 %      const Image *GetCacheViewImage(const CacheView *cache_view)
495 %
496 %  A description of each parameter follows:
497 %
498 %    o cache_view: the cache view.
499 %
500 */
501 MagickExport const Image *GetCacheViewImage(const CacheView *cache_view)
502 {
503   assert(cache_view != (CacheView *) NULL);
504   assert(cache_view->signature == MagickSignature);
505   if (cache_view->debug != MagickFalse)
506     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
507       cache_view->image->filename);
508   return(cache_view->image);
509 }
510 \f
511 /*
512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
513 %                                                                             %
514 %                                                                             %
515 %                                                                             %
516 %   G e t C a c h e V i e w S t o r a g e C l a s s                           %
517 %                                                                             %
518 %                                                                             %
519 %                                                                             %
520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521 %
522 %  GetCacheViewStorageClass() returns the image storage class associated with
523 %  the specified view.
524 %
525 %  The format of the GetCacheViewStorageClass method is:
526 %
527 %      ClassType GetCacheViewStorageClass(const CacheView *cache_view)
528 %
529 %  A description of each parameter follows:
530 %
531 %    o cache_view: the cache view.
532 %
533 */
534 MagickExport ClassType GetCacheViewStorageClass(const CacheView *cache_view)
535 {
536   assert(cache_view != (CacheView *) NULL);
537   assert(cache_view->signature == MagickSignature);
538   if (cache_view->debug != MagickFalse)
539     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
540       cache_view->image->filename);
541   return(GetPixelCacheStorageClass(cache_view->image->cache));
542 }
543 \f
544 /*
545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 %                                                                             %
547 %                                                                             %
548 %                                                                             %
549 %   G e t C a c h e V i e w V i r t u a l M e t a c o n t e n t               %
550 %                                                                             %
551 %                                                                             %
552 %                                                                             %
553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
554 %
555 %  GetCacheViewVirtualMetacontent() returns the meta-content corresponding
556 %  with the last call to GetCacheViewVirtualMetacontent().  The meta-content
557 %  is virtual and therefore cannot be updated.
558 %
559 %  The format of the GetCacheViewVirtualMetacontent() method is:
560 %
561 %      const void *GetCacheViewVirtualMetacontent(
562 %        const CacheView *cache_view)
563 %
564 %  A description of each parameter follows:
565 %
566 %    o cache_view: the cache view.
567 %
568 */
569 MagickExport const void *GetCacheViewVirtualMetacontent(
570   const CacheView *cache_view)
571 {
572   const int
573     id = GetOpenMPThreadId();
574
575   const void
576     *metacontent;
577
578   assert(cache_view != (const CacheView *) NULL);
579   assert(cache_view->signature == MagickSignature);
580   assert(cache_view->image->cache != (Cache) NULL);
581   assert(id < (int) cache_view->number_threads);
582   metacontent=GetVirtualMetacontentFromNexus(cache_view->image->cache,
583     cache_view->nexus_info[id]);
584   return(metacontent);
585 }
586 \f
587 /*
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 %                                                                             %
590 %                                                                             %
591 %                                                                             %
592 %   G e t C a c h e V i e w V i r t u a l P i x e l Q u e u e                 %
593 %                                                                             %
594 %                                                                             %
595 %                                                                             %
596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
597 %
598 %  GetCacheViewVirtualPixelQueue() returns the the pixels associated with
599 %  the last call to GetCacheViewVirtualPixels().  The pixels are virtual
600 %  and therefore cannot be updated.
601 %
602 %  The format of the GetCacheViewVirtualPixelQueue() method is:
603 %
604 %      const Quantum *GetCacheViewVirtualPixelQueue(
605 %        const CacheView *cache_view)
606 %
607 %  A description of each parameter follows:
608 %
609 %    o cache_view: the cache view.
610 %
611 */
612 MagickExport const Quantum *GetCacheViewVirtualPixelQueue(
613   const CacheView *cache_view)
614 {
615   const int
616     id = GetOpenMPThreadId();
617
618   const Quantum
619     *pixels;
620
621   assert(cache_view != (const CacheView *) NULL);
622   assert(cache_view->signature == MagickSignature);
623   assert(cache_view->image->cache != (Cache) NULL);
624   assert(id < (int) cache_view->number_threads);
625   pixels=GetVirtualPixelsNexus(cache_view->image->cache,
626     cache_view->nexus_info[id]);
627   return(pixels);
628 }
629 \f
630 /*
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 %                                                                             %
633 %                                                                             %
634 %                                                                             %
635 %   G e t C a c h e V i e w V i r t u a l P i x e l s                         %
636 %                                                                             %
637 %                                                                             %
638 %                                                                             %
639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640 %
641 %  GetCacheViewVirtualPixels() gets virtual pixels from the in-memory or
642 %  disk pixel cache as defined by the geometry parameters.   A pointer to the
643 %  pixels is returned if the pixels are transferred, otherwise a NULL is
644 %  returned.
645 %
646 %  The format of the GetCacheViewVirtualPixels method is:
647 %
648 %      const Quantum *GetCacheViewVirtualPixels(
649 %        const CacheView *cache_view,const ssize_t x,const ssize_t y,
650 %        const size_t columns,const size_t rows,ExceptionInfo *exception)
651 %
652 %  A description of each parameter follows:
653 %
654 %    o cache_view: the cache view.
655 %
656 %    o x,y,columns,rows:  These values define the perimeter of a region of
657 %      pixels.
658 %
659 %    o exception: return any errors or warnings in this structure.
660 %
661 */
662 MagickExport const Quantum *GetCacheViewVirtualPixels(
663   const CacheView *cache_view,const ssize_t x,const ssize_t y,
664   const size_t columns,const size_t rows,ExceptionInfo *exception)
665 {
666   const int
667     id = GetOpenMPThreadId();
668
669   const Quantum
670     *pixels;
671
672   assert(cache_view != (CacheView *) NULL);
673   assert(cache_view->signature == MagickSignature);
674   assert(id < (int) cache_view->number_threads);
675   pixels=GetVirtualPixelsFromNexus(cache_view->image,
676     cache_view->virtual_pixel_method,x,y,columns,rows,
677     cache_view->nexus_info[id],exception);
678   return(pixels);
679 }
680 \f
681 /*
682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683 %                                                                             %
684 %                                                                             %
685 %                                                                             %
686 %   G e t O n e C a c h e V i e w A u t h e n t i c P i x e l                 %
687 %                                                                             %
688 %                                                                             %
689 %                                                                             %
690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 %
692 %  GetOneCacheViewAuthenticPixel() returns a single pixel at the specified (x,y)
693 %  location.  The image background color is returned if an error occurs.
694 %
695 %  The format of the GetOneCacheViewAuthenticPixel method is:
696 %
697 %      MagickBooleaNType GetOneCacheViewAuthenticPixel(
698 %        const CacheView *cache_view,const ssize_t x,const ssize_t y,
699 %        Quantum *pixel,ExceptionInfo *exception)
700 %
701 %  A description of each parameter follows:
702 %
703 %    o cache_view: the cache view.
704 %
705 %    o x,y:  These values define the offset of the pixel.
706 %
707 %    o pixel: return a pixel at the specified (x,y) location.
708 %
709 %    o exception: return any errors or warnings in this structure.
710 %
711 */
712 MagickExport MagickBooleanType GetOneCacheViewAuthenticPixel(
713   const CacheView *cache_view,const ssize_t x,const ssize_t y,Quantum *pixel,
714   ExceptionInfo *exception)
715 {
716   const int
717     id = GetOpenMPThreadId();
718
719   Quantum
720     *p;
721
722   register ssize_t
723     i;
724
725   assert(cache_view != (CacheView *) NULL);
726   assert(cache_view->signature == MagickSignature);
727   assert(id < (int) cache_view->number_threads);
728   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
729   p=GetAuthenticPixelCacheNexus(cache_view->image,x,y,1,1,
730     cache_view->nexus_info[id],exception);
731   if (p == (const Quantum *) NULL)
732     {
733       PixelInfo
734         background_color;
735
736       background_color=cache_view->image->background_color;
737       pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
738       pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
739       pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
740       pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
741       pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
742       return(MagickFalse);
743     }
744   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
745   {
746     PixelChannel
747       channel;
748
749     channel=GetPixelChannelChannel(cache_view->image,i);
750     pixel[channel]=p[i];
751   }
752   return(MagickTrue);
753 }
754 \f
755 /*
756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 %                                                                             %
758 %                                                                             %
759 %                                                                             %
760 %   G e t O n e C a c h e V i e w V i r t u a l P i x e l                     %
761 %                                                                             %
762 %                                                                             %
763 %                                                                             %
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 %
766 %  GetOneCacheViewVirtualPixel() returns a single pixel at the specified (x,y)
767 %  location.  The image background color is returned if an error occurs.  If
768 %  you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
769 %
770 %  The format of the GetOneCacheViewVirtualPixel method is:
771 %
772 %      MagickBooleanType GetOneCacheViewVirtualPixel(
773 %        const CacheView *cache_view,const ssize_t x,const ssize_t y,
774 %        Quantum *pixel,ExceptionInfo *exception)
775 %
776 %  A description of each parameter follows:
777 %
778 %    o cache_view: the cache view.
779 %
780 %    o x,y:  These values define the offset of the pixel.
781 %
782 %    o pixel: return a pixel at the specified (x,y) location.
783 %
784 %    o exception: return any errors or warnings in this structure.
785 %
786 */
787 MagickExport MagickBooleanType GetOneCacheViewVirtualPixel(
788   const CacheView *cache_view,const ssize_t x,const ssize_t y,Quantum *pixel,
789   ExceptionInfo *exception)
790 {
791   const int
792     id = GetOpenMPThreadId();
793
794   register const Quantum
795     *p;
796
797   register ssize_t
798     i;
799
800   assert(cache_view != (CacheView *) NULL);
801   assert(cache_view->signature == MagickSignature);
802   assert(id < (int) cache_view->number_threads);
803   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
804   p=GetVirtualPixelsFromNexus(cache_view->image,
805     cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[id],
806     exception);
807   if (p == (const Quantum *) NULL)
808     {
809       PixelInfo
810         background_color;
811
812       background_color=cache_view->image->background_color;
813       pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
814       pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
815       pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
816       pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
817       pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
818       return(MagickFalse);
819     }
820   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
821   {
822     PixelChannel
823       channel;
824
825     channel=GetPixelChannelChannel(cache_view->image,i);
826     pixel[channel]=p[i];
827   }
828   return(MagickTrue);
829 }
830 \f
831 /*
832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833 %                                                                             %
834 %                                                                             %
835 %                                                                             %
836 %   G e t O n e C a c h e V i e w V i r t u a l P i x e l I n f o             %
837 %                                                                             %
838 %                                                                             %
839 %                                                                             %
840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
841 %
842 %  GetOneCacheViewVirtualPixelInfo() returns a single pixel at the specified
843 %  (x,y) location.  The image background color is returned if an error occurs.
844 %  If you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
845 %
846 %  The format of the GetOneCacheViewVirtualPixelInfo method is:
847 %
848 %      MagickBooleanType GetOneCacheViewVirtualPixelInfo(
849 %        const CacheView *cache_view,const ssize_t x,const ssize_t y,
850 %        PixelInfo *pixel,ExceptionInfo *exception)
851 %
852 %  A description of each parameter follows:
853 %
854 %    o cache_view: the cache view.
855 %
856 %    o x,y:  These values define the offset of the pixel.
857 %
858 %    o pixel: return a pixel at the specified (x,y) location.
859 %
860 %    o exception: return any errors or warnings in this structure.
861 %
862 */
863 MagickExport MagickBooleanType GetOneCacheViewVirtualPixelInfo(
864   const CacheView *cache_view,const ssize_t x,const ssize_t y,PixelInfo *pixel,
865   ExceptionInfo *exception)
866 {
867   const int
868     id = GetOpenMPThreadId();
869
870   register const Quantum
871     *p;
872
873   assert(cache_view != (CacheView *) NULL);
874   assert(cache_view->signature == MagickSignature);
875   assert(id < (int) cache_view->number_threads);
876   GetPixelInfo(cache_view->image,pixel);
877   p=GetVirtualPixelsFromNexus(cache_view->image,
878     cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[id],
879     exception);
880   if (p == (const Quantum *) NULL)
881     return(MagickFalse);
882   GetPixelInfoPixel(cache_view->image,p,pixel);
883   return(MagickTrue);
884 }
885 \f
886 /*
887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888 %                                                                             %
889 %                                                                             %
890 %                                                                             %
891 %   G e t O n e C a c h e V i e w V i r t u a l P i x e l                     %
892 %                                                                             %
893 %                                                                             %
894 %                                                                             %
895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896 %
897 %  GetOneCacheViewVirtualMethodPixel() returns a single virtual pixel at
898 %  the specified (x,y) location.  The image background color is returned if an
899 %  error occurs.  If you plan to modify the pixel, use
900 %  GetOneCacheViewAuthenticPixel() instead.
901 %
902 %  The format of the GetOneCacheViewVirtualPixel method is:
903 %
904 %      MagickBooleanType GetOneCacheViewVirtualMethodPixel(
905 %        const CacheView *cache_view,
906 %        const VirtualPixelMethod virtual_pixel_method,const ssize_t x,
907 %        const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
908 %
909 %  A description of each parameter follows:
910 %
911 %    o cache_view: the cache view.
912 %
913 %    o virtual_pixel_method: the virtual pixel method.
914 %
915 %    o x,y:  These values define the offset of the pixel.
916 %
917 %    o pixel: return a pixel at the specified (x,y) location.
918 %
919 %    o exception: return any errors or warnings in this structure.
920 %
921 */
922 MagickExport MagickBooleanType GetOneCacheViewVirtualMethodPixel(
923   const CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method,
924   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
925 {
926   const int
927     id = GetOpenMPThreadId();
928
929   const Quantum
930     *p;
931
932   register ssize_t
933     i;
934
935   assert(cache_view != (CacheView *) NULL);
936   assert(cache_view->signature == MagickSignature);
937   assert(id < (int) cache_view->number_threads);
938   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
939   p=GetVirtualPixelsFromNexus(cache_view->image,virtual_pixel_method,x,y,1,1,
940     cache_view->nexus_info[id],exception);
941   if (p == (const Quantum *) NULL)
942     {
943       PixelInfo
944         background_color;
945
946       background_color=cache_view->image->background_color;
947       pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
948       pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
949       pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
950       pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
951       pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
952       return(MagickFalse);
953     }
954   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
955   {
956     PixelChannel
957       channel;
958
959     channel=GetPixelChannelChannel(cache_view->image,i);
960     pixel[channel]=p[i];
961   }
962   return(MagickTrue);
963 }
964 \f
965 /*
966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 %                                                                             %
968 %                                                                             %
969 %                                                                             %
970 %   Q u e u e C a c h e V i e w A u t h e n t i c P i x e l s                 %
971 %                                                                             %
972 %                                                                             %
973 %                                                                             %
974 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 %
976 %  QueueCacheViewAuthenticPixels() queues authentic pixels from the in-memory or
977 %  disk pixel cache as defined by the geometry parameters.   A pointer to the
978 %  pixels is returned if the pixels are transferred, otherwise a NULL is
979 %  returned.
980 %
981 %  The format of the QueueCacheViewAuthenticPixels method is:
982 %
983 %      Quantum *QueueCacheViewAuthenticPixels(CacheView *cache_view,
984 %        const ssize_t x,const ssize_t y,const size_t columns,
985 %        const size_t rows,ExceptionInfo *exception)
986 %
987 %  A description of each parameter follows:
988 %
989 %    o cache_view: the cache view.
990 %
991 %    o x,y,columns,rows:  These values define the perimeter of a region of
992 %      pixels.
993 %
994 %    o exception: return any errors or warnings in this structure.
995 %
996 */
997 MagickExport Quantum *QueueCacheViewAuthenticPixels(CacheView *cache_view,
998   const ssize_t x,const ssize_t y,const size_t columns,const size_t rows,
999   ExceptionInfo *exception)
1000 {
1001   const int
1002     id = GetOpenMPThreadId();
1003
1004   Quantum
1005     *pixels;
1006
1007   assert(cache_view != (CacheView *) NULL);
1008   assert(cache_view->signature == MagickSignature);
1009   assert(id < (int) cache_view->number_threads);
1010   pixels=QueueAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
1011     MagickFalse,cache_view->nexus_info[id],exception);
1012   return(pixels);
1013 }
1014 \f
1015 /*
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 %                                                                             %
1018 %                                                                             %
1019 %                                                                             %
1020 %   S e t C a c h e V i e w S t o r a g e C l a s s                           %
1021 %                                                                             %
1022 %                                                                             %
1023 %                                                                             %
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025 %
1026 %  SetCacheViewStorageClass() sets the image storage class associated with
1027 %  the specified view.
1028 %
1029 %  The format of the SetCacheViewStorageClass method is:
1030 %
1031 %      MagickBooleanType SetCacheViewStorageClass(CacheView *cache_view,
1032 %        const ClassType storage_class,ExceptionInfo *exception)
1033 %
1034 %  A description of each parameter follows:
1035 %
1036 %    o cache_view: the cache view.
1037 %
1038 %    o storage_class: the image storage class: PseudoClass or DirectClass.
1039 %
1040 %    o exception: return any errors or warnings in this structure.
1041 %
1042 */
1043 MagickExport MagickBooleanType SetCacheViewStorageClass(CacheView *cache_view,
1044   const ClassType storage_class,ExceptionInfo *exception)
1045 {
1046   assert(cache_view != (CacheView *) NULL);
1047   assert(cache_view->signature == MagickSignature);
1048   if (cache_view->debug != MagickFalse)
1049     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1050       cache_view->image->filename);
1051   return(SetImageStorageClass(cache_view->image,storage_class,exception));
1052 }
1053 \f
1054 /*
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056 %                                                                             %
1057 %                                                                             %
1058 %                                                                             %
1059 %   S e t C a c h e V i e w V i r t u a l P i x e l M e t h o d               %
1060 %                                                                             %
1061 %                                                                             %
1062 %                                                                             %
1063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 %
1065 %  SetCacheViewVirtualPixelMethod() sets the virtual pixel method associated
1066 %  with the specified cache view.
1067 %
1068 %  The format of the SetCacheViewVirtualPixelMethod method is:
1069 %
1070 %      MagickBooleanType SetCacheViewVirtualPixelMethod(CacheView *cache_view,
1071 %        const VirtualPixelMethod virtual_pixel_method)
1072 %
1073 %  A description of each parameter follows:
1074 %
1075 %    o cache_view: the cache view.
1076 %
1077 %    o virtual_pixel_method: the virtual pixel method.
1078 %
1079 */
1080 MagickExport MagickBooleanType SetCacheViewVirtualPixelMethod(
1081   CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method)
1082 {
1083   assert(cache_view != (CacheView *) NULL);
1084   assert(cache_view->signature == MagickSignature);
1085   if (cache_view->debug != MagickFalse)
1086     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1087       cache_view->image->filename);
1088   cache_view->virtual_pixel_method=virtual_pixel_method;
1089   return(MagickTrue);
1090 }
1091 \f
1092 /*
1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 %                                                                             %
1095 %                                                                             %
1096 %                                                                             %
1097 %   S y n c C a c h e V i e w A u t h e n t i c P i x e l s                   %
1098 %                                                                             %
1099 %                                                                             %
1100 %                                                                             %
1101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1102 %
1103 %  SyncCacheViewAuthenticPixels() saves the cache view pixels to the in-memory
1104 %  or disk cache.  It returns MagickTrue if the pixel region is flushed,
1105 %  otherwise MagickFalse.
1106 %
1107 %  The format of the SyncCacheViewAuthenticPixels method is:
1108 %
1109 %      MagickBooleanType SyncCacheViewAuthenticPixels(CacheView *cache_view,
1110 %        ExceptionInfo *exception)
1111 %
1112 %  A description of each parameter follows:
1113 %
1114 %    o cache_view: the cache view.
1115 %
1116 %    o exception: return any errors or warnings in this structure.
1117 %
1118 */
1119 MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(
1120   CacheView *cache_view,ExceptionInfo *exception)
1121 {
1122   const int
1123     id = GetOpenMPThreadId();
1124
1125   MagickBooleanType
1126     status;
1127
1128   assert(cache_view != (CacheView *) NULL);
1129   assert(cache_view->signature == MagickSignature);
1130   assert(id < (int) cache_view->number_threads);
1131   status=SyncAuthenticPixelCacheNexus(cache_view->image,
1132     cache_view->nexus_info[id],exception);
1133   return(status);
1134 }