2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M EEEEE TTTTT AAA %
13 % Read/Write Embedded Image Profiles. %
20 % Copyright 1999-2010 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 long 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 = (long) 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 -= (long) convertHTMLcodes(s,(int) strlen(s));
417 long diff = outputlen - savedolen;
418 currentpos = TellBlob(ofile);
419 offset=SeekBlob(ofile,savedpos,SEEK_SET);
422 (void) WriteBlobMSBLong(ofile,(unsigned long) 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 long) 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,0xFFFFFFFFUL);
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 long diff = outputlen - savedolen;
505 currentpos = TellBlob(ofile);
506 offset=SeekBlob(ofile,savedpos,SEEK_SET);
509 (void) WriteBlobMSBLong(ofile,(unsigned long) 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 long 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 = (long) 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 -= (long) convertHTMLcodes(s,(int) strlen(s));
693 long diff = outputlen - savedolen;
694 currentpos = TellBlob(ofile);
695 offset=SeekBlob(ofile,savedpos,SEEK_SET);
698 (void) WriteBlobMSBLong(ofile,(unsigned long) 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 long) 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,0xFFFFFFFFUL);
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 long diff = outputlen - savedolen;
780 currentpos = TellBlob(ofile);
781 offset=SeekBlob(ofile,savedpos,SEEK_SET);
784 (void) WriteBlobMSBLong(ofile,(unsigned long) 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) FormatMagickString(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 < (long) length; i+=count)
1245 count=WriteBlob(buff,(size_t) (length-i),buffer+i);
1249 if (i < (long) 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\01");
1311 (void) WriteBlobByte(buff,0xe0);
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 % unsigned long RegisterMETAImage(void)
1400 ModuleExport unsigned long 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);
1415 entry=SetMagickInfo("8BIMTEXT");
1416 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1417 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1418 entry->adjoin=MagickFalse;
1419 entry->stealth=MagickTrue;
1420 entry->seekable_stream=MagickTrue;
1421 entry->description=ConstantString("Photoshop resource text format");
1422 entry->module=ConstantString("META");
1423 (void) RegisterMagickInfo(entry);
1425 entry=SetMagickInfo("8BIMWTEXT");
1426 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1427 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1428 entry->adjoin=MagickFalse;
1429 entry->stealth=MagickTrue;
1430 entry->seekable_stream=MagickTrue;
1431 entry->description=ConstantString("Photoshop resource wide text format");
1432 entry->module=ConstantString("META");
1433 (void) RegisterMagickInfo(entry);
1435 entry=SetMagickInfo("APP1");
1436 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1437 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1438 entry->adjoin=MagickFalse;
1439 entry->stealth=MagickTrue;
1440 entry->seekable_stream=MagickTrue;
1441 entry->description=ConstantString("Raw application information");
1442 entry->module=ConstantString("META");
1443 (void) RegisterMagickInfo(entry);
1445 entry=SetMagickInfo("APP1JPEG");
1446 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1447 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1448 entry->adjoin=MagickFalse;
1449 entry->stealth=MagickTrue;
1450 entry->seekable_stream=MagickTrue;
1451 entry->description=ConstantString("Raw JPEG binary data");
1452 entry->module=ConstantString("META");
1453 (void) RegisterMagickInfo(entry);
1455 entry=SetMagickInfo("EXIF");
1456 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1457 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1458 entry->adjoin=MagickFalse;
1459 entry->stealth=MagickTrue;
1460 entry->seekable_stream=MagickTrue;
1461 entry->description=ConstantString("Exif digital camera binary data");
1462 entry->module=ConstantString("META");
1463 (void) RegisterMagickInfo(entry);
1465 entry=SetMagickInfo("XMP");
1466 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1467 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1468 entry->adjoin=MagickFalse;
1469 entry->stealth=MagickTrue;
1470 entry->seekable_stream=MagickTrue;
1471 entry->description=ConstantString("Adobe XML metadata");
1472 entry->module=ConstantString("META");
1473 (void) RegisterMagickInfo(entry);
1475 entry=SetMagickInfo("ICM");
1476 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1477 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1478 entry->adjoin=MagickFalse;
1479 entry->stealth=MagickTrue;
1480 entry->seekable_stream=MagickTrue;
1481 entry->description=ConstantString("ICC Color Profile");
1482 entry->module=ConstantString("META");
1483 (void) RegisterMagickInfo(entry);
1485 entry=SetMagickInfo("ICC");
1486 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1487 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1488 entry->adjoin=MagickFalse;
1489 entry->stealth=MagickTrue;
1490 entry->seekable_stream=MagickTrue;
1491 entry->description=ConstantString("ICC Color Profile");
1492 entry->module=ConstantString("META");
1493 (void) RegisterMagickInfo(entry);
1495 entry=SetMagickInfo("IPTC");
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");
1502 entry->module=ConstantString("META");
1503 (void) RegisterMagickInfo(entry);
1505 entry=SetMagickInfo("IPTCTEXT");
1506 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1507 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1508 entry->adjoin=MagickFalse;
1509 entry->stealth=MagickTrue;
1510 entry->seekable_stream=MagickTrue;
1511 entry->description=ConstantString("IPTC Newsphoto text format");
1512 entry->module=ConstantString("META");
1513 (void) RegisterMagickInfo(entry);
1515 entry=SetMagickInfo("IPTCWTEXT");
1516 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1517 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1518 entry->adjoin=MagickFalse;
1519 entry->stealth=MagickTrue;
1520 entry->seekable_stream=MagickTrue;
1521 entry->description=ConstantString("IPTC Newsphoto text format");
1522 entry->module=ConstantString("META");
1523 (void) RegisterMagickInfo(entry);
1524 return(MagickImageCoderSignature);
1528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532 % U n r e g i s t e r M E T A I m a g e %
1536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1538 % UnregisterMETAImage() removes format registrations made by the
1539 % META module from the list of supported formats.
1541 % The format of the UnregisterMETAImage method is:
1543 % UnregisterMETAImage(void)
1546 ModuleExport void UnregisterMETAImage(void)
1548 (void) UnregisterMagickInfo("8BIM");
1549 (void) UnregisterMagickInfo("8BIMTEXT");
1550 (void) UnregisterMagickInfo("8BIMWTEXT");
1551 (void) UnregisterMagickInfo("EXIF");
1552 (void) UnregisterMagickInfo("APP1");
1553 (void) UnregisterMagickInfo("APP1JPEG");
1554 (void) UnregisterMagickInfo("ICCTEXT");
1555 (void) UnregisterMagickInfo("ICM");
1556 (void) UnregisterMagickInfo("ICC");
1557 (void) UnregisterMagickInfo("IPTC");
1558 (void) UnregisterMagickInfo("IPTCTEXT");
1559 (void) UnregisterMagickInfo("IPTCWTEXT");
1560 (void) UnregisterMagickInfo("XMP");
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1568 % W r i t e M E T A I m a g e %
1572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574 % WriteMETAImage() writes a META image to a file.
1576 % The format of the WriteMETAImage method is:
1578 % MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
1581 % Compression code contributed by Kyle Shorter.
1583 % A description of each parameter follows:
1585 % o image_info: Specifies a pointer to an ImageInfo structure.
1587 % o image: A pointer to a Image structure.
1591 static size_t GetIPTCStream(unsigned char **info,size_t length)
1599 register unsigned char
1607 buffer[4] = { '\0', '\0', '\0', '\0' };
1617 if ((*p == 0x1c) && (*(p+1) == 0x02))
1620 Extract IPTC from 8BIM resource block.
1622 while (extent >= 12)
1624 if (strncmp((const char *) p,"8BIM",4))
1628 marker=(unsigned int) (*p) << 8 | *(p+1);
1634 if ((size_t) c >= extent)
1640 tag_length=(((unsigned long) *p) << 24) | (((unsigned long) *(p+1)) << 16) |
1641 (((unsigned long) *(p+2)) << 8) | ((unsigned long) *(p+3));
1644 if (tag_length > extent)
1646 if (marker == IPTC_ID)
1651 if ((tag_length & 0x01) != 0)
1657 Find the beginning of the IPTC info.
1673 *info=p; /* let the caller know were it is */
1678 Determine the length of the IPTC info.
1695 Found the 0x1c tag; skip the dataset and record number tags.
1697 c=(*p++); /* should be 2 */
1701 if ((info_length == 1) && (c != 2))
1704 c=(*p++); /* should be 0 */
1708 if ((info_length == 2) && (c != 0))
1712 Decode the length of the block that follows - long or short format.
1719 if ((c & 0x80) != 0)
1721 for (i=0; i < 4; i++)
1729 tag_length=(((unsigned long) buffer[0]) << 24) |
1730 (((unsigned long) buffer[1]) << 16) |
1731 (((unsigned long) buffer[2]) << 8) | (((unsigned long) buffer[3]));
1735 tag_length=(unsigned long) (c << 8);
1743 if (tag_length > (length+1))
1749 info_length+=tag_length;
1751 return(info_length);
1754 static void formatString(Image *ofile, const char *s, int len)
1757 temp[MaxTextExtent];
1759 (void) WriteBlobByte(ofile,'"');
1760 for (; len > 0; len--, s++) {
1764 (void) WriteBlobString(ofile,"&");
1768 (void) WriteBlobString(ofile,"<");
1771 (void) WriteBlobString(ofile,">");
1775 (void) WriteBlobString(ofile,""");
1779 (void) WriteBlobByte(ofile,(unsigned char) *s);
1782 (void) FormatMagickString(temp,MaxTextExtent,"&#%d;", c & 255);
1783 (void) WriteBlobString(ofile,temp);
1788 #if defined(__WINDOWS__)
1789 (void) WriteBlobString(ofile,"\"\r\n");
1791 #if defined(macintosh)
1792 (void) WriteBlobString(ofile,"\"\r");
1794 (void) WriteBlobString(ofile,"\"\n");
1799 typedef struct _tag_spec
1808 static const tag_spec tags[] = {
1809 { 5, "Image Name" },
1810 { 7, "Edit Status" },
1813 { 20, "Supplemental Category" },
1814 { 22, "Fixture Identifier" },
1816 { 30, "Release Date" },
1817 { 35, "Release Time" },
1818 { 40, "Special Instructions" },
1819 { 45, "Reference Service" },
1820 { 47, "Reference Date" },
1821 { 50, "Reference Number" },
1822 { 55, "Created Date" },
1823 { 60, "Created Time" },
1824 { 65, "Originating Program" },
1825 { 70, "Program Version" },
1826 { 75, "Object Cycle" },
1828 { 85, "Byline Title" },
1830 { 95, "Province State" },
1831 { 100, "Country Code" },
1833 { 103, "Original Transmission Reference" },
1834 { 105, "Headline" },
1837 { 116, "Copyright String" },
1839 { 121, "Image Orientation" },
1840 { 122, "Caption Writer" },
1841 { 131, "Local Caption" },
1842 { 200, "Custom Field 1" },
1843 { 201, "Custom Field 2" },
1844 { 202, "Custom Field 3" },
1845 { 203, "Custom Field 4" },
1846 { 204, "Custom Field 5" },
1847 { 205, "Custom Field 6" },
1848 { 206, "Custom Field 7" },
1849 { 207, "Custom Field 8" },
1850 { 208, "Custom Field 9" },
1851 { 209, "Custom Field 10" },
1852 { 210, "Custom Field 11" },
1853 { 211, "Custom Field 12" },
1854 { 212, "Custom Field 13" },
1855 { 213, "Custom Field 14" },
1856 { 214, "Custom Field 15" },
1857 { 215, "Custom Field 16" },
1858 { 216, "Custom Field 17" },
1859 { 217, "Custom Field 18" },
1860 { 218, "Custom Field 19" },
1861 { 219, "Custom Field 20" }
1864 static int formatIPTC(Image *ifile, Image *ofile)
1867 temp[MaxTextExtent];
1887 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
1892 foundiptc = 0; /* found the IPTC-Header */
1893 tagsfound = 0; /* number of tags found */
1895 c = ReadBlobByte(ifile);
1908 /* we found the 0x1c tag and now grab the dataset and record number tags */
1909 c = ReadBlobByte(ifile);
1910 if (c == EOF) return -1;
1911 dataset = (unsigned char) c;
1912 c = ReadBlobByte(ifile);
1913 if (c == EOF) return -1;
1914 recnum = (unsigned char) c;
1915 /* try to match this record to one of the ones in our named table */
1916 for (i=0; i< tagcount; i++)
1918 if (tags[i].id == (short) recnum)
1922 readable = (unsigned char *) tags[i].name;
1924 readable = (unsigned char *) "";
1926 We decode the length of the block that follows - long or short fmt.
1928 c=ReadBlobByte(ifile);
1929 if (c == EOF) return -1;
1930 if (c & (unsigned char) 0x80)
1937 c0=ReadBlobByte(ifile);
1938 if (c0 == EOF) return -1;
1939 taglen = (c << 8) | c0;
1941 if (taglen < 0) return -1;
1942 /* make a buffer to hold the tag datand snag it from the input stream */
1943 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
1945 if (str == (unsigned char *) NULL)
1947 printf("MemoryAllocationFailed");
1950 for (tagindx=0; tagindx<taglen; tagindx++)
1952 c=ReadBlobByte(ifile);
1953 if (c == EOF) return -1;
1954 str[tagindx] = (unsigned char) c;
1958 /* now finish up by formatting this binary data into ASCII equivalent */
1959 if (strlen((char *)readable) > 0)
1960 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=",
1961 (unsigned int) dataset, (unsigned int) recnum, readable);
1963 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=",
1964 (unsigned int) dataset,(unsigned int) recnum);
1965 (void) WriteBlobString(ofile,temp);
1966 formatString( ofile, (char *)str, taglen );
1967 str=(unsigned char *) RelinquishMagickMemory(str);
1971 c=ReadBlobByte(ifile);
1973 return((int) tagsfound);
1976 static int readWordFromBuffer(char **s, long *len)
1987 c = *(*s)++; (*len)--;
1988 if (*len < 0) return -1;
1989 buffer[i] = (unsigned char) c;
1991 return (((int) buffer[ 0 ]) << 8) |
1992 (((int) buffer[ 1 ]));
1995 static int formatIPTCfromBuffer(Image *ofile, char *s, long len)
1998 temp[MaxTextExtent];
2018 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
2023 foundiptc = 0; /* found the IPTC-Header */
2024 tagsfound = 0; /* number of tags found */
2039 We found the 0x1c tag and now grab the dataset and record number tags.
2042 if (len < 0) return -1;
2043 dataset = (unsigned char) c;
2045 if (len < 0) return -1;
2046 recnum = (unsigned char) c;
2047 /* try to match this record to one of the ones in our named table */
2048 for (i=0; i< tagcount; i++)
2049 if (tags[i].id == (short) recnum)
2052 readable=(unsigned char *) tags[i].name;
2054 readable=(unsigned char *) "";
2056 We decode the length of the block that follows - long or short fmt.
2062 if (c & (unsigned char) 0x80)
2068 taglen=readWordFromBuffer(&s, &len);
2072 /* make a buffer to hold the tag datand snag it from the input stream */
2073 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
2075 if (str == (unsigned char *) NULL)
2077 printf("MemoryAllocationFailed");
2080 for (tagindx=0; tagindx<taglen; tagindx++)
2085 str[tagindx]=(unsigned char) c;
2089 /* now finish up by formatting this binary data into ASCII equivalent */
2090 if (strlen((char *)readable) > 0)
2091 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=",
2092 (unsigned int) dataset,(unsigned int) recnum, readable);
2094 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=",
2095 (unsigned int) dataset,(unsigned int) recnum);
2096 (void) WriteBlobString(ofile,temp);
2097 formatString( ofile, (char *)str, taglen );
2098 str=(unsigned char *) RelinquishMagickMemory(str);
2102 return ((int) tagsfound);
2105 static int format8BIM(Image *ifile, Image *ofile)
2108 temp[MaxTextExtent];
2127 foundOSType=0; /* found the OSType */
2128 c=ReadBlobByte(ifile);
2136 buffer[0]=(unsigned char) c;
2139 c=ReadBlobByte(ifile);
2142 buffer[i] = (unsigned char) c;
2145 if (strcmp((const char *)buffer, "8BIM") == 0)
2152 c=ReadBlobByte(ifile);
2156 We found the OSType (8BIM) and now grab the ID, PString, and Size fields.
2158 ID=(int) ReadBlobMSBShort(ifile);
2165 c=ReadBlobByte(ifile);
2168 plen = (unsigned char) c;
2169 PString=(unsigned char *) AcquireQuantumMemory((size_t) (plen+
2170 MaxTextExtent),sizeof(*PString));
2171 if (PString == (unsigned char *) NULL)
2173 printf("MemoryAllocationFailed");
2176 for (i=0; i<plen; i++)
2178 c=ReadBlobByte(ifile);
2179 if (c == EOF) return -1;
2180 PString[i] = (unsigned char) c;
2182 PString[ plen ] = 0;
2183 if ((plen & 0x01) == 0)
2185 c=ReadBlobByte(ifile);
2190 count = (ssize_t) ReadBlobMSBLong(ifile);
2191 if (count < 0) return -1;
2192 /* make a buffer to hold the datand snag it from the input stream */
2193 str=(unsigned char *) AcquireQuantumMemory((size_t) count,sizeof(*str));
2194 if (str == (unsigned char *) NULL)
2196 printf("MemoryAllocationFailed");
2199 for (i=0; i < (long) count; i++)
2201 c=ReadBlobByte(ifile);
2204 str[i]=(unsigned char) c;
2207 /* we currently skip thumbnails, since it does not make
2208 * any sense preserving them in a real world application
2210 if (ID != THUMBNAIL_ID)
2212 /* now finish up by formatting this binary data into
2215 if (strlen((const char *)PString) > 0)
2216 (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d#%s=",ID,
2219 (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d=",ID);
2220 (void) WriteBlobString(ofile,temp);
2223 formatString(ofile, "IPTC", 4);
2224 formatIPTCfromBuffer(ofile, (char *)str, (long) count);
2227 formatString(ofile, (char *)str, (long) count);
2229 str=(unsigned char *) RelinquishMagickMemory(str);
2230 PString=(unsigned char *) RelinquishMagickMemory(PString);
2232 c=ReadBlobByte(ifile);
2237 static MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
2252 assert(image_info != (const ImageInfo *) NULL);
2253 assert(image_info->signature == MagickSignature);
2254 assert(image != (Image *) NULL);
2255 assert(image->signature == MagickSignature);
2256 if (image->debug != MagickFalse)
2257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2259 if (LocaleCompare(image_info->magick,"8BIM") == 0)
2264 profile=GetImageProfile(image,"8bim");
2265 if (profile == (StringInfo *) NULL)
2266 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2267 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2268 if (status == MagickFalse)
2270 (void) WriteBlob(image,GetStringInfoLength(profile),
2271 GetStringInfoDatum(profile));
2272 (void) CloseBlob(image);
2275 if (LocaleCompare(image_info->magick,"iptc") == 0)
2283 profile=GetImageProfile(image,"8bim");
2284 if (profile == (StringInfo *) NULL)
2285 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2286 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2287 info=GetStringInfoDatum(profile);
2288 length=GetStringInfoLength(profile);
2289 length=GetIPTCStream(&info,length);
2291 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2292 (void) WriteBlob(image,length,info);
2293 (void) CloseBlob(image);
2296 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
2301 profile=GetImageProfile(image,"8bim");
2302 if (profile == (StringInfo *) NULL)
2303 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2304 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2305 if (status == MagickFalse)
2307 buff=AcquireImage((ImageInfo *) NULL);
2308 if (buff == (Image *) NULL)
2309 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2310 AttachBlob(buff->blob,GetStringInfoDatum(profile),
2311 GetStringInfoLength(profile));
2312 format8BIM(buff,image);
2313 (void) DetachBlob(buff->blob);
2314 buff=DestroyImage(buff);
2315 (void) CloseBlob(image);
2318 if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
2319 return(MagickFalse);
2320 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
2328 profile=GetImageProfile(image,"8bim");
2329 if (profile == (StringInfo *) NULL)
2330 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2331 info=GetStringInfoDatum(profile);
2332 length=GetStringInfoLength(profile);
2333 length=GetIPTCStream(&info,length);
2335 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2336 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2337 if (status == MagickFalse)
2339 buff=AcquireImage((ImageInfo *) NULL);
2340 if (buff == (Image *) NULL)
2341 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2342 AttachBlob(buff->blob,info,length);
2343 formatIPTC(buff,image);
2344 (void) DetachBlob(buff->blob);
2345 buff=DestroyImage(buff);
2346 (void) CloseBlob(image);
2349 if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
2350 return(MagickFalse);
2351 if ((LocaleCompare(image_info->magick,"APP1") == 0) ||
2352 (LocaleCompare(image_info->magick,"EXIF") == 0) ||
2353 (LocaleCompare(image_info->magick,"XMP") == 0))
2356 (void) Write APP1 image.
2358 profile=GetImageProfile(image,image_info->magick);
2359 if (profile == (StringInfo *) NULL)
2360 ThrowWriterException(CoderError,"NoAPP1DataIsAvailable");
2361 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2362 if (status == MagickFalse)
2364 (void) WriteBlob(image,GetStringInfoLength(profile),
2365 GetStringInfoDatum(profile));
2366 (void) CloseBlob(image);
2369 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
2370 (LocaleCompare(image_info->magick,"ICM") == 0))
2375 profile=GetImageProfile(image,"icc");
2376 if (profile == (StringInfo *) NULL)
2377 ThrowWriterException(CoderError,"NoColorProfileIsAvailable");
2378 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
2379 if (status == MagickFalse)
2381 (void) WriteBlob(image,GetStringInfoLength(profile),
2382 GetStringInfoDatum(profile));
2383 (void) CloseBlob(image);
2386 return(MagickFalse);