Mercurial > octave
changeset 22562:cd2a8d0c0b56
Better Matlab compatibility for images created with gnuplot (bug #49130).
* __gnuplot_draw_axes__.m (mapcdata): Don't do conversion to
double->uint8->double to achieve clamping of RGB values. Keep cdata as double
and use indexing to find and clamp values outside range [0, 255].
For scaled data, use scaling factor of colormap_size rather than
colormap_size-1 for compatibility.
For "direct" integer data, convert range from zero-based indices to ones-based.
For "direct" float data, truncate using "fix" rather than "round" for
compatibility.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 30 Sep 2016 08:51:18 -0700 |
parents | 202c6871f07d |
children | 656f08c45b8e |
files | scripts/plot/util/private/__gnuplot_draw_axes__.m |
diffstat | 1 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Wed Sep 28 15:57:05 2016 -0500 +++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri Sep 30 08:51:18 2016 -0700 @@ -2849,21 +2849,27 @@ function retval = mapcdata (cdata, mode, clim, cmap_sz) if (ndims (cdata) == 3) - # True color, clamp data to 8-bit + ## True Color, clamp data to 8-bit cdata = double (cdata); - cdata = uint8 (255*(cdata-clim(1))/(clim(2)-clim(1))); - # Scale using inverse of gnuplot's cbrange mapping - retval = 1 + double (cdata)*(cmap_sz-1)/255; + cdata = 255 * (cdata - clim(1)) / (clim(2)-clim(1)); + cdata(cdata < 0) = 0; cdata(cdata > 255) = 255; + ## Scale using inverse of gnuplot's cbrange mapping + retval = 1 + cdata * (cmap_sz-1)/255; else if (islogical (cdata)) cdata += 1; elseif (strcmp (mode, "scaled")) cdata = double (cdata); clim = double (clim); - cdata = 1 + fix ((cmap_sz-1)*(cdata-clim(1))/(clim(2)-clim(1))); + cdata = 1 + fix (cmap_sz * (cdata - clim(1)) / (clim(2) - clim(1))); else - cdata = round (cdata); + if (isinteger (cdata)) + cdata += 1; + else + cdata = fix (cdata); + endif endif retval = max (1, min (cdata, cmap_sz)); endif endfunction +