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