2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % DDDD IIIII SSSSS TTTTT RRRR IIIII BBBB U U TTTTT EEEEE %
6 % D D I SS T R R I B B U U T E %
7 % D D I SSS T RRRR I BBBB U U T EEE %
8 % D D I SS T R R I B B U U T E %
9 % DDDDA IIIII SSSSS T R R IIIII BBBB UUU T EEEEE %
11 % CCCC AAA CCCC H H EEEEE %
13 % C AAAAA C HHHHH EEE %
15 % CCCC A A CCCC H H EEEEE %
18 % MagickCore Distributed Pixel Cache Methods %
25 % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
31 % http://www.imagemagick.org/script/license.php %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 % A distributed pixel cache is an extension of the traditional pixel cache
42 % available on a single host. The distributed pixel cache may span multiple
43 % servers so that it can grow in size and transactional capacity to support
44 % very large images. Start up the pixel cache server on one or more machines.
45 % When you read or operate on an image and the local pixel cache resources are
46 % exhausted, ImageMagick contacts one or more of these remote pixel servers to
47 % store or retrieve pixels.
54 #include "MagickCore/studio.h"
55 #include "MagickCore/cache.h"
56 #include "MagickCore/cache-private.h"
57 #include "MagickCore/distribute-cache.h"
58 #include "MagickCore/distribute-cache-private.h"
59 #include "MagickCore/exception.h"
60 #include "MagickCore/exception-private.h"
61 #include "MagickCore/geometry.h"
62 #include "MagickCore/image.h"
63 #include "MagickCore/locale_.h"
64 #include "MagickCore/memory_.h"
65 #include "MagickCore/policy.h"
66 #include "MagickCore/random_.h"
67 #include "MagickCore/registry.h"
68 #include "MagickCore/splay-tree.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/string-private.h"
71 #if defined(MAGICKCORE_HAVE_SOCKET)
72 #include <netinet/in.h>
74 #include <sys/socket.h>
75 #include <arpa/inet.h>
81 #define DPCHostname "127.0.0.1"
83 #define DPCSessionKeyLength 8
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 + A c q u i r e D i s t r i b u t e C a c h e I n f o %
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 % AcquireDistributeCacheInfo() allocates the DistributeCacheInfo structure.
98 % The format of the AcquireDistributeCacheInfo method is:
100 % DistributeCacheInfo *AcquireDistributeCacheInfo(ExceptionInfo *exception)
102 % A description of each parameter follows:
104 % o exception: return any errors or warnings in this structure.
108 static MagickSizeType CRC64(const unsigned char *message,const size_t length)
116 static MagickBooleanType
117 crc_initial = MagickFalse;
119 static MagickSizeType
122 if (crc_initial == MagickFalse)
127 for (i=0; i < 256; i++)
132 alpha=(MagickSizeType) i;
133 for (j=0; j < 8; j++)
135 if ((alpha & 0x01) == 0)
138 alpha=(MagickSizeType) ((alpha >> 1) ^
139 MagickULLConstant(0xd800000000000000));
143 crc_initial=MagickTrue;
146 for (i=0; i < (ssize_t) length; i++)
147 crc=crc_xor[(crc ^ message[i]) & 0xff] ^ (crc >> 8);
151 static int ConnectPixelCacheServer(const char *hostname,const int port,
152 MagickSizeType *session_key,ExceptionInfo *exception)
154 #if defined(MAGICKCORE_HAVE_SOCKET)
156 secret[MaxTextExtent];
175 session[MaxTextExtent];
178 Connect to distributed pixel cache and get session key.
181 shared_secret=GetPolicyValue("shared-secret");
182 if (shared_secret == (const char *) NULL)
184 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
185 "DistributedPixelCache","'%s'","shared secret expected");
188 (void) CopyMagickString((char *) session,shared_secret,MaxTextExtent-
189 DPCSessionKeyLength);
190 host=gethostbyname(hostname);
191 client_socket=socket(AF_INET,SOCK_STREAM,0);
192 if (client_socket == -1)
194 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
195 "DistributedPixelCache","'%s'",hostname);
198 (void) ResetMagickMemory(&address,0,sizeof(address));
199 address.sin_family=AF_INET;
200 address.sin_port=htons((uint16_t) port);
201 address.sin_addr=(*((struct in_addr *) host->h_addr));
202 status=connect(client_socket,(struct sockaddr *) &address,(socklen_t)
203 sizeof(struct sockaddr));
206 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
207 "DistributedPixelCache","'%s'",hostname);
210 count=read(client_socket,secret,MaxTextExtent);
213 (void) memcpy(session+strlen(shared_secret),secret,(size_t) count);
214 *session_key=CRC64(session,strlen(shared_secret)+count);
216 if (*session_key == 0)
218 close(client_socket);
221 return(client_socket);
223 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
224 "DelegateLibrarySupportNotBuiltIn","distributed pixel cache");
229 static char *GetHostname(int *port,ExceptionInfo *exception)
246 Parse host list (e.g. 192.168.100.1:6668,192.168.100.2:6668).
248 hosts=(char *) GetImageRegistry(StringRegistryType,"cache:hosts",
250 if (hosts == (char *) NULL)
253 return(AcquireString(DPCHostname));
255 (void) SubstituteString(&hosts,","," ");
256 hostlist=StringToArgv(hosts,&argc);
257 hosts=DestroyString(hosts);
258 if (hostlist == (char **) NULL)
261 return(AcquireString(DPCHostname));
263 hosts=AcquireString(hostlist[(id++ % (argc-1))+1]);
264 for (i=0; i < (ssize_t) argc; i++)
265 hostlist[i]=DestroyString(hostlist[i]);
266 hostlist=(char **) RelinquishMagickMemory(hostlist);
267 (void) SubstituteString(&hosts,":"," ");
268 hostlist=StringToArgv(hosts,&argc);
269 if (hostlist == (char **) NULL)
272 return(AcquireString(DPCHostname));
274 host=AcquireString(hostlist[1]);
275 if (hostlist[2] == (char *) NULL)
278 *port=StringToLong(hostlist[2]);
279 for (i=0; i < (ssize_t) argc; i++)
280 hostlist[i]=DestroyString(hostlist[i]);
281 hostlist=(char **) RelinquishMagickMemory(hostlist);
285 MagickPrivate DistributeCacheInfo *AcquireDistributeCacheInfo(
286 ExceptionInfo *exception)
292 *distribute_cache_info;
297 distribute_cache_info=(DistributeCacheInfo *) AcquireMagickMemory(
298 sizeof(*distribute_cache_info));
299 if (distribute_cache_info == (DistributeCacheInfo *) NULL)
300 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
301 (void) ResetMagickMemory(distribute_cache_info,0,
302 sizeof(*distribute_cache_info));
303 distribute_cache_info->signature=MagickSignature;
305 Contact pixel cache server.
307 distribute_cache_info->port=0;
308 hostname=GetHostname(&distribute_cache_info->port,exception);
310 distribute_cache_info->file=ConnectPixelCacheServer(hostname,
311 distribute_cache_info->port,&session_key,exception);
312 distribute_cache_info->session_key=session_key;
313 (void) CopyMagickString(distribute_cache_info->hostname,hostname,
315 hostname=DestroyString(hostname);
316 if (distribute_cache_info->file == -1)
317 distribute_cache_info=DestroyDistributeCacheInfo(distribute_cache_info);
318 return(distribute_cache_info);
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 + D e s t r o y D i s t r i b u t e C a c h e I n f o %
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % DestroyDistributeCacheInfo() deallocates memory associated with an
333 % DistributeCacheInfo structure.
335 % The format of the DestroyDistributeCacheInfo method is:
337 % DistributeCacheInfo *DestroyDistributeCacheInfo(
338 % DistributeCacheInfo *distribute_cache_info)
340 % A description of each parameter follows:
342 % o distribute_cache_info: the distributed cache info.
345 MagickPrivate DistributeCacheInfo *DestroyDistributeCacheInfo(
346 DistributeCacheInfo *distribute_cache_info)
348 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
349 assert(distribute_cache_info->signature == MagickSignature);
350 distribute_cache_info->signature=(~MagickSignature);
351 distribute_cache_info=(DistributeCacheInfo *) RelinquishMagickMemory(
352 distribute_cache_info);
353 return(distribute_cache_info);
357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 + D i s t r i b u t e P i x e l C a c h e S e r v e r %
365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 % DistributePixelCacheServer() waits on the specified port for commands to
368 % create, read, update, or destroy a pixel cache.
370 % The format of the DistributePixelCacheServer() method is:
372 % void DistributePixelCacheServer(const size_t port)
374 % A description of each parameter follows:
376 % o port: connect the distributed pixel cache at this port.
378 % o exception: return any errors or warnings in this structure.
382 static MagickBooleanType CreateDistributeCache(SplayTreeInfo *image_registry,
383 int file,const MagickSizeType session_key)
394 register unsigned char
404 buffer[MaxTextExtent];
406 exception=AcquireExceptionInfo();
407 image=AcquireImage((ImageInfo *) NULL,exception);
408 exception=DestroyExceptionInfo(exception);
409 length=sizeof(image->columns)+sizeof(image->rows)+
410 sizeof(image->number_channels);
411 count=read(file,buffer,length);
412 if (count != (ssize_t) length)
415 (void) memcpy(&image->columns,p,sizeof(image->columns));
416 p+=sizeof(image->columns);
417 (void) memcpy(&image->rows,p,sizeof(image->rows));
418 p+=sizeof(image->rows);
419 (void) memcpy(&image->number_channels,p,sizeof(image->number_channels));
420 p+=sizeof(image->number_channels);
421 status=AddValueToSplayTree(image_registry,(const void *) session_key,image);
425 static MagickBooleanType DestroyDistributeCache(SplayTreeInfo *image_registry,
426 int file,const MagickSizeType session_key)
428 return(DeleteNodeFromSplayTree(image_registry,(const void *) session_key));
431 static MagickBooleanType ReadDistributeCacheMetacontent(
432 SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
446 register const Quantum
449 register unsigned char
459 buffer[MaxTextExtent];
461 image=(Image *) GetValueFromSplayTree(image_registry,(const void *)
463 if (image == (Image *) NULL)
465 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
466 sizeof(region.y)+sizeof(length);
467 count=read(file,buffer,length);
468 if (count != (ssize_t) length)
471 (void) memcpy(®ion.width,q,sizeof(region.width));
472 q+=sizeof(region.width);
473 (void) memcpy(®ion.height,q,sizeof(region.height));
474 q+=sizeof(region.width);
475 (void) memcpy(®ion.x,q,sizeof(region.x));
476 q+=sizeof(region.width);
477 (void) memcpy(®ion.y,q,sizeof(region.y));
478 q+=sizeof(region.width);
479 (void) memcpy(&length,q,sizeof(length));
481 exception=AcquireExceptionInfo();
482 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
484 exception=DestroyExceptionInfo(exception);
485 if (p == (const Quantum *) NULL)
487 metacontent=GetVirtualMetacontent(image);
488 count=write(file,metacontent,length);
489 if (count != (ssize_t) length)
494 static MagickBooleanType ReadDistributeCachePixels(
495 SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
506 register const Quantum
509 register unsigned char
519 buffer[MaxTextExtent];
521 image=(Image *) GetValueFromSplayTree(image_registry,(const void *)
523 if (image == (Image *) NULL)
525 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
526 sizeof(region.y)+sizeof(length);
527 count=read(file,buffer,length);
528 if (count != (ssize_t) length)
531 (void) memcpy(®ion.width,q,sizeof(region.width));
532 q+=sizeof(region.width);
533 (void) memcpy(®ion.height,q,sizeof(region.height));
534 q+=sizeof(region.width);
535 (void) memcpy(®ion.x,q,sizeof(region.x));
536 q+=sizeof(region.width);
537 (void) memcpy(®ion.y,q,sizeof(region.y));
538 q+=sizeof(region.width);
539 (void) memcpy(&length,q,sizeof(length));
541 exception=AcquireExceptionInfo();
542 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
544 exception=DestroyExceptionInfo(exception);
545 if (p == (const Quantum *) NULL)
547 count=write(file,p,length);
548 if (count != (ssize_t) length)
553 static MagickBooleanType WriteDistributeCacheMetacontent(
554 SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
571 register unsigned char
581 buffer[MaxTextExtent],
584 image=(Image *) GetValueFromSplayTree(image_registry,(const void *)
586 if (image == (Image *) NULL)
588 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
589 sizeof(region.y)+sizeof(length);
590 count=read(file,buffer,length);
591 if (count != (ssize_t) length)
594 (void) memcpy(®ion.width,p,sizeof(region.width));
595 p+=sizeof(region.width);
596 (void) memcpy(®ion.height,p,sizeof(region.height));
597 p+=sizeof(region.width);
598 (void) memcpy(®ion.x,p,sizeof(region.x));
599 p+=sizeof(region.width);
600 (void) memcpy(®ion.y,p,sizeof(region.y));
601 p+=sizeof(region.width);
602 (void) memcpy(&length,p,sizeof(length));
604 exception=AcquireExceptionInfo();
605 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
607 exception=DestroyExceptionInfo(exception);
608 if (q == (Quantum *) NULL)
610 metacontent=GetAuthenticMetacontent(image);
611 count=read(file,metacontent,length);
612 if (count != (ssize_t) length)
614 status=SyncAuthenticPixels(image,exception);
618 static MagickBooleanType WriteDistributeCachePixels(
619 SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
636 register unsigned char
646 buffer[MaxTextExtent];
648 image=(Image *) GetValueFromSplayTree(image_registry,(const void *)
650 if (image == (Image *) NULL)
652 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
653 sizeof(region.y)+sizeof(length);
654 count=read(file,buffer,length);
655 if (count != (ssize_t) length)
658 (void) memcpy(®ion.width,p,sizeof(region.width));
659 p+=sizeof(region.width);
660 (void) memcpy(®ion.height,p,sizeof(region.height));
661 p+=sizeof(region.width);
662 (void) memcpy(®ion.x,p,sizeof(region.x));
663 p+=sizeof(region.width);
664 (void) memcpy(®ion.y,p,sizeof(region.y));
665 p+=sizeof(region.width);
666 (void) memcpy(&length,p,sizeof(length));
668 exception=AcquireExceptionInfo();
669 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
671 exception=DestroyExceptionInfo(exception);
672 if (q == (Quantum *) NULL)
674 count=read(file,q,length);
675 if (count != (ssize_t) length)
677 status=SyncAuthenticPixels(image,exception);
681 static void *DistributePixelCacheClient(void *socket)
710 session[MaxTextExtent];
713 Generate session key.
715 shared_secret=GetPolicyValue("shared-secret");
716 if (shared_secret == (const char *) NULL)
717 ThrowFatalException(CacheFatalError,"shared secret expected");
718 (void) CopyMagickString((char *) session,shared_secret,MaxTextExtent-
719 DPCSessionKeyLength);
720 random_info=AcquireRandomInfo();
721 secret=GetRandomKey(random_info,DPCSessionKeyLength);
722 (void) memcpy(session+strlen(shared_secret),GetStringInfoDatum(secret),
723 DPCSessionKeyLength);
724 session_key=CRC64(session,strlen(shared_secret)+DPCSessionKeyLength);
725 random_info=DestroyRandomInfo(random_info);
726 image_registry=NewSplayTree((int (*)(const void *,const void *)) NULL,
727 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
728 client_socket=(*(int *) socket);
729 count=write(client_socket,GetStringInfoDatum(secret),DPCSessionKeyLength);
730 secret=DestroyStringInfo(secret);
733 count=read(client_socket,&command,1);
736 count=read(client_socket,&key,sizeof(key));
737 if ((count != (ssize_t) sizeof(key)) && (key != session_key))
744 status=CreateDistributeCache(image_registry,client_socket,session_key);
749 status=ReadDistributeCachePixels(image_registry,client_socket,
755 status=WriteDistributeCachePixels(image_registry,client_socket,
761 status=DestroyDistributeCache(image_registry,client_socket,session_key);
766 status=ReadDistributeCacheMetacontent(image_registry,client_socket,
772 status=WriteDistributeCacheMetacontent(image_registry,client_socket,
779 count=write(client_socket,&status,sizeof(status));
780 if (count != (ssize_t) sizeof(status))
783 return((void *) NULL);
786 MagickExport void DistributePixelCacheServer(const size_t port,
787 ExceptionInfo *exception)
789 #if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_THREAD_SUPPORT)
804 Launch distributed pixel cache server.
806 server_socket=socket(AF_INET,SOCK_STREAM,0);
807 address.sin_family=AF_INET;
808 address.sin_port=htons(port);
809 address.sin_addr.s_addr=htonl(INADDR_ANY);
810 status=bind(server_socket,(struct sockaddr *) &address,(socklen_t)
813 ThrowFatalException(CacheFatalError,"UnableToBind");
814 status=listen(server_socket,32);
816 ThrowFatalException(CacheFatalError,"UnableToListen");
817 pthread_attr_init(&attributes);
826 length=(socklen_t) sizeof(address);
827 client_socket=accept(server_socket,(struct sockaddr *) &address,&length);
828 if (client_socket == -1)
829 ThrowFatalException(CacheFatalError,"UnableToEstablishConnection");
830 status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
831 (void *) &client_socket);
833 ThrowFatalException(CacheFatalError,"UnableToCreateClientThread");
835 (void) close(server_socket);
837 ThrowFatalException(MissingDelegateError,"distributed pixel cache");
842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 + G e t D i s t r i b u t e C a c h e F i l e %
850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852 % GetDistributeCacheFile() returns the file associated with this
853 % DistributeCacheInfo structure.
855 % The format of the GetDistributeCacheFile method is:
857 % int GetDistributeCacheFile(
858 % const DistributeCacheInfo *distribute_cache_info)
860 % A description of each parameter follows:
862 % o distribute_cache_info: the distributed cache info.
865 MagickPrivate int GetDistributeCacheFile(
866 const DistributeCacheInfo *distribute_cache_info)
868 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
869 assert(distribute_cache_info->signature == MagickSignature);
870 return(distribute_cache_info->file);
874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
878 + G e t D i s t r i b u t e C a c h e H o s t n a m e %
882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
884 % GetDistributeCacheHostname() returns the hostname associated with this
885 % DistributeCacheInfo structure.
887 % The format of the GetDistributeCacheHostname method is:
889 % const char *GetDistributeCacheHostname(
890 % const DistributeCacheInfo *distribute_cache_info)
892 % A description of each parameter follows:
894 % o distribute_cache_info: the distributed cache info.
897 MagickPrivate const char *GetDistributeCacheHostname(
898 const DistributeCacheInfo *distribute_cache_info)
900 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
901 assert(distribute_cache_info->signature == MagickSignature);
902 return(distribute_cache_info->hostname);
906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
910 + G e t D i s t r i b u t e C a c h e P o r t %
914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916 % GetDistributeCachePort() returns the port associated with this
917 % DistributeCacheInfo structure.
919 % The format of the GetDistributeCachePort method is:
921 % int GetDistributeCachePort(
922 % const DistributeCacheInfo *distribute_cache_info)
924 % A description of each parameter follows:
926 % o distribute_cache_info: the distributed cache info.
929 MagickPrivate int GetDistributeCachePort(
930 const DistributeCacheInfo *distribute_cache_info)
932 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
933 assert(distribute_cache_info->signature == MagickSignature);
934 return(distribute_cache_info->port);
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942 + O p e n D i s t r i b u t e P i x e l C a c h e %
946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
948 % OpenDistributePixelCache() opens a pixel cache on a remote server.
950 % The format of the OpenDistributePixelCache method is:
952 % MagickBooleanType *OpenDistributePixelCache(
953 % DistributeCacheInfo *distribute_cache_info,Image *image)
955 % A description of each parameter follows:
957 % o distribute_cache_info: the distributed cache info.
959 % o image: the image.
962 MagickPrivate MagickBooleanType OpenDistributePixelCache(
963 DistributeCacheInfo *distribute_cache_info,Image *image)
968 register unsigned char
975 buffer[MaxTextExtent];
977 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
978 assert(distribute_cache_info->signature == MagickSignature);
979 assert(image != (Image *) NULL);
980 assert(image->signature == MagickSignature);
982 *p++='c'; /* create */
983 (void) memcpy(p,&distribute_cache_info->session_key,
984 sizeof(distribute_cache_info->session_key));
985 p+=sizeof(distribute_cache_info->session_key);
986 (void) memcpy(p,&image->columns,sizeof(image->columns));
987 p+=sizeof(image->columns);
988 (void) memcpy(p,&image->rows,sizeof(image->rows));
989 p+=sizeof(image->rows);
990 (void) memcpy(p,&image->number_channels,sizeof(image->number_channels));
991 p+=sizeof(image->number_channels);
992 count=write(distribute_cache_info->file,buffer,p-buffer);
993 if (count != (ssize_t) (p-buffer))
995 count=read(distribute_cache_info->file,&status,sizeof(status));
996 if (count != (ssize_t) sizeof(status))
1002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 + R e a d D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t %
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 % ReadDistributePixelCacheMetacontents() reads metacontent from the specified
1013 % region of the distributed pixel cache.
1015 % The format of the ReadDistributePixelCacheMetacontents method is:
1017 % MagickBooleanType *ReadDistributePixelCacheMetacontents(
1018 % DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1019 % const MagickSizeType length,unsigned char *metacontent)
1021 % A description of each parameter follows:
1023 % o distribute_cache_info: the distributed cache info.
1025 % o image: the image.
1027 % o region: read the metacontent from this region of the image.
1029 % o length: the length in bytes of the metacontent.
1031 % o metacontent: read these metacontent from the pixel cache.
1034 MagickPrivate MagickBooleanType ReadDistributePixelCacheMetacontent(
1035 DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1036 const MagickSizeType length,unsigned char *metacontent)
1041 register unsigned char
1048 buffer[MaxTextExtent];
1050 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
1051 assert(distribute_cache_info->signature == MagickSignature);
1052 assert(region != (RectangleInfo *) NULL);
1053 assert(metacontent != (unsigned char *) NULL);
1054 assert(length == ((size_t) length));
1056 *p++='m'; /* read */
1057 (void) memcpy(p,&distribute_cache_info->session_key,
1058 sizeof(distribute_cache_info->session_key));
1059 p+=sizeof(distribute_cache_info->session_key);
1060 (void) memcpy(p,®ion->width,sizeof(region->width));
1061 p+=sizeof(region->width);
1062 (void) memcpy(p,®ion->height,sizeof(region->height));
1063 p+=sizeof(region->height);
1064 (void) memcpy(p,®ion->x,sizeof(region->x));
1065 p+=sizeof(region->x);
1066 (void) memcpy(p,®ion->y,sizeof(region->y));
1067 p+=sizeof(region->y);
1068 (void) memcpy(p,&length,sizeof(length));
1070 count=write(distribute_cache_info->file,buffer,p-buffer);
1071 if (count != (ssize_t) (p-buffer))
1072 return(MagickFalse);
1073 count=read(distribute_cache_info->file,(unsigned char *) metacontent,(size_t)
1075 if (count != (ssize_t) length)
1076 return(MagickFalse);
1077 count=read(distribute_cache_info->file,&status,sizeof(status));
1078 if (count != (ssize_t) sizeof(status))
1079 return(MagickFalse);
1080 return(status != 0 ? MagickTrue : MagickFalse);
1084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 + R e a d D i s t r i b u t e P i x e l C a c h e P i x e l s %
1092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 % ReadDistributePixelCachePixels() reads pixels from the specified region of
1095 % the distributed pixel cache.
1097 % The format of the ReadDistributePixelCachePixels method is:
1099 % MagickBooleanType *ReadDistributePixelCachePixels(
1100 % DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1101 % const MagickSizeType length,unsigned char *pixels)
1103 % A description of each parameter follows:
1105 % o distribute_cache_info: the distributed cache info.
1107 % o image: the image.
1109 % o region: read the pixels from this region of the image.
1111 % o length: the length in bytes of the pixels.
1113 % o pixels: read these pixels from the pixel cache.
1116 MagickPrivate MagickBooleanType ReadDistributePixelCachePixels(
1117 DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1118 const MagickSizeType length,unsigned char *pixels)
1123 register unsigned char
1130 buffer[MaxTextExtent];
1132 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
1133 assert(distribute_cache_info->signature == MagickSignature);
1134 assert(region != (RectangleInfo *) NULL);
1135 assert(pixels != (unsigned char *) NULL);
1136 assert(length == ((size_t) length));
1138 *p++='r'; /* read */
1139 (void) memcpy(p,&distribute_cache_info->session_key,
1140 sizeof(distribute_cache_info->session_key));
1141 p+=sizeof(distribute_cache_info->session_key);
1142 (void) memcpy(p,®ion->width,sizeof(region->width));
1143 p+=sizeof(region->width);
1144 (void) memcpy(p,®ion->height,sizeof(region->height));
1145 p+=sizeof(region->height);
1146 (void) memcpy(p,®ion->x,sizeof(region->x));
1147 p+=sizeof(region->x);
1148 (void) memcpy(p,®ion->y,sizeof(region->y));
1149 p+=sizeof(region->y);
1150 (void) memcpy(p,&length,sizeof(length));
1152 count=write(distribute_cache_info->file,buffer,p-buffer);
1153 if (count != (ssize_t) (p-buffer))
1154 return(MagickFalse);
1155 count=read(distribute_cache_info->file,(unsigned char *) pixels,(size_t)
1157 if (count != (ssize_t) length)
1158 return(MagickFalse);
1159 count=read(distribute_cache_info->file,&status,sizeof(status));
1160 if (count != (ssize_t) sizeof(status))
1161 return(MagickFalse);
1162 return(status != 0 ? MagickTrue : MagickFalse);
1166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1170 + R e l i n q u i s h D i s t r i b u t e P i x e l C a c h e %
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1176 % RelinquishDistributePixelCache() frees resources acquired with
1177 % OpenDistributePixelCache().
1179 % The format of the RelinquishDistributePixelCache method is:
1181 % MagickBooleanType RelinquishDistributePixelCache(
1182 % DistributeCacheInfo *distribute_cache_info)
1184 % A description of each parameter follows:
1186 % o distribute_cache_info: the distributed cache info.
1189 MagickPrivate MagickBooleanType RelinquishDistributePixelCache(
1190 DistributeCacheInfo *distribute_cache_info)
1192 register unsigned char
1199 buffer[MaxTextExtent];
1201 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
1202 assert(distribute_cache_info->signature == MagickSignature);
1204 *p++='d'; /* delete */
1205 (void) memcpy(p,&distribute_cache_info->session_key,
1206 sizeof(distribute_cache_info->session_key));
1207 p+=sizeof(distribute_cache_info->session_key);
1208 count=write(distribute_cache_info->file,buffer,p-buffer);
1209 if (count != (ssize_t) (p-buffer))
1210 return(MagickFalse);
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1219 + W r i t e D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t %
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1225 % WriteDistributePixelCacheMetacontents() writes image metacontent to the
1226 % specified region of the distributed pixel cache.
1229 % The format of the WriteDistributePixelCacheMetacontents method is:
1231 % MagickBooleanType *WriteDistributePixelCacheMetacontents(
1232 % DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1233 % const MagickSizeType length,const unsigned char *metacontent)
1235 % A description of each parameter follows:
1237 % o distribute_cache_info: the distributed cache info.
1239 % o image: the image.
1241 % o region: write the metacontent to this region of the image.
1243 % o length: the length in bytes of the metacontent.
1245 % o metacontent: write these metacontent to the pixel cache.
1248 MagickPrivate MagickBooleanType WriteDistributePixelCacheMetacontent(
1249 DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1250 const MagickSizeType length,const unsigned char *metacontent)
1255 register unsigned char
1262 buffer[MaxTextExtent];
1264 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
1265 assert(distribute_cache_info->signature == MagickSignature);
1266 assert(region != (RectangleInfo *) NULL);
1267 assert(metacontent != (unsigned char *) NULL);
1268 assert(length == ((size_t) length));
1270 *p++='M'; /* update */
1271 (void) memcpy(p,&distribute_cache_info->session_key,
1272 sizeof(distribute_cache_info->session_key));
1273 p+=sizeof(distribute_cache_info->session_key);
1274 (void) memcpy(p,®ion->width,sizeof(region->width));
1275 p+=sizeof(region->width);
1276 (void) memcpy(p,®ion->height,sizeof(region->height));
1277 p+=sizeof(region->height);
1278 (void) memcpy(p,®ion->x,sizeof(region->x));
1279 p+=sizeof(region->x);
1280 (void) memcpy(p,®ion->y,sizeof(region->y));
1281 p+=sizeof(region->y);
1282 (void) memcpy(p,&length,sizeof(length));
1284 count=write(distribute_cache_info->file,buffer,p-buffer);
1285 if (count != (ssize_t) (p-buffer))
1286 return(MagickFalse);
1287 count=write(distribute_cache_info->file,(unsigned char *) metacontent,(size_t)
1289 if (count != (ssize_t) length)
1290 return(MagickFalse);
1291 count=read(distribute_cache_info->file,&status,sizeof(status));
1292 if (count != (ssize_t) sizeof(status))
1293 return(MagickFalse);
1294 return(status != 0 ? MagickTrue : MagickFalse);
1298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1302 + W r i t e D i s t r i b u t e P i x e l C a c h e P i x e l s %
1306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1308 % WriteDistributePixelCachePixels() writes image pixels to the specified
1309 % region of the distributed pixel cache.
1312 % The format of the WriteDistributePixelCachePixels method is:
1314 % MagickBooleanType *WriteDistributePixelCachePixels(
1315 % DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1316 % const MagickSizeType length,const unsigned char *pixels)
1318 % A description of each parameter follows:
1320 % o distribute_cache_info: the distributed cache info.
1322 % o image: the image.
1324 % o region: write the pixels to this region of the image.
1326 % o length: the length in bytes of the pixels.
1328 % o pixels: write these pixels to the pixel cache.
1331 MagickPrivate MagickBooleanType WriteDistributePixelCachePixels(
1332 DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
1333 const MagickSizeType length,const unsigned char *pixels)
1338 register unsigned char
1345 buffer[MaxTextExtent];
1347 assert(distribute_cache_info != (DistributeCacheInfo *) NULL);
1348 assert(distribute_cache_info->signature == MagickSignature);
1349 assert(region != (RectangleInfo *) NULL);
1350 assert(pixels != (const unsigned char *) NULL);
1351 assert(length == ((size_t) length));
1353 *p++='u'; /* update */
1354 (void) memcpy(p,&distribute_cache_info->session_key,
1355 sizeof(distribute_cache_info->session_key));
1356 p+=sizeof(distribute_cache_info->session_key);
1357 (void) memcpy(p,®ion->width,sizeof(region->width));
1358 p+=sizeof(region->width);
1359 (void) memcpy(p,®ion->height,sizeof(region->height));
1360 p+=sizeof(region->height);
1361 (void) memcpy(p,®ion->x,sizeof(region->x));
1362 p+=sizeof(region->x);
1363 (void) memcpy(p,®ion->y,sizeof(region->y));
1364 p+=sizeof(region->y);
1365 (void) memcpy(p,&length,sizeof(length));
1367 count=write(distribute_cache_info->file,buffer,p-buffer);
1368 if (count != (ssize_t) (p-buffer))
1369 return(MagickFalse);
1370 count=write(distribute_cache_info->file,(unsigned char *) pixels,(size_t)
1372 if (count != (ssize_t) length)
1373 return(MagickFalse);
1374 count=read(distribute_cache_info->file,&status,sizeof(status));
1375 if (count != (ssize_t) sizeof(status))
1376 return(MagickFalse);
1377 return(status != 0 ? MagickTrue : MagickFalse);