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