2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M EEEEE TTTTT AAA %
13 % Read/Write Embedded Image Profiles. %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/exception.h"
46 #include "magick/exception-private.h"
47 #include "magick/image.h"
48 #include "magick/image-private.h"
49 #include "magick/list.h"
50 #include "magick/magick.h"
51 #include "magick/memory_.h"
52 #include "magick/module.h"
53 #include "magick/profile.h"
54 #include "magick/splay-tree.h"
55 #include "magick/quantum-private.h"
56 #include "magick/static.h"
57 #include "magick/string_.h"
58 #include "magick/string-private.h"
59 #include "magick/token.h"
60 #include "magick/utility.h"
65 static MagickBooleanType
66 WriteMETAImage(const ImageInfo *,Image *);
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % IsMETA() returns MagickTrue if the image format type, identified by the
80 % magick string, is META.
82 % The format of the IsMETA method is:
84 % MagickBooleanType IsMETA(const unsigned char *magick,const size_t length)
86 % A description of each parameter follows:
88 % o magick: compare image format pattern against these bytes.
90 % o length: Specifies the length of the magick string.
94 #ifdef IMPLEMENT_IS_FUNCTION
95 static MagickBooleanType IsMETA(const unsigned char *magick,const size_t length)
99 if (LocaleNCompare((char *) magick,"8BIM",4) == 0)
101 if (LocaleNCompare((char *) magick,"APP1",4) == 0)
103 if (LocaleNCompare((char *) magick,"\034\002",2) == 0)
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % R e a d M E T A I m a g e %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 % ReadMETAImage() reads a META image file and returns it. It
121 % allocates the memory necessary for the new Image structure and returns a
122 % pointer to the new image.
124 % The format of the ReadMETAImage method is:
126 % Image *ReadMETAImage(const ImageInfo *image_info,
127 % ExceptionInfo *exception)
129 % Decompression code contributed by Kyle Shorter.
131 % A description of each parameter follows:
133 % o image: Method ReadMETAImage returns a pointer to the image after
134 % reading. A null image is returned if there is a memory shortage or
135 % if the image cannot be read.
137 % o image_info: Specifies a pointer to an ImageInfo structure.
139 % o exception: return any errors or warnings in this structure.
142 #define BUFFER_SZ 4096
144 typedef struct _html_code
153 static html_code html_codes[] = {
163 static int stringnicmp(const char *p,const char *q,size_t n)
171 if (p == (char *) NULL)
173 if (q == (char *) NULL)
175 while ((*p != '\0') && (*q != '\0'))
177 if ((*p == '\0') || (*q == '\0'))
193 return(toupper((int) *p)-toupper((int) *q));
196 static int convertHTMLcodes(char *s, int len)
198 if (len <=0 || s==(char*)NULL || *s=='\0')
205 if (sscanf(s,"&#%d;",&val) == 1)
215 (void) strcpy(s+1,s+1+o);
224 codes = (int) (sizeof(html_codes) / sizeof(html_code));
226 for (i=0; i < codes; i++)
228 if (html_codes[i].len <= len)
229 if (stringnicmp(s,html_codes[i].code,(size_t) html_codes[i].len) == 0)
231 (void) strcpy(s+1,s+html_codes[i].len);
232 *s = html_codes[i].val;
233 return html_codes[i].len-1;
240 static char *super_fgets(char **b, int *blen, Image *file)
251 p=(unsigned char *) (*b);
254 c=ReadBlobByte(file);
255 if (c == EOF || c == '\n')
257 if ((q-p+1) >= (int) len)
264 p=(unsigned char *) ResizeQuantumMemory(p,(size_t) len+2UL,sizeof(*p));
266 if (p == (unsigned char *) NULL)
270 *q=(unsigned char) c;
273 if (p != (unsigned char *) NULL)
280 return (char *) NULL;
287 #define BUFFER_SZ 4096
289 #define THUMBNAIL_ID 1033
291 static ssize_t parse8BIM(Image *ifile, Image *ofile)
312 inputlen = BUFFER_SZ;
327 line = (char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*line));
328 name = token = (char *)NULL;
330 token_info=AcquireTokenInfo();
331 while (super_fgets(&line,&inputlen,ifile)!=NULL)
336 token=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*token));
337 newstr=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*newstr));
338 while (Tokenizer(token_info,0,token,(size_t) inputlen,line,"","=","\"",0,
339 &brkused,&next,"ed)==0)
353 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","#",
354 "", 0,&brkused,&next,"ed)==0)
359 if (strcmp(newstr,"8BIM")==0)
362 dataset = (unsigned char) StringToLong(newstr);
365 recnum = (unsigned int) StringToUnsignedLong(newstr);
368 name=(char *) AcquireQuantumMemory(strlen(newstr)+MaxTextExtent,
371 (void) strcpy(name,newstr);
391 len = (ssize_t) strlen(token);
392 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
393 "",0,&brkused,&next,"ed)==0)
395 if (brkused && next > 0)
400 len -= (ssize_t) convertHTMLcodes(s,(int) strlen(s));
417 ssize_t diff = outputlen - savedolen;
418 currentpos = TellBlob(ofile);
419 offset=SeekBlob(ofile,savedpos,SEEK_SET);
422 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
423 offset=SeekBlob(ofile,currentpos,SEEK_SET);
430 (void) WriteBlobByte(ofile,0x00);
433 (void) WriteBlobString(ofile,"8BIM");
434 (void) WriteBlobMSBShort(ofile,(unsigned short) recnum);
437 nlen = (unsigned char) strlen(name);
438 (void) WriteBlobByte(ofile,nlen);
440 for (i=0; i<nlen; i++)
441 (void) WriteBlobByte(ofile,(unsigned char) name[i]);
443 if ((nlen & 0x01) == 0)
445 (void) WriteBlobByte(ofile,0x00);
448 if (recnum != IPTC_ID)
450 (void) WriteBlobMSBLong(ofile, (unsigned int) len);
456 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
460 (void) WriteBlobByte(ofile,0x00);
466 /* patch in a fake length for now and fix it later */
467 savedpos = TellBlob(ofile);
468 (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
470 savedolen = outputlen;
477 (void) WriteBlobByte(ofile,0x1c);
478 (void) WriteBlobByte(ofile,(unsigned char) dataset);
479 (void) WriteBlobByte(ofile,(unsigned char) (recnum & 0xff));
480 (void) WriteBlobMSBShort(ofile,(unsigned short) len);
485 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
491 token=DestroyString(token);
492 newstr=DestroyString(newstr);
493 if (name != (char *) NULL)
494 name=DestroyString(name);
496 token_info=DestroyTokenInfo(token_info);
497 line=DestroyString(line);
503 ssize_t diff = outputlen - savedolen;
505 currentpos = TellBlob(ofile);
506 offset=SeekBlob(ofile,savedpos,SEEK_SET);
509 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
510 offset=SeekBlob(ofile,currentpos,SEEK_SET);
518 static char *super_fgets_w(char **b, int *blen, Image *file)
529 p=(unsigned char *) (*b);
532 c=(int) ReadBlobLSBShort(file);
533 if ((c == -1) || (c == '\n'))
537 if ((q-p+1) >= (int) len)
544 p=(unsigned char *) ResizeQuantumMemory(p,(size_t) (len+2),sizeof(*p));
546 if (p == (unsigned char *) NULL)
550 *q=(unsigned char) c;
553 if ((*b) != (char *) NULL)
560 return (char *) NULL;
567 static ssize_t parse8BIMW(Image *ifile, Image *ofile)
588 inputlen = BUFFER_SZ;
603 line=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*line));
604 name = token = (char *)NULL;
606 token_info=AcquireTokenInfo();
607 while (super_fgets_w(&line,&inputlen,ifile) != NULL)
612 token=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*token));
613 newstr=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*newstr));
614 while (Tokenizer(token_info,0,token,(size_t) inputlen,line,"","=","\"",0,
615 &brkused,&next,"ed)==0)
629 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","#",
630 "",0,&brkused,&next,"ed)==0)
635 if (strcmp(newstr,"8BIM")==0)
638 dataset = (unsigned char) StringToLong(newstr);
641 recnum=(unsigned int) StringToUnsignedLong(newstr);
644 name=(char *) AcquireQuantumMemory(strlen(newstr)+MaxTextExtent,
647 (void) CopyMagickString(name,newstr,strlen(newstr)+MaxTextExtent);
667 len = (ssize_t) strlen(token);
668 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
669 "",0,&brkused,&next,"ed)==0)
671 if (brkused && next > 0)
676 len -= (ssize_t) convertHTMLcodes(s,(int) strlen(s));
693 ssize_t diff = outputlen - savedolen;
694 currentpos = TellBlob(ofile);
695 offset=SeekBlob(ofile,savedpos,SEEK_SET);
698 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
699 offset=SeekBlob(ofile,currentpos,SEEK_SET);
706 (void) WriteBlobByte(ofile,0x00);
709 (void) WriteBlobString(ofile,"8BIM");
710 (void) WriteBlobMSBShort(ofile,(unsigned short) recnum);
713 nlen = (unsigned char) strlen(name);
714 (void) WriteBlobByte(ofile,(unsigned char) nlen);
716 for (i=0; i<nlen; i++)
717 (void) WriteBlobByte(ofile,(unsigned char) name[i]);
719 if ((nlen & 0x01) == 0)
721 (void) WriteBlobByte(ofile,0x00);
724 if (recnum != IPTC_ID)
726 (void) WriteBlobMSBLong(ofile,(unsigned int) len);
732 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
736 (void) WriteBlobByte(ofile,0x00);
742 /* patch in a fake length for now and fix it later */
743 savedpos = TellBlob(ofile);
744 (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
746 savedolen = outputlen;
753 (void) WriteBlobByte(ofile,0x1c);
754 (void) WriteBlobByte(ofile,dataset);
755 (void) WriteBlobByte(ofile,(unsigned char) (recnum & 0xff));
756 (void) WriteBlobMSBShort(ofile,(unsigned short) len);
761 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
767 token=DestroyString(token);
768 newstr=DestroyString(newstr);
769 name=DestroyString(name);
771 token_info=DestroyTokenInfo(token_info);
772 line=DestroyString(line);
778 ssize_t diff = outputlen - savedolen;
780 currentpos = TellBlob(ofile);
781 offset=SeekBlob(ofile,savedpos,SEEK_SET);
784 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
785 offset=SeekBlob(ofile,currentpos,SEEK_SET);
793 /* some defines for the different JPEG block types */
794 #define M_SOF0 0xC0 /* Start Of Frame N */
795 #define M_SOF1 0xC1 /* N indicates which compression process */
796 #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
798 #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
808 #define M_EOI 0xD9 /* End Of Image (end of datastream) */
809 #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
827 static int jpeg_transfer_1(Image *ifile, Image *ofile)
831 c = ReadBlobByte(ifile);
834 (void) WriteBlobByte(ofile,(unsigned char) c);
839 static int jpeg_skip_1(Image *ifile)
843 c = ReadBlobByte(ifile);
850 static int jpeg_read_remaining(Image *ifile, Image *ofile)
854 while ((c = jpeg_transfer_1(ifile, ofile)) != EOF)
859 static int jpeg_skip_variable(Image *ifile, Image *ofile)
864 if ((c1 = jpeg_transfer_1(ifile, ofile)) == EOF)
866 if ((c2 = jpeg_transfer_1(ifile, ofile)) == EOF)
869 length = (((unsigned char) c1) << 8) + ((unsigned char) c2);
873 if (jpeg_transfer_1(ifile, ofile) == EOF)
879 static int jpeg_skip_variable2(Image *ifile, Image *ofile)
885 if ((c1 = ReadBlobByte(ifile)) == EOF) return M_EOI;
886 if ((c2 = ReadBlobByte(ifile)) == EOF) return M_EOI;
888 length = (((unsigned char) c1) << 8) + ((unsigned char) c2);
892 if (ReadBlobByte(ifile) == EOF)
898 static int jpeg_nextmarker(Image *ifile, Image *ofile)
902 /* transfer anything until we hit 0xff */
905 c = ReadBlobByte(ifile);
907 return M_EOI; /* we hit EOF */
910 (void) WriteBlobByte(ofile,(unsigned char) c);
913 /* get marker byte, swallowing possible padding */
916 c = ReadBlobByte(ifile);
918 return M_EOI; /* we hit EOF */
925 static int jpeg_skip_till_marker(Image *ifile, int marker)
931 /* skip anything until we hit 0xff */
935 c = ReadBlobByte(ifile);
938 return M_EOI; /* we hit EOF */
941 /* get marker byte, swallowing possible padding */
944 c = ReadBlobByte(ifile);
946 return M_EOI; /* we hit EOF */
948 } while (c != marker);
953 static char psheader[] = "\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0";
955 /* Embed binary IPTC data into a JPEG image. */
956 static int jpeg_embed(Image *ifile, Image *ofile, Image *iptc)
959 unsigned int done = 0;
963 if (jpeg_transfer_1(ifile, ofile) != 0xFF)
965 if (jpeg_transfer_1(ifile, ofile) != M_SOI)
968 while (done == MagickFalse)
970 marker=(unsigned int) jpeg_nextmarker(ifile, ofile);
977 if (marker != M_APP13)
979 (void) WriteBlobByte(ofile,0xff);
980 (void) WriteBlobByte(ofile,(unsigned char) marker);
987 /* we are going to write a new APP13 marker, so don't output the old one */
988 jpeg_skip_variable2(ifile, ofile);
992 /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */
993 jpeg_skip_variable(ifile, ofile);
995 if (iptc != (Image *)NULL)
997 len=(unsigned int) GetBlobSize(iptc);
999 len++; /* make the length even */
1000 psheader[2]=(char) ((len+16)>>8);
1001 psheader[3]=(char) ((len+16)&0xff);
1002 for (inx = 0; inx < 18; inx++)
1003 (void) WriteBlobByte(ofile,(unsigned char) psheader[inx]);
1004 jpeg_read_remaining(iptc, ofile);
1005 len=(unsigned int) GetBlobSize(iptc);
1007 (void) WriteBlobByte(ofile,0);
1012 /* we hit data, no more marker-inserting can be done! */
1013 jpeg_read_remaining(ifile, ofile);
1018 jpeg_skip_variable(ifile, ofile);
1025 /* handle stripping the APP13 data out of a JPEG */
1027 static void jpeg_strip(Image *ifile, Image *ofile)
1029 unsigned int marker;
1031 marker = jpeg_skip_till_marker(ifile, M_SOI);
1032 if (marker == M_SOI)
1034 (void) WriteBlobByte(ofile,0xff);
1035 (void) WriteBlobByte(ofile,M_SOI);
1036 jpeg_read_remaining(ifile, ofile);
1040 /* Extract any APP13 binary data into a file. */
1041 static int jpeg_extract(Image *ifile, Image *ofile)
1043 unsigned int marker;
1044 unsigned int done = 0;
1046 if (jpeg_skip_1(ifile) != 0xff)
1048 if (jpeg_skip_1(ifile) != M_SOI)
1051 while (done == MagickFalse)
1053 marker = jpeg_skip_till_marker(ifile, M_APP13);
1054 if (marker == M_APP13)
1056 marker = jpeg_nextmarker(ifile, ofile);
1064 static Image *ReadMETAImage(const ImageInfo *image_info,
1065 ExceptionInfo *exception)
1087 Open file containing binary metadata
1089 assert(image_info != (const ImageInfo *) NULL);
1090 assert(image_info->signature == MagickSignature);
1091 if (image_info->debug != MagickFalse)
1092 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1093 image_info->filename);
1094 assert(exception != (ExceptionInfo *) NULL);
1095 assert(exception->signature == MagickSignature);
1096 image=AcquireImage(image_info);
1097 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1098 if (status == MagickFalse)
1100 image=DestroyImageList(image);
1101 return((Image *) NULL);
1105 if (SetImageBackgroundColor(image) == MagickFalse)
1107 InheritException(exception,&image->exception);
1108 image=DestroyImageList(image);
1109 return((Image *) NULL);
1112 if (LocaleNCompare(image_info->magick,"8BIM",4) == 0)
1115 Read 8BIM binary metadata.
1117 buff=AcquireImage((ImageInfo *) NULL);
1118 if (buff == (Image *) NULL)
1119 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1120 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1121 if (blob == (unsigned char *) NULL)
1123 buff=DestroyImage(buff);
1124 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1126 AttachBlob(buff->blob,blob,length);
1127 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
1129 length=(size_t) parse8BIM(image, buff);
1131 (void) WriteBlobByte(buff,0x0);
1133 else if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
1135 length=(size_t) parse8BIMW(image, buff);
1137 (void) WriteBlobByte(buff,0x0);
1143 c=ReadBlobByte(image);
1146 (void) WriteBlobByte(buff,(unsigned char) c);
1149 profile=AcquireStringInfo((size_t) GetBlobSize(buff));
1150 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1151 status=SetImageProfile(image,"8bim",profile);
1152 profile=DestroyStringInfo(profile);
1153 if (status == MagickFalse)
1154 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1155 blob=DetachBlob(buff->blob);
1156 blob=(unsigned char *) RelinquishMagickMemory(blob);
1157 buff=DestroyImage(buff);
1159 if (LocaleNCompare(image_info->magick,"APP1",4) == 0)
1162 name[MaxTextExtent];
1164 (void) FormatLocaleString(name,MaxTextExtent,"APP%d",1);
1165 buff=AcquireImage((ImageInfo *) NULL);
1166 if (buff == (Image *) NULL)
1167 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1168 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1169 if (blob == (unsigned char *) NULL)
1171 buff=DestroyImage(buff);
1172 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1174 AttachBlob(buff->blob,blob,length);
1175 if (LocaleCompare(image_info->magick,"APP1JPEG") == 0)
1183 if (image_info->profile == (void *) NULL)
1185 blob=DetachBlob(buff->blob);
1186 blob=RelinquishMagickMemory(blob);
1187 buff=DestroyImage(buff);
1188 ThrowReaderException(CoderError,"NoIPTCProfileAvailable");
1190 profile=CloneStringInfo((StringInfo *) image_info->profile);
1191 iptc=AcquireImage((ImageInfo *) NULL);
1192 if (iptc == (Image *) NULL)
1194 blob=DetachBlob(buff->blob);
1195 blob=RelinquishMagickMemory(blob);
1196 buff=DestroyImage(buff);
1197 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1199 AttachBlob(iptc->blob,GetStringInfoDatum(profile),
1200 GetStringInfoLength(profile));
1201 result=jpeg_embed(image,buff,iptc);
1202 blob=DetachBlob(iptc->blob);
1203 blob=RelinquishMagickMemory(blob);
1204 iptc=DestroyImage(iptc);
1207 blob=DetachBlob(buff->blob);
1208 blob=RelinquishMagickMemory(blob);
1209 buff=DestroyImage(buff);
1210 ThrowReaderException(CoderError,"JPEGEmbeddingFailed");
1218 /* Really - really slow - FIX ME PLEASE!!!! */
1219 c=ReadBlobByte(image);
1222 (void) WriteBlobByte(buff,c);
1235 buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
1237 if (buffer != (unsigned char *) NULL)
1240 while ((length=ReadBlob(image,MagickMaxBufferExtent,buffer)) != 0)
1243 for (i=0; i < (ssize_t) length; i+=count)
1245 count=WriteBlob(buff,(size_t) (length-i),buffer+i);
1249 if (i < (ssize_t) length)
1252 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1256 profile=AcquireStringInfo((size_t) GetBlobSize(buff));
1257 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1258 status=SetImageProfile(image,name,profile);
1259 profile=DestroyStringInfo(profile);
1260 if (status == MagickFalse)
1261 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1262 blob=DetachBlob(buff->blob);
1263 blob=RelinquishMagickMemory(blob);
1264 buff=DestroyImage(buff);
1266 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
1267 (LocaleCompare(image_info->magick,"ICM") == 0))
1269 buff=AcquireImage((ImageInfo *) NULL);
1270 if (buff == (Image *) NULL)
1271 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1272 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1273 if (blob == (unsigned char *) NULL)
1275 buff=DestroyImage(buff);
1276 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1278 AttachBlob(buff->blob,blob,length);
1281 c=ReadBlobByte(image);
1284 (void) WriteBlobByte(buff,(unsigned char) c);
1286 profile=AcquireStringInfo((size_t) GetBlobSize(buff));
1287 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1288 (void) SetImageProfile(image,"icc",profile);
1289 profile=DestroyStringInfo(profile);
1290 blob=DetachBlob(buff->blob);
1291 blob=(unsigned char *) RelinquishMagickMemory(blob);
1292 buff=DestroyImage(buff);
1294 if (LocaleCompare(image_info->magick,"IPTC") == 0)
1296 register unsigned char
1299 buff=AcquireImage((ImageInfo *) NULL);
1300 if (buff == (Image *) NULL)
1301 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1302 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1303 if (blob == (unsigned char *) NULL)
1305 buff=DestroyImage(buff);
1306 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1308 AttachBlob(buff->blob,blob,length);
1309 /* write out the header - length field patched below */
1310 (void) WriteBlob(buff,11,(unsigned char *) "8BIM\04\04\0\0\0\0\0");
1311 (void) WriteBlobByte(buff,0xc6);
1312 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
1314 length=(size_t) parse8BIM(image,buff);
1316 (void) WriteBlobByte(buff,0x00);
1318 else if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
1325 c=ReadBlobByte(image);
1328 (void) WriteBlobByte(buff,(unsigned char) c);
1331 profile=AcquireStringInfo((size_t) GetBlobSize(buff));
1333 subtract off the length of the 8BIM stuff.
1335 length=GetStringInfoLength(profile)-12;
1336 p=GetStringInfoDatum(profile);
1337 p[10]=(unsigned char) (length >> 8);
1338 p[11]=(unsigned char) (length & 0xff);
1339 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1340 (void) SetImageProfile(image,"8bim",profile);
1341 profile=DestroyStringInfo(profile);
1342 blob=DetachBlob(buff->blob);
1343 blob=(unsigned char *) RelinquishMagickMemory(blob);
1344 buff=DestroyImage(buff);
1346 if (LocaleCompare(image_info->magick,"XMP") == 0)
1348 buff=AcquireImage((ImageInfo *) NULL);
1349 if (buff == (Image *) NULL)
1350 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1351 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1352 if (blob == (unsigned char *) NULL)
1354 buff=DestroyImage(buff);
1355 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1357 AttachBlob(buff->blob,blob,length);
1360 c=ReadBlobByte(image);
1363 (void) WriteBlobByte(buff,(unsigned char) c);
1365 profile=AcquireStringInfo((size_t) GetBlobSize(buff));
1366 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1367 (void) SetImageProfile(image,"xmp",profile);
1368 profile=DestroyStringInfo(profile);
1369 blob=DetachBlob(buff->blob);
1370 blob=(unsigned char *) RelinquishMagickMemory(blob);
1371 buff=DestroyImage(buff);
1373 (void) CloseBlob(image);
1374 return(GetFirstImageInList(image));
1378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1382 % R e g i s t e r M E T A I m a g e %
1386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1388 % RegisterMETAImage() adds attributes for the META image format to
1389 % the list of supported formats. The attributes include the image format
1390 % tag, a method to read and/or write the format, whether the format
1391 % supports the saving of more than one frame to the same file or blob,
1392 % whether the format supports native in-memory I/O, and a brief
1393 % description of the format.
1395 % The format of the RegisterMETAImage method is:
1397 % size_t RegisterMETAImage(void)
1400 ModuleExport size_t RegisterMETAImage(void)
1405 entry=SetMagickInfo("8BIM");
1406 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1407 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1408 entry->adjoin=MagickFalse;
1409 entry->stealth=MagickTrue;
1410 entry->seekable_stream=MagickTrue;
1411 entry->description=ConstantString("Photoshop resource format");
1412 entry->module=ConstantString("META");
1413 (void) RegisterMagickInfo(entry);
1414 entry=SetMagickInfo("8BIMTEXT");
1415 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1416 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1417 entry->adjoin=MagickFalse;
1418 entry->stealth=MagickTrue;
1419 entry->seekable_stream=MagickTrue;
1420 entry->description=ConstantString("Photoshop resource text format");
1421 entry->module=ConstantString("META");
1422 (void) RegisterMagickInfo(entry);
1423 entry=SetMagickInfo("8BIMWTEXT");
1424 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1425 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1426 entry->adjoin=MagickFalse;
1427 entry->stealth=MagickTrue;
1428 entry->seekable_stream=MagickTrue;
1429 entry->description=ConstantString("Photoshop resource wide text format");
1430 entry->module=ConstantString("META");
1431 (void) RegisterMagickInfo(entry);
1432 entry=SetMagickInfo("APP1");
1433 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1434 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1435 entry->adjoin=MagickFalse;
1436 entry->stealth=MagickTrue;
1437 entry->seekable_stream=MagickTrue;
1438 entry->description=ConstantString("Raw application information");
1439 entry->module=ConstantString("META");
1440 (void) RegisterMagickInfo(entry);
1441 entry=SetMagickInfo("APP1JPEG");
1442 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1443 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1444 entry->adjoin=MagickFalse;
1445 entry->stealth=MagickTrue;
1446 entry->seekable_stream=MagickTrue;
1447 entry->description=ConstantString("Raw JPEG binary data");
1448 entry->module=ConstantString("META");
1449 (void) RegisterMagickInfo(entry);
1450 entry=SetMagickInfo("EXIF");
1451 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1452 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1453 entry->adjoin=MagickFalse;
1454 entry->stealth=MagickTrue;
1455 entry->seekable_stream=MagickTrue;
1456 entry->description=ConstantString("Exif digital camera binary data");
1457 entry->module=ConstantString("META");
1458 (void) RegisterMagickInfo(entry);
1459 entry=SetMagickInfo("XMP");
1460 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1461 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1462 entry->adjoin=MagickFalse;
1463 entry->stealth=MagickTrue;
1464 entry->seekable_stream=MagickTrue;
1465 entry->description=ConstantString("Adobe XML metadata");
1466 entry->module=ConstantString("META");
1467 (void) RegisterMagickInfo(entry);
1468 entry=SetMagickInfo("ICM");
1469 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1470 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1471 entry->adjoin=MagickFalse;
1472 entry->stealth=MagickTrue;
1473 entry->seekable_stream=MagickTrue;
1474 entry->description=ConstantString("ICC Color Profile");
1475 entry->module=ConstantString("META");
1476 (void) RegisterMagickInfo(entry);
1477 entry=SetMagickInfo("ICC");
1478 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1479 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1480 entry->adjoin=MagickFalse;
1481 entry->stealth=MagickTrue;
1482 entry->seekable_stream=MagickTrue;
1483 entry->description=ConstantString("ICC Color Profile");
1484 entry->module=ConstantString("META");
1485 (void) RegisterMagickInfo(entry);
1486 entry=SetMagickInfo("IPTC");
1487 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1488 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1489 entry->adjoin=MagickFalse;
1490 entry->stealth=MagickTrue;
1491 entry->seekable_stream=MagickTrue;
1492 entry->description=ConstantString("IPTC Newsphoto");
1493 entry->module=ConstantString("META");
1494 (void) RegisterMagickInfo(entry);
1495 entry=SetMagickInfo("IPTCTEXT");
1496 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1497 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1498 entry->adjoin=MagickFalse;
1499 entry->stealth=MagickTrue;
1500 entry->seekable_stream=MagickTrue;
1501 entry->description=ConstantString("IPTC Newsphoto text format");
1502 entry->module=ConstantString("META");
1503 (void) RegisterMagickInfo(entry);
1504 entry=SetMagickInfo("IPTCWTEXT");
1505 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1506 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1507 entry->adjoin=MagickFalse;
1508 entry->stealth=MagickTrue;
1509 entry->seekable_stream=MagickTrue;
1510 entry->description=ConstantString("IPTC Newsphoto text format");
1511 entry->module=ConstantString("META");
1512 (void) RegisterMagickInfo(entry);
1513 return(MagickImageCoderSignature);
1517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1521 % U n r e g i s t e r M E T A I m a g e %
1525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1527 % UnregisterMETAImage() removes format registrations made by the
1528 % META module from the list of supported formats.
1530 % The format of the UnregisterMETAImage method is:
1532 % UnregisterMETAImage(void)
1535 ModuleExport void UnregisterMETAImage(void)
1537 (void) UnregisterMagickInfo("8BIM");
1538 (void) UnregisterMagickInfo("8BIMTEXT");
1539 (void) UnregisterMagickInfo("8BIMWTEXT");
1540 (void) UnregisterMagickInfo("EXIF");
1541 (void) UnregisterMagickInfo("APP1");
1542 (void) UnregisterMagickInfo("APP1JPEG");
1543 (void) UnregisterMagickInfo("ICCTEXT");
1544 (void) UnregisterMagickInfo("ICM");
1545 (void) UnregisterMagickInfo("ICC");
1546 (void) UnregisterMagickInfo("IPTC");
1547 (void) UnregisterMagickInfo("IPTCTEXT");
1548 (void) UnregisterMagickInfo("IPTCWTEXT");
1549 (void) UnregisterMagickInfo("XMP");
1553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 % W r i t e M E T A I m a g e %
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1563 % WriteMETAImage() writes a META image to a file.
1565 % The format of the WriteMETAImage method is:
1567 % MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
1570 % Compression code contributed by Kyle Shorter.
1572 % A description of each parameter follows:
1574 % o image_info: Specifies a pointer to an ImageInfo structure.
1576 % o image: A pointer to a Image structure.
1580 static size_t GetIPTCStream(unsigned char **info,size_t length)
1588 register unsigned char
1596 buffer[4] = { '\0', '\0', '\0', '\0' };
1606 if ((*p == 0x1c) && (*(p+1) == 0x02))
1609 Extract IPTC from 8BIM resource block.
1611 while (extent >= 12)
1613 if (strncmp((const char *) p,"8BIM",4))
1617 marker=(unsigned int) (*p) << 8 | *(p+1);
1623 if ((size_t) c >= extent)
1629 tag_length=(((size_t) *p) << 24) | (((size_t) *(p+1)) << 16) |
1630 (((size_t) *(p+2)) << 8) | ((size_t) *(p+3));
1633 if (tag_length > extent)
1635 if (marker == IPTC_ID)
1640 if ((tag_length & 0x01) != 0)
1646 Find the beginning of the IPTC info.
1662 *info=p; /* let the caller know were it is */
1667 Determine the length of the IPTC info.
1684 Found the 0x1c tag; skip the dataset and record number tags.
1686 c=(*p++); /* should be 2 */
1690 if ((info_length == 1) && (c != 2))
1693 c=(*p++); /* should be 0 */
1697 if ((info_length == 2) && (c != 0))
1701 Decode the length of the block that follows - ssize_t or short format.
1708 if ((c & 0x80) != 0)
1710 for (i=0; i < 4; i++)
1718 tag_length=(((size_t) buffer[0]) << 24) |
1719 (((size_t) buffer[1]) << 16) |
1720 (((size_t) buffer[2]) << 8) | (((size_t) buffer[3]));
1724 tag_length=(size_t) (c << 8);
1732 if (tag_length > (length+1))
1738 info_length+=tag_length;
1740 return(info_length);
1743 static void formatString(Image *ofile, const char *s, int len)
1746 temp[MaxTextExtent];
1748 (void) WriteBlobByte(ofile,'"');
1749 for (; len > 0; len--, s++) {
1753 (void) WriteBlobString(ofile,"&");
1757 (void) WriteBlobString(ofile,"<");
1760 (void) WriteBlobString(ofile,">");
1764 (void) WriteBlobString(ofile,""");
1768 (void) WriteBlobByte(ofile,(unsigned char) *s);
1771 (void) FormatLocaleString(temp,MaxTextExtent,"&#%d;", c & 255);
1772 (void) WriteBlobString(ofile,temp);
1777 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1778 (void) WriteBlobString(ofile,"\"\r\n");
1780 #if defined(macintosh)
1781 (void) WriteBlobString(ofile,"\"\r");
1783 (void) WriteBlobString(ofile,"\"\n");
1788 typedef struct _tag_spec
1797 static const tag_spec tags[] = {
1798 { 5, "Image Name" },
1799 { 7, "Edit Status" },
1802 { 20, "Supplemental Category" },
1803 { 22, "Fixture Identifier" },
1805 { 30, "Release Date" },
1806 { 35, "Release Time" },
1807 { 40, "Special Instructions" },
1808 { 45, "Reference Service" },
1809 { 47, "Reference Date" },
1810 { 50, "Reference Number" },
1811 { 55, "Created Date" },
1812 { 60, "Created Time" },
1813 { 65, "Originating Program" },
1814 { 70, "Program Version" },
1815 { 75, "Object Cycle" },
1817 { 85, "Byline Title" },
1819 { 95, "Province State" },
1820 { 100, "Country Code" },
1822 { 103, "Original Transmission Reference" },
1823 { 105, "Headline" },
1826 { 116, "Copyright String" },
1828 { 121, "Image Orientation" },
1829 { 122, "Caption Writer" },
1830 { 131, "Local Caption" },
1831 { 200, "Custom Field 1" },
1832 { 201, "Custom Field 2" },
1833 { 202, "Custom Field 3" },
1834 { 203, "Custom Field 4" },
1835 { 204, "Custom Field 5" },
1836 { 205, "Custom Field 6" },
1837 { 206, "Custom Field 7" },
1838 { 207, "Custom Field 8" },
1839 { 208, "Custom Field 9" },
1840 { 209, "Custom Field 10" },
1841 { 210, "Custom Field 11" },
1842 { 211, "Custom Field 12" },
1843 { 212, "Custom Field 13" },
1844 { 213, "Custom Field 14" },
1845 { 214, "Custom Field 15" },
1846 { 215, "Custom Field 16" },
1847 { 216, "Custom Field 17" },
1848 { 217, "Custom Field 18" },
1849 { 218, "Custom Field 19" },
1850 { 219, "Custom Field 20" }
1853 static int formatIPTC(Image *ifile, Image *ofile)
1856 temp[MaxTextExtent];
1876 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
1881 foundiptc = 0; /* found the IPTC-Header */
1882 tagsfound = 0; /* number of tags found */
1884 c = ReadBlobByte(ifile);
1897 /* we found the 0x1c tag and now grab the dataset and record number tags */
1898 c = ReadBlobByte(ifile);
1899 if (c == EOF) return -1;
1900 dataset = (unsigned char) c;
1901 c = ReadBlobByte(ifile);
1902 if (c == EOF) return -1;
1903 recnum = (unsigned char) c;
1904 /* try to match this record to one of the ones in our named table */
1905 for (i=0; i< tagcount; i++)
1907 if (tags[i].id == (short) recnum)
1911 readable = (unsigned char *) tags[i].name;
1913 readable = (unsigned char *) "";
1915 We decode the length of the block that follows - ssize_t or short fmt.
1917 c=ReadBlobByte(ifile);
1918 if (c == EOF) return -1;
1919 if (c & (unsigned char) 0x80)
1926 c0=ReadBlobByte(ifile);
1927 if (c0 == EOF) return -1;
1928 taglen = (c << 8) | c0;
1930 if (taglen < 0) return -1;
1931 /* make a buffer to hold the tag datand snag it from the input stream */
1932 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
1934 if (str == (unsigned char *) NULL)
1936 printf("MemoryAllocationFailed");
1939 for (tagindx=0; tagindx<taglen; tagindx++)
1941 c=ReadBlobByte(ifile);
1942 if (c == EOF) return -1;
1943 str[tagindx] = (unsigned char) c;
1947 /* now finish up by formatting this binary data into ASCII equivalent */
1948 if (strlen((char *)readable) > 0)
1949 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
1950 (unsigned int) dataset, (unsigned int) recnum, readable);
1952 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
1953 (unsigned int) dataset,(unsigned int) recnum);
1954 (void) WriteBlobString(ofile,temp);
1955 formatString( ofile, (char *)str, taglen );
1956 str=(unsigned char *) RelinquishMagickMemory(str);
1960 c=ReadBlobByte(ifile);
1962 return((int) tagsfound);
1965 static int readWordFromBuffer(char **s, ssize_t *len)
1976 c = *(*s)++; (*len)--;
1977 if (*len < 0) return -1;
1978 buffer[i] = (unsigned char) c;
1980 return (((int) buffer[ 0 ]) << 8) |
1981 (((int) buffer[ 1 ]));
1984 static int formatIPTCfromBuffer(Image *ofile, char *s, ssize_t len)
1987 temp[MaxTextExtent];
2007 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
2012 foundiptc = 0; /* found the IPTC-Header */
2013 tagsfound = 0; /* number of tags found */
2028 We found the 0x1c tag and now grab the dataset and record number tags.
2031 if (len < 0) return -1;
2032 dataset = (unsigned char) c;
2034 if (len < 0) return -1;
2035 recnum = (unsigned char) c;
2036 /* try to match this record to one of the ones in our named table */
2037 for (i=0; i< tagcount; i++)
2038 if (tags[i].id == (short) recnum)
2041 readable=(unsigned char *) tags[i].name;
2043 readable=(unsigned char *) "";
2045 We decode the length of the block that follows - ssize_t or short fmt.
2051 if (c & (unsigned char) 0x80)
2057 taglen=readWordFromBuffer(&s, &len);
2061 /* make a buffer to hold the tag datand snag it from the input stream */
2062 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
2064 if (str == (unsigned char *) NULL)
2066 printf("MemoryAllocationFailed");
2069 for (tagindx=0; tagindx<taglen; tagindx++)
2074 str[tagindx]=(unsigned char) c;
2078 /* now finish up by formatting this binary data into ASCII equivalent */
2079 if (strlen((char *)readable) > 0)
2080 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
2081 (unsigned int) dataset,(unsigned int) recnum, readable);
2083 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
2084 (unsigned int) dataset,(unsigned int) recnum);
2085 (void) WriteBlobString(ofile,temp);
2086 formatString( ofile, (char *)str, taglen );
2087 str=(unsigned char *) RelinquishMagickMemory(str);
2091 return ((int) tagsfound);
2094 static int format8BIM(Image *ifile, Image *ofile)
2097 temp[MaxTextExtent];
2116 foundOSType=0; /* found the OSType */
2118 c=ReadBlobByte(ifile);
2126 buffer[0]=(unsigned char) c;
2129 c=ReadBlobByte(ifile);
2132 buffer[i] = (unsigned char) c;
2135 if (strcmp((const char *)buffer, "8BIM") == 0)
2142 c=ReadBlobByte(ifile);
2146 We found the OSType (8BIM) and now grab the ID, PString, and Size fields.
2148 ID=(int) ReadBlobMSBShort(ifile);
2155 c=ReadBlobByte(ifile);
2158 plen = (unsigned char) c;
2159 PString=(unsigned char *) AcquireQuantumMemory((size_t) (plen+
2160 MaxTextExtent),sizeof(*PString));
2161 if (PString == (unsigned char *) NULL)
2163 printf("MemoryAllocationFailed");
2166 for (i=0; i<plen; i++)
2168 c=ReadBlobByte(ifile);
2169 if (c == EOF) return -1;
2170 PString[i] = (unsigned char) c;
2172 PString[ plen ] = 0;
2173 if ((plen & 0x01) == 0)
2175 c=ReadBlobByte(ifile);
2180 count = (int) ReadBlobMSBLong(ifile);
2181 if (count < 0) return -1;
2182 /* make a buffer to hold the datand snag it from the input stream */
2183 str=(unsigned char *) AcquireQuantumMemory((size_t) count,sizeof(*str));
2184 if (str == (unsigned char *) NULL)
2186 printf("MemoryAllocationFailed");
2189 for (i=0; i < (ssize_t) count; i++)
2191 c=ReadBlobByte(ifile);
2194 str[i]=(unsigned char) c;
2197 /* we currently skip thumbnails, since it does not make
2198 * any sense preserving them in a real world application
2200 if (ID != THUMBNAIL_ID)
2202 /* now finish up by formatting this binary data into
2205 if (strlen((const char *)PString) > 0)
2206 (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d#%s=",ID,
2209 (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d=",ID);
2210 (void) WriteBlobString(ofile,temp);
2213 formatString(ofile, "IPTC", 4);
2214 formatIPTCfromBuffer(ofile, (char *)str, (ssize_t) count);
2217 formatString(ofile, (char *)str, (ssize_t) count);
2219 str=(unsigned char *) RelinquishMagickMemory(str);
2220 PString=(unsigned char *) RelinquishMagickMemory(PString);
2222 c=ReadBlobByte(ifile);
2227 static MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
2242 assert(image_info != (const ImageInfo *) NULL);
2243 assert(image_info->signature == MagickSignature);
2244 assert(image != (Image *) NULL);
2245 assert(image->signature == MagickSignature);
2246 if (image->debug != MagickFalse)
2247 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2249 if (LocaleCompare(image_info->magick,"8BIM") == 0)
2254 profile=GetImageProfile(image,"8bim");
2255 if (profile == (StringInfo *) NULL)
2256 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2257 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2258 if (status == MagickFalse)
2260 (void) WriteBlob(image,GetStringInfoLength(profile),
2261 GetStringInfoDatum(profile));
2262 (void) CloseBlob(image);
2265 if (LocaleCompare(image_info->magick,"iptc") == 0)
2273 profile=GetImageProfile(image,"iptc");
2274 if (profile == (StringInfo *) NULL)
2275 profile=GetImageProfile(image,"8bim");
2276 if (profile == (StringInfo *) NULL)
2277 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2278 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2279 info=GetStringInfoDatum(profile);
2280 length=GetStringInfoLength(profile);
2281 length=GetIPTCStream(&info,length);
2283 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2284 (void) WriteBlob(image,length,info);
2285 (void) CloseBlob(image);
2288 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
2293 profile=GetImageProfile(image,"8bim");
2294 if (profile == (StringInfo *) NULL)
2295 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2296 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2297 if (status == MagickFalse)
2299 buff=AcquireImage((ImageInfo *) NULL);
2300 if (buff == (Image *) NULL)
2301 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2302 AttachBlob(buff->blob,GetStringInfoDatum(profile),
2303 GetStringInfoLength(profile));
2304 format8BIM(buff,image);
2305 (void) DetachBlob(buff->blob);
2306 buff=DestroyImage(buff);
2307 (void) CloseBlob(image);
2310 if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
2311 return(MagickFalse);
2312 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
2320 profile=GetImageProfile(image,"8bim");
2321 if (profile == (StringInfo *) NULL)
2322 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2323 info=GetStringInfoDatum(profile);
2324 length=GetStringInfoLength(profile);
2325 length=GetIPTCStream(&info,length);
2327 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2328 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2329 if (status == MagickFalse)
2331 buff=AcquireImage((ImageInfo *) NULL);
2332 if (buff == (Image *) NULL)
2333 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2334 AttachBlob(buff->blob,info,length);
2335 formatIPTC(buff,image);
2336 (void) DetachBlob(buff->blob);
2337 buff=DestroyImage(buff);
2338 (void) CloseBlob(image);
2341 if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
2342 return(MagickFalse);
2343 if ((LocaleCompare(image_info->magick,"APP1") == 0) ||
2344 (LocaleCompare(image_info->magick,"EXIF") == 0) ||
2345 (LocaleCompare(image_info->magick,"XMP") == 0))
2348 (void) Write APP1 image.
2350 profile=GetImageProfile(image,image_info->magick);
2351 if (profile == (StringInfo *) NULL)
2352 ThrowWriterException(CoderError,"NoAPP1DataIsAvailable");
2353 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2354 if (status == MagickFalse)
2356 (void) WriteBlob(image,GetStringInfoLength(profile),
2357 GetStringInfoDatum(profile));
2358 (void) CloseBlob(image);
2361 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
2362 (LocaleCompare(image_info->magick,"ICM") == 0))
2367 profile=GetImageProfile(image,"icc");
2368 if (profile == (StringInfo *) NULL)
2369 ThrowWriterException(CoderError,"NoColorProfileIsAvailable");
2370 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2371 if (status == MagickFalse)
2373 (void) WriteBlob(image,GetStringInfoLength(profile),
2374 GetStringInfoDatum(profile));
2375 (void) CloseBlob(image);
2378 return(MagickFalse);