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