Skip to content

Commit dbe0da6

Browse files
author
sfeam
committed
new command "set rgbmax <val>"
1 parent 157637a commit dbe0da6

File tree

11 files changed

+106
-21
lines changed

11 files changed

+106
-21
lines changed

ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2017-09-11 Ethan A Merritt <[email protected]>
2+
3+
* src/graphics.c src/graphics.h src/set.c src/tables.c src/tables.h
4+
src/unset.c src/show.c src/save.c demo/image2.dem docs/gnuplot.doc:
5+
The default interpretation of RGB color components on input is that
6+
they are integer values in the range [0:255]. This matches the
7+
content of PNG and JPEG files. Since the interpretation of RGB color
8+
components has been decoupled from the palette range limits controlled
9+
by "set cbrange", data using some other RGB convention must be
10+
rescaled. This patch introduces a new command `set rgbmax`.
11+
The primary use is so that data using the convention that color
12+
components are floating point values in the range [0:1] can be
13+
plotted using
14+
set rgbmax 1.0; plot 'imagedata' with rgbimage
15+
116
2017-09-10 Ethan A Merritt <[email protected]>
217

318
* src/axis.c( gen_tics ) src/axis.h( reorder_if_necessary ):

demo/image2.dem

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ print ""
127127
set title "Close up of pixels having grid points (0,0), (0,2), (2,0) and (2,2)"
128128
set xrange [-1.5:3.5]
129129
set yrange [-1.5:3.5]
130-
set cbrange [0:1]
130+
set rgbmax 1
131131
unset key
132132
plot '-' with rgbimage, '-' with points pt 7 ps 2 lt -1
133133
0 0 0.0 0.0 0.5
@@ -450,14 +450,14 @@ print "that when \'binary\' is specified, Gnuplot will continue"
450450
print "reading until reaching the number of elements specified via"
451451
print "the \'array\' or \'record\' command."
452452
print ""
453-
print "Here is an example of binary data at the command line where"
454-
print "keyboard input has been side stepped by copying 48 bytes from"
455-
print "a pre-existing binary file into this demo file."
453+
print "Here is an example of binary data in the range [0:1] inserted"
454+
print "into the command stream by copying 48 bytes from a pre-existing"
455+
print "binary file into this demo file."
456456
print ""
457457
set title "Binary data specified at the command line, intended for use through pipe"
458458
set xrange [-1.5:3.5]
459459
set yrange [-1.5:3.5]
460-
set cbrange [0:1]
460+
set rgbmax 1
461461
plot '-' binary endian=little array=(2,2) dx=2 format="%float" using 1:2:3 with rgbimage,\
462462
'-' binary endian=little record=4 format="%char" using 1:2 with points pt 7 ps 2 lt -1
463463
????

docs/gnuplot.doc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
C RCS $Id: gnuplot.doc,v 1.1107 2017-09-05 20:18:58 sfeam Exp $
1+
C RCS $Id: gnuplot.doc,v 1.1108 2017-09-11 20:13:24 sfeam Exp $
22
C
33
C Copyright (C) 1986 - 1993, 1998, 1999, 2000, 2001, 2004 Thomas Williams, Colin Kelley et al.
44
C
@@ -4075,12 +4075,17 @@ Ffigure_scaled_image
40754075
values for the red, green, and blue components. Thus 5D data (x,y,r,g,b) is
40764076
needed for `plot` and 6D data (x,y,z,r,g,b) for `splot`. The individual red,
40774077
green, and blue components are assumed to lie in the range [0:255].
4078+
This matches the convention used in PNG and JPEG files (see `binary filetype`).
4079+
However some data files use an alternative convention in which RGB components
4080+
are floating point values in the range [0:1]. To use the `rgbimage` style with
4081+
such data, first use the command `set rgbmax 1.0`.
40784082

40794083
The `rgbalpha` style handles input pixels that contain alpha channel
40804084
(transparency) information in addition to the red, green, and blue components.
40814085
Thus 6D data (x,y,r,g,b,a) is needed for `plot` and 7D data (x,y,z,r,g,b,a)
40824086
for `splot`. The r, g, b, and alpha components are assumed to lie in the range
4083-
[0:255].
4087+
[0:255]. To plot data for which RGBA components are floating point values in
4088+
the range [0:1], first use the command `set rgbmax 1.0`.
40844089
3 transparency
40854090
?image transparency
40864091
?transparency
@@ -12228,6 +12233,20 @@ Ffigure_multiple_keys
1222812233
at the center of the polar plot to indicate that the plot lines and axes do
1222912234
not reach 0. The axis line is drawn using the same line type as the plot
1223012235
border. See `polar`, `rrange`, `rtics`, `rlabel`, `set grid`.
12236+
3 rgbmax
12237+
?commands set rgbmax
12238+
?set rgbmax
12239+
?rgbmax
12240+
?unset rgbmax
12241+
=rgbimage
12242+
Syntax:
12243+
set rgbmax {1.0 | 255}
12244+
unset rgbmax
12245+
The red/green/blue color components of an rgbimage plot are by default
12246+
interpreted as integers in the range [0:255]. `set rgbmax 1.0` tells the
12247+
program that data values used to generate the color components of a plot
12248+
with `rgbimage` or `rgbalpha` are floating point values in the range [0:1].
12249+
`unset rgbmax` returns to the default integer range [0:255].
1223112250
3 rlabel
1223212251
?commands set rlabel
1223312252
?rlabel

src/graphics.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.570 2017-09-10 21:41:52 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.571 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - graphics.c */
@@ -72,6 +72,9 @@ double bar_size = 1.0;
7272
int bar_layer = LAYER_FRONT;
7373
struct lp_style_type bar_lp;
7474

75+
/* 'set rgbmax {0|255}' */
76+
double rgbmax = 255;
77+
7578
/* key placement is calculated in boundary, so we need file-wide variables
7679
* To simplify adjustments to the key, we set all these once [depends on
7780
* key->reverse] and use them throughout.
@@ -134,6 +137,8 @@ static void plot_ellipses __PROTO((struct curve_points *plot));
134137
static void do_rectangle __PROTO((int dimensions, t_object *this_object, fill_style_type *fillstyle));
135138
#endif
136139

140+
static double rgbscale __PROTO((double rawvalue));
141+
137142
static void draw_polar_circle __PROTO((double place));
138143

139144
static void plot_parallel __PROTO((struct curve_points *plot));
@@ -4459,6 +4464,18 @@ check_for_variable_color(struct curve_points *plot, double *colorvalue)
44594464
return FALSE;
44604465
}
44614466

4467+
/* rgbscale
4468+
* RGB image color components are normally in the range [0:255] but some
4469+
* data conventions may use [0:1] instead. This does the conversion.
4470+
*/
4471+
static double
4472+
rgbscale( double component )
4473+
{
4474+
if (rgbmax != 255.)
4475+
component = 255. * component/rgbmax;
4476+
return component > 255 ? 255 : component < 0 ? 0 : component;
4477+
}
4478+
44624479
/* process_image:
44634480
*
44644481
* IMG_PLOT - Plot the coordinates similar to the points option except

src/graphics.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: graphics.h,v 1.72 2017-08-23 00:54:52 sfeam Exp $
2+
* $Id: graphics.h,v 1.73 2017-09-11 20:13:24 sfeam Exp $
33
*/
44

55
/* GNUPLOT - graphics.h */
@@ -96,6 +96,9 @@ extern double bar_size;
9696
extern int bar_layer;
9797
extern struct lp_style_type bar_lp;
9898

99+
/* 'set rgbmax {0|255}' */
100+
extern double rgbmax;
101+
99102
/* function prototypes */
100103

101104
void do_plot __PROTO((struct curve_points *, int));
@@ -112,11 +115,6 @@ typedef enum en_procimg_action {
112115
IMG_UPDATE_CORNERS
113116
} t_procimg_action;
114117

115-
/* Place-holder for a routine that scales RGB color components to fit [0:255]
116-
* For now we just enforce the range limits with no scaling
117-
*/
118-
#define rgbscale(c) (c>255. ? 255. : c<0 ? 0. : c)
119-
120118
void process_image __PROTO((void *plot, t_procimg_action action));
121119
TBOOLEAN check_for_variable_color __PROTO((struct curve_points *plot, double *colorvalue));
122120

src/save.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: save.c,v 1.330 2017-08-01 00:56:21 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: save.c,v 1.331 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - save.c */
@@ -633,6 +633,8 @@ set encoding %s\n\
633633
fprintf(fp, "\nset view %s", aspect_ratio_3D == 2 ? "equal xy" :
634634
aspect_ratio_3D == 3 ? "equal xyz": "");
635635

636+
fprintf(fp, "\nset rgbmax %g", rgbmax);
637+
636638
fprintf(fp, "\n\
637639
set samples %d, %d\n\
638640
set isosamples %d, %d\n\

src/set.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: set.c,v 1.568 2017-09-04 18:02:21 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: set.c,v 1.569 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - set.c */
@@ -132,6 +132,7 @@ static void set_object __PROTO((void));
132132
static void set_obj __PROTO((int, int));
133133
#endif
134134
static void set_psdir __PROTO((void));
135+
static void set_rgbmax __PROTO((void));
135136
static void set_samples __PROTO((void));
136137
static void set_size __PROTO((void));
137138
static void set_style __PROTO((void));
@@ -456,6 +457,9 @@ set_command()
456457
case S_SAMPLES:
457458
set_samples();
458459
break;
460+
case S_RGBMAX:
461+
set_rgbmax();
462+
break;
459463
case S_SIZE:
460464
set_size();
461465
break;
@@ -4522,6 +4526,18 @@ set_obj(int tag, int obj_type)
45224526
}
45234527
#endif
45244528

4529+
static void
4530+
set_rgbmax()
4531+
{
4532+
c_token++;
4533+
if (END_OF_COMMAND)
4534+
rgbmax = 255;
4535+
else
4536+
rgbmax = real_expression();
4537+
if (rgbmax <= 0)
4538+
rgbmax = 255;
4539+
}
4540+
45254541
/* process 'set samples' command */
45264542
static void
45274543
set_samples()

src/show.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: show.c,v 1.391 2017-09-04 18:02:21 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: show.c,v 1.392 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - show.c */
@@ -124,6 +124,7 @@ static void show_palette_colornames __PROTO((void));
124124
static void show_colorbox __PROTO((void));
125125
static void show_pointsize __PROTO((void));
126126
static void show_pointintervalbox __PROTO((void));
127+
static void show_rgbmax __PROTO((void));
127128
static void show_encoding __PROTO((void));
128129
static void show_decimalsign __PROTO((void));
129130
static void show_fit __PROTO((void));
@@ -387,6 +388,9 @@ show_command()
387388
case S_POINTSIZE:
388389
show_pointsize();
389390
break;
391+
case S_RGBMAX:
392+
show_rgbmax();
393+
break;
390394
case S_DECIMALSIGN:
391395
show_decimalsign();
392396
break;
@@ -805,6 +809,7 @@ show_all()
805809
show_pm3d();
806810
show_pointsize();
807811
show_pointintervalbox();
812+
show_rgbmax();
808813
show_encoding();
809814
show_decimalsign();
810815
show_fit();
@@ -2538,6 +2543,14 @@ show_pointintervalbox()
25382543
fprintf(stderr, "\tpointintervalbox is %g\n", pointintervalbox);
25392544
}
25402545

2546+
/* process 'show rgbmax' command */
2547+
static void
2548+
show_rgbmax()
2549+
{
2550+
SHOW_ALL_NL;
2551+
fprintf(stderr, "\tRGB image color components are in range [0:%g]\n", rgbmax);
2552+
}
2553+
25412554

25422555
/* process 'show encoding' command */
25432556
static void

src/tables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: tables.c,v 1.156 2017-09-04 18:02:21 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: tables.c,v 1.157 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - tables.c */
@@ -260,6 +260,7 @@ const struct gen_table set_tbl[] =
260260
{ "pr$int", S_PRINT },
261261
{ "psdir", S_PSDIR },
262262
{ "obj$ect", S_OBJECT },
263+
{ "rgbmax", S_RGBMAX },
263264
{ "sa$mples", S_SAMPLES },
264265
{ "si$ze", S_SIZE },
265266
{ "st$yle", S_STYLE },

src/tables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: tables.h,v 1.104 2017-09-04 18:02:21 sfeam Exp $
2+
* $Id: tables.h,v 1.105 2017-09-11 20:13:24 sfeam Exp $
33
*/
44

55
/* GNUPLOT - tables.h */
@@ -95,7 +95,7 @@ enum set_id {
9595
S_CBLABEL, S_CBRANGE, S_CBTICS, S_NOCBTICS, S_MCBTICS, S_NOMCBTICS,
9696
S_CBDATA, S_CBDTICS, S_NOCBDTICS, S_CBMTICS, S_NOCBMTICS, S_OBJECT,
9797
S_PLOT, S_POINTINTERVALBOX, S_POINTSIZE, S_POLAR, S_PRINT, S_PSDIR,
98-
S_SAMPLES, S_SIZE, S_SURFACE, S_STYLE,
98+
S_RGBMAX, S_SAMPLES, S_SIZE, S_SURFACE, S_STYLE,
9999
S_TABLE, S_TERMINAL, S_TERMOPTIONS, S_THETA,
100100
S_TICS, S_TICSCALE, S_TICSLEVEL, S_TIMEFMT, S_TIMESTAMP, S_TITLE,
101101
S_TRANGE, S_URANGE, S_VARIABLES, S_VERSION, S_VIEW, S_VRANGE,

src/unset.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: unset.c,v 1.257 2017-09-04 18:02:21 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: unset.c,v 1.258 2017-09-11 20:13:24 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - unset.c */
@@ -411,6 +411,9 @@ unset_command()
411411
c_token++;
412412
}
413413
break;
414+
case S_RGBMAX:
415+
rgbmax = 255;
416+
break;
414417
case S_SAMPLES:
415418
unset_samples();
416419
break;
@@ -1950,6 +1953,7 @@ reset_command()
19501953

19511954
unset_size();
19521955
aspect_ratio = 0.0; /* don't force it */
1956+
rgbmax = 255;
19531957

19541958
unset_origin();
19551959
unset_timestamp();

0 commit comments

Comments
 (0)