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