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