Skip to content

Commit

Permalink
Renamed Jpeg2K variable to prevent masking Image reduce method
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 8, 2020
1 parent ef4a0b2 commit bcabaa0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Tests/test_file_jpeg2k.py
Expand Up @@ -110,10 +110,11 @@ def test_prog_res_rt(self):
self.assert_image_equal(im, test_card)

def test_reduce(self):
with Image.open("Tests/images/test-card-lossless.jp2") as im:
im.reduce = 2
im.load()
self.assertEqual(im.size, (160, 120))
for var in ["reduce", "load_reduce"]:
with Image.open("Tests/images/test-card-lossless.jp2") as im:
setattr(im, var, 2)
im.load()
self.assertEqual(im.size, (160, 120))

def test_layers_type(self):
outfile = self.tempfile("temp_layers.jp2")
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_image_reduce.py
Expand Up @@ -242,3 +242,7 @@ def test_mode_F(self):
for factor in self.remarkable_factors:
self.compare_reduce_with_reference(im, factor, 0, 0)
self.compare_reduce_with_box(im, factor)

def test_jpeg2k(self):
with Image.open("Tests/images/test-card-lossless.jp2") as im:
self.assertEqual(im.reduce(2).size, (320, 240))
11 changes: 6 additions & 5 deletions src/PIL/Jpeg2KImagePlugin.py
Expand Up @@ -176,7 +176,7 @@ def _open(self):
if self.size is None or self.mode is None:
raise SyntaxError("unable to determine size/mode")

self.reduce = 0
self.load_reduce = 0
self.layers = 0

fd = -1
Expand All @@ -200,13 +200,14 @@ def _open(self):
"jpeg2k",
(0, 0) + self.size,
0,
(self.codec, self.reduce, self.layers, fd, length),
(self.codec, self.load_reduce, self.layers, fd, length),
)
]

def load(self):
if self.reduce:
power = 1 << self.reduce
reduce = self.reduce if not callable(self.reduce) else self.load_reduce
if reduce:
power = 1 << reduce
adjust = power >> 1
self._size = (
int((self.size[0] + adjust) / power),
Expand All @@ -216,7 +217,7 @@ def load(self):
if self.tile:
# Update the reduce and layers settings
t = self.tile[0]
t3 = (t[3][0], self.reduce, self.layers, t[3][3], t[3][4])
t3 = (t[3][0], reduce, self.layers, t[3][3], t[3][4])
self.tile = [(t[0], (0, 0) + self.size, t[2], t3)]

return ImageFile.ImageFile.load(self)
Expand Down

0 comments on commit bcabaa0

Please sign in to comment.