Skip to main content

Python implementation of swizzle and deswizzle of video games textures

Project description

A python library which allow to swizzle and deswizzle some video games textures. Supported platforms: Nintendo Switch and PS4

Usage

Nintendo Switch:

from pyswizzle import nsw_deswizzle, nsw_swizzle

Deswizzle bytes:

deswizzled_bytes = nsw_deswizzle(bytes, im_size, block_size, bytes_per_block, swizzle_mode)

Swizzle bytes:

swizzled_bytes = nsw_swizzle(bytes, im_size, block_size, bytes_per_block, swizzle_mode)

PS4:

from pyswizzle import ps4_deswizzle, ps4_swizzle

Deswizzle bytes:

deswizzled_bytes = ps4_deswizzle(bytes, im_size, block_size, bytes_per_block)

Swizzle bytes:

swizzled_bytes = ps4_deswizzle(bytes, im_size, block_size, bytes_per_block)

Parameters

bytes: a bytes-like object, representing image data

im_size: a tuple (im_width,im_height) representing the dimensions of the image.

block_size: a tuple (bloc_width,bloc_height) representing the dimensions of the compression blocks of the image encoding. For example, BC7 and BC1 are encoded with blocks of 4x4 pixels, so you should input (4,4), while ASTC6x6 are encoded with blocks of 6x6 pixels, so you should input (6,6). For format that are not block compressed like RGBA8888, you should input (1,1).

bytes_per_block: the number of bytes used to encode one block. For BC7, it's equal to 16; for BC1: 8; for ASTC6x6: 16; for RGBA8888: 4, etc.

swizzle_mode: the swizzle mode, for Nintendo Switch.

Notes

Not all images can be swizzled or deswizzled, they might require some padding.

For Nintendo Switch, the image width must be a multiple of 64 x block_width / bytes_per_block pixels,
and the image_height a multiple of 8 x block_height x (2**swizzle_mode) pixels.

For PS4, the image width must be a multiple of 8 x block_width pixels,
and the image_height a multiple of 8 x block_height pixels.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyswizzle-1.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pyswizzle-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyswizzle-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for pyswizzle-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9a5ccfc2ae764cd7c244ef45c4e896bd388a7f31a2640036c1aff93a2e82a5e6
MD5 1d583968404fadfc98e777bde2c177e9
BLAKE2b-256 dfff8b4373a151bc223a31945a1a8f91a94320c48261e2472a1fa962054415c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page