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