mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-28 04:23:37 +01:00
fxsdk: round RGB16 images to even widths
This allows 4-alignment on the input to be preserved from line to line, which is very valuable for rendering optimizations.
This commit is contained in:
parent
27e60884c3
commit
6788a7b5fe
1 changed files with 11 additions and 5 deletions
|
@ -1096,14 +1096,20 @@ def r5g6b5(img, color_count=0, trim_palette=False, palette_base=0, alpha=None):
|
|||
# Create byte arrays with pixel data and palette data
|
||||
#---
|
||||
|
||||
pixel_count = img.width * img.height
|
||||
stride = 0
|
||||
|
||||
if not color_count:
|
||||
size = pixel_count * 2
|
||||
# In RGB16, preserve alignment between rows
|
||||
stride = (img.width + 1) // 2 * 2
|
||||
size = stride * img.height * 2
|
||||
elif color_count == 256:
|
||||
size = pixel_count
|
||||
# No constraint in P8
|
||||
size = img.width * img.height
|
||||
stride = img.width
|
||||
elif color_count == 16:
|
||||
size = ((img.width + 1) // 2) * img.height
|
||||
# In P4, pad whole bytes
|
||||
stride = (img.width + 1) // 2
|
||||
size = stride * img.height
|
||||
|
||||
# Result of encoding
|
||||
encoded = bytearray(size)
|
||||
|
@ -1116,8 +1122,8 @@ def r5g6b5(img, color_count=0, trim_palette=False, palette_base=0, alpha=None):
|
|||
|
||||
if not color_count:
|
||||
c = alpha_encoding(rgb24to16(pixels[x, y]), a)
|
||||
offset = (stride * y + x) * 2
|
||||
encoded[offset:offset+2] = u16(c)
|
||||
offset += 2
|
||||
|
||||
elif color_count == 16:
|
||||
c = palette_remap[pixels[x, y]][0] if a > 0 else alpha
|
||||
|
|
Loading…
Reference in a new issue