77 #if defined(MAGICKCORE_ZLIB_DELEGATE) 84 #define CacheTick(offset,extent) QuantumTick((MagickOffsetType) offset,extent) 85 #define IsFileDescriptorLimitExceeded() (GetMagickResource(FileResource) > \ 86 GetMagickResourceLimit(FileResource) ? MagickTrue : MagickFalse) 101 #if defined(__cplusplus) || defined(c_plusplus) 140 const ssize_t,
const ssize_t,
const size_t,
const size_t,
144 #if defined(MAGICKCORE_OPENCL_SUPPORT) 149 #if defined(__cplusplus) || defined(c_plusplus) 198 (void) memset(cache_info,0,
sizeof(*cache_info));
201 cache_info->disk_mode=
IOMode;
203 cache_info->file=(-1);
205 cache_info->number_threads=number_threads;
210 if (cache_info->number_threads == 0)
211 cache_info->number_threads=1;
213 if (cache_info->nexus_info == (
NexusInfo **) NULL)
216 if (value != (
const char *) NULL)
222 if (value != (
const char *) NULL)
232 cache_info->reference_count=1;
236 return((
Cache ) cache_info);
270 number_threads,
sizeof(*nexus_info)));
274 2*
sizeof(**nexus_info));
277 (void) memset(*nexus_info,0,2*number_threads*
sizeof(**nexus_info));
278 for (i=0; i < (ssize_t) (2*number_threads); i++)
280 nexus_info[i]=(*nexus_info+i);
281 if (i < (ssize_t) number_threads)
282 nexus_info[i]->virtual_nexus=(*nexus_info+number_threads+i);
322 assert(image != (
const Image *) NULL);
332 return((
void *) NULL);
333 *length=(size_t) cache_info->length;
334 return(cache_info->pixels);
440 if (cache_info == (
Cache) NULL)
453 for (x=0; x < (ssize_t) nexus_info->
region.
width; x++)
513 assert(cache != NULL);
518 cache_info->filename);
520 clone_info->virtual_pixel_method=cache_info->virtual_pixel_method;
521 return((
Cache ) clone_info);
555 assert(clone != (
Cache) NULL);
560 source_info->filename);
561 assert(cache != (
Cache) NULL);
564 source_info->methods=cache_info->methods;
620 if ((lseek(cache_info->file,0,SEEK_SET) < 0) ||
621 (lseek(clone_info->file,0,SEEK_SET) < 0))
624 if ((fstat(cache_info->file,&file_stats) == 0) && (file_stats.st_size > 0))
626 #if defined(MAGICKCORE_HAVE_LINUX_SENDFILE) 627 if (cache_info->length < 0x7ffff000)
629 count=sendfile(clone_info->file,cache_info->file,(off_t *) NULL,
630 (
size_t) cache_info->length);
631 if (count == (ssize_t) cache_info->length)
633 if ((lseek(cache_info->file,0,SEEK_SET) < 0) ||
634 (lseek(clone_info->file,0,SEEK_SET) < 0))
641 if (buffer == (
unsigned char *) NULL)
644 while ((count=read(cache_info->file,buffer,quantum)) > 0)
649 number_bytes=write(clone_info->file,buffer,(
size_t) count);
650 if (number_bytes != count)
652 extent+=number_bytes;
655 if (extent != cache_info->length)
664 #define MaxCacheThreads ((size_t) GetMagickResourceLimit(ThreadResource)) 665 #define cache_number_threads(source,destination,chunk,multithreaded) \ 666 num_threads((multithreaded) == 0 ? 1 : \ 667 (((source)->type != MemoryCache) && ((source)->type != MapCache)) || \ 668 (((destination)->type != MemoryCache) && ((destination)->type != MapCache)) ? \ 669 MagickMax(MagickMin(GetMagickResourceLimit(ThreadResource),2),1) : \ 670 MagickMax(MagickMin((ssize_t) GetMagickResourceLimit(ThreadResource),(ssize_t) (chunk)/256),1)) 686 assert(cache_info != (
CacheInfo *) NULL);
687 assert(clone_info != (
CacheInfo *) NULL);
691 length=cache_info->number_channels*
sizeof(*cache_info->channel_map);
692 if ((cache_info->storage_class == clone_info->storage_class) &&
693 (cache_info->colorspace == clone_info->colorspace) &&
694 (cache_info->alpha_trait == clone_info->alpha_trait) &&
695 (cache_info->channels == clone_info->channels) &&
696 (cache_info->columns == clone_info->columns) &&
697 (cache_info->rows == clone_info->rows) &&
698 (cache_info->number_channels == clone_info->number_channels) &&
699 (memcmp(cache_info->channel_map,clone_info->channel_map,length) == 0) &&
700 (cache_info->metacontent_extent == clone_info->metacontent_extent))
709 (void) memcpy(clone_info->pixels,cache_info->pixels,
710 cache_info->number_channels*cache_info->columns*cache_info->rows*
711 sizeof(*cache_info->pixels));
712 if ((cache_info->metacontent_extent != 0) &&
713 (clone_info->metacontent_extent != 0))
714 (void) memcpy(clone_info->metacontent,cache_info->metacontent,
715 cache_info->columns*cache_info->rows*
716 clone_info->metacontent_extent*
sizeof(
unsigned char));
727 length=cache_info->number_channels*
sizeof(*cache_info->channel_map);
728 optimize=(cache_info->number_channels == clone_info->number_channels) &&
729 (memcmp(cache_info->channel_map,clone_info->channel_map,length) == 0) ?
731 length=(size_t)
MagickMin(cache_info->number_channels*cache_info->columns,
732 clone_info->number_channels*clone_info->columns);
734 #if defined(MAGICKCORE_OPENMP_SUPPORT) 735 #pragma omp parallel for schedule(static) shared(status) \ 736 cache_number_threads(cache_info,clone_info,cache_info->rows,1) 738 for (y=0; y < (ssize_t) cache_info->rows; y++)
751 if (y >= (ssize_t) clone_info->rows)
754 cache_info->columns,1,
MagickFalse,cache_nexus[
id],exception);
755 if (pixels == (
Quantum *) NULL)
761 clone_info->columns,1,
MagickFalse,clone_nexus[
id],exception);
762 if (pixels == (
Quantum *) NULL)
764 (void) memset(clone_nexus[
id]->pixels,0,(
size_t) clone_nexus[id]->length);
766 (void) memcpy(clone_nexus[
id]->pixels,cache_nexus[
id]->pixels,length*
779 p=cache_nexus[id]->pixels;
780 q=clone_nexus[id]->pixels;
781 for (x=0; x < (ssize_t) cache_info->columns; x++)
786 if (x == (ssize_t) clone_info->columns)
788 for (i=0; i < (ssize_t) clone_info->number_channels; i++)
796 channel=clone_info->channel_map[i].channel;
797 traits=cache_info->channel_map[channel].traits;
799 *q=*(p+cache_info->channel_map[channel].offset);
802 p+=cache_info->number_channels;
807 if ((cache_info->metacontent_extent != 0) &&
808 (clone_info->metacontent_extent != 0))
813 length=(size_t)
MagickMin(cache_info->metacontent_extent,
814 clone_info->metacontent_extent);
815 #if defined(MAGICKCORE_OPENMP_SUPPORT) 816 #pragma omp parallel for schedule(static) shared(status) \ 817 cache_number_threads(cache_info,clone_info,cache_info->rows,1) 819 for (y=0; y < (ssize_t) cache_info->rows; y++)
829 if (y >= (ssize_t) clone_info->rows)
832 cache_info->columns,1,
MagickFalse,cache_nexus[
id],exception);
833 if (pixels == (
Quantum *) NULL)
839 clone_info->columns,1,
MagickFalse,clone_nexus[
id],exception);
840 if (pixels == (
Quantum *) NULL)
842 if ((clone_nexus[
id]->metacontent != (
void *) NULL) &&
843 (cache_nexus[
id]->metacontent != (
void *) NULL))
844 (void) memcpy(clone_nexus[
id]->metacontent,
845 cache_nexus[
id]->metacontent,length*
sizeof(
unsigned char));
888 assert(image != (
Image *) NULL);
892 if (image->
cache != (
void *) NULL)
923 assert(image != (
const Image *) NULL);
932 cache_info->methods.destroy_pixel_handler(image);
967 if (cache_info->
file != -1)
969 status=close(cache_info->
file);
970 cache_info->
file=(-1);
978 switch (cache_info->
type)
982 #if defined(MAGICKCORE_OPENCL_SUPPORT) 985 cache_info->
opencl=RelinquishMagickCLCacheInfo(cache_info->
opencl,
1010 if (cache_info->
file != -1)
1038 assert(cache != (
Cache) NULL);
1043 cache_info->filename);
1045 cache_info->reference_count--;
1046 if (cache_info->reference_count != 0)
1049 return((
Cache) NULL);
1058 cache_info->filename);
1064 cache_info->server_info);
1065 if (cache_info->nexus_info != (
NexusInfo **) NULL)
1067 cache_info->number_threads);
1068 if (cache_info->random_info != (
RandomInfo *) NULL)
1120 const size_t number_threads)
1125 assert(nexus_info != (
NexusInfo **) NULL);
1126 for (i=0; i < (ssize_t) (2*number_threads); i++)
1128 if (nexus_info[i]->cache != (
Quantum *) NULL)
1169 assert(image != (
const Image *) NULL);
1174 if (cache_info->methods.get_authentic_metacontent_from_handler !=
1180 metacontent=cache_info->methods.
1181 get_authentic_metacontent_from_handler(image);
1182 return(metacontent);
1184 assert(
id < (
int) cache_info->number_threads);
1185 return(cache_info->nexus_info[
id]->metacontent);
1220 assert(image != (
const Image *) NULL);
1225 assert(
id < (
int) cache_info->number_threads);
1226 return(cache_info->nexus_info[
id]->metacontent);
1229 #if defined(MAGICKCORE_OPENCL_SUPPORT) 1264 assert(image != (
const Image *) NULL);
1267 if ((cache_info->type ==
UndefinedCache) || (cache_info->reference_count > 1))
1273 return((cl_mem) NULL);
1276 (cache_info->opencl->device->context != device->context))
1277 cache_info->opencl=CopyMagickCLCacheInfo(cache_info->opencl);
1280 assert(cache_info->pixels != (
Quantum *) NULL);
1281 cache_info->opencl=AcquireMagickCLCacheInfo(device,cache_info->pixels,
1282 cache_info->length);
1285 RetainOpenCLMemObject(cache_info->opencl->buffer);
1288 return((cl_mem) NULL);
1289 assert(cache_info->opencl->pixels == cache_info->pixels);
1290 return(cache_info->opencl->buffer);
1330 const ssize_t y,
const size_t columns,
const size_t rows,
NexusInfo *nexus_info,
1342 assert(image != (
Image *) NULL);
1345 nexus_info,exception);
1346 if (pixels == (
Quantum *) NULL)
1354 if (cache_info->metacontent_extent != 0)
1391 assert(image != (
const Image *) NULL);
1396 assert(
id < (
int) cache_info->number_threads);
1397 return(cache_info->nexus_info[
id]->pixels);
1432 assert(image != (
const Image *) NULL);
1437 if (cache_info->methods.get_authentic_pixels_from_handler !=
1439 return(cache_info->methods.get_authentic_pixels_from_handler(image));
1440 assert(
id < (
int) cache_info->number_threads);
1441 return(cache_info->nexus_info[
id]->pixels);
1490 const ssize_t y,
const size_t columns,
const size_t rows,
1502 assert(image != (
Image *) NULL);
1507 if (cache_info->methods.get_authentic_pixels_handler !=
1510 pixels=cache_info->methods.get_authentic_pixels_handler(image,x,y,columns,
1514 assert(
id < (
int) cache_info->number_threads);
1516 cache_info->nexus_info[
id],exception);
1552 const ssize_t y,
const size_t columns,
const size_t rows,
1564 assert(image != (
const Image *) NULL);
1568 if (cache_info == (
Cache) NULL)
1571 assert(
id < (
int) cache_info->number_threads);
1573 cache_info->nexus_info[
id],exception);
1608 assert(image != (
Image *) NULL);
1615 assert(
id < (
int) cache_info->number_threads);
1663 p=image->channel_map;
1664 q=cache_info->channel_map;
1665 if ((image->storage_class != cache_info->storage_class) ||
1666 (image->colorspace != cache_info->colorspace) ||
1667 (image->alpha_trait != cache_info->alpha_trait) ||
1668 (image->channels != cache_info->channels) ||
1669 (image->columns != cache_info->columns) ||
1670 (image->rows != cache_info->rows) ||
1671 (image->number_channels != cache_info->number_channels) ||
1672 (memcmp(p,q,image->number_channels*
sizeof(*p)) != 0) ||
1673 (image->metacontent_extent != cache_info->metacontent_extent) ||
1674 (cache_info->nexus_info == (
NexusInfo **) NULL))
1697 if ((cpu_throttle != 0) && ((cycles++ % 32) == 0))
1699 if (cache_epoch == 0)
1710 #if defined(ECANCELED) 1714 if (cache_info->file != -1)
1721 #
if defined(MAGICKCORE_OPENCL_SUPPORT)
1722 CopyOpenCLBuffer(cache_info);
1725 if ((cache_info->reference_count > 1) || (cache_info->mode ==
ReadMode))
1728 if ((cache_info->reference_count > 1) || (cache_info->mode ==
ReadMode))
1739 clone_image=(*image);
1757 image->
cache=clone_info;
1777 if (cache_info->file != -1)
1783 return((
Cache) NULL);
1784 return(image->
cache);
1815 assert(image != (
Image *) NULL);
1820 return(cache_info->type);
1860 if (source == (
const Quantum *) NULL)
1876 destination[channel]=source[i];
1890 assert(image != (
Image *) NULL);
1897 return(cache_info->methods.get_one_authentic_pixel_from_handler(image,x,y,pixel,exception));
1945 assert(image != (
const Image *) NULL);
1950 assert(
id < (
int) cache_info->number_threads);
2000 assert(image != (
const Image *) NULL);
2006 if (cache_info->methods.get_one_virtual_pixel_from_handler !=
2008 return(cache_info->methods.get_one_virtual_pixel_from_handler(image,
2010 assert(
id < (
int) cache_info->number_threads);
2012 1UL,1UL,cache_info->nexus_info[
id],exception);
2063 assert(image != (
const Image *) NULL);
2068 assert(
id < (
int) cache_info->number_threads);
2071 cache_info->nexus_info[
id],exception);
2122 assert(image != (
const Image *) NULL);
2127 assert(
id < (
int) cache_info->number_threads);
2130 cache_info->nexus_info[
id],exception);
2131 if (p == (
const Quantum *) NULL)
2164 assert(cache != (
Cache) NULL);
2169 cache_info->filename);
2170 return(cache_info->colorspace);
2201 assert(image != (
const Image *) NULL);
2206 return(cache_info->cache_filename);
2234 (void) memset(cache_methods,0,
sizeof(*cache_methods));
2285 assert(cache != NULL);
2288 extent=(
MagickSizeType) nexus_info->region.width*nexus_info->region.height;
2327 assert(image != (
const Image *) NULL);
2335 *length=cache_info->length;
2337 return((
void *) NULL);
2338 return((
void *) cache_info->pixels);
2370 assert(cache != (
Cache) NULL);
2375 cache_info->filename);
2376 return(cache_info->storage_class);
2412 assert(image != (
Image *) NULL);
2453 assert(image != (
Image *) NULL);
2458 return(cache_info->virtual_pixel_method);
2495 assert(image != (
const Image *) NULL);
2500 assert(
id < (
int) cache_info->number_threads);
2502 cache_info->nexus_info[
id]);
2503 return(metacontent);
2538 assert(cache != (
Cache) NULL);
2542 return((
void *) NULL);
2543 return(nexus_info->metacontent);
2581 assert(image != (
const Image *) NULL);
2586 metacontent=cache_info->methods.get_virtual_metacontent_from_handler(image);
2587 if (metacontent != (
void *) NULL)
2588 return(metacontent);
2589 assert(
id < (
int) cache_info->number_threads);
2591 cache_info->nexus_info[
id]);
2592 return(metacontent);
2635 0, 48, 12, 60, 3, 51, 15, 63,
2636 32, 16, 44, 28, 35, 19, 47, 31,
2637 8, 56, 4, 52, 11, 59, 7, 55,
2638 40, 24, 36, 20, 43, 27, 39, 23,
2639 2, 50, 14, 62, 1, 49, 13, 61,
2640 34, 18, 46, 30, 33, 17, 45, 29,
2641 10, 58, 6, 54, 9, 57, 5, 53,
2642 42, 26, 38, 22, 41, 25, 37, 21
2645 static inline ssize_t
DitherX(
const ssize_t x,
const size_t columns)
2653 if (index >= (ssize_t) columns)
2654 return((ssize_t) columns-1L);
2658 static inline ssize_t
DitherY(
const ssize_t y,
const size_t rows)
2666 if (index >= (ssize_t) rows)
2667 return((ssize_t) rows-1L);
2671 static inline ssize_t
EdgeX(
const ssize_t x,
const size_t columns)
2675 if (x >= (ssize_t) columns)
2676 return((ssize_t) (columns-1));
2680 static inline ssize_t
EdgeY(
const ssize_t y,
const size_t rows)
2684 if (y >= (ssize_t) rows)
2685 return((ssize_t) (rows-1));
2700 const size_t extent)
2705 modulo.
quotient=offset/((ssize_t) extent);
2706 modulo.
remainder=offset % ((ssize_t) extent);
2707 if ((modulo.
remainder != 0) && ((offset ^ ((ssize_t) extent)) < 0))
2717 const size_t columns,
const size_t rows,
NexusInfo *nexus_info,
2762 assert(image != (
const Image *) NULL);
2768 return((
const Quantum *) NULL);
2769 #if defined(MAGICKCORE_OPENCL_SUPPORT) 2770 CopyOpenCLBuffer(cache_info);
2775 nexus_info,exception);
2776 if (pixels == (
Quantum *) NULL)
2777 return((
const Quantum *) NULL);
2783 number_pixels=(
MagickSizeType) cache_info->columns*cache_info->rows;
2784 if ((offset >= 0) && (((
MagickSizeType) offset+length) < number_pixels))
2785 if ((x >= 0) && ((ssize_t) (x+columns-1) < (ssize_t) cache_info->columns) &&
2786 (y >= 0) && ((ssize_t) (y+rows-1) < (ssize_t) cache_info->rows))
2798 return((
const Quantum *) NULL);
2799 if (cache_info->metacontent_extent != 0)
2803 return((
const Quantum *) NULL);
2812 (
void) memset(virtual_pixel,0,cache_info->number_channels*
2813 sizeof(*virtual_pixel));
2814 virtual_metacontent=(
void *) NULL;
2815 switch (virtual_pixel_method)
2828 if (cache_info->metacontent_extent != 0)
2834 cache_info->metacontent_extent);
2835 if (virtual_metacontent == (
void *) NULL)
2839 return((
const Quantum *) NULL);
2841 (void) memset(virtual_metacontent,0,cache_info->metacontent_extent);
2843 switch (virtual_pixel_method)
2847 for (i=0; i < (ssize_t) cache_info->number_channels; i++)
2854 for (i=0; i < (ssize_t) cache_info->number_channels; i++)
2862 for (i=0; i < (ssize_t) cache_info->number_channels; i++)
2870 for (i=0; i < (ssize_t) cache_info->number_channels; i++)
2895 for (v=0; v < (ssize_t) rows; v++)
2903 y_offset=
EdgeY(y_offset,cache_info->rows);
2904 for (u=0; u < (ssize_t) columns; u+=length)
2911 if (((x_offset < 0) || (x_offset >= (ssize_t) cache_info->columns)) ||
2912 ((y_offset < 0) || (y_offset >= (ssize_t) cache_info->rows)) ||
2923 switch (virtual_pixel_method)
2929 EdgeX(x_offset,cache_info->columns),
2930 EdgeY(y_offset,cache_info->rows),1UL,1UL,virtual_nexus,
2938 if (cache_info->random_info == (
RandomInfo *) NULL)
2941 RandomX(cache_info->random_info,cache_info->columns),
2942 RandomY(cache_info->random_info,cache_info->rows),1UL,1UL,
2943 virtual_nexus,exception);
2950 DitherX(x_offset,cache_info->columns),
2951 DitherY(y_offset,cache_info->rows),1UL,1UL,virtual_nexus,
2969 if ((x_modulo.
quotient & 0x01) == 1L)
2970 x_modulo.
remainder=(ssize_t) cache_info->columns-
2973 if ((y_modulo.
quotient & 0x01) == 1L)
2974 y_modulo.
remainder=(ssize_t) cache_info->rows-
2987 virtual_nexus,exception);
2996 virtual_nexus,exception);
3008 r=virtual_metacontent;
3018 r=virtual_metacontent;
3029 if ((y_offset < 0) || (y_offset >= (ssize_t) cache_info->rows))
3032 r=virtual_metacontent;
3045 if ((x_offset < 0) || (x_offset >= (ssize_t) cache_info->columns))
3048 r=virtual_metacontent;
3060 if (p == (
const Quantum *) NULL)
3062 (void) memcpy(q,p,(
size_t) (cache_info->number_channels*length*
3064 q+=cache_info->number_channels;
3065 if ((s != (
void *) NULL) && (r != (
const void *) NULL))
3067 (void) memcpy(s,r,(
size_t) cache_info->metacontent_extent);
3068 s+=cache_info->metacontent_extent;
3076 (
size_t) length,1UL,virtual_nexus,exception);
3077 if (p == (
const Quantum *) NULL)
3080 (void) memcpy(q,p,(
size_t) (cache_info->number_channels*length*
3082 q+=cache_info->number_channels*length;
3083 if ((r != (
void *) NULL) && (s != (
const void *) NULL))
3085 (void) memcpy(s,r,(
size_t) length);
3086 s+=length*cache_info->metacontent_extent;
3089 if (u < (ssize_t) columns)
3095 if (virtual_metacontent != (
void *) NULL)
3097 if (v < (ssize_t) rows)
3098 return((
const Quantum *) NULL);
3138 const size_t columns,
const size_t rows,
ExceptionInfo *exception)
3149 assert(image != (
const Image *) NULL);
3154 assert(
id < (
int) cache_info->number_threads);
3156 cache_info->nexus_info[
id],exception);
3191 assert(image != (
const Image *) NULL);
3196 if (cache_info->methods.get_virtual_pixels_handler !=
3198 return(cache_info->methods.get_virtual_pixels_handler(image));
3199 assert(
id < (
int) cache_info->number_threads);
3252 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
3264 assert(image != (
const Image *) NULL);
3269 if (cache_info->methods.get_virtual_pixel_handler !=
3271 return(cache_info->methods.get_virtual_pixel_handler(image,
3273 assert(
id < (
int) cache_info->number_threads);
3275 columns,rows,cache_info->nexus_info[
id],exception);
3310 assert(image != (
const Image *) NULL);
3315 assert(
id < (
int) cache_info->number_threads);
3351 assert(cache != (
Cache) NULL);
3356 return((
const Quantum *) nexus_info->pixels);
3430 if (cache_info == (
Cache) NULL)
3438 for (y=0; y < (ssize_t) nexus_info->
region.
height; y++)
3443 for (x=0; x < (ssize_t) nexus_info->
region.
width; x++)
3508 if ((cache_info->
file != -1) && (cache_info->
disk_mode == mode))
3541 if (cache_info->
file != -1)
3543 cache_info->
file=file;
3558 #if !defined(MAGICKCORE_HAVE_PWRITE) 3559 if (lseek(cache_info->file,offset,SEEK_SET) < 0)
3565 #if !defined(MAGICKCORE_HAVE_PWRITE) 3566 count=write(cache_info->file,buffer+i,(
size_t)
MagickMin(length-i,(
size_t)
3569 count=pwrite(cache_info->file,buffer+i,(
size_t)
MagickMin(length-i,(
size_t)
3601 "extend %s (%s[%d], disk, %s)",cache_info->filename,
3602 cache_info->cache_filename,cache_info->file,format);
3619 #if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE) 3621 if (posix_fallocate(cache_info->file,offset+1,extent-offset) != 0)
3657 assert(image != (
const Image *) NULL);
3672 if (value == (
char *) NULL)
3676 #if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS) 3681 "'%s' (policy requires anonymous memory mapping)",image->
filename);
3701 source_info=(*cache_info);
3702 source_info.file=(-1);
3708 cache_info->channels=image->
channels;
3709 cache_info->rows=image->
rows;
3710 cache_info->columns=image->
columns;
3716 cache_info->mode=mode;
3717 number_pixels=(
MagickSizeType) cache_info->columns*cache_info->rows;
3718 packet_size=cache_info->number_channels*
sizeof(
Quantum);
3720 packet_size+=cache_info->metacontent_extent;
3721 length=number_pixels*packet_size;
3722 columns=(size_t) (length/cache_info->rows/packet_size);
3723 if ((cache_info->columns != columns) || ((ssize_t) cache_info->columns < 0) ||
3724 ((ssize_t) cache_info->rows < 0))
3727 cache_info->length=length;
3734 cache_info->columns*cache_info->rows);
3737 length=number_pixels*(cache_info->number_channels*
sizeof(
Quantum)+
3738 cache_info->metacontent_extent);
3758 cache_info->length);
3760 if (cache_info->pixels == (
Quantum *) NULL)
3762 cache_info->mapped=source_info.mapped;
3763 cache_info->pixels=source_info.pixels;
3771 cache_info->metacontent=(
void *) NULL;
3772 if (cache_info->metacontent_extent != 0)
3773 cache_info->metacontent=(
void *) (cache_info->pixels+
3774 cache_info->number_channels*number_pixels);
3789 "open %s (%s %s, %.20gx%.20gx%.20g %s)",
3790 cache_info->filename,cache_info->mapped !=
MagickFalse ?
3791 "Anonymous" :
"Heap",type,(
double) cache_info->columns,
3792 (double) cache_info->rows,(
double)
3793 cache_info->number_channels,format);
3810 if ((status ==
MagickFalse) && (hosts != (
const char *) NULL))
3835 cache_info->server_info=server_info;
3840 cache_info->server_info));
3855 "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",
3856 cache_info->filename,cache_info->cache_filename,
3858 cache_info->server_info),type,(double) cache_info->columns,
3859 (
double) cache_info->rows,(double)
3860 cache_info->number_channels,format);
3874 "CacheResourcesExhausted",
"`%s'",image->
filename);
3884 "CacheResourcesExhausted",
"`%s'",image->
filename);
3891 *cache_info->cache_filename=
'\0';
3901 cache_info->length);
3910 length=number_pixels*(cache_info->number_channels*
sizeof(
Quantum)+
3911 cache_info->metacontent_extent);
3918 cache_info->offset,(
size_t) cache_info->length);
3919 if (cache_info->pixels == (
Quantum *) NULL)
3921 cache_info->mapped=source_info.mapped;
3922 cache_info->pixels=source_info.pixels;
3933 cache_info->metacontent=(
void *) NULL;
3934 if (cache_info->metacontent_extent != 0)
3935 cache_info->metacontent=(
void *) (cache_info->pixels+
3936 cache_info->number_channels*number_pixels);
3951 "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",
3952 cache_info->filename,cache_info->cache_filename,
3953 cache_info->file,type,(
double) cache_info->columns,
3954 (double) cache_info->rows,(
double)
3955 cache_info->number_channels,format);
3981 "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",cache_info->filename,
3982 cache_info->cache_filename,cache_info->file,type,(
double)
3983 cache_info->columns,(double) cache_info->rows,(
double)
3984 cache_info->number_channels,format);
4046 assert(image != (
Image *) NULL);
4050 assert(image->
cache != (
void *) NULL);
4051 assert(filename != (
const char *) NULL);
4056 #if defined(MAGICKCORE_OPENCL_SUPPORT) 4057 CopyOpenCLBuffer(cache_info);
4066 "attach persistent cache");
4070 cache_info->offset=(*offset);
4073 *offset+=cache_info->length+page_size-(cache_info->length % page_size);
4083 "CacheResourcesExhausted",
"`%s'",image->
filename);
4089 clone_info->file=(-1);
4090 clone_info->storage_class=cache_info->storage_class;
4091 clone_info->colorspace=cache_info->colorspace;
4092 clone_info->alpha_trait=cache_info->alpha_trait;
4093 clone_info->channels=cache_info->channels;
4094 clone_info->columns=cache_info->columns;
4095 clone_info->rows=cache_info->rows;
4096 clone_info->number_channels=cache_info->number_channels;
4097 clone_info->metacontent_extent=cache_info->metacontent_extent;
4099 clone_info->length=cache_info->length;
4100 (void) memcpy(clone_info->channel_map,cache_info->channel_map,
4102 clone_info->offset=(*offset);
4104 *offset+=cache_info->length+page_size-(cache_info->length % page_size);
4148 const ssize_t x,
const ssize_t y,
const size_t columns,
const size_t rows,
4166 assert(image != (
const Image *) NULL);
4170 if (cache_info == (
Cache) NULL)
4173 if ((cache_info->columns == 0) || (cache_info->rows == 0) || (x < 0) ||
4174 (y < 0) || (x >= (ssize_t) cache_info->columns) ||
4175 (y >= (ssize_t) cache_info->rows))
4178 "PixelsAreNotAuthentic",
"`%s'",image->
filename);
4184 number_pixels=(
MagickSizeType) cache_info->columns*cache_info->rows;
4194 nexus_info,exception);
4232 const ssize_t y,
const size_t columns,
const size_t rows,
4244 assert(image != (
const Image *) NULL);
4249 assert(
id < (
int) cache_info->number_threads);
4251 cache_info->nexus_info[
id],exception);
4312 const ssize_t y,
const size_t columns,
const size_t rows,
4324 assert(image != (
Image *) NULL);
4329 if (cache_info->methods.queue_authentic_pixels_handler !=
4332 pixels=cache_info->methods.queue_authentic_pixels_handler(image,x,y,
4333 columns,rows,exception);
4336 assert(
id < (
int) cache_info->number_threads);
4338 cache_info->nexus_info[
id],exception);
4381 #if !defined(MAGICKCORE_HAVE_PREAD) 4382 if (lseek(cache_info->file,offset,SEEK_SET) < 0)
4388 #if !defined(MAGICKCORE_HAVE_PREAD) 4389 count=read(cache_info->file,buffer+i,(
size_t)
MagickMin(length-i,(
size_t)
4392 count=pread(cache_info->file,buffer+i,(
size_t)
MagickMin(length-i,(
size_t)
4426 if (cache_info->metacontent_extent == 0)
4428 if (nexus_info->authentic_pixel_cache !=
MagickFalse)
4431 nexus_info->region.x;
4433 cache_info->metacontent_extent;
4434 extent=length*nexus_info->region.height;
4435 rows=nexus_info->region.height;
4437 q=(
unsigned char *) nexus_info->metacontent;
4438 switch (cache_info->type)
4449 if ((cache_info->columns == nexus_info->region.width) &&
4455 p=(
unsigned char *) cache_info->metacontent+offset*
4456 cache_info->metacontent_extent;
4457 for (y=0; y < (ssize_t) rows; y++)
4459 (void) memcpy(q,p,(
size_t) length);
4460 p+=cache_info->metacontent_extent*cache_info->columns;
4461 q+=cache_info->metacontent_extent*nexus_info->region.width;
4474 cache_info->cache_filename);
4478 if ((cache_info->columns == nexus_info->region.width) &&
4485 for (y=0; y < (ssize_t) rows; y++)
4488 cache_info->number_channels*
sizeof(
Quantum)+offset*
4489 cache_info->metacontent_extent,length,(
unsigned char *) q);
4492 offset+=cache_info->columns;
4493 q+=cache_info->metacontent_extent*nexus_info->region.width;
4509 region=nexus_info->region;
4510 if ((cache_info->columns != nexus_info->region.width) ||
4518 for (y=0; y < (ssize_t) rows; y++)
4521 cache_info->server_info,®ion,length,(
unsigned char *) q);
4524 q+=cache_info->metacontent_extent*nexus_info->region.width;
4533 if (y < (ssize_t) rows)
4536 cache_info->cache_filename);
4542 "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double)
4543 nexus_info->region.width,(
double) nexus_info->region.height,(double)
4544 nexus_info->region.x,(
double) nexus_info->region.y);
4598 if (nexus_info->authentic_pixel_cache !=
MagickFalse)
4601 if ((ssize_t) (offset/cache_info->columns) != nexus_info->region.y)
4603 offset+=nexus_info->region.x;
4604 number_channels=cache_info->number_channels;
4605 length=(
MagickSizeType) number_channels*nexus_info->region.width*
4607 if ((length/number_channels/
sizeof(
Quantum)) != nexus_info->region.width)
4609 rows=nexus_info->region.height;
4611 if ((extent == 0) || ((extent/length) != rows))
4614 q=nexus_info->pixels;
4615 switch (cache_info->type)
4626 if ((cache_info->columns == nexus_info->region.width) &&
4632 p=cache_info->pixels+cache_info->number_channels*offset;
4633 for (y=0; y < (ssize_t) rows; y++)
4635 (void) memcpy(q,p,(
size_t) length);
4636 p+=cache_info->number_channels*cache_info->columns;
4637 q+=cache_info->number_channels*nexus_info->region.width;
4650 cache_info->cache_filename);
4654 if ((cache_info->columns == nexus_info->region.width) &&
4660 for (y=0; y < (ssize_t) rows; y++)
4663 cache_info->number_channels*
sizeof(*q),length,(
unsigned char *) q);
4666 offset+=cache_info->columns;
4667 q+=cache_info->number_channels*nexus_info->region.width;
4683 region=nexus_info->region;
4684 if ((cache_info->columns != nexus_info->region.width) ||
4692 for (y=0; y < (ssize_t) rows; y++)
4695 cache_info->server_info,®ion,length,(
unsigned char *) q);
4698 q+=cache_info->number_channels*nexus_info->region.width;
4707 if (y < (ssize_t) rows)
4710 cache_info->cache_filename);
4716 "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->filename,(double)
4717 nexus_info->region.width,(
double) nexus_info->region.height,(double)
4718 nexus_info->region.x,(
double) nexus_info->region.y);
4750 assert(cache != (
Cache *) NULL);
4754 cache_info->reference_count++;
4786 assert(image != (
const Image *) NULL);
4870 get_one_authentic_pixel_from_handler;
4873 get_one_virtual_pixel_from_handler;
4878 assert(cache != (
Cache) NULL);
4884 cache_info->filename);
4886 cache_info->methods.get_virtual_pixel_handler=
4889 cache_info->methods.destroy_pixel_handler=
4893 cache_info->methods.get_virtual_metacontent_from_handler=
4897 cache_info->methods.get_authentic_pixels_handler=
4901 cache_info->methods.queue_authentic_pixels_handler=
4905 cache_info->methods.sync_authentic_pixels_handler=
4909 cache_info->methods.get_authentic_pixels_from_handler=
4913 cache_info->methods.get_authentic_metacontent_from_handler=
4915 get_one_virtual_pixel_from_handler=
4916 cache_info->methods.get_one_virtual_pixel_from_handler;
4917 if (get_one_virtual_pixel_from_handler !=
4919 cache_info->methods.get_one_virtual_pixel_from_handler=
4921 get_one_authentic_pixel_from_handler=
4923 if (get_one_authentic_pixel_from_handler !=
4925 cache_info->methods.get_one_authentic_pixel_from_handler=
4975 cache_info->filename);
4978 nexus_info->length=0;
4984 if (nexus_info->cache != (
Quantum *) NULL)
4985 (
void) memset(nexus_info->cache,0,(
size_t) length);
4990 if (nexus_info->cache != (
Quantum *) NULL)
4993 if (nexus_info->cache == (
Quantum *) NULL)
4997 cache_info->filename);
5000 nexus_info->length=length;
5030 const ssize_t x,
const ssize_t y,
const size_t width,
const size_t height,
5041 assert(cache_info != (
const CacheInfo *) NULL);
5046 (void) memset(&nexus_info->region,0,
sizeof(nexus_info->region));
5047 if ((width == 0) || (height == 0))
5050 "NoPixelsDefinedInCache",
"`%s'",cache_info->filename);
5059 "WidthOrHeightExceedsLimit",
"`%s'",cache_info->filename);
5065 if (((x >= 0) && (y >= 0) &&
5066 (((ssize_t) height+y-1) < (ssize_t) cache_info->rows)) &&
5067 (((x == 0) && (width == cache_info->columns)) || ((height == 1) &&
5068 (((ssize_t) width+x-1) < (ssize_t) cache_info->columns))))
5077 nexus_info->pixels=cache_info->pixels+cache_info->number_channels*
5079 nexus_info->metacontent=(
void *) NULL;
5080 if (cache_info->metacontent_extent != 0)
5081 nexus_info->metacontent=(
unsigned char *) cache_info->metacontent+
5082 offset*cache_info->metacontent_extent;
5083 nexus_info->region.width=width;
5084 nexus_info->region.height=height;
5085 nexus_info->region.x=x;
5086 nexus_info->region.y=y;
5087 nexus_info->authentic_pixel_cache=
MagickTrue;
5089 return(nexus_info->pixels);
5097 cache_info->rows))*cache_info->number_channels*
sizeof(*nexus_info->pixels);
5098 if (cache_info->metacontent_extent != 0)
5099 length+=number_pixels*cache_info->metacontent_extent;
5101 if (nexus_info->cache == (
Quantum *) NULL)
5104 if (nexus_info->length < length)
5111 nexus_info->pixels=nexus_info->cache;
5112 nexus_info->metacontent=(
void *) NULL;
5113 if (cache_info->metacontent_extent != 0)
5114 nexus_info->metacontent=(
void *) (nexus_info->pixels+
5115 cache_info->number_channels*number_pixels);
5116 nexus_info->region.width=width;
5117 nexus_info->region.height=height;
5118 nexus_info->region.x=x;
5119 nexus_info->region.y=y;
5120 nexus_info->authentic_pixel_cache=cache_info->type ==
PingCache ?
5123 return(nexus_info->pixels);
5171 assert(image != (
Image *) NULL);
5181 #if defined(MAGICKCORE_OPENMP_SUPPORT) 5182 #pragma omp parallel for schedule(static) shared(status) \ 5183 magick_number_threads(image,image,image->rows,1) 5185 for (y=0; y < (ssize_t) image->
rows; y++)
5201 for (x=0; x < (ssize_t) image->
columns; x++)
5221 assert(image != (
Image *) NULL);
5228 method=cache_info->virtual_pixel_method;
5229 cache_info->virtual_pixel_method=virtual_pixel_method;
5231 switch (virtual_pixel_method)
5255 #if defined(MAGICKCORE_OPENCL_SUPPORT) 5282 assert(cache_info != (
CacheInfo *) NULL);
5291 cache_info->opencl=CopyMagickCLCacheInfo(cache_info->opencl);
5300 assert(image != (
const Image *) NULL);
5302 CopyOpenCLBuffer(cache_info);
5347 assert(image != (
Image *) NULL);
5364 if (nexus_info->authentic_pixel_cache !=
MagickFalse)
5372 if ((cache_info->metacontent_extent != 0) &&
5419 assert(image != (
Image *) NULL);
5424 assert(
id < (
int) cache_info->number_threads);
5469 assert(image != (
Image *) NULL);
5476 status=cache_info->methods.sync_authentic_pixels_handler(image,
5480 assert(
id < (
int) cache_info->number_threads);
5519 assert(image != (
Image *) NULL);
5575 if (nexus_info->authentic_pixel_cache !=
MagickFalse)
5578 nexus_info->region.x;
5582 rows=nexus_info->region.height;
5584 p=(
unsigned char *) nexus_info->metacontent;
5585 switch (cache_info->
type)
5596 if ((cache_info->
columns == nexus_info->region.width) &&
5602 q=(
unsigned char *) cache_info->
metacontent+offset*
5604 for (y=0; y < (ssize_t) rows; y++)
5606 (void) memcpy(q,p,(
size_t) length);
5625 if ((cache_info->
columns == nexus_info->region.width) &&
5632 for (y=0; y < (ssize_t) rows; y++)
5656 region=nexus_info->region;
5657 if ((cache_info->
columns != nexus_info->region.width) ||
5665 for (y=0; y < (ssize_t) rows; y++)
5668 cache_info->
server_info,®ion,length,(
const unsigned char *) p);
5680 if (y < (ssize_t) rows)
5689 "%s[%.20gx%.20g%+.20g%+.20g]",cache_info->
filename,(double)
5690 nexus_info->region.width,(
double) nexus_info->region.height,(double)
5691 nexus_info->region.x,(
double) nexus_info->region.y);
5744 if (nexus_info->authentic_pixel_cache !=
MagickFalse)
5747 nexus_info->region.x;
5748 length=(
MagickSizeType) cache_info->number_channels*nexus_info->region.width*
5750 extent=length*nexus_info->region.height;
5751 rows=nexus_info->region.height;
5753 p=nexus_info->pixels;
5754 switch (cache_info->type)
5765 if ((cache_info->columns == nexus_info->region.width) &&
5771 q=cache_info->pixels+cache_info->number_channels*offset;
5772 for (y=0; y < (ssize_t) rows; y++)
5774 (void) memcpy(q,p,(
size_t) length);
5775 p+=cache_info->number_channels*nexus_info->region.width;
5776 q+=cache_info->number_channels*cache_info->columns;
5789 cache_info->cache_filename);
5793 if ((cache_info->columns == nexus_info->region.width) &&
5799 for (y=0; y < (ssize_t) rows; y++)
5802 cache_info->number_channels*
sizeof(*p),length,(
const unsigned char *)
5806 p+=cache_info->number_channels*nexus_info->region.width;
5807 offset+=cache_info->columns;
5823 region=nexus_info->region;
5824 if ((cache_info->columns != nexus_info->region.width) ||