From: dirk Date: Sat, 1 Mar 2014 11:22:55 +0000 (+0000) Subject: The ResolutionInfo in the 8BIM profile will be updated when an image is written. X-Git-Tag: 7.0.1-0~2631 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bfa82b3e72f86ae10031bf612f97267dee6e061;p=imagemagick The ResolutionInfo in the 8BIM profile will be updated when an image is written. --- diff --git a/MagickCore/profile.c b/MagickCore/profile.c index 031946b67..dedaa8c44 100644 --- a/MagickCore/profile.c +++ b/MagickCore/profile.c @@ -1361,6 +1361,36 @@ static inline size_t ReadProfileLong(const EndianType endian, return((size_t) (value & 0xffffffff)); } +static inline size_t ReadProfileMSBLong(unsigned char **p, + size_t *length) +{ + size_t + value; + + if (*length < 4) + return(0); + + value=ReadProfileLong(MSBEndian,*p); + (*length)-=4; + *p+=4; + return(value); +} + +static inline unsigned short ReadProfileMSBShort(unsigned char **p, + size_t *length) +{ + unsigned short + value; + + if (*length < 2) + return(0); + + value=ReadProfileShort(MSBEndian,*p); + (*length)-=2; + *p+=2; + return(value); +} + static inline void WriteProfileLong(const EndianType endian, const size_t value,unsigned char *p) { @@ -1401,7 +1431,56 @@ static void WriteProfileShort(const EndianType endian, (void) CopyMagickMemory(p,buffer,2); } -MagickPrivate MagickBooleanType SyncImageProfiles(Image *image) +static MagickBooleanType Sync8BimProfile(Image *image,StringInfo *profile) +{ + size_t + count, + length; + + unsigned char + *p; + + unsigned short + id; + + length=GetStringInfoLength(profile); + p=GetStringInfoDatum(profile); + while(length != 0) + { + if (ReadProfileByte(&p,&length) != 0x38) + continue; + if (ReadProfileByte(&p,&length) != 0x42) + continue; + if (ReadProfileByte(&p,&length) != 0x49) + continue; + if (ReadProfileByte(&p,&length) != 0x4D) + continue; + if (length < 7) + return(MagickFalse); + id=ReadProfileMSBShort(&p,&length); + count=ReadProfileByte(&p,&length); + if (count > length) + return(MagickFalse); + p+=count; + if ((*p & 0x01) == 0) + p++; + count=ReadProfileMSBLong(&p,&length); + if (count > length) + return(MagickFalse); + if (id == 0x3ED && count == 16) + { + WriteProfileShort(MSBEndian, (unsigned short) (image->resolution.x+ + 0.5),p); + WriteProfileShort(MSBEndian, (unsigned short) (image->resolution.y+ + 0.5),p+8); + } + p+=count; + length-=count; + } + return(MagickTrue); +} + +MagickBooleanType SyncExifProfile(Image *image,StringInfo *profile) { #define MaxDirectoryStack 16 #define EXIF_DELIMITER "\n" @@ -1437,9 +1516,6 @@ MagickPrivate MagickBooleanType SyncImageProfiles(Image *image) static int format_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}; - StringInfo - *profile; - unsigned char *directory, *exif; @@ -1447,9 +1523,6 @@ MagickPrivate MagickBooleanType SyncImageProfiles(Image *image) /* Set EXIF resolution tag. */ - profile=(StringInfo *) GetImageProfile(image,"EXIF"); - if (profile == (StringInfo *) NULL) - return(MagickTrue); length=GetStringInfoLength(profile); exif=GetStringInfoDatum(profile); while (length != 0) @@ -1615,3 +1688,23 @@ MagickPrivate MagickBooleanType SyncImageProfiles(Image *image) } while (level > 0); return(MagickTrue); } + +MagickExport MagickBooleanType SyncImageProfiles(Image *image) +{ + MagickBooleanType + status; + + StringInfo + *profile; + + status=MagickTrue; + profile=(StringInfo *) GetImageProfile(image,"8BIM"); + if (profile != (StringInfo *) NULL) + if (Sync8BimProfile(image,profile) == MagickFalse) + status=MagickFalse; + profile=(StringInfo *) GetImageProfile(image,"EXIF"); + if (profile != (StringInfo *) NULL) + if (SyncExifProfile(image,profile) == MagickFalse) + status=MagickFalse; + return(status); +} \ No newline at end of file