File: test_lzw.py

package info (click to toggle)
pylibtiff 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 976 kB
  • sloc: python: 10,219; ansic: 1,064; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 955 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

import numpy
# from tempfile import mktemp
# from libtiff import TIFFfile, TIFF

try:
    import pytest
except ImportError:
    pass
else:
    # when running inside source directory:
    pytest.importorskip('libtiff.tif_lzw')

from libtiff.tif_lzw import encode as c_encode, decode as c_decode

# def TIFFencode(arr):
#    fn = mktemp('.tif')
#    tif = TIFF.open(fn, 'w+')
#    tif.write_image(arr.view(numpy.uint8), compression='lzw')
#    tif.close()
#    tif = TIFFfile(fn)
#    data, names = tif.get_samples(leave_compressed=True)
#    return data[0][0]


def test_encode():
    for arr in [
            numpy.array([7, 7, 7, 8, 8, 7, 7, 6, 6], numpy.uint8),
            numpy.array(list(range(400000)), numpy.uint8),
            numpy.array([1, 3, 7, 15, 31, 63], numpy.uint8)]:

        rarr = c_encode(arr)
        arr2 = c_decode(rarr, arr.nbytes)
        assert arr2.nbytes == arr.nbytes and (arr2 == arr).all(),\
            repr((arr2, arr))