]> granicus.if.org Git - imagemagick/blobdiff - magick/property.c
(no commit message)
[imagemagick] / magick / property.c
index 792b043a4a6ed0d3d09c3270d92ea51abeb6cc30..3d59d775ab4064238acf6a5b343ba8cfdaa1b1f9 100644 (file)
@@ -576,7 +576,7 @@ static MagickBooleanType Get8BIMProperty(const Image *image,const char *key)
     *name='\0';
   sub_number=1;
   if (*name == '#')
-    sub_number=StringToLong(&name[1]);
+    sub_number=(ssize_t) StringToLong(&name[1]);
   sub_number=MagickMax(sub_number,1L);
   resource=(char *) NULL;
   status=MagickFalse;
@@ -1280,7 +1280,7 @@ static MagickBooleanType GetEXIFProperty(const Image *image,
         format;
 
       q=(unsigned char *) (directory+2+(12*entry));
-      tag_value=(ssize_t) ReadPropertyShort(endian,q)+tag_offset;
+      tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
       format=(size_t) ReadPropertyShort(endian,q+2);
       if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
         break;
@@ -1312,13 +1312,13 @@ static MagickBooleanType GetEXIFProperty(const Image *image,
             case EXIF_FMT_BYTE:
             case EXIF_FMT_UNDEFINED:
             {
-              EXIFMultipleValues(1,"%lu",(size_t)
+              EXIFMultipleValues(1,"%.20g",(double)
                 (*(unsigned char *) p1));
               break;
             }
             case EXIF_FMT_SBYTE:
             {
-              EXIFMultipleValues(1,"%ld",(ssize_t) (*(signed char *) p1));
+              EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
               break;
             }
             case EXIF_FMT_SSHORT:
@@ -1333,23 +1333,27 @@ static MagickBooleanType GetEXIFProperty(const Image *image,
             }
             case EXIF_FMT_ULONG:
             {
-              EXIFMultipleValues(4,"%lu",ReadPropertyLong(endian,p1));
+              EXIFMultipleValues(4,"%.20g",(double)
+                ReadPropertyLong(endian,p1));
               break;
             }
             case EXIF_FMT_SLONG:
             {
-              EXIFMultipleValues(4,"%ld",ReadPropertyLong(endian,p1));
+              EXIFMultipleValues(4,"%.20g",(double)
+                ReadPropertyLong(endian,p1));
               break;
             }
             case EXIF_FMT_URATIONAL:
             {
-              EXIFMultipleFractions(8,"%ld/%ld",ReadPropertyLong(endian,p1),
+              EXIFMultipleFractions(8,"%.20g/%.20g",(double)
+                ReadPropertyLong(endian,p1),(double)
                 ReadPropertyLong(endian,p1+4));
               break;
             }
             case EXIF_FMT_SRATIONAL:
             {
-              EXIFMultipleFractions(8,"%ld/%ld",ReadPropertyLong(endian,p1),
+              EXIFMultipleFractions(8,"%.20g/%.20g",(double)
+                ReadPropertyLong(endian,p1),(double)
                 ReadPropertyLong(endian,p1+4));
               break;
             }
@@ -1424,11 +1428,11 @@ static MagickBooleanType GetEXIFProperty(const Image *image,
                 {
                   if (tag_value < 0x10000)
                     (void) FormatMagickString(key,MaxTextExtent,"#%04lx",
-                      tag_value);
+                      (unsigned long) tag_value);
                   else
                     if (tag_value < 0x20000)
                       (void) FormatMagickString(key,MaxTextExtent,"@%04lx",
-                        tag_value & 0xffff);
+                        (unsigned long) (tag_value & 0xffff));
                     else
                       (void) FormatMagickString(key,MaxTextExtent,"unknown");
                   break;
@@ -1804,7 +1808,7 @@ static char *TraceSVGClippath(const unsigned char *blob,size_t length,
     "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
   (void) ConcatenateString(&path,message);
   (void) FormatMagickString(message,MaxTextExtent,
-    "<svg width=\"%lu\" height=\"%lu\">\n",columns,rows);
+    "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
   (void) ConcatenateString(&path,message);
   (void) FormatMagickString(message,MaxTextExtent,"<g>\n");
   (void) ConcatenateString(&path,message);
@@ -1975,8 +1979,7 @@ MagickExport const char *GetImageProperty(const Image *image,
         image->properties);
       return(p);
     }
-  if ((image->properties != (void *) NULL) &&
-      (LocaleNCompare("fx:",property,3) != 0))
+  if (image->properties != (void *) NULL)
     {
       p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
         image->properties,property);
@@ -2028,8 +2031,8 @@ MagickExport const char *GetImageProperty(const Image *image,
               char
                 value[MaxTextExtent];
 
-              (void) FormatMagickString(value,MaxTextExtent,"%g",(double)
-                alpha);
+              (void) FormatMagickString(value,MaxTextExtent,"%.*g",
+                GetMagickPrecision(),(double) alpha);
               (void) SetImageProperty((Image *) image,property,value);
             }
           p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
@@ -2186,7 +2189,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
           if (IsGrayImage(image,&image->exception) != MagickFalse)
             colorspace=GRAYColorspace;
           (void) FormatMagickString(value,MaxTextExtent,"%s",
-            MagickOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace));
+            MagickOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
+            colorspace));
           break;
         }
       break;
@@ -2195,7 +2199,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
     {
       if (LocaleNCompare("depth",property,5) == 0)
         {
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",image->depth);
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
+            image->depth);
           break;
         }
       if (LocaleNCompare("directory",property,9) == 0)
@@ -2221,7 +2226,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
       if (LocaleNCompare("group",property,5) == 0)
         {
           (void) FormatMagickString(value,MaxTextExtent,"0x%lx",
-            image_info->group);
+            (unsigned long) image_info->group);
           break;
         }
       break;
@@ -2230,8 +2235,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
     {
       if (LocaleNCompare("height",property,6) == 0)
         {
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",
-            image->magick_rows != 0 ? image->magick_rows : 256UL);
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",
+            image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
           break;
         }
       break;
@@ -2276,7 +2281,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
 
           (void) GetImageChannelRange(image,image_info->channel,&minimum,
             &maximum,&image->exception);
-          (void) FormatMagickString(value,MaxTextExtent,"%g",maximum);
+          (void) FormatMagickString(value,MaxTextExtent,"%.*g",
+            GetMagickPrecision(),maximum);
           break;
         }
       if (LocaleNCompare("mean",property,4) == 0)
@@ -2299,7 +2305,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
 
           (void) GetImageChannelRange(image,image_info->channel,&minimum,
             &maximum,&image->exception);
-          (void) FormatMagickString(value,MaxTextExtent,"%g",minimum);
+          (void) FormatMagickString(value,MaxTextExtent,"%.*g",
+            GetMagickPrecision(),minimum);
           break;
         }
       break;
@@ -2335,7 +2342,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
           p=image;
           for (page=1; GetPreviousImageInList(p) != (Image *) NULL; page++)
             p=GetPreviousImageInList(p);
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",page);
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
+            page);
           break;
         }
       break;
@@ -2353,15 +2361,16 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
         }
       if (LocaleNCompare("scenes",property,6) == 0)
         {
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",
-            (size_t) GetImageListLength(image));
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
+            GetImageListLength(image));
           break;
         }
       if (LocaleNCompare("scene",property,5) == 0)
         {
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",image->scene);
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
+            image->scene);
           if (image_info->number_scenes != 0)
-            (void) FormatMagickString(value,MaxTextExtent,"%lu",
+            (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double)
               image_info->scene);
           break;
         }
@@ -2406,8 +2415,8 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
     {
       if (LocaleNCompare("width",property,5) == 0)
         {
-          (void) FormatMagickString(value,MaxTextExtent,"%lu",
-            image->magick_columns != 0 ? image->magick_columns : 256UL);
+          (void) FormatMagickString(value,MaxTextExtent,"%.20g",(double) 
+            (image->magick_columns != 0 ? image->magick_columns : 256));
           break;
         }
       break;
@@ -2610,7 +2619,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           File size.
         */
-        (void) FormatMagickString(format,MaxTextExtent,"%lu",(size_t)
+        (void) FormatMagickString(format,MaxTextExtent,"%.20g",(double)
           image->extent);
         if (image->extent != (MagickSizeType) ((size_t) image->extent))
           (void) FormatMagickSize(image->extent,MagickFalse,format);
@@ -2696,8 +2705,9 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Image geometry.
         */
-        q+=FormatMagickString(q,extent,"%lux%lu%+ld%+ld",image->page.width,
-          image->page.height,image->page.x,image->page.y);
+        q+=FormatMagickString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
+          image->page.width,(double) image->page.height,(double)
+          image->page.x,(double) image->page.y);
         break;
       }
       case 'h':
@@ -2705,8 +2715,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Image height.
         */
-        q+=FormatMagickString(q,extent,"%lu",image->rows != 0 ? image->rows :
-          image->magick_rows);
+        q+=FormatMagickString(q,extent,"%.20g",(double)
+          (image->rows != 0 ? image->rows : image->magick_rows));
         break;
       }
       case 'i':
@@ -2722,8 +2732,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Number of unique colors.
         */
-        q+=FormatMagickString(q,extent,"%lu",GetNumberColors(image,
-          (FILE *) NULL,&image->exception));
+        q+=FormatMagickString(q,extent,"%.20g",(double)
+          GetNumberColors(image,(FILE *) NULL,&image->exception));
         break;
       }
       case 'l':
@@ -2768,7 +2778,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Number of images in the list.
         */
-        q+=FormatMagickString(q,extent,"%lu",(size_t)
+        q+=FormatMagickString(q,extent,"%.20g",(double)
           GetImageListLength(image));
         break;
       }
@@ -2794,7 +2804,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         p=image;
         for (page=1; GetPreviousImageInList(p) != (Image *) NULL; page++)
           p=GetPreviousImageInList(p);
-        q+=FormatMagickString(q,extent,"%lu",page);
+        q+=FormatMagickString(q,extent,"%.20g",(double) page);
         break;
       }
       case 'q':
@@ -2802,7 +2812,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Image depth.
         */
-        q+=FormatMagickString(q,extent,"%lu",image->depth);
+        q+=FormatMagickString(q,extent,"%.20g",(double) image->depth);
         break;
       }
       case 'r':
@@ -2828,9 +2838,9 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
           Image scene number.
         */
         if (text_info->number_scenes == 0)
-          q+=FormatMagickString(q,extent,"%lu",image->scene);
+          q+=FormatMagickString(q,extent,"%.20g",(double) image->scene);
         else
-          q+=FormatMagickString(q,extent,"%lu",text_info->scene);
+          q+=FormatMagickString(q,extent,"%.20g",(double) text_info->scene);
         break;
       }
       case 'u':
@@ -2847,8 +2857,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Image width.
         */
-        q+=FormatMagickString(q,extent,"%lu",image->columns != 0 ?
-          image->columns : image->magick_columns);
+        q+=FormatMagickString(q,extent,"%.20g",(double)
+          (image->columns != 0 ? image->columns : image->magick_columns));
         break;
       }
       case 'x':
@@ -2857,7 +2867,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
           Image horizontal resolution.
         */
         q+=FormatMagickString(q,extent,"%g %s",image->x_resolution,
-          MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t) image->units));
+          MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t)
+            image->units));
         break;
       }
       case 'y':
@@ -2866,7 +2877,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
           Image vertical resolution.
         */
         q+=FormatMagickString(q,extent,"%g %s",image->y_resolution,
-          MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t) image->units));
+          MagickOptionToMnemonic(MagickResolutionOptions,(ssize_t)
+          image->units));
         break;
       }
       case 'z':
@@ -2874,7 +2886,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         /*
           Image depth.
         */
-        q+=FormatMagickString(q,extent,"%lu",image->depth);
+        q+=FormatMagickString(q,extent,"%.20g",(double) image->depth);
         break;
       }
       case 'A':
@@ -2906,29 +2918,31 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
       }
       case 'G':
       {
-        q+=FormatMagickString(q,extent,"%lux%lu",image->magick_columns,
-          image->magick_rows);
+        q+=FormatMagickString(q,extent,"%.20gx%.20g",(double)
+          image->magick_columns,(double) image->magick_rows);
         break;
       }
       case 'H':
       {
-        q+=FormatMagickString(q,extent,"%ld",image->page.height);
+        q+=FormatMagickString(q,extent,"%.20g",(double)
+          image->page.height);
         break;
       }
       case 'O':
       {
-        q+=FormatMagickString(q,extent,"%+ld%+ld",image->page.x,image->page.y);
+        q+=FormatMagickString(q,extent,"%+ld%+ld",(long) image->page.x,
+          (long) image->page.y);
         break;
       }
       case 'P':
       {
-        q+=FormatMagickString(q,extent,"%lux%lu",image->page.width,
-          image->page.height);
+        q+=FormatMagickString(q,extent,"%.20gx%.20g",(double) image->page.width,
+          (double) image->page.height);
         break;
       }
       case 'Q':
       {
-        q+=FormatMagickString(q,extent,"%lu",image->quality);
+        q+=FormatMagickString(q,extent,"%.20g",(double) image->quality);
         break;
       }
       case 'S':
@@ -2939,28 +2953,28 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
         if (text_info->number_scenes == 0)
           q+=CopyMagickString(q,"2147483647",extent);
         else
-          q+=FormatMagickString(q,extent,"%lu",text_info->scene+
-            text_info->number_scenes);
+          q+=FormatMagickString(q,extent,"%.20g",(double)
+            (text_info->scene+text_info->number_scenes));
         break;
       }
       case 'T':
       {
-        q+=FormatMagickString(q,extent,"%lu",image->delay);
+        q+=FormatMagickString(q,extent,"%.20g",(double) image->delay);
         break;
       }
       case 'W':
       {
-        q+=FormatMagickString(q,extent,"%ld",image->page.width);
+        q+=FormatMagickString(q,extent,"%.20g",(double) image->page.width);
         break;
       }
       case 'X':
       {
-        q+=FormatMagickString(q,extent,"%+ld",image->page.x);
+        q+=FormatMagickString(q,extent,"%+.20g",(double) image->page.x);
         break;
       }
       case 'Y':
       {
-        q+=FormatMagickString(q,extent,"%+ld",image->page.y);
+        q+=FormatMagickString(q,extent,"%+.20g",(double) image->page.y);
         break;
       }
       case 'Z':
@@ -3098,8 +3112,9 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
           Image bounding box.
         */
         page=GetImageBoundingBox(image,&image->exception);
-        q+=FormatMagickString(q,MaxTextExtent,"%lux%lu%+ld%+ld",page.width,
-          page.height,page.x,page.y);
+        q+=FormatMagickString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
+          (double) page.width,(double) page.height,(double) page.x,(double)
+          page.y);
         break;
       }
       case '#':
@@ -3245,6 +3260,9 @@ MagickExport void ResetImagePropertyIterator(const Image *image)
 MagickExport MagickBooleanType SetImageProperty(Image *image,
   const char *property,const char *value)
 {
+  ExceptionInfo
+    *exception;
+
   MagickBooleanType
     status;
 
@@ -3262,11 +3280,17 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
   if ((value == (const char *) NULL) || (*value == '\0'))
     return(DeleteImageProperty(image,property));
   status=MagickTrue;
+  exception=(&image->exception);
   switch (*property)
   {
     case 'B':
     case 'b':
     {
+      if (LocaleCompare(property,"background") == 0)
+        {
+          (void) QueryColorDatabase(value,&image->background_color,exception);
+          break;
+        }
       if (LocaleCompare(property,"bias") == 0)
         {
           image->bias=SiPrefixToDouble(value,QuantumRange);
@@ -3336,7 +3360,8 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
             if ((flags & LessValue) != 0)
               {
                 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
-                  image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
+                  image->ticks_per_second=(ssize_t)
+                    floor(geometry_info.sigma+0.5);
               }
             else
               image->delay=(size_t) floor(geometry_info.rho+0.5);
@@ -3344,6 +3369,17 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
             image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
           break;
         }
+      if (LocaleCompare(property,"density") == 0)
+        {
+          GeometryInfo
+            geometry_info;
+
+          flags=ParseGeometry(value,&geometry_info);
+          image->x_resolution=geometry_info.rho;
+          image->y_resolution=geometry_info.sigma;
+          if ((flags & SigmaValue) == 0)
+            image->y_resolution=image->x_resolution;
+        }
       if (LocaleCompare(property,"depth") == 0)
         {
           image->depth=StringToUnsignedLong(value);
@@ -3448,8 +3484,8 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
 
           image_info=AcquireImageInfo();
           (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
-          (void) SetImageInfo(image_info,1,&image->exception);
-          profile=FileToStringInfo(image_info->filename,~0UL,&image->exception);
+          (void) SetImageInfo(image_info,1,exception);
+          profile=FileToStringInfo(image_info->filename,~0UL,exception);
           if (profile != (StringInfo *) NULL)
             status=SetImageProfile(image,image_info->magick,profile);
           image_info=DestroyImageInfo(image_info);
@@ -3495,6 +3531,24 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
         ConstantString(property),ConstantString(value));
       break;
     }
+    case 'U':
+    case 'u':
+    {
+      if (LocaleCompare(property,"units") == 0)
+        {
+          ssize_t
+            units;
+
+          units=ParseMagickOption(MagickResolutionOptions,MagickFalse,value);
+          if (units < 0)
+            break;
+          image->units=(ResolutionType) units;
+          break;
+        }
+      status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
+        ConstantString(property),ConstantString(value));
+      break;
+    }
     default:
     {
       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,