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