Commit 4a536738 authored by Jakob Stierhof's avatar Jakob Stierhof

Index fix

parent 69d22205
......@@ -111,38 +111,6 @@ private define hpluv_palette (n)
return rgb2hex(hsluv2rgb(hues, qualifier("s", 0.9), qualifier("l", 0.6)));
}
private define colormap_palette (n, name)
%!%+
%\function{palette--map}
%\synopsis{Retrieve a set of colors from a colormap}
%\usage{UInt_Type[] palette = get_color_palette (String_Type name, UInt_Type len);}
%\qualifiers{
% \qualifier{start[=0.0]}{Starting "color" (lowest value)}
% \qualifier{range[=1.0]}{Range of "color", larger than one causes repetitions}
%}
%\description
% This function is useful if a range of colors is required.
% It returns \code{len} values from a linear mapping of the
% given colormap. If \code{n} is more than 256, repetitions will
% occure.
%!%-
{
#ifexists png_add_colormap
variable map;
try
map = png_get_colormap(name);
catch AnyError:
throw UsageError, "Unknown palette: '$name'"$;
variable ind = (qualifier("start", 0.0) + [0:qualifier("range", 1.0):#n]) mod 1.0;
ind = int((ind-int(ind))*255);
return map[ind];
#else
return ColorPalettes[""];
#endif
}
% HSL, HSLuv palettes %{{{
add_color_palette("hsl", &hsl_palette);
add_color_palette("hsluv", &hsluv_palette);
......@@ -378,7 +346,7 @@ private define blend_palette (n)
mb[winf] = 0.;
weights = weights[[:-2]];
variable idx = [0, int(weights*n), n-1];
variable idx = [0, int(weights*(n-1)), n-1];
variable tr = r[[:-2]]-mr*weights;
variable tg = g[[:-2]]-mg*weights;
variable tb = b[[:-2]]-mb*weights;
......@@ -557,6 +525,45 @@ private define cubehelix_palette (n)
add_color_palette("cubehelix", &cubehelix_palette);
%}}}
private define colormap_palette (n, name)
%!%+
%\function{palette--map}
%\synopsis{Retrieve a set of colors from a colormap}
%\usage{UInt_Type[] palette = get_color_palette (String_Type name, UInt_Type len);}
%\qualifiers{
% \qualifier{start[=0.0]}{Starting "color" (lowest value)}
% \qualifier{range[=1.0]}{Range of "color", larger than one causes repetitions}
%}
%\description
% This function is useful if a range of colors is required.
% It returns \code{len} values from a linear mapping of the
% given colormap. The colors are constructed from palette--blend
% and forwards all qualifiers to this constructor.
%!%-
{
#ifexists png_add_colormap
variable map;
try
map = png_get_colormap(name);
catch AnyError:
throw UsageError, "Unknown palette: '$name'"$;
variable start = qualifier("start", 0.0);
variable range = qualifier("range", 1.0);
while (start<0) start += 1.0;
start = int(start*(length(map)-1));
range = int(range*(length(map)-1));
variable ind = [start:start+range] mod length(map);
vmessage("start: %06x, stop: %06x", (map[ind])[0], (map[ind])[-1]);
return blend_palette(n;; struct { @__qualifiers(), colors=map[ind] });
#else
return ColorPalettes[""];
#endif
}
define get_color_palette (name, n)
%!%+
%\function{get_color_palette}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment