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