Skip to content

Commit

Permalink
new command "set rgbmax <val>"
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeam committed Sep 11, 2017
1 parent 157637a commit dbe0da6
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 21 deletions.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2017-09-11 Ethan A Merritt <[email protected]>

* 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 <[email protected]>

* src/axis.c( gen_tics ) src/axis.h( reorder_if_necessary ):
Expand Down
10 changes: 5 additions & 5 deletions demo/image2.dem
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
????
Expand Down
23 changes: 21 additions & 2 deletions docs/gnuplot.doc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion src/graphics.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/graphics.h
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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));
Expand All @@ -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));

Expand Down
4 changes: 3 additions & 1 deletion src/save.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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\
Expand Down
18 changes: 17 additions & 1 deletion src/set.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -456,6 +457,9 @@ set_command()
case S_SAMPLES:
set_samples();
break;
case S_RGBMAX:
set_rgbmax();
break;
case S_SIZE:
set_size();
break;
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion src/show.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -387,6 +388,9 @@ show_command()
case S_POINTSIZE:
show_pointsize();
break;
case S_RGBMAX:
show_rgbmax();
break;
case S_DECIMALSIGN:
show_decimalsign();
break;
Expand Down Expand Up @@ -805,6 +809,7 @@ show_all()
show_pm3d();
show_pointsize();
show_pointintervalbox();
show_rgbmax();
show_encoding();
show_decimalsign();
show_fit();
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/tables.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions src/tables.h
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/unset.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -411,6 +411,9 @@ unset_command()
c_token++;
}
break;
case S_RGBMAX:
rgbmax = 255;
break;
case S_SAMPLES:
unset_samples();
break;
Expand Down Expand Up @@ -1950,6 +1953,7 @@ reset_command()

unset_size();
aspect_ratio = 0.0; /* don't force it */
rgbmax = 255;

unset_origin();
unset_timestamp();
Expand Down

0 comments on commit dbe0da6

Please sign in to comment.