@@ -425,21 +425,16 @@ def test_lossless_unsigned(self):
425425 assert out .dtype .kind == "u"
426426 assert np .array_equal (arr , out )
427427
428- # @pytest.mark.skipif(sys.byteorder == "big", reason="Running on BE system")
429428 def test_lossless_unsigned_u4 (self ):
430429 """Test encoding unsigned data for bit-depth 17-32"""
431- dtype = "<u4" if sys .byteorder == "little" else ">u4"
432430 rows = 123
433431 cols = 234
434432 planes = 3
435433 for bit_depth in range (17 , 25 ):
436434 maximum = 2 ** bit_depth - 1
437- arr = np .random .randint (0 , high = maximum + 1 , size = (rows , cols ), dtype = dtype )
438- # if sys.byteorder == "big":
439- # arr = arr.byteswap().astype("<u4")
435+ arr = np .random .randint (0 , high = maximum + 1 , size = (rows , cols ), dtype = "u4" )
440436 buffer = encode_array (arr , photometric_interpretation = PI .MONOCHROME2 )
441437 out = decode (buffer )
442- print (bit_depth , out .min (), out .max ())
443438
444439 param = parse_j2k (buffer )
445440 assert param ["precision" ] == bit_depth
@@ -451,7 +446,7 @@ def test_lossless_unsigned_u4(self):
451446 assert np .array_equal (arr , out )
452447
453448 arr = np .random .randint (
454- 0 , high = maximum + 1 , size = (rows , cols , planes ), dtype = dtype
449+ 0 , high = maximum + 1 , size = (rows , cols , planes ), dtype = "u4"
455450 )
456451 buffer = encode_array (arr , photometric_interpretation = PI .RGB , use_mct = False )
457452 out = decode (buffer )
@@ -521,8 +516,7 @@ def test_lossless_signed(self):
521516 assert out .dtype .kind == "i"
522517 assert np .array_equal (arr , out )
523518
524- # @pytest.mark.skipif(sys.byteorder == "big", reason="Running on BE system")
525- def test_lossless_signed_u4 (self ):
519+ def test_lossless_signed_i4 (self ):
526520 """Test encoding signed data for bit-depth 17-32"""
527521 rows = 123
528522 cols = 234
@@ -531,7 +525,7 @@ def test_lossless_signed_u4(self):
531525 maximum = 2 ** (bit_depth - 1 ) - 1
532526 minimum = - (2 ** (bit_depth - 1 ))
533527 arr = np .random .randint (
534- low = minimum , high = maximum + 1 , size = (rows , cols ), dtype = "< i4"
528+ low = minimum , high = maximum + 1 , size = (rows , cols ), dtype = "i4"
535529 )
536530 buffer = encode_array (arr , photometric_interpretation = PI .MONOCHROME2 )
537531 out = decode (buffer )
@@ -546,7 +540,7 @@ def test_lossless_signed_u4(self):
546540 assert np .array_equal (arr , out )
547541
548542 arr = np .random .randint (
549- low = minimum , high = maximum + 1 , size = (rows , cols , planes ), dtype = "< i4"
543+ low = minimum , high = maximum + 1 , size = (rows , cols , planes ), dtype = "i4"
550544 )
551545 buffer = encode_array (arr , photometric_interpretation = PI .RGB , use_mct = False )
552546 out = decode (buffer )
@@ -1227,7 +1221,7 @@ def test_lossless_unsigned_u4(self):
12271221 rows = 123
12281222 cols = 234
12291223 planes = 3
1230- for bit_depth in range (24 , 32 ):
1224+ for bit_depth in range (17 , 25 ):
12311225 maximum = 2 ** bit_depth - 1
12321226 arr = np .random .randint (0 , high = maximum + 1 , size = (rows , cols ), dtype = "u4" )
12331227 if sys .byteorder == "big" :
@@ -1243,14 +1237,6 @@ def test_lossless_unsigned_u4(self):
12431237 photometric_interpretation = PI .MONOCHROME2 ,
12441238 )
12451239 out = decode (buffer )
1246- print (bit_depth , arr .min (), arr .max ())
1247- print (bit_depth , out .min (), out .max ())
1248- import matplotlib .pyplot as plt
1249-
1250- fig , (ax1 , ax2 ) = plt .subplots (1 , 2 )
1251- ax1 .imshow (arr )
1252- ax2 .imshow (out )
1253- plt .show ()
12541240
12551241 param = parse_j2k (buffer )
12561242 assert param ["precision" ] == bit_depth
@@ -1462,12 +1448,15 @@ def test_lossless_signed_i4(self):
14621448 rows = 123
14631449 cols = 234
14641450 planes = 3
1465- for bit_depth in range (24 , 32 ):
1451+ for bit_depth in range (17 , 25 ):
14661452 maximum = 2 ** (bit_depth - 1 ) - 1
14671453 minimum = - (2 ** (bit_depth - 1 ))
14681454 arr = np .random .randint (
1469- low = minimum , high = maximum + 1 , size = (rows , cols ), dtype = "< i4"
1455+ low = minimum , high = maximum + 1 , size = (rows , cols ), dtype = "i4"
14701456 )
1457+ if sys .byteorder == "big" :
1458+ arr = arr .byteswap ().view ("<i4" )
1459+
14711460 buffer = encode_buffer (
14721461 arr .tobytes (),
14731462 cols ,
@@ -1478,14 +1467,7 @@ def test_lossless_signed_i4(self):
14781467 photometric_interpretation = PI .MONOCHROME2 ,
14791468 )
14801469 out = decode (buffer )
1481- print (bit_depth , arr .min (), arr .max ())
1482- print (bit_depth , out .min (), out .max ())
1483- import matplotlib .pyplot as plt
14841470
1485- fig , (ax1 , ax2 ) = plt .subplots (1 , 2 )
1486- ax1 .imshow (arr )
1487- ax2 .imshow (out )
1488- plt .show ()
14891471
14901472 param = parse_j2k (buffer )
14911473 assert param ["precision" ] == bit_depth
@@ -1497,8 +1479,11 @@ def test_lossless_signed_i4(self):
14971479 assert np .array_equal (arr , out )
14981480
14991481 arr = np .random .randint (
1500- low = minimum , high = maximum + 1 , size = (rows , cols , planes ), dtype = "< i4"
1482+ low = minimum , high = maximum + 1 , size = (rows , cols , planes ), dtype = "i4"
15011483 )
1484+ if sys .byteorder == "big" :
1485+ arr = arr .byteswap ().view ("<i4" )
1486+
15021487 buffer = encode_buffer (
15031488 arr .tobytes (),
15041489 cols ,
0 commit comments