gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 2ebcf3f: ConvertType: non-color output formats


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2ebcf3f: ConvertType: non-color output formats don't scale to uint8
Date: Thu, 2 May 2019 13:16:07 -0400 (EDT)

branch: master
commit 2ebcf3f788b1cc2c3fec491c4b006726a2da1068
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    ConvertType: non-color output formats don't scale to uint8
    
    Just before release 0.8, we added colormaps to ConverType. They are very
    useful when dealing with output formats that accept color. However, when
    they don't (for example converting a plain text array to FITS), ConvertType
    still scales the range to unsigned 8-bit integer.
    
    With this commit, this scaling is now taken only in the parts of formats
    that accept color. When they don't, the dataset is written to the output as
    it is.
    
    Also, while doing this, a problem with reading plain text files as an array
    was also fixed: instead of requiring a format for every "column", when the
    array is an image, a single format is used all the time.
    
    This fixes bug #56256 and bug #56257.
---
 NEWS                    |  2 ++
 bin/convertt/color.c    | 22 ++++++++++++++++++++--
 bin/convertt/color.h    |  3 +++
 bin/convertt/convertt.c | 19 +++----------------
 bin/convertt/convertt.h |  3 +++
 bin/convertt/ui.c       |  6 ++++--
 lib/txt.c               | 12 +++++++-----
 7 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/NEWS b/NEWS
index 2d70f51..b726fe3 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ See the end of the file for license conditions.
 ** Bugs fixed
   bug #56195: astscript-sort-by-night crashing because of AWK.
   bug #56246: Single-valued measurement must abort with no value in Statistics.
+  bug #56256: Segmentation fault when reading plain text array/image.
+  bug #56257: ConvertType: Values not preserved when converting text to FITS.
 
 
 
diff --git a/bin/convertt/color.c b/bin/convertt/color.c
index 72806ee..7346e1d 100644
--- a/bin/convertt/color.c
+++ b/bin/convertt/color.c
@@ -31,8 +31,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/statistics.h>
 
 #include "main.h"
-
-
+#include "convertt.h"
 
 
 
@@ -435,6 +434,25 @@ color_from_mono_sls(struct converttparams *p)
 
 
 
+void
+color_map_prepare(struct converttparams *p)
+{
+  switch(p->colormap->status)
+    {
+    case COLOR_HSV:  color_from_mono_hsv(p);     break;
+    case COLOR_SLS:  color_from_mono_sls(p);     break;
+    case COLOR_GRAY: convertt_scale_to_uchar(p); break;
+    default:
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
+            "the problem. The value %d is not a recognized color-space "
+            "code", __func__, PACKAGE_BUGREPORT, p->colormap->status);
+    }
+}
+
+
+
+
+
 
 
 
diff --git a/bin/convertt/color.h b/bin/convertt/color.h
index 1e329c5..a856ca9 100644
--- a/bin/convertt/color.h
+++ b/bin/convertt/color.h
@@ -24,6 +24,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define COLOR_H
 
 void
+color_map_prepare(struct converttparams *p);
+
+void
 color_from_mono_hsv(struct converttparams *p);
 
 void
diff --git a/bin/convertt/convertt.c b/bin/convertt/convertt.c
index b02971f..513f593 100644
--- a/bin/convertt/convertt.c
+++ b/bin/convertt/convertt.c
@@ -323,19 +323,6 @@ convertt(struct converttparams *p)
       convertt_truncate(p);
     }
 
-  /* Convert a mono/single color channel to a color format. */
-  if(p->colormap)
-    switch(p->colormap->status)
-      {
-      case COLOR_HSV:  color_from_mono_hsv(p);     break;
-      case COLOR_SLS:  color_from_mono_sls(p);     break;
-      case COLOR_GRAY: convertt_scale_to_uchar(p); break;
-      default:
-        error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
-              "the problem. The value %d is not a recognized color-space "
-              "code", __func__, PACKAGE_BUGREPORT, p->colormap->status);
-      }
-
   /* Save the outputs: */
   switch(p->outformat)
     {
@@ -355,20 +342,20 @@ convertt(struct converttparams *p)
 
     /* JPEG: */
     case OUT_FORMAT_JPEG:
-      if(!p->colormap) convertt_scale_to_uchar(p);
+      if(p->colormap) color_map_prepare(p); else convertt_scale_to_uchar(p);
       gal_jpeg_write(p->chll, p->cp.output, p->quality, p->widthincm);
       break;
 
     /* EPS. */
     case OUT_FORMAT_EPS:
-      if(!p->colormap) convertt_scale_to_uchar(p);
+      if(p->colormap) color_map_prepare(p); else convertt_scale_to_uchar(p);
       gal_eps_write(p->chll, p->cp.output, p->widthincm, p->borderwidth,
                     p->hex, p->forcemin || p->forcemax, 0);
       break;
 
     /* PDF */
     case OUT_FORMAT_PDF:
-      if(!p->colormap) convertt_scale_to_uchar(p);
+      if(p->colormap) color_map_prepare(p); else convertt_scale_to_uchar(p);
       gal_pdf_write(p->chll, p->cp.output, p->widthincm, p->borderwidth,
                     p->forcemin || p->forcemax);
       break;
diff --git a/bin/convertt/convertt.h b/bin/convertt/convertt.h
index 35f1ac8..d693421 100644
--- a/bin/convertt/convertt.h
+++ b/bin/convertt/convertt.h
@@ -24,6 +24,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define CONVERTT_H
 
 void
+convertt_scale_to_uchar(struct converttparams *p);
+
+void
 convertt(struct converttparams *p);
 
 #endif
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 284801c..a3c3330 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -809,7 +809,8 @@ ui_set_output(struct converttparams *p)
     {
       if(p->borderwidth==0 && p->widthincm==0)
         error(EXIT_FAILURE, 0, "at least one of `--widthincm' (`-u'), or "
-              "`--borderwidth (`-b') options are necessary for an EPS output");
+              "`--borderwidth (`-b') options are necessary for an EPS "
+              "output");
       p->outformat=OUT_FORMAT_EPS;
       if( gal_eps_suffix_is_eps(cp->output) )
         ui_add_dot_use_automatic_output(p);
@@ -820,7 +821,8 @@ ui_set_output(struct converttparams *p)
     {
       if(p->borderwidth==0 && p->widthincm==0)
         error(EXIT_FAILURE, 0, "at least one of `--widthincm' (`-u'), or "
-              "`--borderwidth (`-b') options are necessary for a PDF output");
+              "`--borderwidth (`-b') options are necessary for a PDF "
+                 "output");
       p->outformat=OUT_FORMAT_PDF;
       if( gal_pdf_suffix_is_pdf(cp->output) )
         ui_add_dot_use_automatic_output(p);
diff --git a/lib/txt.c b/lib/txt.c
index 4404e2f..3ed8643 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -808,7 +808,7 @@ txt_read_token(gal_data_t *data, gal_data_t *info, char 
*token,
 static void
 txt_fill(char *in_line, char **tokens, size_t maxcolnum, gal_data_t *info,
          gal_data_t *out, size_t rowind, char *filename, size_t lineno,
-         int inplace)
+         int inplace, int format)
 {
   size_t i, n=0;
   gal_data_t *data;
@@ -838,8 +838,10 @@ txt_fill(char *in_line, char **tokens, size_t maxcolnum, 
gal_data_t *info,
       if(n>maxcolnum) break;
 
       /* Set the pointer to the start of this token/column. See
-         explanations in `txt_info_from_first_row'. */
-      if( info[n-1].type == GAL_TYPE_STRING )
+         explanations in `txt_info_from_first_row'. Note that an image has
+         a single `info' element for the whole array, while a table has one
+         for each column. */
+      if( info[format==TXT_FORMAT_TABLE ? n-1 : 0].type == GAL_TYPE_STRING )
         {
           /* Remove any delimiters and stop at the first non-delimiter. If
              we have reached the end of the line then its an error, because
@@ -1016,7 +1018,7 @@ txt_read(char *filename, gal_list_str_t *lines, size_t 
*dsize,
           ++lineno;
           if( gal_txt_line_stat(line) == GAL_TXT_LINESTAT_DATAROW )
             txt_fill(line, tokens, maxcolnum, info, out, rowind++,
-                     filename, lineno, 1);
+                     filename, lineno, 1, format);
         }
 
       /* Clean up and close the file. */
@@ -1032,7 +1034,7 @@ txt_read(char *filename, gal_list_str_t *lines, size_t 
*dsize,
         ++lineno;
         if( gal_txt_line_stat(tmp->v) == GAL_TXT_LINESTAT_DATAROW )
           txt_fill(tmp->v, tokens, maxcolnum, info, out, rowind++,
-                   filename, lineno, 0);
+                   filename, lineno, 0, format);
       }
 
   /* Clean up and return. */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]