]> git.imager.perl.org - imager.git/commitdiff
- the i_xres and i_yres tags are now stored in a resolution similar
authorTony Cook <tony@develop=help.com>
Sat, 1 Jan 2005 13:58:33 +0000 (13:58 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 1 Jan 2005 13:58:33 +0000 (13:58 +0000)
  to their source.
  Resolves: https://rt.cpan.org/Ticket/Display.html?id=8520

Changes
bmp.c
image.h
png.c
tags.c
tiff.c

diff --git a/Changes b/Changes
index 65fa598dfb666b247d8fe9d171c058b2a26747d1..a9ab351df69c20e89e98cdfe2e4aa1f9464df954 100644 (file)
--- a/Changes
+++ b/Changes
@@ -982,6 +982,9 @@ Revision history for Perl extension Imager.
 - the tiff reader now puts warning messages produced during reading into
   the i_warning tag.
   Resolves: https://rt.cpan.org/Ticket/Display.html?id=8722
 - the tiff reader now puts warning messages produced during reading into
   the i_warning tag.
   Resolves: https://rt.cpan.org/Ticket/Display.html?id=8722
+- the i_xres and i_yres tags are now stored in a resolution similar
+  to their source.
+  Resolves: https://rt.cpan.org/Ticket/Display.html?id=8520
 
 =================================================================
 
 
 =================================================================
 
diff --git a/bmp.c b/bmp.c
index d155fd885450b23ad4cb7004f40c201ba6b41e34..35ec116a79dbfb673a816ba73a2a31ce2790332f 100644 (file)
--- a/bmp.c
+++ b/bmp.c
@@ -165,8 +165,8 @@ i_readbmp_wiol(io_glue *ig) {
     else if (yres && !xres)
       xres = yres;
     if (xres) {
     else if (yres && !xres)
       xres = yres;
     if (xres) {
-      i_tags_set_float(&im->tags, "i_xres", 0, xres * 0.0254);
-      i_tags_set_float(&im->tags, "i_yres", 0, yres * 0.0254);
+      i_tags_set_float2(&im->tags, "i_xres", 0, xres * 0.0254, 4);
+      i_tags_set_float2(&im->tags, "i_yres", 0, yres * 0.0254, 4);
     }
     i_tags_addn(&im->tags, "bmp_compression", 0, compression);
     i_tags_addn(&im->tags, "bmp_important_colors", 0, clr_important);
     }
     i_tags_addn(&im->tags, "bmp_compression", 0, compression);
     i_tags_addn(&im->tags, "bmp_important_colors", 0, clr_important);
diff --git a/image.h b/image.h
index 2f7046acb255896fa1bf1fb2f9543f49e0b57827..5278c09a0e94af1ae10477c83cfd9ff0cd3623f0 100644 (file)
--- a/image.h
+++ b/image.h
@@ -779,6 +779,8 @@ extern int i_tags_get_float(i_img_tags *tags, char const *name, int code,
                            double *value);
 extern int i_tags_set_float(i_img_tags *tags, char const *name, int code, 
                            double value);
                            double *value);
 extern int i_tags_set_float(i_img_tags *tags, char const *name, int code, 
                            double value);
+extern int i_tags_set_float2(i_img_tags *tags, char const *name, int code, 
+                           double value, int places);
 extern int i_tags_get_int(i_img_tags *tags, char const *name, int code, 
                           int *value);
 extern int i_tags_get_string(i_img_tags *tags, char const *name, int code, 
 extern int i_tags_get_int(i_img_tags *tags, char const *name, int code, 
                           int *value);
 extern int i_tags_get_string(i_img_tags *tags, char const *name, int code, 
diff --git a/png.c b/png.c
index 5693f4c92fcfcea90b04ca395f9d2e6584626f94..03900270895ebe293eaf348bcaa004ff39d4efc7 100644 (file)
--- a/png.c
+++ b/png.c
@@ -282,8 +282,8 @@ static void get_png_tags(i_img *im, png_structp png_ptr, png_infop info_ptr) {
   if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) {
     mm_log((1,"pHYs (%d, %d) %d\n", xres, yres, unit_type));
     if (unit_type == PNG_RESOLUTION_METER) {
   if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) {
     mm_log((1,"pHYs (%d, %d) %d\n", xres, yres, unit_type));
     if (unit_type == PNG_RESOLUTION_METER) {
-      i_tags_set_float(&im->tags, "i_xres", 0, xres * 0.0254);
-      i_tags_set_float(&im->tags, "i_yres", 0, yres * 0.0254);
+      i_tags_set_float2(&im->tags, "i_xres", 0, xres * 0.0254, 5);
+      i_tags_set_float2(&im->tags, "i_yres", 0, yres * 0.0254, 5);
     }
     else {
       i_tags_addn(&im->tags, "i_xres", 0, xres);
     }
     else {
       i_tags_addn(&im->tags, "i_xres", 0, xres);
diff --git a/tags.c b/tags.c
index 09880667eea1a90771a69f68057a12b2d362153c..3e5049730ce5a4a917dc613b704a96df99e2cad3 100644 (file)
--- a/tags.c
+++ b/tags.c
@@ -15,6 +15,10 @@ tags.c - functions for manipulating an images tags list
   i_tags_delete(&tags, index);
   count = i_tags_delbyname(tags, name);
   count = i_tags_delbycode(tags, code);
   i_tags_delete(&tags, index);
   count = i_tags_delbyname(tags, name);
   count = i_tags_delbycode(tags, code);
+  if (i_tags_get_float(&tags, name, code, &float_value)) { found }
+  i_tags_set_float(&tags, name, code, value);
+  i_tags_set_float2(&tags, name, code, value, sig_digits);
+  i_tags_get_int(&tags, name, code, &int_value);
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -258,9 +262,31 @@ int i_tags_get_float(i_img_tags *tags, char const *name, int code,
 
 int i_tags_set_float(i_img_tags *tags, char const *name, int code, 
                      double value) {
 
 int i_tags_set_float(i_img_tags *tags, char const *name, int code, 
                      double value) {
+  return i_tags_set_float2(tags, name, code, value, 30);
+}
+
+/*
+=item i_tags_set_float2(tags, name, code, value, places)
+
+Sets the tag with the given name and code to the given floating point
+value.
+
+Since tags are strings or ints, we convert the value to a string before
+storage at the precision specified by C<places>.
+
+=cut
+*/
+
+int i_tags_set_float2(i_img_tags *tags, char const *name, int code, 
+                      double value, int places) {
   char temp[40];
 
   char temp[40];
 
-  sprintf(temp, "%.30g", value);
+  if (places < 0) 
+    places = 30;
+  else if (places > 30) 
+    places = 30;
+
+  sprintf(temp, "%.*g", places, value);
   if (name)
     i_tags_delbyname(tags, name);
   else
   if (name)
     i_tags_delbyname(tags, name);
   else
diff --git a/tiff.c b/tiff.c
index 1ce8031eb2fbe708c02e485899669c417de3f9d7..e7f8249e9803ca3657d66fd135b48bb6b2579380 100644 (file)
--- a/tiff.c
+++ b/tiff.c
@@ -207,8 +207,11 @@ static i_img *read_one_tiff(TIFF *tif) {
     i_tags_addn(&im->tags, "tiff_resolutionunit", 0, resunit);
     if (resunit == RESUNIT_NONE)
       i_tags_addn(&im->tags, "i_aspect_only", 0, 1);
     i_tags_addn(&im->tags, "tiff_resolutionunit", 0, resunit);
     if (resunit == RESUNIT_NONE)
       i_tags_addn(&im->tags, "i_aspect_only", 0, 1);
-    i_tags_set_float(&im->tags, "i_xres", 0, xres);
-    i_tags_set_float(&im->tags, "i_yres", 0, yres);
+    /* tifflib doesn't seem to provide a way to get to the original rational
+       value of these, which would let me provide a more reasonable
+       precision. So make up a number. */
+    i_tags_set_float2(&im->tags, "i_xres", 0, xres, 6);
+    i_tags_set_float2(&im->tags, "i_yres", 0, yres, 6);
   }
 
   /* Text tags */
   }
 
   /* Text tags */