progress on write
This commit is contained in:
parent
8f8e9eff85
commit
e1846c31e0
3 changed files with 33 additions and 51 deletions
|
|
@ -60,10 +60,8 @@ class TestCallbacks(unittest.TestCase):
|
|||
j = glymur.Jp2k(self.jp2file)
|
||||
tiledata = j[:]
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
jp2 = glymur.Jp2k(tfile.name, 'wb')
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
jp2.verbose = True
|
||||
jp2[:] = tiledata
|
||||
jp2 = glymur.Jp2k(tfile.name, data=tiledata, verbose=True)
|
||||
actual = fake_out.getvalue().strip()
|
||||
expected = '[INFO] tile number 1 / 1'
|
||||
self.assertEqual(actual, expected)
|
||||
|
|
|
|||
|
|
@ -97,9 +97,8 @@ class TestSuiteNegativeWrite(unittest.TestCase):
|
|||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cinema2k=36)
|
||||
j = Jp2k(tfile.name, data=data, cinema2k=36)
|
||||
|
||||
|
||||
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
|
||||
|
|
@ -109,9 +108,9 @@ class TestSuiteNegativeWrite(unittest.TestCase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, psnr=[30, 35, 40], cratios=[2, 3, 4])
|
||||
j = Jp2k(tfile.name,
|
||||
data=data, psnr=[30, 35, 40], cratios=[2, 3, 4])
|
||||
|
||||
def test_code_block_dimensions(self):
|
||||
"""don't allow extreme codeblock sizes"""
|
||||
|
|
@ -119,44 +118,38 @@ class TestSuiteNegativeWrite(unittest.TestCase):
|
|||
# to be too small or too big, so neither will we.
|
||||
data = np.zeros((256, 256), dtype=np.uint8)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
||||
# opj_compress doesn't allow code block area to exceed 4096.
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cbsize=(256, 256))
|
||||
j = Jp2k(tfile.name, data=data, cbsize=(256, 256))
|
||||
|
||||
# opj_compress doesn't allow either dimension to be less than 4.
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cbsize=(2048, 2))
|
||||
j = Jp2k(tfile.name, data=data, cbsize=(2048, 2))
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cbsize=(2, 2048))
|
||||
j = Jp2k(tfile.name, data=data, cbsize=(2, 2048))
|
||||
|
||||
def test_precinct_size_not_p2(self):
|
||||
"""precinct sizes should be powers of two."""
|
||||
ifile = Jp2k(self.j2kfile)
|
||||
data = ifile[::4, ::4]
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
ofile = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
ofile.write(data, psizes=[(13, 13)])
|
||||
ofile = Jp2k(tfile.name, data=data, psizes=[(13, 13)])
|
||||
|
||||
def test_cblk_size_not_power_of_two(self):
|
||||
"""code block sizes should be powers of two."""
|
||||
ifile = Jp2k(self.j2kfile)
|
||||
data = ifile[::4, ::4]
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
ofile = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
ofile.write(data, cbsize=(13, 12))
|
||||
ofile = Jp2k(tfile.name, data=data, cbsize=(13, 12))
|
||||
|
||||
def test_cblk_size_precinct_size(self):
|
||||
"""code block sizes should never exceed half that of precinct size."""
|
||||
ifile = Jp2k(self.j2kfile)
|
||||
data = ifile[::4, ::4]
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
ofile = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
ofile.write(data,
|
||||
cbsize=(64, 64),
|
||||
psizes=[(64, 64)])
|
||||
ofile = Jp2k(tfile.name,
|
||||
data=data, cbsize=(64, 64), psizes=[(64, 64)])
|
||||
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ class WriteCinema(CinemaBase):
|
|||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cinema2k=48, cratios=[200, 100, 50])
|
||||
j = Jp2k(tfile.name, data=data,
|
||||
cinema2k=48, cratios=[200, 100, 50])
|
||||
|
||||
def test_cinema4K_with_others(self):
|
||||
"""Can't specify cinema4k with any other options."""
|
||||
|
|
@ -97,9 +97,9 @@ class WriteCinema(CinemaBase):
|
|||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cinema4k=True, cratios=[200, 100, 50])
|
||||
j = Jp2k(tfile.name, data=data,
|
||||
cinema4k=True, cratios=[200, 100, 50])
|
||||
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
|
|
@ -248,8 +248,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
expdata = np.fromfile(filename, dtype=np.uint16)
|
||||
expdata.resize((2816, 2048))
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(expdata, irreversible=True)
|
||||
j = Jp2k(tfile.name, data=expdata, irreversible=True)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.assertEqual(codestream.segment[2].spcod[8],
|
||||
|
|
@ -261,8 +260,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cratios=[200, 100, 50])
|
||||
j = Jp2k(tfile.name, data=data, cratios=[200, 100, 50])
|
||||
|
||||
# Should be three layers.
|
||||
c = j.get_codestream()
|
||||
|
|
@ -293,8 +291,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, psnr=[30, 35, 40], numres=2)
|
||||
j = Jp2k(tfile.name, data=data, psnr=[30, 35, 40], numres=2)
|
||||
|
||||
# Should be three layers.
|
||||
codestream = j.get_codestream()
|
||||
|
|
@ -325,9 +322,9 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, psnr=[30, 35, 40], cbsize=(16, 16),
|
||||
psizes=[(64, 64)])
|
||||
j = Jp2k(tfile.name,
|
||||
data=data,
|
||||
psnr=[30, 35, 40], cbsize=(16, 16), psizes=[(64, 64)])
|
||||
|
||||
# Should be three layers.
|
||||
codestream = j.get_codestream()
|
||||
|
|
@ -360,8 +357,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data,
|
||||
j = Jp2k(tfile.name,
|
||||
data=data,
|
||||
psizes=[(128, 128)] * 3,
|
||||
cratios=[100, 20, 2],
|
||||
tilesize=(480, 640),
|
||||
|
|
@ -397,8 +394,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, tilesize=(127, 127), prog="PCRL")
|
||||
j = Jp2k(tfile.name, data=data, tilesize=(127, 127), prog="PCRL")
|
||||
|
||||
codestream = j.get_codestream()
|
||||
|
||||
|
|
@ -428,8 +424,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, subsam=(2, 2), sop=True)
|
||||
j = Jp2k(tfile.name, data=data, subsam=(2, 2), sop=True)
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
@ -464,8 +459,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, modesw=38, eph=True)
|
||||
j = Jp2k(tfile.name, data=data, modesw=38, eph=True)
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
@ -499,8 +493,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, grid_offset=[300, 150], cratios=[800])
|
||||
j = Jp2k(tfile.name,
|
||||
data=data, grid_offset=[300, 150], cratios=[800])
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
@ -530,8 +524,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Cevennes1.bmp')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cratios=[800])
|
||||
j = Jp2k(tfile.name, data=data, cratios=[800])
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
@ -561,8 +554,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/Cevennes2.ppm')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cratios=[50])
|
||||
j = Jp2k(tfile.name, data=data, cratios=[50])
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
@ -591,8 +583,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
"""NR-ENC-Rome.bmp-11-encode"""
|
||||
data = read_image(opj_data_file('input/nonregression/Rome.bmp'))
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
jp2 = Jp2k(tfile.name, 'wb')
|
||||
jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3)
|
||||
jp2 = Jp2k(tfile.name,
|
||||
data=data, psnr=[30, 35, 50], prog='LRCP', numres=3)
|
||||
|
||||
ids = [box.box_id for box in jp2.box]
|
||||
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
|
||||
|
|
@ -657,8 +649,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
|
|||
infile = opj_data_file('input/nonregression/random-issue-0005.tif')
|
||||
data = read_image(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data)
|
||||
j = Jp2k(tfile.name, data=data)
|
||||
|
||||
codestream = j.get_codestream(header_only=False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue