Hi,

I noticed the other day that running `identify -verbose image.jpg`
produced wrong units for some fields:
"   [...]
      Filesize: 11.01MB
      Number pixels: 8.551MB
      Pixels per second: 12.76MB
    [...]
"
Pixel counts should not be expressed in bytes. This behavior was
observed on ImageMagick 6.5.8 and SVN trunk. The patch below fixes it
for me (applies to SVN trunk). With the patch applied, the output is
now:
"   [...]
      Filesize: 11.01MB
      Number pixels: 8.551M
      Pixels per second: 12.04M
    [...]
"

---
diff --git a/magick/identify.c b/magick/identify.c
index 950008f..4844b62 100644
--- a/magick/identify.c
+++ b/magick/identify.c
@@ -1029,10 +1029,10 @@ MagickExport MagickBooleanType IdentifyImage(Image 
*image,FILE *file,
     MagickBooleanOptions,(long) image->taint));
   (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
   (void) fprintf(file,"  Filesize: %s\n",format);
-  (void) FormatMagickSize((MagickSizeType) image->columns*image->rows,
+  (void) FormatMagickNumber((MagickSizeType) image->columns*image->rows,
      MagickFalse,format);
   (void) fprintf(file,"  Number pixels: %s\n",format);
-  (void) FormatMagickSize((MagickSizeType) ((double) 
image->columns*image->rows/
+  (void) FormatMagickNumber((MagickSizeType) ((double) 
image->columns*image->rows/
     elapsed_time+0.5),MagickFalse,format);
   (void) fprintf(file,"  Pixels per second: %s\n",format);
   (void) fprintf(file,"  User time: %0.3fu\n",user_time);
diff --git a/magick/string.c b/magick/string.c
index 09a5486..b26b514 100644
--- a/magick/string.c
+++ b/magick/string.c
@@ -978,19 +978,20 @@ MagickExport StringInfo *FileToStringInfo(const char 
*filename,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%  F o r m a t M a g i c k S i z e                                            %
+%  F o r m a t M a g i c k N u m b e r                                        %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  FormatMagickSize() converts a size to a human readable format, for example,
-%  14kb, 234mb, 2.7gb, or 3.0tb.  Scaling is done by repetitively dividing by
-%  1000.
+%  FormatMagickNumber() converts a number to a human readable format, for 
example,
+%  14K, 234M, 2.7G, or 3.0T.  Scaling is done by repetitively dividing by
+%  1000 (or 1024).
 %
-%  The format of the FormatMagickSize method is:
+%  The format of the FormatMagickNumber method is:
 %
-%      long FormatMagickSize(const MagickSizeType size,char *format)
+%      long FormatMagickNumber(const MagickSizeType size,
+%                              const MagickBooleanType bi,char *format)
 %
 %  A description of each parameter follows:
 %
@@ -1001,7 +1002,7 @@ MagickExport StringInfo *FileToStringInfo(const char 
*filename,
 %    o format:  human readable format.
 %
 */
-MagickExport long FormatMagickSize(const MagickSizeType size,
+MagickExport long FormatMagickNumber(const MagickSizeType size,
   const MagickBooleanType bi,char *format)
 {
   const char
@@ -1021,11 +1022,11 @@ MagickExport long FormatMagickSize(const MagickSizeType 
size,
   static const char
     *bi_units[] =
     {
-      "b", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", (char *) 
NULL
+      "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi", (char *) NULL
     },
     *traditional_units[] =
     {
-      "b", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", (char *) NULL
+      "", "K", "M", "G", "T", "P", "E", "Z", "Y", (char *) NULL
     };
 
   bytes=1000.0;
@@ -1057,6 +1058,44 @@ MagickExport long FormatMagickSize(const MagickSizeType 
size,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%  F o r m a t M a g i c k S i z e                                            %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  FormatMagickSize() converts a size to a human readable format, for example,
+%  14KB, 234MB, 2.7GB, or 3.0TB.  Scaling is done by repetitively dividing by
+%  1000 (or 1024).
+%
+%  The format of the FormatMagickSize method is:
+%
+%      long FormatMagickSize(const MagickSizeType size,
+%                            const MagickBooleanType bi,char *format)
+%
+%  A description of each parameter follows:
+%
+%    o size:  convert this size to a human readable format.
+%
+%    o bi:  use power of two rather than power of ten.
+%
+%    o format:  human readable format.
+%
+*/
+MagickExport long FormatMagickSize(const MagickSizeType size,
+  const MagickBooleanType bi,char *format)
+{
+  char buffer[MaxTextExtent];
+  long count=FormatMagickNumber(size,bi,buffer);
+  FormatMagickString(format,MaxTextExtent,"%sB",buffer);
+  return(count);
+}
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %  F o r m a t M a g i c k S t r i n g                                        %
 %                                                                             %
 %                                                                             %
diff --git a/magick/string_.h b/magick/string_.h
index afad01c..7a2dfc7 100644
--- a/magick/string_.h
+++ b/magick/string_.h
@@ -65,6 +65,7 @@ extern MagickExport int
   LocaleNCompare(const char *,const char *,const size_t);
 
 extern MagickExport long
+  FormatMagickNumber(const MagickSizeType,const MagickBooleanType,char *),
   FormatMagickSize(const MagickSizeType,const MagickBooleanType,char *),
   FormatMagickString(char *,const size_t,const char *,...)
     magick_attribute((format (printf,3,4))),
-- 
1.7.0

_______________________________________________
Magick-developers mailing list
Magick-developers@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-developers
  • ... Benoît Knecht
    • ... da . mihi . sis . bubulae . frustrum . assae . solana . tuberosa . in . modo . gallico . fricta . ac . quassum . lactatum . coagulatum . crassum

Reply via email to