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