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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/exception.h"
46 #include "MagickCore/exception-private.h"
47 #include "MagickCore/image.h"
48 #include "MagickCore/image-private.h"
49 #include "MagickCore/list.h"
50 #include "MagickCore/magick.h"
51 #include "MagickCore/memory_.h"
52 #include "MagickCore/module.h"
53 #include "MagickCore/profile.h"
54 #include "MagickCore/splay-tree.h"
55 #include "MagickCore/quantum-private.h"
56 #include "MagickCore/static.h"
57 #include "MagickCore/string_.h"
58 #include "MagickCore/string-private.h"
59 #include "MagickCore/token.h"
60 #include "MagickCore/utility.h"
65 static MagickBooleanType
66 WriteMETAImage(const ImageInfo *,Image *,ExceptionInfo *);
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,exception);
1097 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1098 if (status == MagickFalse)
1100 image=DestroyImageList(image);
1101 return((Image *) NULL);
1105 if (SetImageBackgroundColor(image,exception) == MagickFalse)
1107 image=DestroyImageList(image);
1108 return((Image *) NULL);
1111 if (LocaleNCompare(image_info->magick,"8BIM",4) == 0)
1114 Read 8BIM binary metadata.
1116 buff=AcquireImage((ImageInfo *) NULL,exception);
1117 if (buff == (Image *) NULL)
1118 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1119 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1120 if (blob == (unsigned char *) NULL)
1122 buff=DestroyImage(buff);
1123 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1125 AttachBlob(buff->blob,blob,length);
1126 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
1128 length=(size_t) parse8BIM(image, buff);
1130 (void) WriteBlobByte(buff,0x0);
1132 else if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
1134 length=(size_t) parse8BIMW(image, buff);
1136 (void) WriteBlobByte(buff,0x0);
1142 c=ReadBlobByte(image);
1145 (void) WriteBlobByte(buff,(unsigned char) c);
1148 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1150 if (profile == (StringInfo *) NULL)
1151 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1152 status=SetImageProfile(image,"8bim",profile,exception);
1153 profile=DestroyStringInfo(profile);
1154 if (status == MagickFalse)
1155 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1156 blob=DetachBlob(buff->blob);
1157 blob=(unsigned char *) RelinquishMagickMemory(blob);
1158 buff=DestroyImage(buff);
1160 if (LocaleNCompare(image_info->magick,"APP1",4) == 0)
1163 name[MaxTextExtent];
1165 (void) FormatLocaleString(name,MaxTextExtent,"APP%d",1);
1166 buff=AcquireImage((ImageInfo *) NULL,exception);
1167 if (buff == (Image *) NULL)
1168 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1169 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1170 if (blob == (unsigned char *) NULL)
1172 buff=DestroyImage(buff);
1173 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1175 AttachBlob(buff->blob,blob,length);
1176 if (LocaleCompare(image_info->magick,"APP1JPEG") == 0)
1184 if (image_info->profile == (void *) NULL)
1186 blob=DetachBlob(buff->blob);
1187 blob=RelinquishMagickMemory(blob);
1188 buff=DestroyImage(buff);
1189 ThrowReaderException(CoderError,"NoIPTCProfileAvailable");
1191 profile=CloneStringInfo((StringInfo *) image_info->profile);
1192 iptc=AcquireImage((ImageInfo *) NULL,exception);
1193 if (iptc == (Image *) NULL)
1195 blob=DetachBlob(buff->blob);
1196 blob=RelinquishMagickMemory(blob);
1197 buff=DestroyImage(buff);
1198 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1200 AttachBlob(iptc->blob,GetStringInfoDatum(profile),
1201 GetStringInfoLength(profile));
1202 result=jpeg_embed(image,buff,iptc);
1203 blob=DetachBlob(iptc->blob);
1204 blob=RelinquishMagickMemory(blob);
1205 iptc=DestroyImage(iptc);
1208 blob=DetachBlob(buff->blob);
1209 blob=RelinquishMagickMemory(blob);
1210 buff=DestroyImage(buff);
1211 ThrowReaderException(CoderError,"JPEGEmbeddingFailed");
1219 /* Really - really slow - FIX ME PLEASE!!!! */
1220 c=ReadBlobByte(image);
1223 (void) WriteBlobByte(buff,c);
1236 buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
1238 if (buffer != (unsigned char *) NULL)
1241 while ((length=ReadBlob(image,MagickMaxBufferExtent,buffer)) != 0)
1244 for (i=0; i < (ssize_t) length; i+=count)
1246 count=WriteBlob(buff,(size_t) (length-i),buffer+i);
1250 if (i < (ssize_t) length)
1253 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1257 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1259 if (profile == (StringInfo *) NULL)
1260 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1261 status=SetImageProfile(image,name,profile,exception);
1262 profile=DestroyStringInfo(profile);
1263 if (status == MagickFalse)
1264 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1265 blob=DetachBlob(buff->blob);
1266 blob=RelinquishMagickMemory(blob);
1267 buff=DestroyImage(buff);
1269 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
1270 (LocaleCompare(image_info->magick,"ICM") == 0))
1272 buff=AcquireImage((ImageInfo *) NULL,exception);
1273 if (buff == (Image *) NULL)
1274 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1275 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1276 if (blob == (unsigned char *) NULL)
1278 buff=DestroyImage(buff);
1279 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1281 AttachBlob(buff->blob,blob,length);
1284 c=ReadBlobByte(image);
1287 (void) WriteBlobByte(buff,(unsigned char) c);
1289 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1291 if (profile == (StringInfo *) NULL)
1292 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1293 (void) SetImageProfile(image,"icc",profile,exception);
1294 profile=DestroyStringInfo(profile);
1295 blob=DetachBlob(buff->blob);
1296 blob=(unsigned char *) RelinquishMagickMemory(blob);
1297 buff=DestroyImage(buff);
1299 if (LocaleCompare(image_info->magick,"IPTC") == 0)
1301 register unsigned char
1304 buff=AcquireImage((ImageInfo *) NULL,exception);
1305 if (buff == (Image *) NULL)
1306 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1307 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1308 if (blob == (unsigned char *) NULL)
1310 buff=DestroyImage(buff);
1311 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1313 AttachBlob(buff->blob,blob,length);
1314 /* write out the header - length field patched below */
1315 (void) WriteBlob(buff,11,(unsigned char *) "8BIM\04\04\0\0\0\0\0");
1316 (void) WriteBlobByte(buff,0xc6);
1317 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
1319 length=(size_t) parse8BIM(image,buff);
1321 (void) WriteBlobByte(buff,0x00);
1323 else if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
1330 c=ReadBlobByte(image);
1333 (void) WriteBlobByte(buff,(unsigned char) c);
1336 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1338 if (profile == (StringInfo *) NULL)
1339 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1341 subtract off the length of the 8BIM stuff.
1343 length=GetStringInfoLength(profile)-12;
1344 p=GetStringInfoDatum(profile);
1345 p[10]=(unsigned char) (length >> 8);
1346 p[11]=(unsigned char) (length & 0xff);
1347 SetStringInfoDatum(profile,GetBlobStreamData(buff));
1348 (void) SetImageProfile(image,"8bim",profile,exception);
1349 profile=DestroyStringInfo(profile);
1350 blob=DetachBlob(buff->blob);
1351 blob=(unsigned char *) RelinquishMagickMemory(blob);
1352 buff=DestroyImage(buff);
1354 if (LocaleCompare(image_info->magick,"XMP") == 0)
1356 buff=AcquireImage((ImageInfo *) NULL,exception);
1357 if (buff == (Image *) NULL)
1358 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1359 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1360 if (blob == (unsigned char *) NULL)
1362 buff=DestroyImage(buff);
1363 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1365 AttachBlob(buff->blob,blob,length);
1368 c=ReadBlobByte(image);
1371 (void) WriteBlobByte(buff,(unsigned char) c);
1373 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1375 if (profile == (StringInfo *) NULL)
1376 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1377 (void) SetImageProfile(image,"xmp",profile,exception);
1378 profile=DestroyStringInfo(profile);
1379 blob=DetachBlob(buff->blob);
1380 blob=(unsigned char *) RelinquishMagickMemory(blob);
1381 buff=DestroyImage(buff);
1383 (void) CloseBlob(image);
1384 return(GetFirstImageInList(image));
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1392 % R e g i s t e r M E T A I m a g e %
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398 % RegisterMETAImage() adds attributes for the META image format to
1399 % the list of supported formats. The attributes include the image format
1400 % tag, a method to read and/or write the format, whether the format
1401 % supports the saving of more than one frame to the same file or blob,
1402 % whether the format supports native in-memory I/O, and a brief
1403 % description of the format.
1405 % The format of the RegisterMETAImage method is:
1407 % size_t RegisterMETAImage(void)
1410 ModuleExport size_t RegisterMETAImage(void)
1415 entry=SetMagickInfo("8BIM");
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 format");
1422 entry->module=ConstantString("META");
1423 (void) RegisterMagickInfo(entry);
1424 entry=SetMagickInfo("8BIMTEXT");
1425 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1426 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1427 entry->adjoin=MagickFalse;
1428 entry->stealth=MagickTrue;
1429 entry->seekable_stream=MagickTrue;
1430 entry->description=ConstantString("Photoshop resource text format");
1431 entry->module=ConstantString("META");
1432 (void) RegisterMagickInfo(entry);
1433 entry=SetMagickInfo("8BIMWTEXT");
1434 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1435 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1436 entry->adjoin=MagickFalse;
1437 entry->stealth=MagickTrue;
1438 entry->seekable_stream=MagickTrue;
1439 entry->description=ConstantString("Photoshop resource wide text format");
1440 entry->module=ConstantString("META");
1441 (void) RegisterMagickInfo(entry);
1442 entry=SetMagickInfo("APP1");
1443 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1444 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1445 entry->adjoin=MagickFalse;
1446 entry->stealth=MagickTrue;
1447 entry->seekable_stream=MagickTrue;
1448 entry->description=ConstantString("Raw application information");
1449 entry->module=ConstantString("META");
1450 (void) RegisterMagickInfo(entry);
1451 entry=SetMagickInfo("APP1JPEG");
1452 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1453 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1454 entry->adjoin=MagickFalse;
1455 entry->stealth=MagickTrue;
1456 entry->seekable_stream=MagickTrue;
1457 entry->description=ConstantString("Raw JPEG binary data");
1458 entry->module=ConstantString("META");
1459 (void) RegisterMagickInfo(entry);
1460 entry=SetMagickInfo("EXIF");
1461 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1462 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1463 entry->adjoin=MagickFalse;
1464 entry->stealth=MagickTrue;
1465 entry->seekable_stream=MagickTrue;
1466 entry->description=ConstantString("Exif digital camera binary data");
1467 entry->module=ConstantString("META");
1468 (void) RegisterMagickInfo(entry);
1469 entry=SetMagickInfo("XMP");
1470 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1471 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1472 entry->adjoin=MagickFalse;
1473 entry->stealth=MagickTrue;
1474 entry->seekable_stream=MagickTrue;
1475 entry->description=ConstantString("Adobe XML metadata");
1476 entry->module=ConstantString("META");
1477 (void) RegisterMagickInfo(entry);
1478 entry=SetMagickInfo("ICM");
1479 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1480 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1481 entry->adjoin=MagickFalse;
1482 entry->stealth=MagickTrue;
1483 entry->seekable_stream=MagickTrue;
1484 entry->description=ConstantString("ICC Color Profile");
1485 entry->module=ConstantString("META");
1486 (void) RegisterMagickInfo(entry);
1487 entry=SetMagickInfo("ICC");
1488 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1489 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1490 entry->adjoin=MagickFalse;
1491 entry->stealth=MagickTrue;
1492 entry->seekable_stream=MagickTrue;
1493 entry->description=ConstantString("ICC Color Profile");
1494 entry->module=ConstantString("META");
1495 (void) RegisterMagickInfo(entry);
1496 entry=SetMagickInfo("IPTC");
1497 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1498 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1499 entry->adjoin=MagickFalse;
1500 entry->stealth=MagickTrue;
1501 entry->seekable_stream=MagickTrue;
1502 entry->description=ConstantString("IPTC Newsphoto");
1503 entry->module=ConstantString("META");
1504 (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);
1514 entry=SetMagickInfo("IPTCWTEXT");
1515 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1516 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1517 entry->adjoin=MagickFalse;
1518 entry->stealth=MagickTrue;
1519 entry->seekable_stream=MagickTrue;
1520 entry->description=ConstantString("IPTC Newsphoto text format");
1521 entry->module=ConstantString("META");
1522 (void) RegisterMagickInfo(entry);
1523 return(MagickImageCoderSignature);
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531 % U n r e g i s t e r M E T A I m a g e %
1535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % UnregisterMETAImage() removes format registrations made by the
1538 % META module from the list of supported formats.
1540 % The format of the UnregisterMETAImage method is:
1542 % UnregisterMETAImage(void)
1545 ModuleExport void UnregisterMETAImage(void)
1547 (void) UnregisterMagickInfo("8BIM");
1548 (void) UnregisterMagickInfo("8BIMTEXT");
1549 (void) UnregisterMagickInfo("8BIMWTEXT");
1550 (void) UnregisterMagickInfo("EXIF");
1551 (void) UnregisterMagickInfo("APP1");
1552 (void) UnregisterMagickInfo("APP1JPEG");
1553 (void) UnregisterMagickInfo("ICCTEXT");
1554 (void) UnregisterMagickInfo("ICM");
1555 (void) UnregisterMagickInfo("ICC");
1556 (void) UnregisterMagickInfo("IPTC");
1557 (void) UnregisterMagickInfo("IPTCTEXT");
1558 (void) UnregisterMagickInfo("IPTCWTEXT");
1559 (void) UnregisterMagickInfo("XMP");
1563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567 % W r i t e M E T A I m a g e %
1571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1573 % WriteMETAImage() writes a META image to a file.
1575 % The format of the WriteMETAImage method is:
1577 % MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
1578 % Image *image,ExceptionInfo *exception)
1580 % Compression code contributed by Kyle Shorter.
1582 % A description of each parameter follows:
1584 % o image_info: Specifies a pointer to an ImageInfo structure.
1586 % o image: A pointer to a Image structure.
1588 % o exception: return any errors or warnings in this structure.
1592 static size_t GetIPTCStream(unsigned char **info,size_t length)
1600 register unsigned char
1615 if ((*p == 0x1c) && (*(p+1) == 0x02))
1618 Extract IPTC from 8BIM resource block.
1620 while (extent >= 12)
1622 if (strncmp((const char *) p,"8BIM",4))
1626 marker=(unsigned int) (*p) << 8 | *(p+1);
1632 if ((size_t) c >= extent)
1638 tag_length=(((size_t) *p) << 24) | (((size_t) *(p+1)) << 16) |
1639 (((size_t) *(p+2)) << 8) | ((size_t) *(p+3));
1642 if (tag_length > extent)
1644 if (marker == IPTC_ID)
1649 if ((tag_length & 0x01) != 0)
1655 Find the beginning of the IPTC info.
1671 *info=p; /* let the caller know were it is */
1676 Determine the length of the IPTC info.
1693 Found the 0x1c tag; skip the dataset and record number tags.
1695 c=(*p++); /* should be 2 */
1699 if ((info_length == 1) && (c != 2))
1702 c=(*p++); /* should be 0 */
1706 if ((info_length == 2) && (c != 0))
1710 Decode the length of the block that follows - ssize_t or short format.
1717 if ((c & 0x80) != 0)
1723 for (i=0; i < 4; i++)
1738 tag_length=((long) c) << 8;
1744 tag_length|=(long) c;
1746 if (tag_length > (length+1))
1752 info_length+=tag_length;
1754 return(info_length);
1757 static void formatString(Image *ofile, const char *s, int len)
1760 temp[MaxTextExtent];
1762 (void) WriteBlobByte(ofile,'"');
1763 for (; len > 0; len--, s++) {
1767 (void) WriteBlobString(ofile,"&");
1771 (void) WriteBlobString(ofile,"<");
1774 (void) WriteBlobString(ofile,">");
1778 (void) WriteBlobString(ofile,""");
1782 (void) WriteBlobByte(ofile,(unsigned char) *s);
1785 (void) FormatLocaleString(temp,MaxTextExtent,"&#%d;", c & 255);
1786 (void) WriteBlobString(ofile,temp);
1791 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1792 (void) WriteBlobString(ofile,"\"\r\n");
1794 #if defined(macintosh)
1795 (void) WriteBlobString(ofile,"\"\r");
1797 (void) WriteBlobString(ofile,"\"\n");
1802 typedef struct _tag_spec
1811 static const tag_spec tags[] = {
1812 { 5, "Image Name" },
1813 { 7, "Edit Status" },
1816 { 20, "Supplemental Category" },
1817 { 22, "Fixture Identifier" },
1819 { 30, "Release Date" },
1820 { 35, "Release Time" },
1821 { 40, "Special Instructions" },
1822 { 45, "Reference Service" },
1823 { 47, "Reference Date" },
1824 { 50, "Reference Number" },
1825 { 55, "Created Date" },
1826 { 60, "Created Time" },
1827 { 65, "Originating Program" },
1828 { 70, "Program Version" },
1829 { 75, "Object Cycle" },
1831 { 85, "Byline Title" },
1833 { 95, "Province State" },
1834 { 100, "Country Code" },
1836 { 103, "Original Transmission Reference" },
1837 { 105, "Headline" },
1840 { 116, "Copyright String" },
1842 { 121, "Image Orientation" },
1843 { 122, "Caption Writer" },
1844 { 131, "Local Caption" },
1845 { 200, "Custom Field 1" },
1846 { 201, "Custom Field 2" },
1847 { 202, "Custom Field 3" },
1848 { 203, "Custom Field 4" },
1849 { 204, "Custom Field 5" },
1850 { 205, "Custom Field 6" },
1851 { 206, "Custom Field 7" },
1852 { 207, "Custom Field 8" },
1853 { 208, "Custom Field 9" },
1854 { 209, "Custom Field 10" },
1855 { 210, "Custom Field 11" },
1856 { 211, "Custom Field 12" },
1857 { 212, "Custom Field 13" },
1858 { 213, "Custom Field 14" },
1859 { 214, "Custom Field 15" },
1860 { 215, "Custom Field 16" },
1861 { 216, "Custom Field 17" },
1862 { 217, "Custom Field 18" },
1863 { 218, "Custom Field 19" },
1864 { 219, "Custom Field 20" }
1867 static int formatIPTC(Image *ifile, Image *ofile)
1870 temp[MaxTextExtent];
1890 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
1895 foundiptc = 0; /* found the IPTC-Header */
1896 tagsfound = 0; /* number of tags found */
1898 c = ReadBlobByte(ifile);
1911 /* we found the 0x1c tag and now grab the dataset and record number tags */
1912 c = ReadBlobByte(ifile);
1913 if (c == EOF) return -1;
1914 dataset = (unsigned char) c;
1915 c = ReadBlobByte(ifile);
1916 if (c == EOF) return -1;
1917 recnum = (unsigned char) c;
1918 /* try to match this record to one of the ones in our named table */
1919 for (i=0; i< tagcount; i++)
1921 if (tags[i].id == (short) recnum)
1925 readable = (unsigned char *) tags[i].name;
1927 readable = (unsigned char *) "";
1929 We decode the length of the block that follows - ssize_t or short fmt.
1931 c=ReadBlobByte(ifile);
1932 if (c == EOF) return -1;
1933 if (c & (unsigned char) 0x80)
1940 c0=ReadBlobByte(ifile);
1941 if (c0 == EOF) return -1;
1942 taglen = (c << 8) | c0;
1944 if (taglen < 0) return -1;
1945 /* make a buffer to hold the tag datand snag it from the input stream */
1946 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
1948 if (str == (unsigned char *) NULL)
1950 printf("MemoryAllocationFailed");
1953 for (tagindx=0; tagindx<taglen; tagindx++)
1955 c=ReadBlobByte(ifile);
1956 if (c == EOF) return -1;
1957 str[tagindx] = (unsigned char) c;
1961 /* now finish up by formatting this binary data into ASCII equivalent */
1962 if (strlen((char *)readable) > 0)
1963 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
1964 (unsigned int) dataset, (unsigned int) recnum, readable);
1966 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
1967 (unsigned int) dataset,(unsigned int) recnum);
1968 (void) WriteBlobString(ofile,temp);
1969 formatString( ofile, (char *)str, taglen );
1970 str=(unsigned char *) RelinquishMagickMemory(str);
1974 c=ReadBlobByte(ifile);
1976 return((int) tagsfound);
1979 static int readWordFromBuffer(char **s, ssize_t *len)
1990 c = *(*s)++; (*len)--;
1991 if (*len < 0) return -1;
1992 buffer[i] = (unsigned char) c;
1994 return (((int) buffer[ 0 ]) << 8) |
1995 (((int) buffer[ 1 ]));
1998 static int formatIPTCfromBuffer(Image *ofile, char *s, ssize_t len)
2001 temp[MaxTextExtent];
2021 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
2026 foundiptc = 0; /* found the IPTC-Header */
2027 tagsfound = 0; /* number of tags found */
2042 We found the 0x1c tag and now grab the dataset and record number tags.
2045 if (len < 0) return -1;
2046 dataset = (unsigned char) c;
2048 if (len < 0) return -1;
2049 recnum = (unsigned char) c;
2050 /* try to match this record to one of the ones in our named table */
2051 for (i=0; i< tagcount; i++)
2052 if (tags[i].id == (short) recnum)
2055 readable=(unsigned char *) tags[i].name;
2057 readable=(unsigned char *) "";
2059 We decode the length of the block that follows - ssize_t or short fmt.
2065 if (c & (unsigned char) 0x80)
2071 taglen=readWordFromBuffer(&s, &len);
2075 /* make a buffer to hold the tag datand snag it from the input stream */
2076 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MaxTextExtent),
2078 if (str == (unsigned char *) NULL)
2080 printf("MemoryAllocationFailed");
2083 for (tagindx=0; tagindx<taglen; tagindx++)
2088 str[tagindx]=(unsigned char) c;
2092 /* now finish up by formatting this binary data into ASCII equivalent */
2093 if (strlen((char *)readable) > 0)
2094 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
2095 (unsigned int) dataset,(unsigned int) recnum, readable);
2097 (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
2098 (unsigned int) dataset,(unsigned int) recnum);
2099 (void) WriteBlobString(ofile,temp);
2100 formatString( ofile, (char *)str, taglen );
2101 str=(unsigned char *) RelinquishMagickMemory(str);
2105 return ((int) tagsfound);
2108 static int format8BIM(Image *ifile, Image *ofile)
2111 temp[MaxTextExtent];
2130 foundOSType=0; /* found the OSType */
2132 c=ReadBlobByte(ifile);
2140 buffer[0]=(unsigned char) c;
2143 c=ReadBlobByte(ifile);
2146 buffer[i] = (unsigned char) c;
2149 if (strcmp((const char *)buffer, "8BIM") == 0)
2156 c=ReadBlobByte(ifile);
2160 We found the OSType (8BIM) and now grab the ID, PString, and Size fields.
2162 ID=(int) ReadBlobMSBShort(ifile);
2169 c=ReadBlobByte(ifile);
2172 plen = (unsigned char) c;
2173 PString=(unsigned char *) AcquireQuantumMemory((size_t) (plen+
2174 MaxTextExtent),sizeof(*PString));
2175 if (PString == (unsigned char *) NULL)
2177 printf("MemoryAllocationFailed");
2180 for (i=0; i<plen; i++)
2182 c=ReadBlobByte(ifile);
2183 if (c == EOF) return -1;
2184 PString[i] = (unsigned char) c;
2186 PString[ plen ] = 0;
2187 if ((plen & 0x01) == 0)
2189 c=ReadBlobByte(ifile);
2194 count = (int) ReadBlobMSBLong(ifile);
2195 if (count < 0) return -1;
2196 /* make a buffer to hold the datand snag it from the input stream */
2197 str=(unsigned char *) AcquireQuantumMemory((size_t) count,sizeof(*str));
2198 if (str == (unsigned char *) NULL)
2200 printf("MemoryAllocationFailed");
2203 for (i=0; i < (ssize_t) count; i++)
2205 c=ReadBlobByte(ifile);
2208 str[i]=(unsigned char) c;
2211 /* we currently skip thumbnails, since it does not make
2212 * any sense preserving them in a real world application
2214 if (ID != THUMBNAIL_ID)
2216 /* now finish up by formatting this binary data into
2219 if (strlen((const char *)PString) > 0)
2220 (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d#%s=",ID,
2223 (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d=",ID);
2224 (void) WriteBlobString(ofile,temp);
2227 formatString(ofile, "IPTC", 4);
2228 formatIPTCfromBuffer(ofile, (char *)str, (ssize_t) count);
2231 formatString(ofile, (char *)str, (ssize_t) count);
2233 str=(unsigned char *) RelinquishMagickMemory(str);
2234 PString=(unsigned char *) RelinquishMagickMemory(PString);
2236 c=ReadBlobByte(ifile);
2241 static MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
2242 Image *image,ExceptionInfo *exception)
2256 assert(image_info != (const ImageInfo *) NULL);
2257 assert(image_info->signature == MagickSignature);
2258 assert(image != (Image *) NULL);
2259 assert(image->signature == MagickSignature);
2260 if (image->debug != MagickFalse)
2261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2263 if (LocaleCompare(image_info->magick,"8BIM") == 0)
2268 profile=GetImageProfile(image,"8bim");
2269 if (profile == (StringInfo *) NULL)
2270 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2271 assert(exception != (ExceptionInfo *) NULL);
2272 assert(exception->signature == MagickSignature);
2273 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2274 if (status == MagickFalse)
2276 (void) WriteBlob(image,GetStringInfoLength(profile),
2277 GetStringInfoDatum(profile));
2278 (void) CloseBlob(image);
2281 if (LocaleCompare(image_info->magick,"iptc") == 0)
2289 profile=GetImageProfile(image,"iptc");
2290 if (profile == (StringInfo *) NULL)
2291 profile=GetImageProfile(image,"8bim");
2292 if (profile == (StringInfo *) NULL)
2293 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2294 assert(exception != (ExceptionInfo *) NULL);
2295 assert(exception->signature == MagickSignature);
2296 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2297 info=GetStringInfoDatum(profile);
2298 length=GetStringInfoLength(profile);
2299 length=GetIPTCStream(&info,length);
2301 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2302 (void) WriteBlob(image,length,info);
2303 (void) CloseBlob(image);
2306 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
2311 profile=GetImageProfile(image,"8bim");
2312 if (profile == (StringInfo *) NULL)
2313 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2314 assert(exception != (ExceptionInfo *) NULL);
2315 assert(exception->signature == MagickSignature);
2316 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2317 if (status == MagickFalse)
2319 buff=AcquireImage((ImageInfo *) NULL,exception);
2320 if (buff == (Image *) NULL)
2321 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2322 AttachBlob(buff->blob,GetStringInfoDatum(profile),
2323 GetStringInfoLength(profile));
2324 format8BIM(buff,image);
2325 (void) DetachBlob(buff->blob);
2326 buff=DestroyImage(buff);
2327 (void) CloseBlob(image);
2330 if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
2331 return(MagickFalse);
2332 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
2340 profile=GetImageProfile(image,"8bim");
2341 if (profile == (StringInfo *) NULL)
2342 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2343 info=GetStringInfoDatum(profile);
2344 length=GetStringInfoLength(profile);
2345 length=GetIPTCStream(&info,length);
2347 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2348 assert(exception != (ExceptionInfo *) NULL);
2349 assert(exception->signature == MagickSignature);
2350 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2351 if (status == MagickFalse)
2353 buff=AcquireImage((ImageInfo *) NULL,exception);
2354 if (buff == (Image *) NULL)
2355 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2356 AttachBlob(buff->blob,info,length);
2357 formatIPTC(buff,image);
2358 (void) DetachBlob(buff->blob);
2359 buff=DestroyImage(buff);
2360 (void) CloseBlob(image);
2363 if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
2364 return(MagickFalse);
2365 if ((LocaleCompare(image_info->magick,"APP1") == 0) ||
2366 (LocaleCompare(image_info->magick,"EXIF") == 0) ||
2367 (LocaleCompare(image_info->magick,"XMP") == 0))
2370 (void) Write APP1 image.
2372 profile=GetImageProfile(image,image_info->magick);
2373 if (profile == (StringInfo *) NULL)
2374 ThrowWriterException(CoderError,"NoAPP1DataIsAvailable");
2375 assert(exception != (ExceptionInfo *) NULL);
2376 assert(exception->signature == MagickSignature);
2377 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2378 if (status == MagickFalse)
2380 (void) WriteBlob(image,GetStringInfoLength(profile),
2381 GetStringInfoDatum(profile));
2382 (void) CloseBlob(image);
2385 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
2386 (LocaleCompare(image_info->magick,"ICM") == 0))
2391 profile=GetImageProfile(image,"icc");
2392 if (profile == (StringInfo *) NULL)
2393 ThrowWriterException(CoderError,"NoColorProfileIsAvailable");
2394 assert(exception != (ExceptionInfo *) NULL);
2395 assert(exception->signature == MagickSignature);
2396 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2397 if (status == MagickFalse)
2399 (void) WriteBlob(image,GetStringInfoLength(profile),
2400 GetStringInfoDatum(profile));
2401 (void) CloseBlob(image);
2404 return(MagickFalse);