2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M EEEEE TTTTT AAA %
13 % Read/Write Embedded Image Profiles. %
20 % Copyright 1999-2016 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/channel.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/image.h"
49 #include "MagickCore/image-private.h"
50 #include "MagickCore/list.h"
51 #include "MagickCore/magick.h"
52 #include "MagickCore/memory_.h"
53 #include "MagickCore/module.h"
54 #include "MagickCore/profile.h"
55 #include "MagickCore/splay-tree.h"
56 #include "MagickCore/quantum-private.h"
57 #include "MagickCore/static.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/string-private.h"
60 #include "MagickCore/token.h"
61 #include "MagickCore/utility.h"
66 static MagickBooleanType
67 WriteMETAImage(const ImageInfo *,Image *,ExceptionInfo *);
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % IsMETA() returns MagickTrue if the image format type, identified by the
81 % magick string, is META.
83 % The format of the IsMETA method is:
85 % MagickBooleanType IsMETA(const unsigned char *magick,const size_t length)
87 % A description of each parameter follows:
89 % o magick: compare image format pattern against these bytes.
91 % o length: Specifies the length of the magick string.
95 #ifdef IMPLEMENT_IS_FUNCTION
96 static MagickBooleanType IsMETA(const unsigned char *magick,const size_t length)
100 if (LocaleNCompare((char *) magick,"8BIM",4) == 0)
102 if (LocaleNCompare((char *) magick,"APP1",4) == 0)
104 if (LocaleNCompare((char *) magick,"\034\002",2) == 0)
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % R e a d M E T A I m a g e %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 % ReadMETAImage() reads a META image file and returns it. It
122 % allocates the memory necessary for the new Image structure and returns a
123 % pointer to the new image.
125 % The format of the ReadMETAImage method is:
127 % Image *ReadMETAImage(const ImageInfo *image_info,
128 % ExceptionInfo *exception)
130 % Decompression code contributed by Kyle Shorter.
132 % A description of each parameter follows:
134 % o image: Method ReadMETAImage returns a pointer to the image after
135 % reading. A null image is returned if there is a memory shortage or
136 % if the image cannot be read.
138 % o image_info: Specifies a pointer to an ImageInfo structure.
140 % o exception: return any errors or warnings in this structure.
144 typedef struct _html_code
154 static const html_code html_codes[] = {
164 static int stringnicmp(const char *p,const char *q,size_t n)
172 if (p == (char *) NULL)
174 if (q == (char *) NULL)
176 while ((*p != '\0') && (*q != '\0'))
178 if ((*p == '\0') || (*q == '\0'))
194 return(toupper((int) *p)-toupper((int) *q));
197 static size_t convertHTMLcodes(char *s, const size_t len)
202 if ((len == 0) || (s == (char*) NULL) || (*s=='\0'))
204 if ((len > 3) && (s[1] == '#') && (strchr(s,';') != (char *) NULL) &&
205 (sscanf(s,"&#%d;",&value) == 1))
215 (void) memmove(s+1,s+1+o,strlen(s+1+o)+1);
225 codes=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) memmove(s+1,s+html_codes[i].len,
232 strlen(s+html_codes[i].len)+1);
233 *s=html_codes[i].val;
234 return(html_codes[i].len-1);
241 static char *super_fgets(char **b, int *blen, Image *file)
252 p=(unsigned char *) (*b);
255 c=ReadBlobByte(file);
256 if (c == EOF || c == '\n')
258 if ((q-p+1) >= (int) len)
265 p=(unsigned char *) ResizeQuantumMemory(p,(size_t) len+2UL,sizeof(*p));
267 if (p == (unsigned char *) NULL)
271 *q=(unsigned char) c;
274 if (p != (unsigned char *) NULL)
281 return (char *) NULL;
289 #define THUMBNAIL_ID 1033
291 static ssize_t parse8BIM(Image *ifile, Image *ofile)
312 inputlen = MagickPathExtent;
327 line = (char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*line));
328 if (line == (char *) NULL)
330 newstr = name = token = (char *) NULL;
332 token_info=AcquireTokenInfo();
333 while (super_fgets(&line,&inputlen,ifile)!=NULL)
338 token=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*token));
339 if (token == (char *) NULL)
341 newstr=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*newstr));
342 if (newstr == (char *) NULL)
344 while (Tokenizer(token_info,0,token,(size_t) inputlen,line,"","=","\"",0,
345 &brkused,&next,"ed)==0)
359 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","#",
360 "", 0,&brkused,&next,"ed)==0)
365 if (strcmp(newstr,"8BIM")==0)
368 dataset = (unsigned char) StringToLong(newstr);
371 recnum = (unsigned int) StringToUnsignedLong(newstr);
374 name=(char *) AcquireQuantumMemory(strlen(newstr)+MagickPathExtent,
377 (void) strcpy(name,newstr);
397 len = (ssize_t) strlen(token);
398 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
399 "",0,&brkused,&next,"ed)==0)
401 if (brkused && next > 0)
406 len -= (ssize_t) convertHTMLcodes(s,strlen(s));
423 ssize_t diff = outputlen - savedolen;
424 currentpos = TellBlob(ofile);
427 offset=SeekBlob(ofile,savedpos,SEEK_SET);
430 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
431 offset=SeekBlob(ofile,currentpos,SEEK_SET);
438 (void) WriteBlobByte(ofile,0x00);
441 (void) WriteBlobString(ofile,"8BIM");
442 (void) WriteBlobMSBShort(ofile,(unsigned short) recnum);
445 nlen = (unsigned char) strlen(name);
446 (void) WriteBlobByte(ofile,nlen);
448 for (i=0; i<nlen; i++)
449 (void) WriteBlobByte(ofile,(unsigned char) name[i]);
451 if ((nlen & 0x01) == 0)
453 (void) WriteBlobByte(ofile,0x00);
456 if (recnum != IPTC_ID)
458 (void) WriteBlobMSBLong(ofile, (unsigned int) len);
464 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
468 (void) WriteBlobByte(ofile,0x00);
474 /* patch in a fake length for now and fix it later */
475 savedpos = TellBlob(ofile);
478 (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
480 savedolen = outputlen;
487 (void) WriteBlobByte(ofile,0x1c);
488 (void) WriteBlobByte(ofile,(unsigned char) dataset);
489 (void) WriteBlobByte(ofile,(unsigned char) (recnum & 0xff));
490 (void) WriteBlobMSBShort(ofile,(unsigned short) len);
495 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
501 if (token != (char *) NULL)
502 token=DestroyString(token);
503 if (newstr != (char *) NULL)
504 newstr=DestroyString(newstr);
505 if (name != (char *) NULL)
506 name=DestroyString(name);
508 token_info=DestroyTokenInfo(token_info);
509 if (token != (char *) NULL)
510 token=DestroyString(token);
511 if (newstr != (char *) NULL)
512 newstr=DestroyString(newstr);
513 if (name != (char *) NULL)
514 name=DestroyString(name);
515 line=DestroyString(line);
521 ssize_t diff = outputlen - savedolen;
523 currentpos = TellBlob(ofile);
526 offset=SeekBlob(ofile,savedpos,SEEK_SET);
529 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
530 offset=SeekBlob(ofile,currentpos,SEEK_SET);
538 static char *super_fgets_w(char **b, int *blen, Image *file)
549 p=(unsigned char *) (*b);
552 c=ReadBlobLSBSignedShort(file);
553 if ((c == -1) || (c == '\n'))
557 if ((q-p+1) >= (int) len)
564 p=(unsigned char *) ResizeQuantumMemory(p,(size_t) (len+2),sizeof(*p));
566 if (p == (unsigned char *) NULL)
570 *q=(unsigned char) c;
573 if ((*b) != (char *) NULL)
580 return (char *) NULL;
587 static ssize_t parse8BIMW(Image *ifile, Image *ofile)
608 inputlen = MagickPathExtent;
623 line=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*line));
624 if (line == (char *) NULL)
626 newstr = name = token = (char *) NULL;
628 token_info=AcquireTokenInfo();
629 while (super_fgets_w(&line,&inputlen,ifile) != NULL)
634 token=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*token));
635 if (token == (char *) NULL)
637 newstr=(char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*newstr));
638 if (newstr == (char *) NULL)
640 while (Tokenizer(token_info,0,token,(size_t) inputlen,line,"","=","\"",0,
641 &brkused,&next,"ed)==0)
655 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","#",
656 "",0,&brkused,&next,"ed)==0)
661 if (strcmp(newstr,"8BIM")==0)
664 dataset = (unsigned char) StringToLong(newstr);
667 recnum=(unsigned int) StringToUnsignedLong(newstr);
670 name=(char *) AcquireQuantumMemory(strlen(newstr)+MagickPathExtent,
673 (void) CopyMagickString(name,newstr,strlen(newstr)+MagickPathExtent);
693 len = (ssize_t) strlen(token);
694 while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
695 "",0,&brkused,&next,"ed)==0)
697 if (brkused && next > 0)
702 len -= (ssize_t) convertHTMLcodes(s,strlen(s));
719 ssize_t diff = outputlen - savedolen;
720 currentpos = TellBlob(ofile);
723 offset=SeekBlob(ofile,savedpos,SEEK_SET);
726 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
727 offset=SeekBlob(ofile,currentpos,SEEK_SET);
734 (void) WriteBlobByte(ofile,0x00);
737 (void) WriteBlobString(ofile,"8BIM");
738 (void) WriteBlobMSBShort(ofile,(unsigned short) recnum);
741 nlen = (unsigned char) strlen(name);
742 (void) WriteBlobByte(ofile,(unsigned char) nlen);
744 for (i=0; i<nlen; i++)
745 (void) WriteBlobByte(ofile,(unsigned char) name[i]);
747 if ((nlen & 0x01) == 0)
749 (void) WriteBlobByte(ofile,0x00);
752 if (recnum != IPTC_ID)
754 (void) WriteBlobMSBLong(ofile,(unsigned int) len);
760 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
764 (void) WriteBlobByte(ofile,0x00);
770 /* patch in a fake length for now and fix it later */
771 savedpos = TellBlob(ofile);
774 (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
776 savedolen = outputlen;
783 (void) WriteBlobByte(ofile,0x1c);
784 (void) WriteBlobByte(ofile,dataset);
785 (void) WriteBlobByte(ofile,(unsigned char) (recnum & 0xff));
786 (void) WriteBlobMSBShort(ofile,(unsigned short) len);
791 (void) WriteBlobByte(ofile,(unsigned char) token[next++]);
797 if (token != (char *) NULL)
798 token=DestroyString(token);
799 if (newstr != (char *) NULL)
800 newstr=DestroyString(newstr);
801 if (name != (char *) NULL)
802 name=DestroyString(name);
804 token_info=DestroyTokenInfo(token_info);
805 if (token != (char *) NULL)
806 token=DestroyString(token);
807 if (newstr != (char *) NULL)
808 newstr=DestroyString(newstr);
809 if (name != (char *) NULL)
810 name=DestroyString(name);
811 line=DestroyString(line);
817 ssize_t diff = outputlen - savedolen;
819 currentpos = TellBlob(ofile);
822 offset=SeekBlob(ofile,savedpos,SEEK_SET);
825 (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
826 offset=SeekBlob(ofile,currentpos,SEEK_SET);
834 /* some defines for the different JPEG block types */
835 #define M_SOF0 0xC0 /* Start Of Frame N */
836 #define M_SOF1 0xC1 /* N indicates which compression process */
837 #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
839 #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
849 #define M_EOI 0xD9 /* End Of Image (end of datastream) */
850 #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
868 static int jpeg_transfer_1(Image *ifile, Image *ofile)
872 c = ReadBlobByte(ifile);
875 (void) WriteBlobByte(ofile,(unsigned char) c);
880 static int jpeg_skip_1(Image *ifile)
884 c = ReadBlobByte(ifile);
891 static int jpeg_read_remaining(Image *ifile, Image *ofile)
895 while ((c = jpeg_transfer_1(ifile, ofile)) != EOF)
900 static int jpeg_skip_variable(Image *ifile, Image *ofile)
905 if ((c1 = jpeg_transfer_1(ifile, ofile)) == EOF)
907 if ((c2 = jpeg_transfer_1(ifile, ofile)) == EOF)
910 length = (((unsigned char) c1) << 8) + ((unsigned char) c2);
914 if (jpeg_transfer_1(ifile, ofile) == EOF)
920 static int jpeg_skip_variable2(Image *ifile, Image *ofile)
926 if ((c1 = ReadBlobByte(ifile)) == EOF) return M_EOI;
927 if ((c2 = ReadBlobByte(ifile)) == EOF) return M_EOI;
929 length = (((unsigned char) c1) << 8) + ((unsigned char) c2);
933 if (ReadBlobByte(ifile) == EOF)
939 static int jpeg_nextmarker(Image *ifile, Image *ofile)
943 /* transfer anything until we hit 0xff */
946 c = ReadBlobByte(ifile);
948 return M_EOI; /* we hit EOF */
951 (void) WriteBlobByte(ofile,(unsigned char) c);
954 /* get marker byte, swallowing possible padding */
957 c = ReadBlobByte(ifile);
959 return M_EOI; /* we hit EOF */
966 static int jpeg_skip_till_marker(Image *ifile, int marker)
972 /* skip anything until we hit 0xff */
976 c = ReadBlobByte(ifile);
979 return M_EOI; /* we hit EOF */
982 /* get marker byte, swallowing possible padding */
985 c = ReadBlobByte(ifile);
987 return M_EOI; /* we hit EOF */
989 } while (c != marker);
994 /* Embed binary IPTC data into a JPEG image. */
995 static int jpeg_embed(Image *ifile, Image *ofile, Image *iptc)
998 unsigned int done = 0;
1002 if (jpeg_transfer_1(ifile, ofile) != 0xFF)
1004 if (jpeg_transfer_1(ifile, ofile) != M_SOI)
1007 while (done == MagickFalse)
1009 marker=(unsigned int) jpeg_nextmarker(ifile, ofile);
1010 if (marker == M_EOI)
1016 if (marker != M_APP13)
1018 (void) WriteBlobByte(ofile,0xff);
1019 (void) WriteBlobByte(ofile,(unsigned char) marker);
1026 /* we are going to write a new APP13 marker, so don't output the old one */
1027 jpeg_skip_variable2(ifile, ofile);
1031 /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */
1032 jpeg_skip_variable(ifile, ofile);
1034 if (iptc != (Image *) NULL)
1037 psheader[] = "\xFF\xED\0\0Photoshop 3.0\0" "8BIM\x04\x04\0\0\0\0";
1039 len=(unsigned int) GetBlobSize(iptc);
1041 len++; /* make the length even */
1042 psheader[2]=(char) ((len+16)>>8);
1043 psheader[3]=(char) ((len+16)&0xff);
1044 for (inx = 0; inx < 18; inx++)
1045 (void) WriteBlobByte(ofile,(unsigned char) psheader[inx]);
1046 jpeg_read_remaining(iptc, ofile);
1047 len=(unsigned int) GetBlobSize(iptc);
1049 (void) WriteBlobByte(ofile,0);
1054 /* we hit data, no more marker-inserting can be done! */
1055 jpeg_read_remaining(ifile, ofile);
1060 jpeg_skip_variable(ifile, ofile);
1067 /* handle stripping the APP13 data out of a JPEG */
1069 static void jpeg_strip(Image *ifile, Image *ofile)
1071 unsigned int marker;
1073 marker = jpeg_skip_till_marker(ifile, M_SOI);
1074 if (marker == M_SOI)
1076 (void) WriteBlobByte(ofile,0xff);
1077 (void) WriteBlobByte(ofile,M_SOI);
1078 jpeg_read_remaining(ifile, ofile);
1082 /* Extract any APP13 binary data into a file. */
1083 static int jpeg_extract(Image *ifile, Image *ofile)
1085 unsigned int marker;
1086 unsigned int done = 0;
1088 if (jpeg_skip_1(ifile) != 0xff)
1090 if (jpeg_skip_1(ifile) != M_SOI)
1093 while (done == MagickFalse)
1095 marker = jpeg_skip_till_marker(ifile, M_APP13);
1096 if (marker == M_APP13)
1098 marker = jpeg_nextmarker(ifile, ofile);
1106 static inline void CopyBlob(Image *source,Image *destination)
1118 buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
1120 if (buffer != (unsigned char *) NULL)
1123 while ((length=ReadBlob(source,MagickMaxBufferExtent,buffer)) != 0)
1126 for (i=0; i < (ssize_t) length; i+=count)
1128 count=WriteBlob(destination,(size_t) (length-i),buffer+i);
1132 if (i < (ssize_t) length)
1135 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1139 static Image *ReadMETAImage(const ImageInfo *image_info,
1140 ExceptionInfo *exception)
1159 Open file containing binary metadata
1161 assert(image_info != (const ImageInfo *) NULL);
1162 assert(image_info->signature == MagickCoreSignature);
1163 if (image_info->debug != MagickFalse)
1164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1165 image_info->filename);
1166 assert(exception != (ExceptionInfo *) NULL);
1167 assert(exception->signature == MagickCoreSignature);
1168 image=AcquireImage(image_info,exception);
1169 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1170 if (status == MagickFalse)
1172 image=DestroyImageList(image);
1173 return((Image *) NULL);
1177 if (SetImageBackgroundColor(image,exception) == MagickFalse)
1179 image=DestroyImageList(image);
1180 return((Image *) NULL);
1183 if (LocaleNCompare(image_info->magick,"8BIM",4) == 0)
1186 Read 8BIM binary metadata.
1188 buff=AcquireImage((ImageInfo *) NULL,exception);
1189 if (buff == (Image *) NULL)
1190 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1191 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1192 if (blob == (unsigned char *) NULL)
1194 buff=DestroyImage(buff);
1195 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1197 AttachBlob(buff->blob,blob,length);
1198 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
1200 length=(size_t) parse8BIM(image, buff);
1202 (void) WriteBlobByte(buff,0x0);
1204 else if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
1206 length=(size_t) parse8BIMW(image, buff);
1208 (void) WriteBlobByte(buff,0x0);
1211 CopyBlob(image,buff);
1212 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1214 if (profile == (StringInfo *) NULL)
1215 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1216 status=SetImageProfile(image,"8bim",profile,exception);
1217 profile=DestroyStringInfo(profile);
1218 if (status == MagickFalse)
1219 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1220 blob=DetachBlob(buff->blob);
1221 blob=(unsigned char *) RelinquishMagickMemory(blob);
1222 buff=DestroyImage(buff);
1224 if (LocaleNCompare(image_info->magick,"APP1",4) == 0)
1227 name[MagickPathExtent];
1229 (void) FormatLocaleString(name,MagickPathExtent,"APP%d",1);
1230 buff=AcquireImage((ImageInfo *) NULL,exception);
1231 if (buff == (Image *) NULL)
1232 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1233 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1234 if (blob == (unsigned char *) NULL)
1236 buff=DestroyImage(buff);
1237 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1239 AttachBlob(buff->blob,blob,length);
1240 if (LocaleCompare(image_info->magick,"APP1JPEG") == 0)
1248 if (image_info->profile == (void *) NULL)
1250 blob=DetachBlob(buff->blob);
1251 blob=RelinquishMagickMemory(blob);
1252 buff=DestroyImage(buff);
1253 ThrowReaderException(CoderError,"NoIPTCProfileAvailable");
1255 profile=CloneStringInfo((StringInfo *) image_info->profile);
1256 iptc=AcquireImage((ImageInfo *) NULL,exception);
1257 if (iptc == (Image *) NULL)
1259 blob=DetachBlob(buff->blob);
1260 blob=RelinquishMagickMemory(blob);
1261 buff=DestroyImage(buff);
1262 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1264 AttachBlob(iptc->blob,GetStringInfoDatum(profile),
1265 GetStringInfoLength(profile));
1266 result=jpeg_embed(image,buff,iptc);
1267 blob=DetachBlob(iptc->blob);
1268 blob=RelinquishMagickMemory(blob);
1269 iptc=DestroyImage(iptc);
1272 blob=DetachBlob(buff->blob);
1273 blob=RelinquishMagickMemory(blob);
1274 buff=DestroyImage(buff);
1275 ThrowReaderException(CoderError,"JPEGEmbeddingFailed");
1279 CopyBlob(image,buff);
1280 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1282 if (profile == (StringInfo *) NULL)
1283 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1284 status=SetImageProfile(image,name,profile,exception);
1285 profile=DestroyStringInfo(profile);
1286 if (status == MagickFalse)
1287 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1288 blob=DetachBlob(buff->blob);
1289 blob=RelinquishMagickMemory(blob);
1290 buff=DestroyImage(buff);
1292 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
1293 (LocaleCompare(image_info->magick,"ICM") == 0))
1295 buff=AcquireImage((ImageInfo *) NULL,exception);
1296 if (buff == (Image *) NULL)
1297 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1298 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1299 if (blob == (unsigned char *) NULL)
1301 buff=DestroyImage(buff);
1302 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1304 AttachBlob(buff->blob,blob,length);
1305 CopyBlob(image,buff);
1306 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1308 if (profile == (StringInfo *) NULL)
1309 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1310 (void) SetImageProfile(image,"icc",profile,exception);
1311 profile=DestroyStringInfo(profile);
1312 blob=DetachBlob(buff->blob);
1313 blob=(unsigned char *) RelinquishMagickMemory(blob);
1314 buff=DestroyImage(buff);
1316 if (LocaleCompare(image_info->magick,"IPTC") == 0)
1318 buff=AcquireImage((ImageInfo *) NULL,exception);
1319 if (buff == (Image *) NULL)
1320 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1321 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1322 if (blob == (unsigned char *) NULL)
1324 buff=DestroyImage(buff);
1325 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1327 AttachBlob(buff->blob,blob,length);
1328 CopyBlob(image,buff);
1329 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1331 if (profile == (StringInfo *) NULL)
1332 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1333 (void) SetImageProfile(image,"8bim",profile,exception);
1334 profile=DestroyStringInfo(profile);
1335 blob=DetachBlob(buff->blob);
1336 blob=(unsigned char *) RelinquishMagickMemory(blob);
1337 buff=DestroyImage(buff);
1339 if (LocaleCompare(image_info->magick,"XMP") == 0)
1341 buff=AcquireImage((ImageInfo *) NULL,exception);
1342 if (buff == (Image *) NULL)
1343 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1344 blob=(unsigned char *) AcquireQuantumMemory(length,sizeof(unsigned char));
1345 if (blob == (unsigned char *) NULL)
1347 buff=DestroyImage(buff);
1348 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1350 AttachBlob(buff->blob,blob,length);
1351 CopyBlob(image,buff);
1352 profile=BlobToStringInfo(GetBlobStreamData(buff),(size_t)
1354 if (profile == (StringInfo *) NULL)
1355 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1356 (void) SetImageProfile(image,"xmp",profile,exception);
1357 profile=DestroyStringInfo(profile);
1358 blob=DetachBlob(buff->blob);
1359 blob=(unsigned char *) RelinquishMagickMemory(blob);
1360 buff=DestroyImage(buff);
1362 (void) CloseBlob(image);
1363 return(GetFirstImageInList(image));
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 % R e g i s t e r M E T A I m a g e %
1375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1377 % RegisterMETAImage() adds attributes for the META image format to
1378 % the list of supported formats. The attributes include the image format
1379 % tag, a method to read and/or write the format, whether the format
1380 % supports the saving of more than one frame to the same file or blob,
1381 % whether the format supports native in-memory I/O, and a brief
1382 % description of the format.
1384 % The format of the RegisterMETAImage method is:
1386 % size_t RegisterMETAImage(void)
1389 ModuleExport size_t RegisterMETAImage(void)
1394 entry=AcquireMagickInfo("META","8BIM","Photoshop resource format");
1395 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1396 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1397 entry->flags^=CoderAdjoinFlag;
1398 entry->flags|=CoderStealthFlag;
1399 entry->flags|=CoderSeekableStreamFlag;
1400 (void) RegisterMagickInfo(entry);
1401 entry=AcquireMagickInfo("META","8BIMTEXT","Photoshop resource text format");
1402 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1403 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1404 entry->flags^=CoderAdjoinFlag;
1405 entry->flags|=CoderStealthFlag;
1406 entry->flags|=CoderSeekableStreamFlag;
1407 (void) RegisterMagickInfo(entry);
1408 entry=AcquireMagickInfo("META","8BIMWTEXT",
1409 "Photoshop resource wide text format");
1410 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1411 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1412 entry->flags^=CoderAdjoinFlag;
1413 entry->flags|=CoderStealthFlag;
1414 entry->flags|=CoderSeekableStreamFlag;
1415 (void) RegisterMagickInfo(entry);
1416 entry=AcquireMagickInfo("META","APP1","Raw application information");
1417 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1418 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1419 entry->flags^=CoderAdjoinFlag;
1420 entry->flags|=CoderStealthFlag;
1421 entry->flags|=CoderSeekableStreamFlag;
1422 (void) RegisterMagickInfo(entry);
1423 entry=AcquireMagickInfo("META","APP1JPEG","Raw JPEG binary data");
1424 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1425 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1426 entry->flags^=CoderAdjoinFlag;
1427 entry->flags|=CoderStealthFlag;
1428 entry->flags|=CoderSeekableStreamFlag;
1429 (void) RegisterMagickInfo(entry);
1430 entry=AcquireMagickInfo("META","EXIF","Exif digital camera binary data");
1431 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1432 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1433 entry->flags^=CoderAdjoinFlag;
1434 entry->flags|=CoderStealthFlag;
1435 entry->flags|=CoderSeekableStreamFlag;
1436 (void) RegisterMagickInfo(entry);
1437 entry=AcquireMagickInfo("META","XMP","Adobe XML metadata");
1438 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1439 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1440 entry->flags^=CoderAdjoinFlag;
1441 entry->flags|=CoderStealthFlag;
1442 entry->flags|=CoderSeekableStreamFlag;
1443 (void) RegisterMagickInfo(entry);
1444 entry=AcquireMagickInfo("META","ICM","ICC Color Profile");
1445 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1446 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1447 entry->flags^=CoderAdjoinFlag;
1448 entry->flags|=CoderStealthFlag;
1449 entry->flags|=CoderSeekableStreamFlag;
1450 (void) RegisterMagickInfo(entry);
1451 entry=AcquireMagickInfo("META","ICC","ICC Color Profile");
1452 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1453 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1454 entry->flags^=CoderAdjoinFlag;
1455 entry->flags|=CoderStealthFlag;
1456 entry->flags|=CoderSeekableStreamFlag;
1457 (void) RegisterMagickInfo(entry);
1458 entry=AcquireMagickInfo("META","IPTC","IPTC Newsphoto");
1459 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1460 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1461 entry->flags^=CoderAdjoinFlag;
1462 entry->flags|=CoderStealthFlag;
1463 entry->flags|=CoderSeekableStreamFlag;
1464 (void) RegisterMagickInfo(entry);
1465 entry=AcquireMagickInfo("META","IPTCTEXT","IPTC Newsphoto text format");
1466 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1467 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1468 entry->flags^=CoderAdjoinFlag;
1469 entry->flags|=CoderStealthFlag;
1470 entry->flags|=CoderSeekableStreamFlag;
1471 (void) RegisterMagickInfo(entry);
1472 entry=AcquireMagickInfo("META","IPTCWTEXT","IPTC Newsphoto text format");
1473 entry->decoder=(DecodeImageHandler *) ReadMETAImage;
1474 entry->encoder=(EncodeImageHandler *) WriteMETAImage;
1475 entry->flags^=CoderAdjoinFlag;
1476 entry->flags|=CoderStealthFlag;
1477 entry->flags|=CoderSeekableStreamFlag;
1478 (void) RegisterMagickInfo(entry);
1479 return(MagickImageCoderSignature);
1483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1487 % U n r e g i s t e r M E T A I m a g e %
1491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1493 % UnregisterMETAImage() removes format registrations made by the
1494 % META module from the list of supported formats.
1496 % The format of the UnregisterMETAImage method is:
1498 % UnregisterMETAImage(void)
1501 ModuleExport void UnregisterMETAImage(void)
1503 (void) UnregisterMagickInfo("8BIM");
1504 (void) UnregisterMagickInfo("8BIMTEXT");
1505 (void) UnregisterMagickInfo("8BIMWTEXT");
1506 (void) UnregisterMagickInfo("EXIF");
1507 (void) UnregisterMagickInfo("APP1");
1508 (void) UnregisterMagickInfo("APP1JPEG");
1509 (void) UnregisterMagickInfo("ICCTEXT");
1510 (void) UnregisterMagickInfo("ICM");
1511 (void) UnregisterMagickInfo("ICC");
1512 (void) UnregisterMagickInfo("IPTC");
1513 (void) UnregisterMagickInfo("IPTCTEXT");
1514 (void) UnregisterMagickInfo("IPTCWTEXT");
1515 (void) UnregisterMagickInfo("XMP");
1519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523 % W r i t e M E T A I m a g e %
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1529 % WriteMETAImage() writes a META image to a file.
1531 % The format of the WriteMETAImage method is:
1533 % MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
1534 % Image *image,ExceptionInfo *exception)
1536 % Compression code contributed by Kyle Shorter.
1538 % A description of each parameter follows:
1540 % o image_info: Specifies a pointer to an ImageInfo structure.
1542 % o image: A pointer to a Image structure.
1544 % o exception: return any errors or warnings in this structure.
1548 static size_t GetIPTCStream(unsigned char **info,size_t length)
1556 register unsigned char
1571 if ((*p == 0x1c) && (*(p+1) == 0x02))
1574 Extract IPTC from 8BIM resource block.
1576 while (extent >= 12)
1578 if (strncmp((const char *) p,"8BIM",4))
1582 marker=(unsigned int) (*p) << 8 | *(p+1);
1588 if ((size_t) c >= extent)
1594 tag_length=(((size_t) *p) << 24) | (((size_t) *(p+1)) << 16) |
1595 (((size_t) *(p+2)) << 8) | ((size_t) *(p+3));
1598 if (tag_length > extent)
1600 if (marker == IPTC_ID)
1605 if ((tag_length & 0x01) != 0)
1611 Find the beginning of the IPTC info.
1627 *info=p; /* let the caller know were it is */
1632 Determine the length of the IPTC info.
1649 Found the 0x1c tag; skip the dataset and record number tags.
1651 c=(*p++); /* should be 2 */
1655 if ((info_length == 1) && (c != 2))
1658 c=(*p++); /* should be 0 */
1662 if ((info_length == 2) && (c != 0))
1666 Decode the length of the block that follows - ssize_t or short format.
1673 if ((c & 0x80) != 0)
1679 for (i=0; i < 4; i++)
1694 tag_length=((long) c) << 8;
1700 tag_length|=(long) c;
1702 if (tag_length > (length+1))
1708 info_length+=tag_length;
1710 return(info_length);
1713 static void formatString(Image *ofile, const char *s, int len)
1716 temp[MagickPathExtent];
1718 (void) WriteBlobByte(ofile,'"');
1719 for (; len > 0; len--, s++) {
1723 (void) WriteBlobString(ofile,"&");
1727 (void) WriteBlobString(ofile,"<");
1730 (void) WriteBlobString(ofile,">");
1734 (void) WriteBlobString(ofile,""");
1738 (void) WriteBlobByte(ofile,(unsigned char) *s);
1741 (void) FormatLocaleString(temp,MagickPathExtent,"&#%d;", c & 255);
1742 (void) WriteBlobString(ofile,temp);
1747 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1748 (void) WriteBlobString(ofile,"\"\r\n");
1750 #if defined(macintosh)
1751 (void) WriteBlobString(ofile,"\"\r");
1753 (void) WriteBlobString(ofile,"\"\n");
1758 typedef struct _tag_spec
1767 static const tag_spec tags[] = {
1768 { 5, "Image Name" },
1769 { 7, "Edit Status" },
1772 { 20, "Supplemental Category" },
1773 { 22, "Fixture Identifier" },
1775 { 30, "Release Date" },
1776 { 35, "Release Time" },
1777 { 40, "Special Instructions" },
1778 { 45, "Reference Service" },
1779 { 47, "Reference Date" },
1780 { 50, "Reference Number" },
1781 { 55, "Created Date" },
1782 { 60, "Created Time" },
1783 { 65, "Originating Program" },
1784 { 70, "Program Version" },
1785 { 75, "Object Cycle" },
1787 { 85, "Byline Title" },
1789 { 92, "Sub-Location" },
1790 { 95, "Province State" },
1791 { 100, "Country Code" },
1793 { 103, "Original Transmission Reference" },
1794 { 105, "Headline" },
1797 { 116, "Copyright String" },
1799 { 121, "Image Orientation" },
1800 { 122, "Caption Writer" },
1801 { 131, "Local Caption" },
1802 { 200, "Custom Field 1" },
1803 { 201, "Custom Field 2" },
1804 { 202, "Custom Field 3" },
1805 { 203, "Custom Field 4" },
1806 { 204, "Custom Field 5" },
1807 { 205, "Custom Field 6" },
1808 { 206, "Custom Field 7" },
1809 { 207, "Custom Field 8" },
1810 { 208, "Custom Field 9" },
1811 { 209, "Custom Field 10" },
1812 { 210, "Custom Field 11" },
1813 { 211, "Custom Field 12" },
1814 { 212, "Custom Field 13" },
1815 { 213, "Custom Field 14" },
1816 { 214, "Custom Field 15" },
1817 { 215, "Custom Field 16" },
1818 { 216, "Custom Field 17" },
1819 { 217, "Custom Field 18" },
1820 { 218, "Custom Field 19" },
1821 { 219, "Custom Field 20" }
1824 static int formatIPTC(Image *ifile, Image *ofile)
1827 temp[MagickPathExtent];
1847 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
1852 foundiptc = 0; /* found the IPTC-Header */
1853 tagsfound = 0; /* number of tags found */
1855 c = ReadBlobByte(ifile);
1871 /* we found the 0x1c tag and now grab the dataset and record number tags */
1872 c = ReadBlobByte(ifile);
1873 if (c == EOF) return -1;
1874 dataset = (unsigned char) c;
1875 c = ReadBlobByte(ifile);
1876 if (c == EOF) return -1;
1877 recnum = (unsigned char) c;
1878 /* try to match this record to one of the ones in our named table */
1879 for (i=0; i< tagcount; i++)
1881 if (tags[i].id == (short) recnum)
1885 readable = (unsigned char *) tags[i].name;
1887 readable = (unsigned char *) "";
1889 We decode the length of the block that follows - ssize_t or short fmt.
1891 c=ReadBlobByte(ifile);
1892 if (c == EOF) return -1;
1893 if (c & (unsigned char) 0x80)
1900 c0=ReadBlobByte(ifile);
1901 if (c0 == EOF) return -1;
1902 taglen = (c << 8) | c0;
1904 if (taglen < 0) return -1;
1905 /* make a buffer to hold the tag datand snag it from the input stream */
1906 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MagickPathExtent),
1908 if (str == (unsigned char *) NULL)
1910 printf("MemoryAllocationFailed");
1913 for (tagindx=0; tagindx<taglen; tagindx++)
1915 c=ReadBlobByte(ifile);
1916 if (c == EOF) return -1;
1917 str[tagindx] = (unsigned char) c;
1921 /* now finish up by formatting this binary data into ASCII equivalent */
1922 if (strlen((char *)readable) > 0)
1923 (void) FormatLocaleString(temp,MagickPathExtent,"%d#%d#%s=",
1924 (unsigned int) dataset, (unsigned int) recnum, readable);
1926 (void) FormatLocaleString(temp,MagickPathExtent,"%d#%d=",
1927 (unsigned int) dataset,(unsigned int) recnum);
1928 (void) WriteBlobString(ofile,temp);
1929 formatString( ofile, (char *)str, taglen );
1930 str=(unsigned char *) RelinquishMagickMemory(str);
1934 c=ReadBlobByte(ifile);
1936 return((int) tagsfound);
1939 static int readWordFromBuffer(char **s, ssize_t *len)
1950 c = *(*s)++; (*len)--;
1951 if (*len < 0) return -1;
1952 buffer[i] = (unsigned char) c;
1954 return (((int) buffer[ 0 ]) << 8) |
1955 (((int) buffer[ 1 ]));
1958 static int formatIPTCfromBuffer(Image *ofile, char *s, ssize_t len)
1961 temp[MagickPathExtent];
1981 tagcount = (int) (sizeof(tags) / sizeof(tag_spec));
1986 foundiptc = 0; /* found the IPTC-Header */
1987 tagsfound = 0; /* number of tags found */
2002 We found the 0x1c tag and now grab the dataset and record number tags.
2005 if (len < 0) return -1;
2006 dataset = (unsigned char) c;
2008 if (len < 0) return -1;
2009 recnum = (unsigned char) c;
2010 /* try to match this record to one of the ones in our named table */
2011 for (i=0; i< tagcount; i++)
2012 if (tags[i].id == (short) recnum)
2015 readable=(unsigned char *) tags[i].name;
2017 readable=(unsigned char *) "";
2019 We decode the length of the block that follows - ssize_t or short fmt.
2025 if (c & (unsigned char) 0x80)
2031 taglen=readWordFromBuffer(&s, &len);
2037 /* make a buffer to hold the tag datand snag it from the input stream */
2038 str=(unsigned char *) AcquireQuantumMemory((size_t) (taglen+MagickPathExtent),
2040 if (str == (unsigned char *) NULL)
2042 printf("MemoryAllocationFailed");
2045 for (tagindx=0; tagindx<taglen; tagindx++)
2050 str[tagindx]=(unsigned char) c;
2054 /* now finish up by formatting this binary data into ASCII equivalent */
2055 if (strlen((char *)readable) > 0)
2056 (void) FormatLocaleString(temp,MagickPathExtent,"%d#%d#%s=",
2057 (unsigned int) dataset,(unsigned int) recnum, readable);
2059 (void) FormatLocaleString(temp,MagickPathExtent,"%d#%d=",
2060 (unsigned int) dataset,(unsigned int) recnum);
2061 (void) WriteBlobString(ofile,temp);
2062 formatString( ofile, (char *)str, taglen );
2063 str=(unsigned char *) RelinquishMagickMemory(str);
2067 return ((int) tagsfound);
2070 static int format8BIM(Image *ifile, Image *ofile)
2073 temp[MagickPathExtent];
2092 foundOSType=0; /* found the OSType */
2094 c=ReadBlobByte(ifile);
2102 buffer[0]=(unsigned char) c;
2105 c=ReadBlobByte(ifile);
2108 buffer[i] = (unsigned char) c;
2111 if (strcmp((const char *)buffer, "8BIM") == 0)
2118 c=ReadBlobByte(ifile);
2122 We found the OSType (8BIM) and now grab the ID, PString, and Size fields.
2124 ID=ReadBlobMSBSignedShort(ifile);
2131 c=ReadBlobByte(ifile);
2134 plen = (unsigned char) c;
2135 PString=(unsigned char *) AcquireQuantumMemory((size_t) (plen+
2136 MagickPathExtent),sizeof(*PString));
2137 if (PString == (unsigned char *) NULL)
2139 printf("MemoryAllocationFailed");
2142 for (i=0; i<plen; i++)
2144 c=ReadBlobByte(ifile);
2145 if (c == EOF) return -1;
2146 PString[i] = (unsigned char) c;
2148 PString[ plen ] = 0;
2149 if ((plen & 0x01) == 0)
2151 c=ReadBlobByte(ifile);
2156 count=ReadBlobMSBSignedLong(ifile);
2157 if (count < 0) return -1;
2158 /* make a buffer to hold the datand snag it from the input stream */
2159 str=(unsigned char *) AcquireQuantumMemory((size_t) count,sizeof(*str));
2160 if (str == (unsigned char *) NULL)
2162 printf("MemoryAllocationFailed");
2165 for (i=0; i < (ssize_t) count; i++)
2167 c=ReadBlobByte(ifile);
2170 str[i]=(unsigned char) c;
2173 /* we currently skip thumbnails, since it does not make
2174 * any sense preserving them in a real world application
2176 if (ID != THUMBNAIL_ID)
2178 /* now finish up by formatting this binary data into
2181 if (strlen((const char *)PString) > 0)
2182 (void) FormatLocaleString(temp,MagickPathExtent,"8BIM#%d#%s=",ID,
2185 (void) FormatLocaleString(temp,MagickPathExtent,"8BIM#%d=",ID);
2186 (void) WriteBlobString(ofile,temp);
2189 formatString(ofile, "IPTC", 4);
2190 formatIPTCfromBuffer(ofile, (char *)str, (ssize_t) count);
2193 formatString(ofile, (char *)str, (ssize_t) count);
2195 str=(unsigned char *) RelinquishMagickMemory(str);
2196 PString=(unsigned char *) RelinquishMagickMemory(PString);
2198 c=ReadBlobByte(ifile);
2203 static MagickBooleanType WriteMETAImage(const ImageInfo *image_info,
2204 Image *image,ExceptionInfo *exception)
2218 assert(image_info != (const ImageInfo *) NULL);
2219 assert(image_info->signature == MagickCoreSignature);
2220 assert(image != (Image *) NULL);
2221 assert(image->signature == MagickCoreSignature);
2222 if (image->debug != MagickFalse)
2223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2225 if (LocaleCompare(image_info->magick,"8BIM") == 0)
2230 profile=GetImageProfile(image,"8bim");
2231 if (profile == (StringInfo *) NULL)
2232 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2233 assert(exception != (ExceptionInfo *) NULL);
2234 assert(exception->signature == MagickCoreSignature);
2235 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2236 if (status == MagickFalse)
2238 (void) WriteBlob(image,GetStringInfoLength(profile),
2239 GetStringInfoDatum(profile));
2240 (void) CloseBlob(image);
2243 if (LocaleCompare(image_info->magick,"iptc") == 0)
2251 profile=GetImageProfile(image,"iptc");
2252 if (profile == (StringInfo *) NULL)
2253 profile=GetImageProfile(image,"8bim");
2254 if (profile == (StringInfo *) NULL)
2255 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2256 assert(exception != (ExceptionInfo *) NULL);
2257 assert(exception->signature == MagickCoreSignature);
2258 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2259 info=GetStringInfoDatum(profile);
2260 length=GetStringInfoLength(profile);
2261 length=GetIPTCStream(&info,length);
2263 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2264 (void) WriteBlob(image,length,info);
2265 (void) CloseBlob(image);
2268 if (LocaleCompare(image_info->magick,"8BIMTEXT") == 0)
2273 profile=GetImageProfile(image,"8bim");
2274 if (profile == (StringInfo *) NULL)
2275 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2276 assert(exception != (ExceptionInfo *) NULL);
2277 assert(exception->signature == MagickCoreSignature);
2278 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2279 if (status == MagickFalse)
2281 buff=AcquireImage((ImageInfo *) NULL,exception);
2282 if (buff == (Image *) NULL)
2283 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2284 AttachBlob(buff->blob,GetStringInfoDatum(profile),
2285 GetStringInfoLength(profile));
2286 format8BIM(buff,image);
2287 (void) DetachBlob(buff->blob);
2288 buff=DestroyImage(buff);
2289 (void) CloseBlob(image);
2292 if (LocaleCompare(image_info->magick,"8BIMWTEXT") == 0)
2293 return(MagickFalse);
2294 if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
2302 profile=GetImageProfile(image,"8bim");
2303 if (profile == (StringInfo *) NULL)
2304 ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
2305 info=GetStringInfoDatum(profile);
2306 length=GetStringInfoLength(profile);
2307 length=GetIPTCStream(&info,length);
2309 ThrowWriterException(CoderError,"NoIPTCProfileAvailable");
2310 assert(exception != (ExceptionInfo *) NULL);
2311 assert(exception->signature == MagickCoreSignature);
2312 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2313 if (status == MagickFalse)
2315 buff=AcquireImage((ImageInfo *) NULL,exception);
2316 if (buff == (Image *) NULL)
2317 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
2318 AttachBlob(buff->blob,info,length);
2319 formatIPTC(buff,image);
2320 (void) DetachBlob(buff->blob);
2321 buff=DestroyImage(buff);
2322 (void) CloseBlob(image);
2325 if (LocaleCompare(image_info->magick,"IPTCWTEXT") == 0)
2326 return(MagickFalse);
2327 if ((LocaleCompare(image_info->magick,"APP1") == 0) ||
2328 (LocaleCompare(image_info->magick,"EXIF") == 0) ||
2329 (LocaleCompare(image_info->magick,"XMP") == 0))
2332 (void) Write APP1 image.
2334 profile=GetImageProfile(image,image_info->magick);
2335 if (profile == (StringInfo *) NULL)
2336 ThrowWriterException(CoderError,"NoAPP1DataIsAvailable");
2337 assert(exception != (ExceptionInfo *) NULL);
2338 assert(exception->signature == MagickCoreSignature);
2339 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2340 if (status == MagickFalse)
2342 (void) WriteBlob(image,GetStringInfoLength(profile),
2343 GetStringInfoDatum(profile));
2344 (void) CloseBlob(image);
2347 if ((LocaleCompare(image_info->magick,"ICC") == 0) ||
2348 (LocaleCompare(image_info->magick,"ICM") == 0))
2353 profile=GetImageProfile(image,"icc");
2354 if (profile == (StringInfo *) NULL)
2355 ThrowWriterException(CoderError,"NoColorProfileIsAvailable");
2356 assert(exception != (ExceptionInfo *) NULL);
2357 assert(exception->signature == MagickCoreSignature);
2358 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
2359 if (status == MagickFalse)
2361 (void) WriteBlob(image,GetStringInfoLength(profile),
2362 GetStringInfoDatum(profile));
2363 (void) CloseBlob(image);
2366 return(MagickFalse);