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"
112MagickExport
CacheView *AcquireAuthenticCacheView(
const Image *image,
116 *magick_restrict cache_view;
118 cache_view=AcquireVirtualCacheView(image,exception);
149MagickExport
CacheView *AcquireVirtualCacheView(
const Image *image,
153 *magick_restrict cache_view;
155 magick_unreferenced(exception);
156 assert(image != (
Image *) NULL);
157 assert(image->signature == MagickCoreSignature);
158 if (IsEventLogging() != MagickFalse)
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
160#if defined(MAGICKCORE_OPENCL_SUPPORT)
161 SyncAuthenticOpenCLBuffer(image);
163 cache_view=(
CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
164 sizeof(*cache_view)));
166 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
167 (void) memset(cache_view,0,
sizeof(*cache_view));
168 cache_view->image=ReferenceImage((
Image *) image);
169 cache_view->number_threads=GetOpenMPMaximumThreads();
170 if (GetMagickResourceLimit(ThreadResource) > cache_view->number_threads)
171 cache_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
172 if (cache_view->number_threads == 0)
173 cache_view->number_threads=1;
174 cache_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
175 cache_view->virtual_pixel_method=GetImageVirtualPixelMethod(image);
176 cache_view->debug=(GetLogEventMask() & CacheEvent) != 0 ? MagickTrue :
178 cache_view->signature=MagickCoreSignature;
207 *magick_restrict clone_view;
209 assert(cache_view != (
CacheView *) NULL);
210 assert(cache_view->signature == MagickCoreSignature);
211 if (IsEventLogging() != MagickFalse)
212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
213 cache_view->image->filename);
214 clone_view=(
CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
215 sizeof(*clone_view)));
217 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
218 (void) memset(clone_view,0,
sizeof(*clone_view));
219 clone_view->image=ReferenceImage(cache_view->image);
220 clone_view->number_threads=cache_view->number_threads;
221 clone_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
222 clone_view->virtual_pixel_method=cache_view->virtual_pixel_method;
223 clone_view->debug=cache_view->debug;
224 clone_view->signature=MagickCoreSignature;
253 assert(cache_view != (
CacheView *) NULL);
254 assert(cache_view->signature == MagickCoreSignature);
255 if (IsEventLogging() != MagickFalse)
256 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
257 cache_view->image->filename);
258 if (cache_view->nexus_info != (
NexusInfo **) NULL)
259 cache_view->nexus_info=DestroyPixelCacheNexus(cache_view->nexus_info,
260 cache_view->number_threads);
261 cache_view->image=DestroyImage(cache_view->image);
262 cache_view->signature=(~MagickCoreSignature);
263 cache_view=(
CacheView *) RelinquishAlignedMemory(cache_view);
298MagickExport Quantum *GetCacheViewAuthenticPixels(
CacheView *cache_view,
299 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
303 id = GetOpenMPThreadId();
306 *magick_restrict pixels;
308 assert(cache_view != (
CacheView *) NULL);
309 assert(cache_view->signature == MagickCoreSignature);
310 assert(
id < (
int) cache_view->number_threads);
311 pixels=GetAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
312 cache_view->nexus_info[
id],exception);
341MagickExport
void *GetCacheViewAuthenticMetacontent(
CacheView *cache_view)
344 id = GetOpenMPThreadId();
346 assert(cache_view != (
CacheView *) NULL);
347 assert(cache_view->signature == MagickCoreSignature);
348 assert(cache_view->image->cache != (Cache) NULL);
349 assert(
id < (
int) cache_view->number_threads);
350 return(cache_view->nexus_info[
id]->metacontent);
378MagickExport Quantum *GetCacheViewAuthenticPixelQueue(
CacheView *cache_view)
381 id = GetOpenMPThreadId();
383 assert(cache_view != (
CacheView *) NULL);
384 assert(cache_view->signature == MagickCoreSignature);
385 assert(cache_view->image->cache != (Cache) NULL);
386 assert(
id < (
int) cache_view->number_threads);
387 return(cache_view->nexus_info[
id]->pixels);
413MagickExport ColorspaceType GetCacheViewColorspace(
const CacheView *cache_view)
415 assert(cache_view != (
CacheView *) NULL);
416 assert(cache_view->signature == MagickCoreSignature);
417 if (IsEventLogging() != MagickFalse)
418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
419 cache_view->image->filename);
420 return(GetPixelCacheColorspace(cache_view->image->cache));
447MagickExport MagickSizeType GetCacheViewExtent(
const CacheView *cache_view)
450 id = GetOpenMPThreadId();
455 assert(cache_view != (
CacheView *) NULL);
456 assert(cache_view->signature == MagickCoreSignature);
457 if (IsEventLogging() != MagickFalse)
458 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
459 cache_view->image->filename);
460 assert(cache_view->image->cache != (Cache) NULL);
461 assert(
id < (
int) cache_view->number_threads);
462 extent=GetPixelCacheNexusExtent(cache_view->image->cache,
463 cache_view->nexus_info[
id]);
489MagickExport
const Image *GetCacheViewImage(
const CacheView *cache_view)
491 assert(cache_view != (
CacheView *) NULL);
492 assert(cache_view->signature == MagickCoreSignature);
493 if (IsEventLogging() != MagickFalse)
494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
495 cache_view->image->filename);
496 return(cache_view->image);
522MagickExport ClassType GetCacheViewStorageClass(
const CacheView *cache_view)
524 assert(cache_view != (
CacheView *) NULL);
525 assert(cache_view->signature == MagickCoreSignature);
526 if (IsEventLogging() != MagickFalse)
527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
528 cache_view->image->filename);
529 return(GetPixelCacheStorageClass(cache_view->image->cache));
557MagickExport
const void *GetCacheViewVirtualMetacontent(
561 id = GetOpenMPThreadId();
564 *magick_restrict metacontent;
566 assert(cache_view != (
const CacheView *) NULL);
567 assert(cache_view->signature == MagickCoreSignature);
568 assert(cache_view->image->cache != (Cache) NULL);
569 assert(
id < (
int) cache_view->number_threads);
570 metacontent=GetVirtualMetacontentFromNexus(cache_view->image->cache,
571 cache_view->nexus_info[
id]);
600MagickExport
const Quantum *GetCacheViewVirtualPixelQueue(
604 id = GetOpenMPThreadId();
607 *magick_restrict pixels;
609 assert(cache_view != (
const CacheView *) NULL);
610 assert(cache_view->signature == MagickCoreSignature);
611 assert(cache_view->image->cache != (Cache) NULL);
612 assert(
id < (
int) cache_view->number_threads);
613 pixels=GetVirtualPixelsNexus(cache_view->image->cache,
614 cache_view->nexus_info[
id]);
650MagickExport
const Quantum *GetCacheViewVirtualPixels(
651 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,
652 const size_t columns,
const size_t rows,
ExceptionInfo *exception)
655 id = GetOpenMPThreadId();
658 *magick_restrict pixels;
660 assert(cache_view != (
CacheView *) NULL);
661 assert(cache_view->signature == MagickCoreSignature);
662 assert(
id < (
int) cache_view->number_threads);
663 pixels=GetVirtualPixelCacheNexus(cache_view->image,
664 cache_view->virtual_pixel_method,x,y,columns,rows,
665 cache_view->nexus_info[
id],exception);
700MagickExport MagickBooleanType GetOneCacheViewAuthenticPixel(
701 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,Quantum *pixel,
705 id = GetOpenMPThreadId();
713 assert(cache_view != (
CacheView *) NULL);
714 assert(cache_view->signature == MagickCoreSignature);
715 assert(
id < (
int) cache_view->number_threads);
716 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
717 q=GetAuthenticPixelCacheNexus(cache_view->image,x,y,1,1,
718 cache_view->nexus_info[
id],exception);
719 if (q == (
const Quantum *) NULL)
724 background_color=cache_view->image->background_color;
725 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
726 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
727 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
728 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
729 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
732 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
734 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
772MagickExport MagickBooleanType GetOneCacheViewVirtualPixel(
773 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,Quantum *pixel,
777 id = GetOpenMPThreadId();
785 assert(cache_view != (
CacheView *) NULL);
786 assert(cache_view->signature == MagickCoreSignature);
787 assert(
id < (
int) cache_view->number_threads);
788 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
789 p=GetVirtualPixelCacheNexus(cache_view->image,
790 cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[
id],
792 if (p == (
const Quantum *) NULL)
797 background_color=cache_view->image->background_color;
798 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
799 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
800 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
801 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
802 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
805 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
807 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
845MagickExport MagickBooleanType GetOneCacheViewVirtualPixelInfo(
850 id = GetOpenMPThreadId();
855 assert(cache_view != (
CacheView *) NULL);
856 assert(cache_view->signature == MagickCoreSignature);
857 assert(
id < (
int) cache_view->number_threads);
858 GetPixelInfo(cache_view->image,pixel);
859 p=GetVirtualPixelCacheNexus(cache_view->image,
860 cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[
id],
862 if (p == (
const Quantum *) NULL)
864 GetPixelInfoPixel(cache_view->image,p,pixel);
904MagickExport MagickBooleanType GetOneCacheViewVirtualMethodPixel(
905 const CacheView *cache_view,
const VirtualPixelMethod virtual_pixel_method,
906 const ssize_t x,
const ssize_t y,Quantum *pixel,
ExceptionInfo *exception)
909 id = GetOpenMPThreadId();
917 assert(cache_view != (
CacheView *) NULL);
918 assert(cache_view->signature == MagickCoreSignature);
919 assert(
id < (
int) cache_view->number_threads);
920 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
921 p=GetVirtualPixelCacheNexus(cache_view->image,virtual_pixel_method,x,y,1,1,
922 cache_view->nexus_info[
id],exception);
923 if (p == (
const Quantum *) NULL)
928 background_color=cache_view->image->background_color;
929 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
930 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
931 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
932 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
933 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
936 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
938 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
976MagickExport Quantum *QueueCacheViewAuthenticPixels(
CacheView *cache_view,
977 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
981 id = GetOpenMPThreadId();
984 *magick_restrict pixels;
986 assert(cache_view != (
CacheView *) NULL);
987 assert(cache_view->signature == MagickCoreSignature);
988 assert(
id < (
int) cache_view->number_threads);
989 pixels=QueueAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
990 MagickFalse,cache_view->nexus_info[
id],exception);
1022MagickExport MagickBooleanType SetCacheViewStorageClass(
CacheView *cache_view,
1025 assert(cache_view != (
CacheView *) NULL);
1026 assert(cache_view->signature == MagickCoreSignature);
1027 if (IsEventLogging() != MagickFalse)
1028 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1029 cache_view->image->filename);
1030 return(SetImageStorageClass(cache_view->image,storage_class,exception));
1059MagickExport MagickBooleanType SetCacheViewVirtualPixelMethod(
1061 const VirtualPixelMethod virtual_pixel_method)
1063 assert(cache_view != (
CacheView *) NULL);
1064 assert(cache_view->signature == MagickCoreSignature);
1065 if (IsEventLogging() != MagickFalse)
1066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1067 cache_view->image->filename);
1068 cache_view->virtual_pixel_method=virtual_pixel_method;
1099MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(
1103 id = GetOpenMPThreadId();
1108 assert(cache_view != (
CacheView *) NULL);
1109 assert(cache_view->signature == MagickCoreSignature);
1110 assert(
id < (
int) cache_view->number_threads);
1111 status=SyncAuthenticPixelCacheNexus(cache_view->image,
1112 cache_view->nexus_info[
id],exception);