fixed printing of j2k files with "-c 0", closes #294
It's kind of meaningless to supply that option with a raw codestream, but if it's what the user wanted to do, then it's what the user wanted to do.
This commit is contained in:
parent
41eaec6464
commit
4ffb46833f
2 changed files with 18 additions and 5 deletions
|
|
@ -2,9 +2,11 @@
|
||||||
Entry point for console script jp2dump.
|
Entry point for console script jp2dump.
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
from . import Jp2k, set_printoptions
|
|
||||||
|
from . import Jp2k, set_printoptions, lib
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
|
|
@ -55,11 +57,13 @@ def main():
|
||||||
|
|
||||||
# JP2 metadata can be extensive, so don't print any warnings until we
|
# JP2 metadata can be extensive, so don't print any warnings until we
|
||||||
# are done with the metadata.
|
# are done with the metadata.
|
||||||
j = Jp2k(filename)
|
jp2 = Jp2k(filename)
|
||||||
if print_full_codestream:
|
if jp2._codec_format == lib.openjp2.CODEC_J2K and codestream_level == 0:
|
||||||
print(j.get_codestream(header_only=False))
|
print('File: {0}'.format(os.path.basename(filename)))
|
||||||
|
elif print_full_codestream:
|
||||||
|
print(jp2.get_codestream(header_only=False))
|
||||||
else:
|
else:
|
||||||
print(j)
|
print(jp2)
|
||||||
|
|
||||||
# Re-emit any warnings that may have been suppressed.
|
# Re-emit any warnings that may have been suppressed.
|
||||||
if len(wctx) > 0:
|
if len(wctx) > 0:
|
||||||
|
|
|
||||||
|
|
@ -1102,3 +1102,12 @@ class TestJp2dump(unittest.TestCase):
|
||||||
actual = self.run_jp2dump(['', '-x', self.jp2file])
|
actual = self.run_jp2dump(['', '-x', self.jp2file])
|
||||||
|
|
||||||
self.assertEqual(actual, fixtures.nemo_dump_no_codestream_no_xml)
|
self.assertEqual(actual, fixtures.nemo_dump_no_codestream_no_xml)
|
||||||
|
|
||||||
|
def test_codestream_0_with_j2k_file(self):
|
||||||
|
"""-c 0 should print just a single line when used on a codestream."""
|
||||||
|
sys.argv = ['', '-c', '0', self.j2kfile]
|
||||||
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
|
command_line.main()
|
||||||
|
actual = fake_out.getvalue().strip()
|
||||||
|
self.assertRegex(actual, "File: .*")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue