Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed May 1, 2021
2 parents d63a08a + f11b1ec commit e97650d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Tim Skillman, Patrick Gaunt, Tom Ritchford

Date Amends

v2.45
2021-04-30 Improvement: Found that texture widths can be any multiple of four
up to GL_MAX_TEXTURE_SIZE

v2.44
2021-03-30 Improvement: FixedString wrapping on pixel widths for accurate fitting
on screen
Expand Down
45 changes: 19 additions & 26 deletions pi3d/Texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

LOGGER = logging.getLogger(__name__)
DEFER_TEXTURE_LOADING = True
# from v.2.45 WIDTHS is deprecated but left in for backward compatibility
WIDTHS = [4, 8, 16, 32, 48, 64, 72, 96, 128, 144, 192, 256,
288, 384, 512, 576, 640, 720, 768, 800, 960, 1024, 1080, 1920]
MAX_SIZE = max(WIDTHS)
288, 384, 512, 576, 640, 720, 768, 800, 960, 1024, 1080, 1920, 2048]
MAX_SIZE = max(WIDTHS) # also deprecated from v2.45
FILE = 0
PIL_IMAGE = 1
NUMPY = 2
Expand Down Expand Up @@ -102,6 +103,7 @@ def __init__(self, file_string, blend=False, flip=False, size=0,
normal map where Luminance value is proportional to height. The
value of nomral_map is used the scale the effect (see _normal_map())
*automatic_resize*
deprecated from v2.45 - has no effect
default to True, only set to False if you have ensured that any image
dimensions match ones that the GPU can cope with, no resizing will take place.
"""
Expand Down Expand Up @@ -236,30 +238,21 @@ def _load_disk(self):
else:
resize_type = Image.NEAREST

# work out if sizes > MAX_SIZE or coerce to golden values in WIDTHS
if (self.automatic_resize): # have to explicitly turn off as can cause image scrambling
widths = WIDTHS
from pi3d.Display import Display
if Display.INSTANCE is not None:
max_texture_size = Display.INSTANCE.opengl.max_texture_size.value
if max_texture_size > widths[-1]: # OpenGL size is greater than last in list so add powers of two up to this
pwr = int(np.log(max_texture_size) / np.log(2)) # use np seeing as it's already imported!
last_pwr = int(np.log(widths[-1]) / np.log(2))
extend_list = [2 ** i for i in range(last_pwr + 1, pwr + 1)]
widths.extend(extend_list)
max_size = max(widths)
if self.iy > self.ix and self.iy > max_size: # fairly rare circumstance
im = im.resize((int((max_size * self.ix) / self.iy), max_size))
self.ix, self.iy = im.size
n = len(widths)
for i in xrange(n-1, 0, -1):
if self.ix == widths[i]:
break # no need to resize as already a golden size
if self.ix > widths[i]:
im = im.resize((widths[i], int((widths[i] * self.iy) / self.ix)),
resize_type)
self.ix, self.iy = im.size
break
# work out if sizes > MAX_SIZE or coerce to multiple of 4
(new_w, new_h) = (self.ix, self.iy)
from pi3d.Display import Display
if Display.INSTANCE is not None:
max_size = Display.INSTANCE.opengl.max_texture_size.value
else:
max_size = MAX_SIZE
if new_h > new_w and new_h > max_size: # fairly rare circumstance
(new_w, new_h) = (int(max_size * new_x / new_h), max_size)
if (new_w % 4) != 0:
new_w = int(new_w / 4) * 4
new_h = int(self.iy * new_w / self.ix)
if new_w != self.ix: # only resize if had to change width
im = im.resize((new_w, new_h), resize_type)
(self.ix, self.iy) = (new_w, new_h)

LOGGER.debug('Loading ...%s', s)

Expand Down
2 changes: 1 addition & 1 deletion pi3d/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import logging

__version__ = '2.44'
__version__ = '2.45'
year = time.localtime().tm_year

STARTUP_MESSAGE = """
Expand Down
7 changes: 1 addition & 6 deletions pi3d/util/FixedString.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,8 @@ def __init__(self, font, string, camera=None, color=(255,255,255,255),
if line_wid > maxwid:
maxwid = line_wid
maxwid += 2.0 * margin
texture_wid = WIDTHS[-1]
texture_wid = min(int(maxwid / 4) * 4, 2048)
nlines = len(lines)

for l in WIDTHS:
if l > maxwid:
texture_wid = l
break
texture_hgt = int(nlines * height + 2 * margin)

self.im = Image.new("RGBA", (texture_wid, texture_hgt), background_color)
Expand Down

0 comments on commit e97650d

Please sign in to comment.