add heif tests
This commit is contained in:
parent
4a461e2507
commit
2ab2a90e06
@ -29,6 +29,7 @@ DICOM_FILE = os.path.join(IMAGES, "dicom_test_image.dcm")
|
||||
BMP_FILE = os.path.join(IMAGES, "MARBLES.BMP")
|
||||
NIFTI_FILE = os.path.join(IMAGES, "avg152T1_LR_nifti.nii.gz")
|
||||
ICO_FILE = os.path.join(IMAGES, "favicon.ico")
|
||||
HEIC_FILE = os.path.join(IMAGES, "Example1.heic")
|
||||
|
||||
unsigned_formats = [pyvips.BandFormat.UCHAR,
|
||||
pyvips.BandFormat.USHORT,
|
||||
|
BIN
test/test-suite/images/Example1.heic
Normal file
BIN
test/test-suite/images/Example1.heic
Normal file
Binary file not shown.
@ -10,7 +10,7 @@ from helpers import \
|
||||
JPEG_FILE, SRGB_FILE, MATLAB_FILE, PNG_FILE, TIF_FILE, OME_FILE, \
|
||||
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, \
|
||||
BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, \
|
||||
temp_filename, assert_almost_equal_objects, have, skip_if_no
|
||||
|
||||
|
||||
@ -561,13 +561,6 @@ class TestForeign:
|
||||
assert im.height == 9919
|
||||
assert im.bands == 1
|
||||
|
||||
print("NIFTI_FILE =", NIFTI_FILE)
|
||||
im = pyvips.Operation.call("niftiload", NIFTI_FILE)
|
||||
print("width = ", im.width)
|
||||
|
||||
im = pyvips.Operation.call("niftiload", "test/images/avg152T1_LR_nifti.nii.gz")
|
||||
print("width = ", im.width)
|
||||
|
||||
self.file_loader("niftiload", NIFTI_FILE, nifti_valid)
|
||||
self.save_load("%s.nii.gz", self.mono)
|
||||
|
||||
@ -822,5 +815,53 @@ class TestForeign:
|
||||
buf = self.colour.dzsave_buffer(region_shrink="mode")
|
||||
buf = self.colour.dzsave_buffer(region_shrink="median")
|
||||
|
||||
@skip_if_no("heifload")
|
||||
def test_heifload(self):
|
||||
def heif_valid(im):
|
||||
a = im(10, 10)
|
||||
assert_almost_equal_objects(a, [75.0, 86.0, 81.0])
|
||||
assert im.width == 4032
|
||||
assert im.height == 3024
|
||||
assert im.bands == 3
|
||||
|
||||
self.file_loader("heifload", HEIC_FILE, heif_valid)
|
||||
self.buffer_loader("heifload_buffer", HEIC_FILE, heif_valid)
|
||||
self.save_load_buffer("heifsave_buffer", "heifload_buffer",
|
||||
self.colour, 70)
|
||||
self.save_load("%s.heic", self.colour)
|
||||
|
||||
# test lossless mode
|
||||
im = pyvips.Image.new_from_file(HEIC_FILE)
|
||||
buf = im.heifsave_buffer(lossless=True)
|
||||
im2 = pyvips.Image.new_from_buffer(buf, "")
|
||||
# not in fact quite lossless
|
||||
assert abs(im.avg() - im2.avg()) < 3
|
||||
|
||||
# higher Q should mean a bigger buffer
|
||||
b1 = im.heifsave_buffer(Q=10)
|
||||
b2 = im.heifsave_buffer(Q=90)
|
||||
assert len(b2) > len(b1)
|
||||
|
||||
# try saving an image with an ICC profile and reading it back
|
||||
buf = self.colour.heifsave_buffer()
|
||||
im = pyvips.Image.new_from_buffer(buf, "")
|
||||
p1 = self.colour.get("icc-profile-data")
|
||||
p2 = im.get("icc-profile-data")
|
||||
assert p1 == p2
|
||||
|
||||
# add tests for exif, xmp, ipct
|
||||
# the exif test will need us to be able to walk the header,
|
||||
# we can't just check exif-data
|
||||
|
||||
# test that exif changes change the output of heifsave
|
||||
# first make sure we have exif support
|
||||
z = pyvips.Image.new_from_file(JPEG_FILE)
|
||||
if z.get_typeof("exif-ifd0-Orientation") != 0:
|
||||
x = self.colour.copy()
|
||||
x.set("orientation", 6)
|
||||
buf = x.heifsave_buffer()
|
||||
y = pyvips.Image.new_from_buffer(buf, "")
|
||||
assert y.get("orientation") == 6
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user