From 99d7573ab6b8d526816fead367a23c919b2a2267 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 16 Jun 2020 21:49:07 +0100 Subject: [PATCH] add tests for 2 and 4 bit tiff --- test/test-suite/helpers/helpers.py | 2 ++ test/test-suite/images/result2Bit.tif | Bin 0 -> 1234 bytes test/test-suite/images/result4Bit.tif | Bin 0 -> 722 bytes test/test-suite/test_foreign.py | 38 ++++++++++++++++++++++---- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 test/test-suite/images/result2Bit.tif create mode 100644 test/test-suite/images/result4Bit.tif diff --git a/test/test-suite/helpers/helpers.py b/test/test-suite/helpers/helpers.py index e6eb3251..175954fd 100644 --- a/test/test-suite/helpers/helpers.py +++ b/test/test-suite/helpers/helpers.py @@ -14,6 +14,8 @@ SRGB_FILE = os.path.join(IMAGES, "sRGB.icm") MATLAB_FILE = os.path.join(IMAGES, "sample.mat") PNG_FILE = os.path.join(IMAGES, "sample.png") TIF_FILE = os.path.join(IMAGES, "sample.tif") +TIF2_FILE = os.path.join(IMAGES, "result2Bit.tif") +TIF4_FILE = os.path.join(IMAGES, "result4Bit.tif") OME_FILE = os.path.join(IMAGES, "multi-channel-z-series.ome.tif") ANALYZE_FILE = os.path.join(IMAGES, "t00740_tr1_segm.hdr") GIF_FILE = os.path.join(IMAGES, "cramps.gif") diff --git a/test/test-suite/images/result2Bit.tif b/test/test-suite/images/result2Bit.tif new file mode 100644 index 0000000000000000000000000000000000000000..68849e977dac4f965401a57b4287d2d1c486870b GIT binary patch literal 1234 zcmebD)MDUZVW1dw$DC=CD#y&p=U_g7Kq{r{u>rz`}9di?VAR`M{FG!6LlDH@mTMWu>0ICs(s%HRNAjQZE)_VxZ hmWHxV0ogK0dNrVIW}x0+Byk{@0hIFh)^c#dXaLM+e0 literal 0 HcmV?d00001 diff --git a/test/test-suite/images/result4Bit.tif b/test/test-suite/images/result4Bit.tif new file mode 100644 index 0000000000000000000000000000000000000000..52d79d7fed265931d2bfeeeb5828a03a38882841 GIT binary patch literal 722 zcmebD)MDUZVt@ldC{Tg|V<>Qef>0<(gMxA>=zxNmP_POLc0<7#D7Xs+@1Wp66u=xX zYCj|d=pFw23=E9S42+;?01}K)HVcr;gv4fsvO((Dkl2EZEMUDHKye`?aZx0;7?j-r xR3i>m&j3t$QjDx%y@!BoX(;;?kS&9xR|Cps2I>t)5(jb_KnZAXEe9uz1^@xe4lMux literal 0 HcmV?d00001 diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index c0bf6391..fe5911d3 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -12,10 +12,12 @@ from helpers import \ ANALYZE_FILE, GIF_FILE, WEBP_FILE, EXR_FILE, FITS_FILE, OPENSLIDE_FILE, \ PDF_FILE, SVG_FILE, SVGZ_FILE, SVG_GZ_FILE, GIF_ANIM_FILE, DICOM_FILE, \ BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, TRUNCATED_FILE, \ - GIF_ANIM_EXPECTED_PNG_FILE, \ - GIF_ANIM_DISPOSE_BACKGROUND_FILE, GIF_ANIM_DISPOSE_BACKGROUND_EXPECTED_PNG_FILE, \ - GIF_ANIM_DISPOSE_PREVIOUS_FILE, GIF_ANIM_DISPOSE_PREVIOUS_EXPECTED_PNG_FILE, \ - temp_filename, assert_almost_equal_objects, have, skip_if_no + GIF_ANIM_EXPECTED_PNG_FILE, GIF_ANIM_DISPOSE_BACKGROUND_FILE, \ + GIF_ANIM_DISPOSE_BACKGROUND_EXPECTED_PNG_FILE, \ + GIF_ANIM_DISPOSE_PREVIOUS_FILE, \ + GIF_ANIM_DISPOSE_PREVIOUS_EXPECTED_PNG_FILE, \ + temp_filename, assert_almost_equal_objects, have, skip_if_no, \ + TIF2_FILE, TIF4_FILE class TestForeign: @@ -322,6 +324,25 @@ class TestForeign: self.file_loader("tiffload", TIF_FILE, tiff_valid) self.buffer_loader("tiffload_buffer", TIF_FILE, tiff_valid) + + def tiff2_valid(im): + a = im(80, 0) + assert_almost_equal_objects(a, [85.0]) + assert im.width == 256 + assert im.height == 4 + assert im.bands == 1 + + self.file_loader("tiffload", TIF2_FILE, tiff2_valid) + + def tiff4_valid(im): + a = im(109, 0) + assert_almost_equal_objects(a, [102.0]) + assert im.width == 256 + assert im.height == 4 + assert im.bands == 1 + + self.file_loader("tiffload", TIF4_FILE, tiff4_valid) + if pyvips.at_least_libvips(8, 5): self.save_load_buffer("tiffsave_buffer", "tiffload_buffer", @@ -331,9 +352,9 @@ class TestForeign: self.save_load("%s.tif", self.cmyk) self.save_load("%s.tif", self.onebit) - self.save_load_file(".tif", "[squash]", self.onebit, 0) + self.save_load_file(".tif", "[bitdepth=1]", self.onebit, 0) self.save_load_file(".tif", "[miniswhite]", self.onebit, 0) - self.save_load_file(".tif", "[squash,miniswhite]", self.onebit, 0) + self.save_load_file(".tif", "[bitdepth=1,miniswhite]", self.onebit, 0) self.save_load_file(".tif", "[profile={0}]".format(SRGB_FILE), @@ -351,6 +372,11 @@ class TestForeign: self.save_load_file(".tif", "[tile,tile-width=256]", self.colour, 10) + im = pyvips.Image.new_from_file(TIF4_FILE) + self.save_load_file(".tif", "[bitdepth=4]", im, 0) + im = pyvips.Image.new_from_file(TIF2_FILE) + self.save_load_file(".tif", "[bitdepth=2]", im, 0) + filename = temp_filename(self.tempdir, '.tif') x = pyvips.Image.new_from_file(TIF_FILE) x = x.copy()