Mercurial > octave-nkf
changeset 17850:45e325002810
imwrite: fill colormap with black (RGB 0,0,0) for missing colors (bug #33615)
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Mon, 04 Nov 2013 21:48:45 +0000 |
parents | e432697a0621 |
children | af685269e06c |
files | scripts/image/private/__imwrite__.m |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/private/__imwrite__.m Mon Nov 04 13:20:04 2013 -0800 +++ b/scripts/image/private/__imwrite__.m Mon Nov 04 21:48:45 2013 +0000 @@ -94,6 +94,19 @@ elseif (ndims (img) != 2 && ndims (img) != 4) error ("imwrite: indexed image must have 2 or 4 dimensions (found %i)", ndims (img)); endif + + ## Fill in the colormap as required with rgb (0, 0, 0) (bug #33615) + nColors = rows (map); + if (any (strcmp (class (img), {"uint8", "uint16", "logical"}))) + required_colors = max (img(:)) +1; + else + required_colors = max (img(:)); + endif + if (nColors < required_colors) + warning ("imwrite: MAP has not enough colors. Filling with black"); + map(nColors+1:required_colors,:) = 0; + endif + ## If the image is floating point, then we convert it to integer (makes ## it easier in __magick_write__ since it only handles integers. Also, ## if it's floating point, it has an offset of 1