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;
179 if (cache_view->nexus_info == (
NexusInfo **) NULL)
180 ThrowFatalException(CacheFatalError,
"UnableToAcquireCacheView");
209 *magick_restrict clone_view;
211 assert(cache_view != (
CacheView *) NULL);
212 assert(cache_view->signature == MagickCoreSignature);
213 if (IsEventLogging() != MagickFalse)
214 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
215 cache_view->image->filename);
216 clone_view=(
CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
217 sizeof(*clone_view)));
219 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
220 (void) memset(clone_view,0,
sizeof(*clone_view));
221 clone_view->image=ReferenceImage(cache_view->image);
222 clone_view->number_threads=cache_view->number_threads;
223 clone_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
224 clone_view->virtual_pixel_method=cache_view->virtual_pixel_method;
225 clone_view->debug=cache_view->debug;
226 clone_view->signature=MagickCoreSignature;
255 assert(cache_view != (
CacheView *) NULL);
256 assert(cache_view->signature == MagickCoreSignature);
257 if (IsEventLogging() != MagickFalse)
258 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
259 cache_view->image->filename);
260 if (cache_view->nexus_info != (
NexusInfo **) NULL)
261 cache_view->nexus_info=DestroyPixelCacheNexus(cache_view->nexus_info,
262 cache_view->number_threads);
263 cache_view->image=DestroyImage(cache_view->image);
264 cache_view->signature=(~MagickCoreSignature);
265 cache_view=(
CacheView *) RelinquishAlignedMemory(cache_view);
300MagickExport Quantum *GetCacheViewAuthenticPixels(
CacheView *cache_view,
301 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
305 id = GetOpenMPThreadId();
308 *magick_restrict pixels;
310 assert(cache_view != (
CacheView *) NULL);
311 assert(cache_view->signature == MagickCoreSignature);
312 assert(
id < (
int) cache_view->number_threads);
313 pixels=GetAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
314 cache_view->nexus_info[
id],exception);
343MagickExport
void *GetCacheViewAuthenticMetacontent(
CacheView *cache_view)
346 id = GetOpenMPThreadId();
348 assert(cache_view != (
CacheView *) NULL);
349 assert(cache_view->signature == MagickCoreSignature);
350 assert(cache_view->image->cache != (Cache) NULL);
351 assert(
id < (
int) cache_view->number_threads);
352 return(cache_view->nexus_info[
id]->metacontent);
380MagickExport Quantum *GetCacheViewAuthenticPixelQueue(
CacheView *cache_view)
383 id = GetOpenMPThreadId();
385 assert(cache_view != (
CacheView *) NULL);
386 assert(cache_view->signature == MagickCoreSignature);
387 assert(cache_view->image->cache != (Cache) NULL);
388 assert(
id < (
int) cache_view->number_threads);
389 return(cache_view->nexus_info[
id]->pixels);
415MagickExport ColorspaceType GetCacheViewColorspace(
const CacheView *cache_view)
417 assert(cache_view != (
CacheView *) NULL);
418 assert(cache_view->signature == MagickCoreSignature);
419 if (IsEventLogging() != MagickFalse)
420 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
421 cache_view->image->filename);
422 return(GetPixelCacheColorspace(cache_view->image->cache));
449MagickExport MagickSizeType GetCacheViewExtent(
const CacheView *cache_view)
452 id = GetOpenMPThreadId();
457 assert(cache_view != (
CacheView *) NULL);
458 assert(cache_view->signature == MagickCoreSignature);
459 if (IsEventLogging() != MagickFalse)
460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
461 cache_view->image->filename);
462 assert(cache_view->image->cache != (Cache) NULL);
463 assert(
id < (
int) cache_view->number_threads);
464 extent=GetPixelCacheNexusExtent(cache_view->image->cache,
465 cache_view->nexus_info[
id]);
491MagickExport
const Image *GetCacheViewImage(
const CacheView *cache_view)
493 assert(cache_view != (
CacheView *) NULL);
494 assert(cache_view->signature == MagickCoreSignature);
495 if (IsEventLogging() != MagickFalse)
496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
497 cache_view->image->filename);
498 return(cache_view->image);
524MagickExport ClassType GetCacheViewStorageClass(
const CacheView *cache_view)
526 assert(cache_view != (
CacheView *) NULL);
527 assert(cache_view->signature == MagickCoreSignature);
528 if (IsEventLogging() != MagickFalse)
529 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
530 cache_view->image->filename);
531 return(GetPixelCacheStorageClass(cache_view->image->cache));
559MagickExport
const void *GetCacheViewVirtualMetacontent(
563 id = GetOpenMPThreadId();
566 *magick_restrict metacontent;
568 assert(cache_view != (
const 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 metacontent=GetVirtualMetacontentFromNexus(cache_view->image->cache,
573 cache_view->nexus_info[
id]);
602MagickExport
const Quantum *GetCacheViewVirtualPixelQueue(
606 id = GetOpenMPThreadId();
609 *magick_restrict pixels;
611 assert(cache_view != (
const CacheView *) NULL);
612 assert(cache_view->signature == MagickCoreSignature);
613 assert(cache_view->image->cache != (Cache) NULL);
614 assert(
id < (
int) cache_view->number_threads);
615 pixels=GetVirtualPixelsNexus(cache_view->image->cache,
616 cache_view->nexus_info[
id]);
652MagickExport
const Quantum *GetCacheViewVirtualPixels(
653 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,
654 const size_t columns,
const size_t rows,
ExceptionInfo *exception)
657 id = GetOpenMPThreadId();
660 *magick_restrict pixels;
662 assert(cache_view != (
CacheView *) NULL);
663 assert(cache_view->signature == MagickCoreSignature);
664 assert(
id < (
int) cache_view->number_threads);
665 pixels=GetVirtualPixelCacheNexus(cache_view->image,
666 cache_view->virtual_pixel_method,x,y,columns,rows,
667 cache_view->nexus_info[
id],exception);
702MagickExport MagickBooleanType GetOneCacheViewAuthenticPixel(
703 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,Quantum *pixel,
707 id = GetOpenMPThreadId();
715 assert(cache_view != (
CacheView *) NULL);
716 assert(cache_view->signature == MagickCoreSignature);
717 assert(
id < (
int) cache_view->number_threads);
718 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
719 q=GetAuthenticPixelCacheNexus(cache_view->image,x,y,1,1,
720 cache_view->nexus_info[
id],exception);
721 if (q == (
const Quantum *) NULL)
726 background_color=cache_view->image->background_color;
727 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
728 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
729 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
730 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
731 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
734 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
736 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
774MagickExport MagickBooleanType GetOneCacheViewVirtualPixel(
775 const CacheView *cache_view,
const ssize_t x,
const ssize_t y,Quantum *pixel,
779 id = GetOpenMPThreadId();
787 assert(cache_view != (
CacheView *) NULL);
788 assert(cache_view->signature == MagickCoreSignature);
789 assert(
id < (
int) cache_view->number_threads);
790 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
791 p=GetVirtualPixelCacheNexus(cache_view->image,
792 cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[
id],
794 if (p == (
const Quantum *) NULL)
799 background_color=cache_view->image->background_color;
800 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
801 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
802 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
803 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
804 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
807 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
809 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
847MagickExport MagickBooleanType GetOneCacheViewVirtualPixelInfo(
852 id = GetOpenMPThreadId();
857 assert(cache_view != (
CacheView *) NULL);
858 assert(cache_view->signature == MagickCoreSignature);
859 assert(
id < (
int) cache_view->number_threads);
860 GetPixelInfo(cache_view->image,pixel);
861 p=GetVirtualPixelCacheNexus(cache_view->image,
862 cache_view->virtual_pixel_method,x,y,1,1,cache_view->nexus_info[
id],
864 if (p == (
const Quantum *) NULL)
866 GetPixelInfoPixel(cache_view->image,p,pixel);
906MagickExport MagickBooleanType GetOneCacheViewVirtualMethodPixel(
907 const CacheView *cache_view,
const VirtualPixelMethod virtual_pixel_method,
908 const ssize_t x,
const ssize_t y,Quantum *pixel,
ExceptionInfo *exception)
911 id = GetOpenMPThreadId();
919 assert(cache_view != (
CacheView *) NULL);
920 assert(cache_view->signature == MagickCoreSignature);
921 assert(
id < (
int) cache_view->number_threads);
922 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
923 p=GetVirtualPixelCacheNexus(cache_view->image,virtual_pixel_method,x,y,1,1,
924 cache_view->nexus_info[
id],exception);
925 if (p == (
const Quantum *) NULL)
930 background_color=cache_view->image->background_color;
931 pixel[RedPixelChannel]=ClampToQuantum(background_color.red);
932 pixel[GreenPixelChannel]=ClampToQuantum(background_color.green);
933 pixel[BluePixelChannel]=ClampToQuantum(background_color.blue);
934 pixel[BlackPixelChannel]=ClampToQuantum(background_color.black);
935 pixel[AlphaPixelChannel]=ClampToQuantum(background_color.alpha);
938 for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
940 PixelChannel channel = GetPixelChannelChannel(cache_view->image,i);
978MagickExport Quantum *QueueCacheViewAuthenticPixels(
CacheView *cache_view,
979 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
983 id = GetOpenMPThreadId();
986 *magick_restrict pixels;
988 assert(cache_view != (
CacheView *) NULL);
989 assert(cache_view->signature == MagickCoreSignature);
990 assert(
id < (
int) cache_view->number_threads);
991 pixels=QueueAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
992 MagickFalse,cache_view->nexus_info[
id],exception);
1024MagickExport MagickBooleanType SetCacheViewStorageClass(
CacheView *cache_view,
1027 assert(cache_view != (
CacheView *) NULL);
1028 assert(cache_view->signature == MagickCoreSignature);
1029 if (IsEventLogging() != MagickFalse)
1030 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1031 cache_view->image->filename);
1032 return(SetImageStorageClass(cache_view->image,storage_class,exception));
1061MagickExport MagickBooleanType SetCacheViewVirtualPixelMethod(
1063 const VirtualPixelMethod virtual_pixel_method)
1065 assert(cache_view != (
CacheView *) NULL);
1066 assert(cache_view->signature == MagickCoreSignature);
1067 if (IsEventLogging() != MagickFalse)
1068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1069 cache_view->image->filename);
1070 cache_view->virtual_pixel_method=virtual_pixel_method;
1101MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(
1105 id = GetOpenMPThreadId();
1110 assert(cache_view != (
CacheView *) NULL);
1111 assert(cache_view->signature == MagickCoreSignature);
1112 assert(
id < (
int) cache_view->number_threads);
1113 status=SyncAuthenticPixelCacheNexus(cache_view->image,
1114 cache_view->nexus_info[
id],exception);