Mercurial > forge
changeset 3081:7b0f8d45d511 octave-forge
Use truecolor format if colourmap is longer than 256.
author | pkienzle |
---|---|
date | Thu, 08 Feb 2007 00:04:05 +0000 |
parents | bd48f9574ecc |
children | aa42f20ffa5d |
files | main/image/inst/bmpwrite.m |
diffstat | 1 files changed, 11 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/main/image/inst/bmpwrite.m Wed Feb 07 20:27:01 2007 +0000 +++ b/main/image/inst/bmpwrite.m Thu Feb 08 00:04:05 2007 +0000 @@ -13,14 +13,14 @@ function bmpwrite(x,colormap_or_file,file) if nargin==2 - bmpwrite_truecolor(x,colormap_or_file); + bmpwrite_truecolor(x(:,:,1),x(:,:,2),x(:,:,3),colormap_or_file); else bmpwrite_indexed(x,colormap_or_file,file); endif endfunction -function bmpwrite_truecolor(x,file) - h = rows(x); w = columns(x); +function bmpwrite_truecolor(R,G,B,file) + h = rows(R); w = columns(R); padw = ceil(3*w/4)*4-3*w; header = 14+40; filesize = header+h*(3*w+padw); @@ -45,9 +45,9 @@ fwrite(file,0,"long",0,arch); # number of "important" colors ## raster image, lines written bottom to top. - R = x(end:-1:1,:,1)'; - G = x(end:-1:1,:,2)'; - B = x(end:-1:1,:,3)'; + R = R(end:-1:1,:)'; + G = G(end:-1:1,:)'; + B = B(end:-1:1,:)'; RGB=[B(:),G(:),R(:)]'; # Now [[B;G;R],[B;G;R],...,[B;G;R]] RGB=reshape(RGB,3*w,h); # Now [[B;G;R;...;B;G;R],...,[B;G;R;...;B;G;R]] fwrite(file,[RGB;zeros(padw,h)],"uchar",0,arch); @@ -57,7 +57,11 @@ function bmpwrite_indexed(x,map,file) if rows(map) > 256, - error("bmpwrite supports at most 256 color indexed images"); + bmpwrite_truecolor(reshape(map(x,1),size(x))*255, + reshape(map(x,2),size(x))*255, + reshape(map(x,3),size(x))*255, + file); + return; endif [h,w] = size(x); padw = ceil(w/4)*4-w;