From dbe0da6a11adea6f1c1bdbf5dc14bf7bed7d5608 Mon Sep 17 00:00:00 2001 From: sfeam Date: Mon, 11 Sep 2017 20:13:24 +0000 Subject: [PATCH] new command "set rgbmax " --- ChangeLog | 15 +++++++++++++++ demo/image2.dem | 10 +++++----- docs/gnuplot.doc | 23 +++++++++++++++++++++-- src/graphics.c | 19 ++++++++++++++++++- src/graphics.h | 10 ++++------ src/save.c | 4 +++- src/set.c | 18 +++++++++++++++++- src/show.c | 15 ++++++++++++++- src/tables.c | 3 ++- src/tables.h | 4 ++-- src/unset.c | 6 +++++- 11 files changed, 106 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd4aa09fa..23999c4b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2017-09-11 Ethan A Merritt + + * src/graphics.c src/graphics.h src/set.c src/tables.c src/tables.h + src/unset.c src/show.c src/save.c demo/image2.dem docs/gnuplot.doc: + The default interpretation of RGB color components on input is that + they are integer values in the range [0:255]. This matches the + content of PNG and JPEG files. Since the interpretation of RGB color + components has been decoupled from the palette range limits controlled + by "set cbrange", data using some other RGB convention must be + rescaled. This patch introduces a new command `set rgbmax`. + The primary use is so that data using the convention that color + components are floating point values in the range [0:1] can be + plotted using + set rgbmax 1.0; plot 'imagedata' with rgbimage + 2017-09-10 Ethan A Merritt * src/axis.c( gen_tics ) src/axis.h( reorder_if_necessary ): diff --git a/demo/image2.dem b/demo/image2.dem index f6c9b15a4..c5384a0ae 100644 --- a/demo/image2.dem +++ b/demo/image2.dem @@ -127,7 +127,7 @@ print "" set title "Close up of pixels having grid points (0,0), (0,2), (2,0) and (2,2)" set xrange [-1.5:3.5] set yrange [-1.5:3.5] -set cbrange [0:1] +set rgbmax 1 unset key plot '-' with rgbimage, '-' with points pt 7 ps 2 lt -1 0 0 0.0 0.0 0.5 @@ -450,14 +450,14 @@ print "that when \'binary\' is specified, Gnuplot will continue" print "reading until reaching the number of elements specified via" print "the \'array\' or \'record\' command." print "" -print "Here is an example of binary data at the command line where" -print "keyboard input has been side stepped by copying 48 bytes from" -print "a pre-existing binary file into this demo file." +print "Here is an example of binary data in the range [0:1] inserted" +print "into the command stream by copying 48 bytes from a pre-existing" +print "binary file into this demo file." print "" set title "Binary data specified at the command line, intended for use through pipe" set xrange [-1.5:3.5] set yrange [-1.5:3.5] -set cbrange [0:1] +set rgbmax 1 plot '-' binary endian=little array=(2,2) dx=2 format="%float" using 1:2:3 with rgbimage,\ '-' binary endian=little record=4 format="%char" using 1:2 with points pt 7 ps 2 lt -1 ???? diff --git a/docs/gnuplot.doc b/docs/gnuplot.doc index ca1ccbcb3..f5291f1e1 100644 --- a/docs/gnuplot.doc +++ b/docs/gnuplot.doc @@ -1,4 +1,4 @@ -C RCS $Id: gnuplot.doc,v 1.1107 2017-09-05 20:18:58 sfeam Exp $ +C RCS $Id: gnuplot.doc,v 1.1108 2017-09-11 20:13:24 sfeam Exp $ C C Copyright (C) 1986 - 1993, 1998, 1999, 2000, 2001, 2004 Thomas Williams, Colin Kelley et al. C @@ -4075,12 +4075,17 @@ Ffigure_scaled_image values for the red, green, and blue components. Thus 5D data (x,y,r,g,b) is needed for `plot` and 6D data (x,y,z,r,g,b) for `splot`. The individual red, green, and blue components are assumed to lie in the range [0:255]. + This matches the convention used in PNG and JPEG files (see `binary filetype`). + However some data files use an alternative convention in which RGB components + are floating point values in the range [0:1]. To use the `rgbimage` style with + such data, first use the command `set rgbmax 1.0`. The `rgbalpha` style handles input pixels that contain alpha channel (transparency) information in addition to the red, green, and blue components. Thus 6D data (x,y,r,g,b,a) is needed for `plot` and 7D data (x,y,z,r,g,b,a) for `splot`. The r, g, b, and alpha components are assumed to lie in the range - [0:255]. + [0:255]. To plot data for which RGBA components are floating point values in + the range [0:1], first use the command `set rgbmax 1.0`. 3 transparency ?image transparency ?transparency @@ -12228,6 +12233,20 @@ Ffigure_multiple_keys at the center of the polar plot to indicate that the plot lines and axes do not reach 0. The axis line is drawn using the same line type as the plot border. See `polar`, `rrange`, `rtics`, `rlabel`, `set grid`. +3 rgbmax +?commands set rgbmax +?set rgbmax +?rgbmax +?unset rgbmax +=rgbimage + Syntax: + set rgbmax {1.0 | 255} + unset rgbmax + The red/green/blue color components of an rgbimage plot are by default + interpreted as integers in the range [0:255]. `set rgbmax 1.0` tells the + program that data values used to generate the color components of a plot + with `rgbimage` or `rgbalpha` are floating point values in the range [0:1]. + `unset rgbmax` returns to the default integer range [0:255]. 3 rlabel ?commands set rlabel ?rlabel diff --git a/src/graphics.c b/src/graphics.c index e8ec0ef67..07bbef724 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: graphics.c,v 1.570 2017-09-10 21:41:52 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: graphics.c,v 1.571 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - graphics.c */ @@ -72,6 +72,9 @@ double bar_size = 1.0; int bar_layer = LAYER_FRONT; struct lp_style_type bar_lp; +/* 'set rgbmax {0|255}' */ +double rgbmax = 255; + /* key placement is calculated in boundary, so we need file-wide variables * To simplify adjustments to the key, we set all these once [depends on * key->reverse] and use them throughout. @@ -134,6 +137,8 @@ static void plot_ellipses __PROTO((struct curve_points *plot)); static void do_rectangle __PROTO((int dimensions, t_object *this_object, fill_style_type *fillstyle)); #endif +static double rgbscale __PROTO((double rawvalue)); + static void draw_polar_circle __PROTO((double place)); static void plot_parallel __PROTO((struct curve_points *plot)); @@ -4459,6 +4464,18 @@ check_for_variable_color(struct curve_points *plot, double *colorvalue) return FALSE; } +/* rgbscale + * RGB image color components are normally in the range [0:255] but some + * data conventions may use [0:1] instead. This does the conversion. + */ +static double +rgbscale( double component ) +{ + if (rgbmax != 255.) + component = 255. * component/rgbmax; + return component > 255 ? 255 : component < 0 ? 0 : component; +} + /* process_image: * * IMG_PLOT - Plot the coordinates similar to the points option except diff --git a/src/graphics.h b/src/graphics.h index 97dc1d373..2033b5565 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -1,5 +1,5 @@ /* - * $Id: graphics.h,v 1.72 2017-08-23 00:54:52 sfeam Exp $ + * $Id: graphics.h,v 1.73 2017-09-11 20:13:24 sfeam Exp $ */ /* GNUPLOT - graphics.h */ @@ -96,6 +96,9 @@ extern double bar_size; extern int bar_layer; extern struct lp_style_type bar_lp; +/* 'set rgbmax {0|255}' */ +extern double rgbmax; + /* function prototypes */ void do_plot __PROTO((struct curve_points *, int)); @@ -112,11 +115,6 @@ typedef enum en_procimg_action { IMG_UPDATE_CORNERS } t_procimg_action; -/* Place-holder for a routine that scales RGB color components to fit [0:255] - * For now we just enforce the range limits with no scaling - */ -#define rgbscale(c) (c>255. ? 255. : c<0 ? 0. : c) - void process_image __PROTO((void *plot, t_procimg_action action)); TBOOLEAN check_for_variable_color __PROTO((struct curve_points *plot, double *colorvalue)); diff --git a/src/save.c b/src/save.c index e1e08fed0..90e1dd158 100644 --- a/src/save.c +++ b/src/save.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: save.c,v 1.330 2017-08-01 00:56:21 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: save.c,v 1.331 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - save.c */ @@ -633,6 +633,8 @@ set encoding %s\n\ fprintf(fp, "\nset view %s", aspect_ratio_3D == 2 ? "equal xy" : aspect_ratio_3D == 3 ? "equal xyz": ""); + fprintf(fp, "\nset rgbmax %g", rgbmax); + fprintf(fp, "\n\ set samples %d, %d\n\ set isosamples %d, %d\n\ diff --git a/src/set.c b/src/set.c index 3078a6f95..9d2afa1a3 100644 --- a/src/set.c +++ b/src/set.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: set.c,v 1.568 2017-09-04 18:02:21 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: set.c,v 1.569 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - set.c */ @@ -132,6 +132,7 @@ static void set_object __PROTO((void)); static void set_obj __PROTO((int, int)); #endif static void set_psdir __PROTO((void)); +static void set_rgbmax __PROTO((void)); static void set_samples __PROTO((void)); static void set_size __PROTO((void)); static void set_style __PROTO((void)); @@ -456,6 +457,9 @@ set_command() case S_SAMPLES: set_samples(); break; + case S_RGBMAX: + set_rgbmax(); + break; case S_SIZE: set_size(); break; @@ -4522,6 +4526,18 @@ set_obj(int tag, int obj_type) } #endif +static void +set_rgbmax() +{ + c_token++; + if (END_OF_COMMAND) + rgbmax = 255; + else + rgbmax = real_expression(); + if (rgbmax <= 0) + rgbmax = 255; +} + /* process 'set samples' command */ static void set_samples() diff --git a/src/show.c b/src/show.c index 0f44340ce..b54cdc7b9 100644 --- a/src/show.c +++ b/src/show.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: show.c,v 1.391 2017-09-04 18:02:21 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: show.c,v 1.392 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - show.c */ @@ -124,6 +124,7 @@ static void show_palette_colornames __PROTO((void)); static void show_colorbox __PROTO((void)); static void show_pointsize __PROTO((void)); static void show_pointintervalbox __PROTO((void)); +static void show_rgbmax __PROTO((void)); static void show_encoding __PROTO((void)); static void show_decimalsign __PROTO((void)); static void show_fit __PROTO((void)); @@ -387,6 +388,9 @@ show_command() case S_POINTSIZE: show_pointsize(); break; + case S_RGBMAX: + show_rgbmax(); + break; case S_DECIMALSIGN: show_decimalsign(); break; @@ -805,6 +809,7 @@ show_all() show_pm3d(); show_pointsize(); show_pointintervalbox(); + show_rgbmax(); show_encoding(); show_decimalsign(); show_fit(); @@ -2538,6 +2543,14 @@ show_pointintervalbox() fprintf(stderr, "\tpointintervalbox is %g\n", pointintervalbox); } +/* process 'show rgbmax' command */ +static void +show_rgbmax() +{ + SHOW_ALL_NL; + fprintf(stderr, "\tRGB image color components are in range [0:%g]\n", rgbmax); +} + /* process 'show encoding' command */ static void diff --git a/src/tables.c b/src/tables.c index d43a075a8..a8997e8ff 100644 --- a/src/tables.c +++ b/src/tables.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: tables.c,v 1.156 2017-09-04 18:02:21 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: tables.c,v 1.157 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - tables.c */ @@ -260,6 +260,7 @@ const struct gen_table set_tbl[] = { "pr$int", S_PRINT }, { "psdir", S_PSDIR }, { "obj$ect", S_OBJECT }, + { "rgbmax", S_RGBMAX }, { "sa$mples", S_SAMPLES }, { "si$ze", S_SIZE }, { "st$yle", S_STYLE }, diff --git a/src/tables.h b/src/tables.h index 8d15e685d..cc0917316 100644 --- a/src/tables.h +++ b/src/tables.h @@ -1,5 +1,5 @@ /* - * $Id: tables.h,v 1.104 2017-09-04 18:02:21 sfeam Exp $ + * $Id: tables.h,v 1.105 2017-09-11 20:13:24 sfeam Exp $ */ /* GNUPLOT - tables.h */ @@ -95,7 +95,7 @@ enum set_id { S_CBLABEL, S_CBRANGE, S_CBTICS, S_NOCBTICS, S_MCBTICS, S_NOMCBTICS, S_CBDATA, S_CBDTICS, S_NOCBDTICS, S_CBMTICS, S_NOCBMTICS, S_OBJECT, S_PLOT, S_POINTINTERVALBOX, S_POINTSIZE, S_POLAR, S_PRINT, S_PSDIR, - S_SAMPLES, S_SIZE, S_SURFACE, S_STYLE, + S_RGBMAX, S_SAMPLES, S_SIZE, S_SURFACE, S_STYLE, S_TABLE, S_TERMINAL, S_TERMOPTIONS, S_THETA, S_TICS, S_TICSCALE, S_TICSLEVEL, S_TIMEFMT, S_TIMESTAMP, S_TITLE, S_TRANGE, S_URANGE, S_VARIABLES, S_VERSION, S_VIEW, S_VRANGE, diff --git a/src/unset.c b/src/unset.c index 41d02762f..738f10528 100644 --- a/src/unset.c +++ b/src/unset.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: unset.c,v 1.257 2017-09-04 18:02:21 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: unset.c,v 1.258 2017-09-11 20:13:24 sfeam Exp $"); } #endif /* GNUPLOT - unset.c */ @@ -411,6 +411,9 @@ unset_command() c_token++; } break; + case S_RGBMAX: + rgbmax = 255; + break; case S_SAMPLES: unset_samples(); break; @@ -1950,6 +1953,7 @@ reset_command() unset_size(); aspect_ratio = 0.0; /* don't force it */ + rgbmax = 255; unset_origin(); unset_timestamp();