# HG changeset patch # User adb014 # Date 1156979538 0 # Node ID eddf1f21c6a830a572f3e6510e855ecee6c4bf73 # Parent 99a4febc0947d9687a24fa7e8988a8400e1497a5 move image test code to jpgwrite/pngwrite using test/assert code diff --git a/inst/testimio.m b/inst/testimio.m deleted file mode 100644 --- a/inst/testimio.m +++ /dev/null @@ -1,56 +0,0 @@ -## This program is public domain. - -## build image for image r/w tests -x=linspace(-8,8,200); -[xx,yy]=meshgrid(x,x); -r=sqrt(xx.^2+yy.^2) + eps; -map=colormap(hsv); -A=sin(r)./r; -minval = min(A(:)); -maxval = max(A(:)); -z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1; -Rw=Gw=Bw=z; -Rw(:)=fix(255*map(z,1)); -Gw(:)=fix(255*map(z,2)); -Bw(:)=fix(255*map(z,3)); -Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners - -if exist("jpgwrite") - disp(">jpgwrite"); - jpgwrite('test.jpg',Rw,Gw,Bw); - stats=stat("test.jpg"); - assert(stats.size,6423); - disp(">jpgread"); - im = jpgread('test.jpg'); - Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); - assert(all(Rw(:)-double(Rr(:))<35)); - assert(all(Gw(:)-double(Gr(:))<35)); - assert(all(Bw(:)-double(Br(:))<35)); - unlink('test.jpg'); -else - disp(">jpgread ... not available"); - disp(">jpgwrite ... not available"); -endif - -if exist("pngwrite") - disp(">pngwrite"); - pngwrite('test.png',Rw,Gw,Bw,Aw); - stats=stat("test.png"); - assert(stats.size,24738); - disp(">pngread"); - im = pngread('test.png'); - Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); - assert(all(double(Rr(:))==Rw(:))); - assert(all(double(Gr(:))==Gw(:))); - assert(all(double(Br(:))==Bw(:))); - [im,Ar] = pngread('test.png'); - Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); - assert(all(double(Rr(:))==Rw(:))); - assert(all(double(Gr(:))==Gw(:))); - assert(all(double(Br(:))==Bw(:))); - assert(all(double(Ar(:))==Aw(:))); - unlink('test.png'); -else - disp(">pngread ... not available"); - disp(">pngwrite ... not available"); -endif diff --git a/src/jpgwrite.cc b/src/jpgwrite.cc --- a/src/jpgwrite.cc +++ b/src/jpgwrite.cc @@ -219,3 +219,30 @@ return retval; } + +%!test +%! if exist("jpgwrite","file") +%! ## build test image for r/w tests +%! x=linspace(-8,8,200); +%! [xx,yy]=meshgrid(x,x); +%! r=sqrt(xx.^2+yy.^2) + eps; +%! map=colormap(hsv); +%! A=sin(r)./r; +%! minval = min(A(:)); +%! maxval = max(A(:)); +%! z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1; +%! Rw=Gw=Bw=z; +%! Rw(:)=fix(255*map(z,1)); +%! Gw(:)=fix(255*map(z,2)); +%! Bw(:)=fix(255*map(z,3)); +%! Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners +%! jpgwrite('test.jpg',Rw,Gw,Bw); +%! stats=stat("test.jpg"); +%! assert(stats.size,6423); +%! im = jpgread('test.jpg'); +%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); +%! assert(all(Rw(:)-double(Rr(:))<35)); +%! assert(all(Gw(:)-double(Gr(:))<35)); +%! assert(all(Bw(:)-double(Br(:))<35)); +%! unlink('test.jpg'); +%! endif diff --git a/src/pngwrite.cc b/src/pngwrite.cc --- a/src/pngwrite.cc +++ b/src/pngwrite.cc @@ -164,3 +164,36 @@ png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); } + +%!test +%! if exist("jpgwrite","file") +%! ## build test image for r/w tests +%! x=linspace(-8,8,200); +%! [xx,yy]=meshgrid(x,x); +%! r=sqrt(xx.^2+yy.^2) + eps; +%! map=colormap(hsv); +%! A=sin(r)./r; +%! minval = min(A(:)); +%! maxval = max(A(:)); +%! z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1; +%! Rw=Gw=Bw=z; +%! Rw(:)=fix(255*map(z,1)); +%! Gw(:)=fix(255*map(z,2)); +%! Bw(:)=fix(255*map(z,3)); +%! Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners +%! pngwrite('test.png',Rw,Gw,Bw,Aw); +%! stats=stat("test.png"); +%! assert(stats.size,24738); +%! im = pngread('test.png'); +%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); +%! assert(all(double(Rr(:))==Rw(:))); +%! assert(all(double(Gr(:))==Gw(:))); +%! assert(all(double(Br(:))==Bw(:))); +%! [im,Ar] = pngread('test.png'); +%! Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3); +%! assert(all(double(Rr(:))==Rw(:))); +%! assert(all(double(Gr(:))==Gw(:))); +%! assert(all(double(Br(:))==Bw(:))); +%! assert(all(double(Ar(:))==Aw(:))); +%! unlink('test.png'); +%! endif