Gnuplot/palette: Difference between revisions
< Gnuplot
[checked revision] | [checked revision] |
Content deleted Content added
show |
→Show: test |
||
Line 14: | Line 14: | ||
Color-Model: RGB |
Color-Model: RGB |
||
gamma is 1.5 |
gamma is 1.5 |
||
=test= |
|||
Wykres składowych koloru otrzymamy: |
|||
test palette<ref>/src/command.c</ref> |
|||
[[Grafika:RGB_profiles_of_the_color_palette.gif|thumb|right|Standardowy gradient w Gnuplocie]] |
|||
Możemy to zapisać do pliku png: |
|||
set terminal png |
|||
set output 'p.png' |
|||
test palette |
|||
gdzie : |
|||
* NTSC |
|||
** gray value : calculated using NTSC coefficients to map RGB onto a grayscale<ref>[http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/POYNTON1/ColorFAQ.html#RTFToC9 Poynton's Color FAQ by Charles Poynton]</ref> |
|||
** the NTSC luminance, which corresponds to the Y channel in the YIQ model. It indicates the result if the color were displayed on a black-and-white TV screen<ref>[https://livebook.manning.com/book/gnuplot-in-action-second-edition/appendix-d/75 https://livebook gnuplot-in-action-second-edition by P K Janert]</ref> |
|||
** ważona suma liniowych składników RGB<ref>[[:w:en:Luma_(video)|Luma_(video) w ang wikipedii]]</ref> <math>Y = 0.2126 R + 0.7152 G + 0.0722 B</math> |
|||
<source lang=c> |
|||
//from function test_palette_subcommand from command.c |
|||
ntsc = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b; |
|||
</source> |
|||
Kod : |
|||
<source lang=c> |
|||
// command.c |
|||
/* |
|||
* process the 'test palette' command |
|||
* 1) Write a sequence of plot commands + set commands into a temp file |
|||
* 2) Create a datablock with palette values |
|||
* 3) Load the temp file to plot from the datablock |
|||
* The set commands then act to restore the initial state |
|||
*/ |
|||
static void |
|||
test_palette_subcommand() |
|||
{ |
|||
enum {test_palette_colors = 256}; |
|||
struct udvt_entry *datablock; |
|||
char *save_replot_line; |
|||
TBOOLEAN save_is_3d_plot; |
|||
int i; |
|||
static const char pre1[] = "\ |
|||
reset;\ |
|||
uns border; se tics scale 0;\ |
|||
se cbtic 0,0.1,1 mirr format '' scale 1;\ |
|||
se xr[0:1];se yr[0:1];se zr[0:1];se cbr[0:1];\ |
|||
set colorbox hor user orig 0.05,0.02 size 0.925,0.12;"; |
|||
static const char pre2[] = "\ |
|||
se lmarg scre 0.05;se rmarg scre 0.975; se bmarg scre 0.22; se tmarg scre 0.86;\ |
|||
se grid; se xtics 0,0.1;se ytics 0,0.1;\ |
|||
se key top right at scre 0.975,0.975 horizontal \ |
|||
title 'R,G,B profiles of the current color palette';"; |
|||
static const char pre3[] = "\ |
|||
p NaN lc palette notit,\ |
|||
$PALETTE u 1:2 t 'red' w l lt 1 lc rgb 'red',\ |
|||
'' u 1:3 t 'green' w l lt 1 lc rgb 'green',\ |
|||
'' u 1:4 t 'blue' w l lt 1 lc rgb 'blue',\ |
|||
'' u 1:5 t 'NTSC' w l lt 1 lc rgb 'black'\ |
|||
\n"; |
|||
FILE *f = tmpfile(); |
|||
#if defined(_MSC_VER) || defined(__MINGW32__) |
|||
/* On Vista/Windows 7 tmpfile() fails. */ |
|||
if (!f) { |
|||
char buf[PATH_MAX]; |
|||
/* We really want the "ANSI" version */ |
|||
GetTempPathA(sizeof(buf), buf); |
|||
strcat(buf, "gnuplot-pal.tmp"); |
|||
f = fopen(buf, "w+"); |
|||
} |
|||
#endif |
|||
while (!END_OF_COMMAND) |
|||
c_token++; |
|||
if (!f) |
|||
int_error(NO_CARET, "cannot write temporary file"); |
|||
/* Store R/G/B/Int curves in a datablock */ |
|||
datablock = add_udv_by_name("$PALETTE"); |
|||
if (datablock->udv_value.type != NOTDEFINED) |
|||
gpfree_datablock(&datablock->udv_value); |
|||
datablock->udv_value.type = DATABLOCK; |
|||
datablock->udv_value.v.data_array = NULL; |
|||
/* Part of the purpose for writing these values into a datablock */ |
|||
/* is so that the user can read them back if desired. But data */ |
|||
/* will be read back using the current numeric locale, so for */ |
|||
/* consistency we must also use the locale when creating it. */ |
|||
set_numeric_locale(); |
|||
for (i = 0; i < test_palette_colors; i++) { |
|||
char dataline[64]; |
|||
rgb_color rgb; |
|||
double ntsc; |
|||
double z = (double)i / (test_palette_colors - 1); |
|||
double gray = (sm_palette.positive == SMPAL_NEGATIVE) ? 1. - z : z; |
|||
rgb1_from_gray(gray, &rgb); |
|||
ntsc = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b; |
|||
sprintf(dataline, "%0.4f %0.4f %0.4f %0.4f %0.4f %c", |
|||
z, rgb.r, rgb.g, rgb.b, ntsc, '\0'); |
|||
append_to_datablock(&datablock->udv_value, strdup(dataline)); |
|||
} |
|||
reset_numeric_locale(); |
|||
/* commands to setup the test palette plot */ |
|||
enable_reset_palette = 0; |
|||
save_replot_line = gp_strdup(replot_line); |
|||
save_is_3d_plot = is_3d_plot; |
|||
fputs(pre1, f); |
|||
fputs(pre2, f); |
|||
fputs(pre3, f); |
|||
/* save current gnuplot 'set' status because of the tricky sets |
|||
* for our temporary testing plot. |
|||
*/ |
|||
save_set(f); |
|||
/* execute all commands from the temporary file */ |
|||
rewind(f); |
|||
load_file(f, NULL, 1); /* note: it does fclose(f) */ |
|||
/* enable reset_palette() and restore replot line */ |
|||
enable_reset_palette = 1; |
|||
free(replot_line); |
|||
replot_line = save_replot_line; |
|||
is_3d_plot = save_is_3d_plot; |
|||
} |
|||
</source> |
|||
= References= |
= References= |
Revision as of 18:20, 12 January 2020
Palette or color gradient[1]
Show
Check the standard color gradient (traditional pm3d is black-blue-red-yellow):
show palette
Output:
palette is COLOR rgb color mapping by rgbformulae are 7,5,15 figure is POSITIVE all color formulae ARE NOT written into output postscript file allocating ALL remaining color positions for discrete palette terminals Color-Model: RGB gamma is 1.5
test
Wykres składowych koloru otrzymamy:
test palette[2]
thumb|right|Standardowy gradient w Gnuplocie Możemy to zapisać do pliku png:
set terminal png set output 'p.png' test palette
gdzie :
- NTSC
//from function test_palette_subcommand from command.c
ntsc = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
Kod :
// command.c
/*
* process the 'test palette' command
* 1) Write a sequence of plot commands + set commands into a temp file
* 2) Create a datablock with palette values
* 3) Load the temp file to plot from the datablock
* The set commands then act to restore the initial state
*/
static void
test_palette_subcommand()
{
enum {test_palette_colors = 256};
struct udvt_entry *datablock;
char *save_replot_line;
TBOOLEAN save_is_3d_plot;
int i;
static const char pre1[] = "\
reset;\
uns border; se tics scale 0;\
se cbtic 0,0.1,1 mirr format '' scale 1;\
se xr[0:1];se yr[0:1];se zr[0:1];se cbr[0:1];\
set colorbox hor user orig 0.05,0.02 size 0.925,0.12;";
static const char pre2[] = "\
se lmarg scre 0.05;se rmarg scre 0.975; se bmarg scre 0.22; se tmarg scre 0.86;\
se grid; se xtics 0,0.1;se ytics 0,0.1;\
se key top right at scre 0.975,0.975 horizontal \
title 'R,G,B profiles of the current color palette';";
static const char pre3[] = "\
p NaN lc palette notit,\
$PALETTE u 1:2 t 'red' w l lt 1 lc rgb 'red',\
'' u 1:3 t 'green' w l lt 1 lc rgb 'green',\
'' u 1:4 t 'blue' w l lt 1 lc rgb 'blue',\
'' u 1:5 t 'NTSC' w l lt 1 lc rgb 'black'\
\n";
FILE *f = tmpfile();
#if defined(_MSC_VER) || defined(__MINGW32__)
/* On Vista/Windows 7 tmpfile() fails. */
if (!f) {
char buf[PATH_MAX];
/* We really want the "ANSI" version */
GetTempPathA(sizeof(buf), buf);
strcat(buf, "gnuplot-pal.tmp");
f = fopen(buf, "w+");
}
#endif
while (!END_OF_COMMAND)
c_token++;
if (!f)
int_error(NO_CARET, "cannot write temporary file");
/* Store R/G/B/Int curves in a datablock */
datablock = add_udv_by_name("$PALETTE");
if (datablock->udv_value.type != NOTDEFINED)
gpfree_datablock(&datablock->udv_value);
datablock->udv_value.type = DATABLOCK;
datablock->udv_value.v.data_array = NULL;
/* Part of the purpose for writing these values into a datablock */
/* is so that the user can read them back if desired. But data */
/* will be read back using the current numeric locale, so for */
/* consistency we must also use the locale when creating it. */
set_numeric_locale();
for (i = 0; i < test_palette_colors; i++) {
char dataline[64];
rgb_color rgb;
double ntsc;
double z = (double)i / (test_palette_colors - 1);
double gray = (sm_palette.positive == SMPAL_NEGATIVE) ? 1. - z : z;
rgb1_from_gray(gray, &rgb);
ntsc = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
sprintf(dataline, "%0.4f %0.4f %0.4f %0.4f %0.4f %c",
z, rgb.r, rgb.g, rgb.b, ntsc, '\0');
append_to_datablock(&datablock->udv_value, strdup(dataline));
}
reset_numeric_locale();
/* commands to setup the test palette plot */
enable_reset_palette = 0;
save_replot_line = gp_strdup(replot_line);
save_is_3d_plot = is_3d_plot;
fputs(pre1, f);
fputs(pre2, f);
fputs(pre3, f);
/* save current gnuplot 'set' status because of the tricky sets
* for our temporary testing plot.
*/
save_set(f);
/* execute all commands from the temporary file */
rewind(f);
load_file(f, NULL, 1); /* note: it does fclose(f) */
/* enable reset_palette() and restore replot line */
enable_reset_palette = 1;
free(replot_line);
replot_line = save_replot_line;
is_3d_plot = save_is_3d_plot;
}