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