gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b3c4c2e: gal_eps_write: new dontoptimize argum


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b3c4c2e: gal_eps_write: new dontoptimize argument to disable bit-optimization
Date: Sat, 23 Mar 2019 22:46:07 -0400 (EDT)

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

    gal_eps_write: new dontoptimize argument to disable bit-optimization
    
    Until now, bit-optimization (specific to EPS and PDF) was done on any
    dataset with two values. However, in some situations (for example when the
    user gives `--forcemin' or `--forcemax' to ConvertType), the user doesn't
    want the contrast to be the full contrast between black and white.
    
    With this commit, `gal_eps_write' has the new `dontoptimize' option to let
    the caller determine if bit-optimization should be applied or not.
---
 NEWS                    |  2 ++
 bin/convertt/convertt.c |  7 +++----
 doc/gnuastro.texi       | 38 ++++++++++++++++++++++++++++++++++++--
 lib/eps.c               |  8 ++++----
 lib/gnuastro/eps.h      |  2 +-
 lib/gnuastro/pdf.h      |  2 +-
 lib/pdf.c               |  4 ++--
 7 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/NEWS b/NEWS
index f9cb668..b74135a 100644
--- a/NEWS
+++ b/NEWS
@@ -156,6 +156,8 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
   Library
    gal_arithmetic: new argument: number of threads to use (when relevant).
+   gal_eps_write: new argument: optional bit-optimization with `dontoptimize'.
+   gal_pdf_write: new argument: optional bit-optimization with `dontoptimize'.
 
 ** Bugs fixed
   bug #55313: Fits program writing --write values in reverse order
diff --git a/bin/convertt/convertt.c b/bin/convertt/convertt.c
index 128dde6..b02971f 100644
--- a/bin/convertt/convertt.c
+++ b/bin/convertt/convertt.c
@@ -240,7 +240,6 @@ convertt_scale_to_uchar(struct converttparams *p)
   m=(float)maxbyte/(max-min);
 
 
-
   /* Convert all the non-blank channels to unsigned char. */
   prev=NULL;
   for(channel=p->chll; channel!=NULL; channel=channel->next)
@@ -282,7 +281,6 @@ convertt_scale_to_uchar(struct converttparams *p)
 
       /* Set the prev pointer. */
       prev=channel;
-
     }
 }
 
@@ -365,13 +363,14 @@ convertt(struct converttparams *p)
     case OUT_FORMAT_EPS:
       if(!p->colormap) convertt_scale_to_uchar(p);
       gal_eps_write(p->chll, p->cp.output, p->widthincm, p->borderwidth,
-                    p->hex, 0);
+                    p->hex, p->forcemin || p->forcemax, 0);
       break;
 
     /* PDF */
     case OUT_FORMAT_PDF:
       if(!p->colormap) convertt_scale_to_uchar(p);
-      gal_pdf_write(p->chll, p->cp.output, p->widthincm, p->borderwidth);
+      gal_pdf_write(p->chll, p->cp.output, p->widthincm, p->borderwidth,
+                    p->forcemin || p->forcemax);
       break;
 
     /* Not recognized. */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 79664bc..a01efc9 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -11109,6 +11109,18 @@ want them all to have the same range of colors, 
independent of the contents
 of the dataset. Note that if the minimum value is smaller than
 @option{--fluxlow}, then this option is redundant.
 
address@hidden PDF
address@hidden EPS
address@hidden PostScript
+By default, when the dataset only has two values, @emph{and} the output
+format is PDF or EPS, ConvertType will use the PostScript optimization that
+allows setting the pixel values per bit, not byte (@ref{Recognized file
+formats}). This can greatly help reduce the file size. However, when
address@hidden or @option{--fluxhigh} are called, this optimization is
+disabeled: even though there are only two values (is binary), the
+difference between them does not correspond to the full contrast of black
+and white.
+
 @item -B INT
 @itemx --forcemax=INT
 Similar to @option{--forcemin}, but for the maximum.
@@ -26758,7 +26770,7 @@ function). The first element in @code{w_h_in_pt} is the 
width and the
 second is the height of the image.
 @end deftypefun
 
address@hidden {void} gal_eps_write (gal_data_t @code{*in}, char 
@code{*filename}, float @code{widthincm}, uint32_t @code{borderwidth}, int 
@code{hex}, int @code{forpdf})
address@hidden {void} gal_eps_write (gal_data_t @code{*in}, char 
@code{*filename}, float @code{widthincm}, uint32_t @code{borderwidth}, int 
@code{hex}, int @code{dontoptimize}, int @code{forpdf})
 Write the @code{in} dataset into an EPS file called
 @code{filename}. @code{in} has to be an unsigned 8-bit character type
 (@code{GAL_TYPE_UINT8}, see @ref{Numeric data types}). The desired width of
@@ -26777,6 +26789,17 @@ encoding. To use Hexadecimal encoding, set @code{hex} 
to a non-zero
 value. Currently If you don't directly want to import the EPS file into a
 PostScript document but want to later compile it into a PDF file, set the
 @code{forpdf} argument to @code{1}.
+
address@hidden PDF
address@hidden EPS
address@hidden PostScript
+By default, when the dataset only has two values, this function will use
+the PostScript optimization that allows setting the pixel values per bit,
+not byte (@ref{Recognized file formats}). This can greatly help reduce the
+file size. However, when @option{dontoptimize!=0}, this optimization is
+disabeled: even though there are only two values (is binary), the
+difference between them does not correspond to the full contrast of black
+and white.
 @end deftypefun
 
 
@@ -26805,7 +26828,7 @@ Return @code{1} if @code{suffix} is a recognized PDF 
suffix. The recognized
 suffixes are @code{.pdf} and @code{.PDF}.
 @end deftypefun
 
address@hidden {void} gal_pdf_write (gal_data_t @code{*in}, char 
@code{*filename}, float @code{widthincm}, uint32_t @code{borderwidth})
address@hidden {void} gal_pdf_write (gal_data_t @code{*in}, char 
@code{*filename}, float @code{widthincm}, uint32_t @code{borderwidth}, int 
@code{dontoptimize})
 Write the @code{in} dataset into an EPS file called
 @code{filename}. @code{in} has to be an unsigned 8-bit character type
 (@code{GAL_TYPE_UINT8}, see @ref{Numeric data types}). The desired width of
@@ -26821,6 +26844,17 @@ EPS file to a PDF file. Therefore if GhostScript 
doesn't exist, doesn't have
 the proper version, or fails for any other reason, the EPS file will
 remain. It can be used to find the cause, or use another converter or
 PostScript compiler.
+
address@hidden PDF
address@hidden EPS
address@hidden PostScript
+By default, when the dataset only has two values, this function will use
+the PostScript optimization that allows setting the pixel values per bit,
+not byte (@ref{Recognized file formats}). This can greatly help reduce the
+file size. However, when @option{dontoptimize!=0}, this optimization is
+disabeled: even though there are only two values (is binary), the
+difference between them does not correspond to the full contrast of black
+and white.
 @end deftypefun
 
 
diff --git a/lib/eps.c b/lib/eps.c
index b787d5e..997fc09 100644
--- a/lib/eps.c
+++ b/lib/eps.c
@@ -290,7 +290,7 @@ eps_write_ascii85(gal_data_t *write, FILE *fp, size_t 
numbytes)
 
 
 static void
-eps_write_image(gal_data_t *in, FILE *fp, int hex)
+eps_write_image(gal_data_t *in, FILE *fp, int hex, int dontoptimize)
 {
   int bpc=8;
   uint8_t bitone;
@@ -299,7 +299,7 @@ eps_write_image(gal_data_t *in, FILE *fp, int hex)
   size_t numch=gal_list_data_number(in);
 
   /* Set the number of bits per component. */
-  if( numch==1 && eps_is_binary(in, &bitone) )
+  if( numch==1 && dontoptimize==0 && eps_is_binary(in, &bitone) )
     {
       bpc=1;
       write=eps_convert_to_bitstream(in, &numbytes, bitone);
@@ -366,7 +366,7 @@ gal_eps_to_pt(float widthincm, size_t *dsize, size_t 
*w_h_in_pt)
 
 void
 gal_eps_write(gal_data_t *in, char *filename, float widthincm,
-              uint32_t borderwidth, int hex, int forpdf)
+              uint32_t borderwidth, int hex, int dontoptimize, int forpdf)
 {
   FILE *fp;
   float hbw;
@@ -427,7 +427,7 @@ gal_eps_write(gal_data_t *in, char *filename, float 
widthincm,
   fprintf(fp, "%% Draw the image:\n");
   fprintf(fp, "%d %d translate\n", borderwidth, borderwidth);
   fprintf(fp, "%zu %zu scale\n", w_h_in_pt[0], w_h_in_pt[1]);
-  eps_write_image(in, fp, hex);
+  eps_write_image(in, fp, hex, dontoptimize);
 
 
   /* Ending of the EPS file: */
diff --git a/lib/gnuastro/eps.h b/lib/gnuastro/eps.h
index f2a6d3f..4026bde 100644
--- a/lib/gnuastro/eps.h
+++ b/lib/gnuastro/eps.h
@@ -65,7 +65,7 @@ gal_eps_to_pt(float widthincm, size_t *dsize, size_t 
*w_h_in_pt);
 
 void
 gal_eps_write(gal_data_t *in, char *filename, float widthincm,
-              uint32_t borderwidth, int hex, int forpdf);
+              uint32_t borderwidth, int hex, int dontoptimize, int forpdf);
 
 
 
diff --git a/lib/gnuastro/pdf.h b/lib/gnuastro/pdf.h
index 1987127..5ca76c4 100644
--- a/lib/gnuastro/pdf.h
+++ b/lib/gnuastro/pdf.h
@@ -62,7 +62,7 @@ gal_pdf_suffix_is_pdf(char *name);
 
 void
 gal_pdf_write(gal_data_t *in, char *filename, float widthincm,
-              uint32_t borderwidth);
+              uint32_t borderwidth, int dontoptimize);
 
 
 
diff --git a/lib/pdf.c b/lib/pdf.c
index b090267..29628c8 100644
--- a/lib/pdf.c
+++ b/lib/pdf.c
@@ -90,14 +90,14 @@ gal_pdf_suffix_is_pdf(char *name)
  *************************************************************/
 void
 gal_pdf_write(gal_data_t *in, char *filename, float widthincm,
-              uint32_t borderwidth)
+              uint32_t borderwidth, int dontoptimize)
 {
   char command[20000];
   size_t w_h_in_pt[2];
   char *epsname=gal_checkset_malloc_cat(filename, ".ps");
 
   /* Write the EPS file. */
-  gal_eps_write(in, epsname, widthincm, borderwidth, 0, 1);
+  gal_eps_write(in, epsname, widthincm, borderwidth, 0, dontoptimize, 1);
 
   /* Get the size of the image in `pt' units. */
   gal_eps_to_pt(widthincm, in->dsize, w_h_in_pt);



reply via email to

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