% July 2001 %
% %
% %
-% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
/*
Include declarations.
*/
-#include "magick/studio.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/exception.h"
-#include "magick/exception-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/splay-tree.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
-#include "magick/token.h"
-#include "magick/utility.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/module.h"
+#include "MagickCore/profile.h"
+#include "MagickCore/splay-tree.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
+#include "MagickCore/token.h"
+#include "MagickCore/utility.h"
\f
/*
Forward declarations.
static int stringnicmp(const char *p,const char *q,size_t n)
{
- register long
+ register ssize_t
i,
j;
#define IPTC_ID 1028
#define THUMBNAIL_ID 1033
-static long parse8BIM(Image *ifile, Image *ofile)
+static ssize_t parse8BIM(Image *ifile, Image *ofile)
{
char
brkused,
int
inputlen = BUFFER_SZ;
- long
- savedolen = 0L,
- outputlen = 0L;
-
MagickOffsetType
savedpos,
currentpos;
+ ssize_t
+ savedolen = 0L,
+ outputlen = 0L;
+
TokenInfo
*token_info;
if (strcmp(newstr,"8BIM")==0)
dataset = 255;
else
- dataset = (unsigned char) atoi(newstr);
+ dataset = (unsigned char) StringToLong(newstr);
break;
case 1:
- recnum = (unsigned int) atoi(newstr);
+ recnum = (unsigned int) StringToUnsignedLong(newstr);
break;
case 2:
name=(char *) AcquireQuantumMemory(strlen(newstr)+MaxTextExtent,
int
next;
- long
+ ssize_t
len;
char
quoted;
next=0;
- len = (long) strlen(token);
+ len = (ssize_t) strlen(token);
while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
"",0,&brkused,&next,"ed)==0)
{
char
*s = &token[next-1];
- len -= (long) convertHTMLcodes(s,(int) strlen(s));
+ len -= (ssize_t) convertHTMLcodes(s,(int) strlen(s));
}
}
MagickOffsetType
offset;
- long diff = outputlen - savedolen;
+ ssize_t diff = outputlen - savedolen;
currentpos = TellBlob(ofile);
offset=SeekBlob(ofile,savedpos,SEEK_SET);
if (offset < 0)
return(-1);
- (void) WriteBlobMSBLong(ofile,(unsigned long) diff);
+ (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
offset=SeekBlob(ofile,currentpos,SEEK_SET);
if (offset < 0)
return(-1);
}
if (recnum != IPTC_ID)
{
- (void) WriteBlobMSBLong(ofile, (unsigned long) len);
+ (void) WriteBlobMSBLong(ofile, (unsigned int) len);
outputlen += 4;
next=0;
{
/* patch in a fake length for now and fix it later */
savedpos = TellBlob(ofile);
- (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);
+ (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
outputlen += 4;
savedolen = outputlen;
}
MagickOffsetType
offset;
- long diff = outputlen - savedolen;
+ ssize_t diff = outputlen - savedolen;
currentpos = TellBlob(ofile);
offset=SeekBlob(ofile,savedpos,SEEK_SET);
if (offset < 0)
return(-1);
- (void) WriteBlobMSBLong(ofile,(unsigned long) diff);
+ (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
offset=SeekBlob(ofile,currentpos,SEEK_SET);
if (offset < 0)
return(-1);
return((char *) p);
}
-static long parse8BIMW(Image *ifile, Image *ofile)
+static ssize_t parse8BIMW(Image *ifile, Image *ofile)
{
char
brkused,
int
inputlen = BUFFER_SZ;
- long
+ ssize_t
savedolen = 0L,
outputlen = 0L;
if (strcmp(newstr,"8BIM")==0)
dataset = 255;
else
- dataset = (unsigned char) atoi(newstr);
+ dataset = (unsigned char) StringToLong(newstr);
break;
case 1:
- recnum=(unsigned int) atoi(newstr);
+ recnum=(unsigned int) StringToUnsignedLong(newstr);
break;
case 2:
name=(char *) AcquireQuantumMemory(strlen(newstr)+MaxTextExtent,
int
next;
- long
+ ssize_t
len;
char
quoted;
next=0;
- len = (long) strlen(token);
+ len = (ssize_t) strlen(token);
while (Tokenizer(token_info,0,newstr,(size_t) inputlen,token,"","&",
"",0,&brkused,&next,"ed)==0)
{
char
*s = &token[next-1];
- len -= (long) convertHTMLcodes(s,(int) strlen(s));
+ len -= (ssize_t) convertHTMLcodes(s,(int) strlen(s));
}
}
MagickOffsetType
offset;
- long diff = outputlen - savedolen;
+ ssize_t diff = outputlen - savedolen;
currentpos = TellBlob(ofile);
offset=SeekBlob(ofile,savedpos,SEEK_SET);
if (offset < 0)
return(-1);
- (void) WriteBlobMSBLong(ofile,(unsigned long) diff);
+ (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
offset=SeekBlob(ofile,currentpos,SEEK_SET);
if (offset < 0)
return(-1);
}
if (recnum != IPTC_ID)
{
- (void) WriteBlobMSBLong(ofile,(unsigned long) len);
+ (void) WriteBlobMSBLong(ofile,(unsigned int) len);
outputlen += 4;
next=0;
{
/* patch in a fake length for now and fix it later */
savedpos = TellBlob(ofile);
- (void) WriteBlobMSBLong(ofile,0xFFFFFFFFUL);
+ (void) WriteBlobMSBLong(ofile,0xFFFFFFFFU);
outputlen += 4;
savedolen = outputlen;
}
MagickOffsetType
offset;
- long diff = outputlen - savedolen;
+ ssize_t diff = outputlen - savedolen;
currentpos = TellBlob(ofile);
offset=SeekBlob(ofile,savedpos,SEEK_SET);
if (offset < 0)
return(-1);
- (void) WriteBlobMSBLong(ofile,(unsigned long) diff);
+ (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
offset=SeekBlob(ofile,currentpos,SEEK_SET);
if (offset < 0)
return(-1);
}
image->columns=1;
image->rows=1;
- (void) SetImageBackgroundColor(image);
+ if (SetImageBackgroundColor(image) == MagickFalse)
+ {
+ InheritException(exception,&image->exception);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
length=1;
if (LocaleNCompare(image_info->magick,"8BIM",4) == 0)
{
char
name[MaxTextExtent];
- (void) FormatMagickString(name,MaxTextExtent,"APP%d",1);
+ (void) FormatLocaleString(name,MaxTextExtent,"APP%d",1);
buff=AcquireImage((ImageInfo *) NULL);
if (buff == (Image *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) WriteBlobByte(buff,c);
}
#else
- long
+ ssize_t
i;
unsigned char
while ((length=ReadBlob(image,MagickMaxBufferExtent,buffer)) != 0)
{
count=0;
- for (i=0; i < (long) length; i+=count)
+ for (i=0; i < (ssize_t) length; i+=count)
{
count=WriteBlob(buff,(size_t) (length-i),buffer+i);
if (count <= 0)
break;
}
- if (i < (long) length)
+ if (i < (ssize_t) length)
break;
}
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
}
AttachBlob(buff->blob,blob,length);
/* write out the header - length field patched below */
- (void) WriteBlob(buff,11,(unsigned char *) "8BIM\04\04\0\0\0\0\01");
- (void) WriteBlobByte(buff,0xe0);
+ (void) WriteBlob(buff,11,(unsigned char *) "8BIM\04\04\0\0\0\0\0");
+ (void) WriteBlobByte(buff,0xc6);
if (LocaleCompare(image_info->magick,"IPTCTEXT") == 0)
{
length=(size_t) parse8BIM(image,buff);
%
% The format of the RegisterMETAImage method is:
%
-% unsigned long RegisterMETAImage(void)
+% size_t RegisterMETAImage(void)
%
*/
-ModuleExport unsigned long RegisterMETAImage(void)
+ModuleExport size_t RegisterMETAImage(void)
{
MagickInfo
*entry;
entry->description=ConstantString("Photoshop resource format");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("8BIMTEXT");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Photoshop resource text format");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("8BIMWTEXT");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Photoshop resource wide text format");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("APP1");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Raw application information");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("APP1JPEG");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Raw JPEG binary data");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("EXIF");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Exif digital camera binary data");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("XMP");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("Adobe XML metadata");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("ICM");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("ICC Color Profile");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("ICC");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("ICC Color Profile");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("IPTC");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("IPTC Newsphoto");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("IPTCTEXT");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
entry->description=ConstantString("IPTC Newsphoto text format");
entry->module=ConstantString("META");
(void) RegisterMagickInfo(entry);
-
entry=SetMagickInfo("IPTCWTEXT");
entry->decoder=(DecodeImageHandler *) ReadMETAImage;
entry->encoder=(EncodeImageHandler *) WriteMETAImage;
int
c;
- register long
+ register ssize_t
i;
register unsigned char
unsigned int
marker;
- unsigned long
+ size_t
tag_length;
p=(*info);
extent-=c;
if (extent < 4)
break;
- tag_length=(((unsigned long) *p) << 24) | (((unsigned long) *(p+1)) << 16) |
- (((unsigned long) *(p+2)) << 8) | ((unsigned long) *(p+3));
+ tag_length=(((size_t) *p) << 24) | (((size_t) *(p+1)) << 16) |
+ (((size_t) *(p+2)) << 8) | ((size_t) *(p+3));
p+=4;
extent-=4;
if (tag_length > extent)
break;
if (marker == IPTC_ID)
{
- *info=p; /* let the caller know were it is */
- return(extent);
+ *info=p;
+ return(tag_length);
}
+ if ((tag_length & 0x01) != 0)
+ tag_length++;
p+=tag_length;
extent-=tag_length;
}
goto iptc_find;
info_length++;
/*
- Decode the length of the block that follows - long or short format.
+ Decode the length of the block that follows - ssize_t or short format.
*/
c=(*p++);
length--;
break;
info_length++;
}
- tag_length=(((unsigned long) buffer[0]) << 24) |
- (((unsigned long) buffer[1]) << 16) |
- (((unsigned long) buffer[2]) << 8) | (((unsigned long) buffer[3]));
+ tag_length=(((size_t) buffer[0]) << 24) |
+ (((size_t) buffer[1]) << 16) |
+ (((size_t) buffer[2]) << 8) | (((size_t) buffer[3]));
}
else
{
- tag_length=(unsigned long) (c << 8);
+ tag_length=(size_t) (c << 8);
c=(*p++);
length--;
if (length == 0)
(void) WriteBlobByte(ofile,(unsigned char) *s);
else
{
- (void) FormatMagickString(temp,MaxTextExtent,"&#%d;", c & 255);
+ (void) FormatLocaleString(temp,MaxTextExtent,"&#%d;", c & 255);
(void) WriteBlobString(ofile,temp);
}
break;
}
}
-#if defined(__WINDOWS__)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
(void) WriteBlobString(ofile,"\"\r\n");
#else
#if defined(macintosh)
*readable,
*str;
- long
+ ssize_t
tagindx,
taglen;
else
readable = (unsigned char *) "";
/*
- We decode the length of the block that follows - long or short fmt.
+ We decode the length of the block that follows - ssize_t or short fmt.
*/
c=ReadBlobByte(ifile);
if (c == EOF) return -1;
/* now finish up by formatting this binary data into ASCII equivalent */
if (strlen((char *)readable) > 0)
- (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=",
+ (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
(unsigned int) dataset, (unsigned int) recnum, readable);
else
- (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=",
+ (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
(unsigned int) dataset,(unsigned int) recnum);
(void) WriteBlobString(ofile,temp);
formatString( ofile, (char *)str, taglen );
return((int) tagsfound);
}
-static int readWordFromBuffer(char **s, long *len)
+static int readWordFromBuffer(char **s, ssize_t *len)
{
unsigned char
buffer[2];
(((int) buffer[ 1 ]));
}
-static int formatIPTCfromBuffer(Image *ofile, char *s, long len)
+static int formatIPTCfromBuffer(Image *ofile, char *s, ssize_t len)
{
char
temp[MaxTextExtent];
*readable,
*str;
- long
+ ssize_t
tagindx,
taglen;
else
readable=(unsigned char *) "";
/*
- We decode the length of the block that follows - long or short fmt.
+ We decode the length of the block that follows - ssize_t or short fmt.
*/
c=(*s++);
len--;
/* now finish up by formatting this binary data into ASCII equivalent */
if (strlen((char *)readable) > 0)
- (void) FormatMagickString(temp,MaxTextExtent,"%d#%d#%s=",
+ (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d#%s=",
(unsigned int) dataset,(unsigned int) recnum, readable);
else
- (void) FormatMagickString(temp,MaxTextExtent,"%d#%d=",
+ (void) FormatLocaleString(temp,MaxTextExtent,"%d#%d=",
(unsigned int) dataset,(unsigned int) recnum);
(void) WriteBlobString(ofile,temp);
formatString( ofile, (char *)str, taglen );
resCount=0;
foundOSType=0; /* found the OSType */
+ (void) foundOSType;
c=ReadBlobByte(ifile);
while (c != EOF)
{
return(-1);
}
}
- count = (ssize_t) ReadBlobMSBLong(ifile);
+ count = (int) ReadBlobMSBLong(ifile);
if (count < 0) return -1;
/* make a buffer to hold the datand snag it from the input stream */
str=(unsigned char *) AcquireQuantumMemory((size_t) count,sizeof(*str));
printf("MemoryAllocationFailed");
return 0;
}
- for (i=0; i < (long) count; i++)
+ for (i=0; i < (ssize_t) count; i++)
{
c=ReadBlobByte(ifile);
if (c == EOF)
* ASCII equivalent
*/
if (strlen((const char *)PString) > 0)
- (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d#%s=",ID,
+ (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d#%s=",ID,
PString);
else
- (void) FormatMagickString(temp,MaxTextExtent,"8BIM#%d=",ID);
+ (void) FormatLocaleString(temp,MaxTextExtent,"8BIM#%d=",ID);
(void) WriteBlobString(ofile,temp);
if (ID == IPTC_ID)
{
formatString(ofile, "IPTC", 4);
- formatIPTCfromBuffer(ofile, (char *)str, (long) count);
+ formatIPTCfromBuffer(ofile, (char *)str, (ssize_t) count);
}
else
- formatString(ofile, (char *)str, (long) count);
+ formatString(ofile, (char *)str, (ssize_t) count);
}
str=(unsigned char *) RelinquishMagickMemory(str);
PString=(unsigned char *) RelinquishMagickMemory(PString);
unsigned char
*info;
- profile=GetImageProfile(image,"8bim");
+ profile=GetImageProfile(image,"iptc");
+ if (profile == (StringInfo *) NULL)
+ profile=GetImageProfile(image,"8bim");
if (profile == (StringInfo *) NULL)
ThrowWriterException(CoderError,"No8BIMDataIsAvailable");
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);