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