Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/meta.c File Reference

#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob_private.h"
#include "magick/error.h"
#include "magick/error_private.h"
#include "magick/image.h"
#include "magick/image_private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/profile.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/token.h"
#include "magick/utility.h"

Include dependency graph for meta.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  _html_code
struct  _tag_spec

Defines

#define BUFFER_SZ   4096
#define BUFFER_SZ   4096
#define IPTC_ID   1028
#define THUMBNAIL_ID   1033
#define M_SOF0   0xC0 /* Start Of Frame N */
#define M_SOF1   0xC1 /* N indicates which compression process */
#define M_SOF2   0xC2 /* Only SOF0-SOF2 are now in common use */
#define M_SOF3   0xC3
#define M_SOF5   0xC5 /* NB: codes C4 and CC are NOT SOF markers */
#define M_SOF6   0xC6
#define M_SOF7   0xC7
#define M_SOF9   0xC9
#define M_SOF10   0xCA
#define M_SOF11   0xCB
#define M_SOF13   0xCD
#define M_SOF14   0xCE
#define M_SOF15   0xCF
#define M_SOI   0xD8
#define M_EOI   0xD9 /* End Of Image (end of datastream) */
#define M_SOS   0xDA /* Start Of Scan (begins compressed data) */
#define M_APP0   0xe0
#define M_APP1   0xe1
#define M_APP2   0xe2
#define M_APP3   0xe3
#define M_APP4   0xe4
#define M_APP5   0xe5
#define M_APP6   0xe6
#define M_APP7   0xe7
#define M_APP8   0xe8
#define M_APP9   0xe9
#define M_APP10   0xea
#define M_APP11   0xeb
#define M_APP12   0xec
#define M_APP13   0xed
#define M_APP14   0xee
#define M_APP15   0xef
#define MaxBufferSize   65541

Typedefs

typedef _html_code html_code
typedef _tag_spec tag_spec

Functions

MagickBooleanType WriteMETAImage (const ImageInfo *, Image *)
int stringnicmp (const char *p, const char *q, size_t n)
int convertHTMLcodes (char *s, int len)
char * super_fgets (char **b, int *blen, Image *file)
long parse8BIM (Image *ifile, Image *ofile)
char * super_fgets_w (char **b, int *blen, Image *file)
long parse8BIMW (Image *ifile, Image *ofile)
int jpeg_transfer_1 (Image *ifile, Image *ofile)
int jpeg_read_remaining (Image *ifile, Image *ofile)
int jpeg_skip_variable (Image *ifile, Image *ofile)
int jpeg_skip_variable2 (Image *ifile, Image *ofile)
int jpeg_nextmarker (Image *ifile, Image *ofile)
int jpeg_embed (Image *ifile, Image *ofile, Image *iptc)
ImageReadMETAImage (const ImageInfo *image_info, ExceptionInfo *exception)
ModuleExport void RegisterMETAImage (void)
ModuleExport void UnregisterMETAImage (void)
long GetIPTCStream (unsigned char **info, unsigned long length)
void formatString (Image *ofile, const char *s, int len)
int formatIPTC (Image *ifile, Image *ofile)
int readWordFromBuffer (char **s, long *len)
int formatIPTCfromBuffer (Image *ofile, char *s, long len)
int format8BIM (Image *ifile, Image *ofile)

Variables

html_code html_codes []
char psheader [] = "\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0"
tag_spec tags []


Define Documentation

#define BUFFER_SZ   4096
 

Definition at line 285 of file meta.c.

#define BUFFER_SZ   4096
 

Definition at line 285 of file meta.c.

Referenced by parse8BIM(), and parse8BIMW().

#define IPTC_ID   1028
 

Definition at line 286 of file meta.c.

Referenced by format8BIM(), parse8BIM(), and parse8BIMW().

#define M_APP0   0xe0
 

Definition at line 775 of file meta.c.

Referenced by jpeg_embed().

#define M_APP1   0xe1
 

Definition at line 776 of file meta.c.

#define M_APP10   0xea
 

Definition at line 785 of file meta.c.

#define M_APP11   0xeb
 

Definition at line 786 of file meta.c.

#define M_APP12   0xec
 

Definition at line 787 of file meta.c.

#define M_APP13   0xed
 

Definition at line 788 of file meta.c.

Referenced by jpeg_embed().

#define M_APP14   0xee
 

Definition at line 789 of file meta.c.

#define M_APP15   0xef
 

Definition at line 790 of file meta.c.

#define M_APP2   0xe2
 

Definition at line 777 of file meta.c.

#define M_APP3   0xe3
 

Definition at line 778 of file meta.c.

#define M_APP4   0xe4
 

Definition at line 779 of file meta.c.

#define M_APP5   0xe5
 

Definition at line 780 of file meta.c.

#define M_APP6   0xe6
 

Definition at line 781 of file meta.c.

#define M_APP7   0xe7
 

Definition at line 782 of file meta.c.

#define M_APP8   0xe8
 

Definition at line 783 of file meta.c.

#define M_APP9   0xe9
 

Definition at line 784 of file meta.c.

#define M_EOI   0xD9 /* End Of Image (end of datastream) */
 

Definition at line 773 of file meta.c.

Referenced by jpeg_embed(), jpeg_nextmarker(), jpeg_read_remaining(), jpeg_skip_variable(), and jpeg_skip_variable2().

#define M_SOF0   0xC0 /* Start Of Frame N */
 

Definition at line 759 of file meta.c.

#define M_SOF1   0xC1 /* N indicates which compression process */
 

Definition at line 760 of file meta.c.

#define M_SOF10   0xCA
 

Definition at line 767 of file meta.c.

#define M_SOF11   0xCB
 

Definition at line 768 of file meta.c.

#define M_SOF13   0xCD
 

Definition at line 769 of file meta.c.

#define M_SOF14   0xCE
 

Definition at line 770 of file meta.c.

#define M_SOF15   0xCF
 

Definition at line 771 of file meta.c.

#define M_SOF2   0xC2 /* Only SOF0-SOF2 are now in common use */
 

Definition at line 761 of file meta.c.

#define M_SOF3   0xC3
 

Definition at line 762 of file meta.c.

#define M_SOF5   0xC5 /* NB: codes C4 and CC are NOT SOF markers */
 

Definition at line 763 of file meta.c.

#define M_SOF6   0xC6
 

Definition at line 764 of file meta.c.

#define M_SOF7   0xC7
 

Definition at line 765 of file meta.c.

#define M_SOF9   0xC9
 

Definition at line 766 of file meta.c.

#define M_SOI   0xD8
 

Definition at line 772 of file meta.c.

Referenced by jpeg_embed().

#define M_SOS   0xDA /* Start Of Scan (begins compressed data) */
 

Definition at line 774 of file meta.c.

Referenced by jpeg_embed().

#define MaxBufferSize   65541
 

Referenced by ReadMETAImage().

#define THUMBNAIL_ID   1033
 

Definition at line 287 of file meta.c.

Referenced by format8BIM().


Typedef Documentation

typedef struct _html_code html_code
 

typedef struct _tag_spec tag_spec
 


Function Documentation

int convertHTMLcodes char *  s,
int  len
[static]
 

Definition at line 194 of file meta.c.

References html_codes, _html_code::len, stringnicmp(), and _html_code::val.

Referenced by parse8BIM(), and parse8BIMW().

00195 { 00196 if (len <=0 || s==(char*)NULL || *s=='\0') 00197 return 0; 00198 00199 if (s[1] == '#') 00200 { 00201 int val, o; 00202 00203 if (sscanf(s,"&#%d;",&val) == 1) 00204 { 00205 o = 3; 00206 while (s[o] != ';') 00207 { 00208 o++; 00209 if (o > 5) 00210 break; 00211 } 00212 if (o < 6) 00213 (void) strcpy(s+1, s+1+o); 00214 *s = val; 00215 return o; 00216 } 00217 } 00218 else 00219 { 00220 int 00221 i, 00222 codes = sizeof(html_codes) / sizeof(html_code); 00223 00224 for (i=0; i < codes; i++) 00225 { 00226 if (html_codes[i].len <= len) 00227 if (stringnicmp(s, html_codes[i].code, html_codes[i].len) == 0) 00228 { 00229 (void) strcpy(s+1, s+html_codes[i].len); 00230 *s = html_codes[i].val; 00231 return html_codes[i].len-1; 00232 } 00233 } 00234 } 00235 return 0; 00236 }

Here is the call graph for this function:

int format8BIM Image ifile,
Image ofile
[static]
 

Definition at line 1986 of file meta.c.

References AcquireMagickMemory(), formatIPTCfromBuffer(), FormatMagickString(), formatString(), IPTC_ID, MagickOffsetType, MaxTextExtent, ReadBlobByte(), ReadBlobMSBLong(), ReadBlobMSBShort(), RelinquishMagickMemory(), strcmp, THUMBNAIL_ID, and WriteBlobString().

Referenced by WriteMETAImage().

01987 { 01988 char 01989 temp[MaxTextExtent]; 01990 01991 unsigned int 01992 foundOSType; 01993 01994 MagickOffsetType 01995 Size; 01996 01997 int 01998 ID, 01999 resCount, 02000 i, 02001 c; 02002 02003 unsigned char 02004 *PString, 02005 *str; 02006 02007 resCount = foundOSType = 0; /* found the OSType */ 02008 02009 c =ReadBlobByte(ifile); 02010 while (c != EOF) 02011 { 02012 if (c == '8') 02013 { 02014 unsigned char 02015 buffer[5]; 02016 02017 buffer[0] = (unsigned char) c; 02018 for (i=1; i<4; i++) 02019 { 02020 c=ReadBlobByte(ifile); 02021 if (c == EOF) return -1; 02022 buffer[i] = (unsigned char) c; 02023 } 02024 buffer[4] = 0; 02025 if (strcmp((const char *)buffer, "8BIM") == 0) 02026 foundOSType = 1; 02027 else 02028 continue; 02029 } 02030 else 02031 { 02032 c=ReadBlobByte(ifile); 02033 continue; 02034 } 02035 /* 02036 We found the OSType (8BIM) and now grab the ID, PString, and Size fields. 02037 */ 02038 ID = ReadBlobMSBShort(ifile); 02039 if (ID < 0) return -1; 02040 { 02041 unsigned char 02042 plen; 02043 02044 c=ReadBlobByte(ifile); 02045 if (c == EOF) return -1; 02046 plen = (unsigned char) c; 02047 PString=(unsigned char *) 02048 AcquireMagickMemory((size_t) (plen+MaxTextExtent)); 02049 if (PString == (unsigned char *) NULL) 02050 { 02051 printf("MemoryAllocationFailed"); 02052 return 0; 02053 } 02054 for (i=0; i<plen; i++) 02055 { 02056 c=ReadBlobByte(ifile); 02057 if (c == EOF) return -1; 02058 PString[i] = (unsigned char) c; 02059 } 02060 PString[ plen ] = 0; 02061 if ((plen & 0x01) == 0) 02062 { 02063 c=ReadBlobByte(ifile); 02064 if (c == EOF) return -1; 02065 } 02066 } 02067 Size = ReadBlobMSBLong(ifile); 02068 if (Size < 0) return -1; 02069 /* make a buffer to hold the data and snag it from the input stream */ 02070 str=(unsigned char *) AcquireMagickMemory((size_t) Size); 02071 if (str == (unsigned char *) NULL) 02072 { 02073 printf("MemoryAllocationFailed"); 02074 return 0; 02075 } 02076 for (i=0; i<Size; i++) 02077 { 02078 c=ReadBlobByte(ifile); 02079 if (c == EOF) return -1; 02080 str[i] = (unsigned char) c; 02081 } 02082 02083 /* we currently skip thumbnails, since it does not make 02084 * any sense preserving them in a real world application 02085 */ 02086 if (ID != THUMBNAIL_ID) 02087 { 02088 /* now finish up by formatting this binary data into 02089 * ASCII equivalent 02090 */ 02091 if (strlen((const char *)PString) > 0) 02092 (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d#%s=",ID, 02093 PString); 02094 else 02095 (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d=",ID); 02096 WriteBlobString(ofile,temp); 02097 if (ID == IPTC_ID) 02098 { 02099 formatString(ofile, "IPTC", 4); 02100 formatIPTCfromBuffer(ofile, (char *)str, (long) Size); 02101 } 02102 else 02103 formatString(ofile, (char *)str, (long) Size); 02104 } 02105 str=(unsigned char *) RelinquishMagickMemory(str); 02106 PString=(unsigned char *) RelinquishMagickMemory(PString); 02107 02108 resCount++; 02109 02110 c=ReadBlobByte(ifile); 02111 } 02112 return resCount; 02113 }

Here is the call graph for this function:

int formatIPTC Image ifile,
Image ofile
[static]
 

Definition at line 1750 of file meta.c.

References AcquireMagickMemory(), FormatMagickString(), formatString(), _tag_spec::id, MaxTextExtent, _tag_spec::name, ReadBlobByte(), RelinquishMagickMemory(), tags, and WriteBlobString().

Referenced by WriteMETAImage().

01751 { 01752 char 01753 temp[MaxTextExtent]; 01754 01755 unsigned int 01756 foundiptc, 01757 tagsfound; 01758 01759 unsigned char 01760 recnum, 01761 dataset; 01762 01763 unsigned char 01764 *readable, 01765 *str; 01766 01767 long 01768 tagindx, 01769 taglen; 01770 01771 int 01772 i, 01773 tagcount = sizeof(tags) / sizeof(tag_spec); 01774 01775 int 01776 c; 01777 01778 foundiptc = 0; /* found the IPTC-Header */ 01779 tagsfound = 0; /* number of tags found */ 01780 01781 c = ReadBlobByte(ifile); 01782 while (c != EOF) 01783 { 01784 if (c == 0x1c) 01785 foundiptc = 1; 01786 else 01787 { 01788 if (foundiptc) 01789 return -1; 01790 else 01791 continue; 01792 } 01793 01794 /* we found the 0x1c tag and now grab the dataset and record number tags */ 01795 c = ReadBlobByte(ifile); 01796 if (c == EOF) return -1; 01797 dataset = (unsigned char) c; 01798 c = ReadBlobByte(ifile); 01799 if (c == EOF) return -1; 01800 recnum = (unsigned char) c; 01801 /* try to match this record to one of the ones in our named table */ 01802 for (i=0; i< tagcount; i++) 01803 { 01804 if (tags[i].id == recnum) 01805 break; 01806 } 01807 if (i < tagcount) 01808 readable = (unsigned char *) tags[i].name; 01809 else 01810 readable = (unsigned char *) ""; 01811 /* 01812 We decode the length of the block that follows - long or short fmt. 01813 */ 01814 c=ReadBlobByte(ifile); 01815 if (c == EOF) return -1; 01816 if (c & (unsigned char) 0x80) 01817 return 0; 01818 else 01819 { 01820 int 01821 c0; 01822 01823 c0=ReadBlobByte(ifile); 01824 if (c0 == EOF) return -1; 01825 taglen = (c << 8) | c0; 01826 } 01827 if (taglen < 0) return -1; 01828 /* make a buffer to hold the tag data and snag it from the input stream */ 01829 str=(unsigned char *) AcquireMagickMemory((size_t) (taglen+MaxTextExtent)); 01830 if (str == (unsigned char *) NULL) 01831 { 01832 printf("MemoryAllocationFailed"); 01833 return 0; 01834 } 01835 for (tagindx=0; tagindx<taglen; tagindx++) 01836 { 01837 c=ReadBlobByte(ifile); 01838 if (c == EOF) return -1; 01839 str[tagindx] = (unsigned char) c; 01840 } 01841 str[taglen] = 0; 01842 01843 /* now finish up by formatting this binary data into ASCII equivalent */ 01844 if (strlen((char *)readable) > 0) 01845 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=", 01846 (unsigned int) dataset, (unsigned int) recnum, readable); 01847 else 01848 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=", 01849 (unsigned int) dataset,(unsigned int) recnum); 01850 WriteBlobString(ofile,temp); 01851 formatString( ofile, (char *)str, taglen ); 01852 str=(unsigned char *) RelinquishMagickMemory(str); 01853 01854 tagsfound++; 01855 01856 c=ReadBlobByte(ifile); 01857 } 01858 return tagsfound; 01859 }

Here is the call graph for this function:

int formatIPTCfromBuffer Image ofile,
char *  s,
long  len
[static]
 

Definition at line 1880 of file meta.c.

References AcquireMagickMemory(), FormatMagickString(), formatString(), _tag_spec::id, MaxTextExtent, _tag_spec::name, readWordFromBuffer(), RelinquishMagickMemory(), tags, and WriteBlobString().

Referenced by format8BIM().

01881 { 01882 char 01883 temp[MaxTextExtent]; 01884 01885 unsigned int 01886 foundiptc, 01887 tagsfound; 01888 01889 unsigned char 01890 recnum, 01891 dataset; 01892 01893 unsigned char 01894 *readable, 01895 *str; 01896 01897 long 01898 tagindx, 01899 taglen; 01900 01901 int 01902 i, 01903 tagcount = sizeof(tags) / sizeof(tag_spec); 01904 01905 int 01906 c; 01907 01908 foundiptc = 0; /* found the IPTC-Header */ 01909 tagsfound = 0; /* number of tags found */ 01910 01911 while (len > 0) 01912 { 01913 c = *s++; len--; 01914 if (c == 0x1c) 01915 foundiptc = 1; 01916 else 01917 { 01918 if (foundiptc) 01919 return -1; 01920 else 01921 continue; 01922 } 01923 /* 01924 We found the 0x1c tag and now grab the dataset and record number tags. 01925 */ 01926 c = *s++; len--; 01927 if (len < 0) return -1; 01928 dataset = (unsigned char) c; 01929 c = *s++; len--; 01930 if (len < 0) return -1; 01931 recnum = (unsigned char) c; 01932 /* try to match this record to one of the ones in our named table */ 01933 for (i=0; i< tagcount; i++) 01934 { 01935 if (tags[i].id == recnum) 01936 break; 01937 } 01938 if (i < tagcount) 01939 readable = (unsigned char *) tags[i].name; 01940 else 01941 readable = (unsigned char *) ""; 01942 /* 01943 We decode the length of the block that follows - long or short fmt. 01944 */ 01945 c = *s++; len--; 01946 if (len < 0) return -1; 01947 if (c & (unsigned char) 0x80) 01948 return 0; 01949 else 01950 { 01951 s--; len++; 01952 taglen = readWordFromBuffer(&s, &len); 01953 } 01954 if (taglen < 0) return -1; 01955 /* make a buffer to hold the tag data and snag it from the input stream */ 01956 str=(unsigned char *) AcquireMagickMemory((size_t) (taglen+MaxTextExtent)); 01957 if (str == (unsigned char *) NULL) 01958 { 01959 printf("MemoryAllocationFailed"); 01960 return 0; 01961 } 01962 for (tagindx=0; tagindx<taglen; tagindx++) 01963 { 01964 c = *s++; len--; 01965 if (len < 0) return -1; 01966 str[tagindx] = (unsigned char) c; 01967 } 01968 str[ taglen ] = 0; 01969 01970 /* now finish up by formatting this binary data into ASCII equivalent */ 01971 if (strlen((char *)readable) > 0) 01972 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=", 01973 (unsigned int) dataset,(unsigned int) recnum, readable); 01974 else 01975 (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=", 01976 (unsigned int) dataset,(unsigned int) recnum); 01977 WriteBlobString(ofile,temp); 01978 formatString( ofile, (char *)str, taglen ); 01979 str=(unsigned char *) RelinquishMagickMemory(str); 01980 01981 tagsfound++; 01982 } 01983 return tagsfound; 01984 }

Here is the call graph for this function:

void formatString Image ofile,
const char *  s,
int  len
[static]
 

Definition at line 1640 of file meta.c.

References FormatMagickString(), MaxTextExtent, WriteBlobByte(), and WriteBlobString().

Referenced by format8BIM(), formatIPTC(), and formatIPTCfromBuffer().

01641 { 01642 char 01643 temp[MaxTextExtent]; 01644 01645 WriteBlobByte(ofile,'"'); 01646 for (; len > 0; len--, s++) { 01647 int c = (*s) & 255; 01648 switch (c) { 01649 case '&': 01650 WriteBlobString(ofile,"&amp;"); 01651 break; 01652 #ifdef HANDLE_GT_LT 01653 case '<': 01654 WriteBlobString(ofile,"&lt;"); 01655 break; 01656 case '>': 01657 WriteBlobString(ofile,"&gt;"); 01658 break; 01659 #endif 01660 case '"': 01661 WriteBlobString(ofile,"&quot;"); 01662 break; 01663 default: 01664 if (isprint(c)) 01665 WriteBlobByte(ofile,*s); 01666 else 01667 { 01668 (void) FormatMagickString(temp,MaxTextExtent,"&#%d;", c & 255); 01669 WriteBlobString(ofile,temp); 01670 } 01671 break; 01672 } 01673 } 01674 #if defined(__WINDOWS__) 01675 WriteBlobString(ofile,"\"\r\n"); 01676 #else 01677 #if defined(macintosh) 01678 WriteBlobString(ofile,"\"\r"); 01679 #else 01680 WriteBlobString(ofile,"\"\n"); 01681 #endif 01682 #endif 01683 }

Here is the call graph for this function:

long GetIPTCStream unsigned char **  info,
unsigned long  length
[static]
 

Definition at line 1520 of file meta.c.

References MagickFalse, and MagickTrue.

Referenced by WriteMETAImage().

01521 { 01522 int 01523 c; 01524 01525 long 01526 info_length; 01527 01528 register long 01529 i; 01530 01531 register unsigned char 01532 *p; 01533 01534 unsigned char 01535 buffer[4]; 01536 01537 unsigned int 01538 marker; 01539 01540 unsigned long 01541 tag_length; 01542 01543 /* 01544 Find the beginning of the IPTC info. 01545 */ 01546 p=(*info); 01547 tag_length=0; 01548 iptc_find: 01549 info_length=0; 01550 marker=MagickFalse; 01551 while (length != 0) 01552 { 01553 c=(*p++); 01554 length--; 01555 if (length == 0) 01556 break; 01557 if (c == 0x1c) 01558 { 01559 p--; 01560 *info=p; /* let the caller know were it is */ 01561 break; 01562 } 01563 } 01564 /* 01565 Determine the length of the IPTC info. 01566 */ 01567 while (length != 0) 01568 { 01569 c=(*p++); 01570 length--; 01571 if (length == 0) 01572 break; 01573 if (c == 0x1c) 01574 marker=MagickTrue; 01575 else 01576 if (marker) 01577 break; 01578 else 01579 continue; 01580 info_length++; 01581 /* 01582 Found the 0x1c tag; skip the dataset and record number tags. 01583 */ 01584 c=(*p++); /* should be 2 */ 01585 length--; 01586 if (length == 0) 01587 break; 01588 if ((info_length == 1) && (c != 2)) 01589 goto iptc_find; 01590 info_length++; 01591 c=(*p++); /* should be 0 */ 01592 length--; 01593 if (length == 0) 01594 break; 01595 if ((info_length == 2) && (c != 0)) 01596 goto iptc_find; 01597 info_length++; 01598 /* 01599 Decode the length of the block that follows - long or short format. 01600 */ 01601 c=(*p++); 01602 length--; 01603 if (length == 0) 01604 break; 01605 info_length++; 01606 if ((c & 0x80) != 0) 01607 { 01608 for (i=0; i < 4; i++) 01609 { 01610 buffer[i]=(*p++); 01611 length--; 01612 if (length == 0) 01613 break; 01614 info_length++; 01615 } 01616 tag_length=(((long) buffer[0]) << 24) | (((long) buffer[1]) << 16) | 01617 (((long) buffer[2]) << 8) | (((long) buffer[3])); 01618 } 01619 else 01620 { 01621 tag_length=(c << 8); 01622 c=(*p++); 01623 length--; 01624 if (length == 0) 01625 break; 01626 info_length++; 01627 tag_length|=c; 01628 } 01629 if (tag_length > (length+1)) 01630 break; 01631 p+=tag_length; 01632 length-=tag_length; 01633 if (length == 0) 01634 break; 01635 info_length+=tag_length; 01636 } 01637 return(info_length); 01638 }

int jpeg_embed Image ifile,
Image ofile,
Image iptc
[static]
 

Definition at line 920 of file meta.c.

References GetBlobSize(), jpeg_nextmarker(), jpeg_read_remaining(), jpeg_skip_variable(), jpeg_skip_variable2(), jpeg_transfer_1(), M_APP0, M_APP13, M_EOI, M_SOI, M_SOS, MagickFalse, psheader, and WriteBlobByte().

Referenced by ReadMETAImage().

00921 { 00922 unsigned int marker; 00923 unsigned int done = 0; 00924 unsigned int len; 00925 int inx; 00926 00927 if (jpeg_transfer_1(ifile, ofile) != 0xFF) 00928 return 0; 00929 if (jpeg_transfer_1(ifile, ofile) != M_SOI) 00930 return 0; 00931 00932 while (done == MagickFalse) 00933 { 00934 marker = jpeg_nextmarker(ifile, ofile); 00935 if (marker == M_EOI) 00936 { /* EOF */ 00937 break; 00938 } 00939 else 00940 { 00941 if (marker != M_APP13) 00942 { 00943 WriteBlobByte(ofile,0xff); 00944 WriteBlobByte(ofile,marker); 00945 } 00946 } 00947 00948 switch (marker) 00949 { 00950 case M_APP13: 00951 /* we are going to write a new APP13 marker, so don't output the old one */ 00952 jpeg_skip_variable2(ifile, ofile); 00953 break; 00954 00955 case M_APP0: 00956 /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */ 00957 jpeg_skip_variable(ifile, ofile); 00958 00959 if (iptc != (Image *)NULL) 00960 { 00961 len=GetBlobSize(iptc); 00962 if (len & 1) 00963 len++; /* make the length even */ 00964 psheader[ 2 ] = (len+16)>>8; 00965 psheader[ 3 ] = (len+16)&0xff; 00966 for (inx = 0; inx < 18; inx++) 00967 WriteBlobByte(ofile,psheader[inx]); 00968 jpeg_read_remaining(iptc, ofile); 00969 len=GetBlobSize(iptc); 00970 if (len & 1) 00971 WriteBlobByte(ofile,0); 00972 } 00973 break; 00974 00975 case M_SOS: 00976 /* we hit data, no more marker-inserting can be done! */ 00977 jpeg_read_remaining(ifile, ofile); 00978 done = 1; 00979 break; 00980 00981 default: 00982 jpeg_skip_variable(ifile, ofile); 00983 break; 00984 } 00985 } 00986 return 1; 00987 }

Here is the call graph for this function:

int jpeg_nextmarker Image ifile,
Image ofile
[static]
 

Definition at line 862 of file meta.c.

References M_EOI, ReadBlobByte(), and WriteBlobByte().

Referenced by jpeg_embed().

00863 { 00864 int c; 00865 00866 /* transfer anything until we hit 0xff */ 00867 do 00868 { 00869 c = ReadBlobByte(ifile); 00870 if (c == EOF) 00871 return M_EOI; /* we hit EOF */ 00872 else 00873 if (c != 0xff) 00874 WriteBlobByte(ofile,c); 00875 } while (c != 0xff); 00876 00877 /* get marker byte, swallowing possible padding */ 00878 do 00879 { 00880 c = ReadBlobByte(ifile); 00881 if (c == EOF) 00882 return M_EOI; /* we hit EOF */ 00883 } while (c == 0xff); 00884 00885 return c; 00886 }

Here is the call graph for this function:

int jpeg_read_remaining Image ifile,
Image ofile
[static]
 

Definition at line 815 of file meta.c.

References jpeg_transfer_1(), and M_EOI.

Referenced by jpeg_embed().

00816 { 00817 int c; 00818 00819 while ((c = jpeg_transfer_1(ifile, ofile)) != EOF) 00820 continue; 00821 return M_EOI; 00822 }

Here is the call graph for this function:

int jpeg_skip_variable Image ifile,
Image ofile
[static]
 

Definition at line 824 of file meta.c.

References jpeg_transfer_1(), and M_EOI.

Referenced by jpeg_embed().

00825 { 00826 unsigned int length; 00827 int c1,c2; 00828 00829 if ((c1 = jpeg_transfer_1(ifile, ofile)) == EOF) 00830 return M_EOI; 00831 if ((c2 = jpeg_transfer_1(ifile, ofile)) == EOF) 00832 return M_EOI; 00833 00834 length = (((unsigned char) c1) << 8) + ((unsigned char) c2); 00835 length -= 2; 00836 00837 while (length--) 00838 if (jpeg_transfer_1(ifile, ofile) == EOF) 00839 return M_EOI; 00840 00841 return 0; 00842 }

Here is the call graph for this function:

int jpeg_skip_variable2 Image ifile,
Image ofile
[static]
 

Definition at line 844 of file meta.c.

References M_EOI, and ReadBlobByte().

Referenced by jpeg_embed().

00845 { 00846 unsigned int length; 00847 int c1,c2; 00848 00849 if ((c1 = ReadBlobByte(ifile)) == EOF) return M_EOI; 00850 if ((c2 = ReadBlobByte(ifile)) == EOF) return M_EOI; 00851 00852 length = (((unsigned char) c1) << 8) + ((unsigned char) c2); 00853 length -= 2; 00854 00855 while (length--) 00856 if (ReadBlobByte(ifile) == EOF) 00857 return M_EOI; 00858 00859 return 0; 00860 }

Here is the call graph for this function:

int jpeg_transfer_1 Image ifile,
Image ofile
[static]
 

Definition at line 792 of file meta.c.

References ReadBlobByte(), and WriteBlobByte().

Referenced by jpeg_embed(), jpeg_read_remaining(), and jpeg_skip_variable().

00793 { 00794 int c; 00795 00796 c = ReadBlobByte(ifile); 00797 if (c == EOF) 00798 return EOF; 00799 WriteBlobByte(ofile,c); 00800 return c; 00801 }

Here is the call graph for this function:

long parse8BIM Image ifile,
Image ofile
[static]
 

Definition at line 289 of file meta.c.

References AcquireMagickMemory(), BUFFER_SZ, convertHTMLcodes(), IPTC_ID, MagickOffsetType, MaxTextExtent, name, RelinquishMagickMemory(), SeekBlob(), strcmp, super_fgets(), TellBlob(), TokenInfo, Tokenizer(), WriteBlobByte(), WriteBlobMSBLong(), WriteBlobMSBShort(), and WriteBlobString().

Referenced by ReadMETAImage().

00290 { 00291 char 00292 brkused, 00293 quoted, 00294 *line, 00295 *token, 00296 *newstr, 00297 *name; 00298 00299 int 00300 state, 00301 next; 00302 00303 unsigned char 00304 dataset; 00305 00306 unsigned int 00307 recnum; 00308 00309 int 00310 inputlen = BUFFER_SZ; 00311 00312 long 00313 savedolen = 0L, 00314 outputlen = 0L; 00315 00316 MagickOffsetType 00317 savedpos, 00318 currentpos; 00319 00320 TokenInfo 00321 token_info; 00322 00323 dataset = 0; 00324 recnum = 0; 00325 line = (char *) AcquireMagickMemory(inputlen); 00326 name = token = (char *)NULL; 00327 savedpos = 0; 00328 while(super_fgets(&line,&inputlen,ifile)!=NULL) 00329 { 00330 state=0; 00331 next=0; 00332 00333 token = (char *) AcquireMagickMemory(inputlen); 00334 newstr = (char *) AcquireMagickMemory(inputlen); 00335 while (Tokenizer(&token_info, 0, token, inputlen, line, 00336 (char *) "", (char *) "=", 00337 (char *) "\"", 0, &brkused,&next,&quoted)==0) 00338 { 00339 if (state == 0) 00340 { 00341 int 00342 state, 00343 next; 00344 00345 char 00346 brkused, 00347 quoted; 00348 00349 state=0; 00350 next=0; 00351 while(Tokenizer(&token_info, 0, newstr, inputlen, token, (char *) "", 00352 (char *) "#", (char *) "", 0, &brkused, &next, &quoted)==0) 00353 { 00354 switch (state) 00355 { 00356 case 0: 00357 if (strcmp(newstr,"8BIM")==0) 00358 dataset = 255; 00359 else 00360 dataset = (unsigned char) atoi(newstr); 00361 break; 00362 case 1: 00363 recnum = atoi(newstr); 00364 break; 00365 case 2: 00366 name=(char *) AcquireMagickMemory(strlen(newstr)+MaxTextExtent); 00367 if (name) 00368 (void) strcpy(name,newstr); 00369 break; 00370 } 00371 state++; 00372 } 00373 } 00374 else 00375 if (state == 1) 00376 { 00377 int 00378 next; 00379 00380 unsigned long 00381 len; 00382 00383 char 00384 brkused, 00385 quoted; 00386 00387 next=0; 00388 len = strlen(token); 00389 while (Tokenizer(&token_info,0, newstr, inputlen, token, (char *) "", 00390 (char *) "&", (char *) "", 0, &brkused, &next, &quoted)==0) 00391 { 00392 if (brkused && next > 0) 00393 { 00394 char 00395 *s = &token[next-1]; 00396 00397 len -= convertHTMLcodes(s, strlen(s)); 00398 } 00399 } 00400 00401 if (dataset == 255) 00402 { 00403 unsigned char 00404 nlen = 0; 00405 00406 int 00407 i; 00408 00409 if (savedolen > 0) 00410 { 00411 long diff = outputlen - savedolen; 00412 currentpos = TellBlob(ofile); 00413 SeekBlob(ofile,savedpos,SEEK_SET); 00414 WriteBlobMSBLong(ofile,diff); 00415 SeekBlob(ofile,currentpos,SEEK_SET); 00416 savedolen = 0L; 00417 } 00418 if (outputlen & 1) 00419 { 00420 WriteBlobByte(ofile,0x00); 00421 outputlen++; 00422 } 00423 WriteBlobString(ofile,"8BIM"); 00424 WriteBlobMSBShort(ofile,recnum); 00425 outputlen += 6; 00426 if (name) 00427 nlen = strlen(name); 00428 WriteBlobByte(ofile,nlen); 00429 outputlen++; 00430 for (i=0; i<nlen; i++) 00431 WriteBlobByte(ofile,name[i]); 00432 outputlen += nlen; 00433 if ((nlen & 0x01) == 0) 00434 { 00435 WriteBlobByte(ofile,0x00); 00436 outputlen++; 00437 } 00438 if (recnum != IPTC_ID) 00439 { 00440 WriteBlobMSBLong(ofile, len); 00441 outputlen += 4; 00442 00443 next=0; 00444 outputlen += len; 00445 while (len--) 00446 WriteBlo