Skip to main content

Image resizing using Scale2x, Scale3x, Scale2xSFX and Scale3xSFX algorithms, in pure Python.

Project description

Pixel art image scaling - Scale2x, Scale3x, Scale2xSFX and Scale3xSFX in pure Python

PyPI - Python Version PyPI - Version

Overview

ScaleNx, encompassing Scale2x, Scale3x, Scale2xSFX, and Scale3xSFX, is a group of pixel-art scaling algorithms, intended to rescale images without blurring sharp edges.

Scale2x and Scale3x (aka AdvMAME2x and AdvMAME3x) algorithms were developed by Andrea Mazzoleni for the sole purpose of scaling up small graphics like icons and game sprites while keeping sharp edges and avoiding blurs.

Later on versions called Scale2xSFX and Scale3xSFX were introduced for the same purpose, providing better diagonals rendering and less artifacts on some patterns.

Fig. 1. Example of consecutive upscaling with Scale3xSFX.
Consecutive upscaling with Scale3xSFX
Consecutive upscaling of tiny diagonal object with Scale3xSFX thrice. Source object on the left upscaled 3x3x3=27 times bigger in linear size, i.e. 27x27=729 times bigger by area, meaning that 728 out of 729 resulting pixels are purely artificial; yet the result looks surprisingly clear.

Being initially created for tiny game sprite images, these algorithms appeared to be useful for some completely different tasks, e.g. scaling up text scans with low resolution before OCR, to improve OCR quality, or upscaling old low quality gravure and line art prints. One of the advantages of these algorithms is that they don't use any empirical chroma mask or something else specifically adopted for game sprites on screen, and therefore are capable to work efficiently on any image, including images intended for print.

Fig. 2. Example of low resolution drawing upscaling with Scale3xSFX.
Upscaling with Scale3xSFX
Jagged lines of low resolution original are turned into smoother diagonals.

Unfortunately, while specialised Scale2x and Scale3x screen renderers (e.g. for DOS emulators) are numerous, it appears to be next to impossible to find ready-made batch processing application working with arbitrary images in common graphics formats.

Therefore, current general purpose pure Python implementation of algorithms above was developed. Current implementation does not use any import, neither Python standard nor third party, and therefore is quite cross-platform and next to omnicompatible.

Note that current PyPI-distributed package is intended for developers, and therefore include ScaleNx core module only. For example of practical Python program utilizing this module, with Tkinter GUI, multiprocessing etc., please visit ScaleNx at Github (PNG support in this program is based on PyPNG, and PPM and PGM support - on PyPNM, both of the above being pure Python modules as well).

Python compatibility

Current ScaleNx version is maximal backward compatibility build, created for PyPI distribution. While most of the development was performed using Python 3.12, testing with other versions was carried out, and ScaleNx proven to work with antique Python 3.4 under Windows XP 32-bit.

Installation

python -m pip install --upgrade scalenx, then from scalenx import scalenx, scalenxsfx.

Usage

Example for Scale3xSFX:

scaled_image = scalenxsfx.scale3x(source_image)

where both images are of 3D nested list (image) of lists (rows) of lists (pixels) of int (channel values) type.

Note that functions names in scalenx and scalenxsfx match, making it easy to switch external software from older scalenx to scalenxsfx or vs. by changing one import line. When creating new software, one may easily make it reconfigurable with reassigning functions names, like

if use_sfx:
    chosen_scaler = scalenxsfx.scale2x
else:
    chosen_scaler = scalenx.scale2x

scaled_image = chosen_scaler(source_image)

Copyright and redistribution

Current Python implementation was written by Ilya Razmanov and may be freely used, copied and improved. In case of making substantial improvements it's almost obligatory to share your work with the developer and lesser species.

References

  1. Scale2x and Scale3x algorithms description by the inventor, Andrea Mazzoleni.

  2. Scale2xSFX and Scale3xSFX algorithms description at forums archive.

  3. Pixel-art scaling algorithms review at Wikipedia.

  4. ScaleNx source code at Github - current ScaleNx source at Github, containing main program for single and batch image processing, with GUI, multiprocessing etc..

  5. ScaleNx source code for Python 3.4 at Github - same as above, but fully compatible with Python 3.4 (both ScaleNx and image formats I/O and main application).

Project details


Download files

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

Source Distribution

scalenx-2025.9.25.34.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

scalenx-2025.9.25.34-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file scalenx-2025.9.25.34.tar.gz.

File metadata

  • Download URL: scalenx-2025.9.25.34.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for scalenx-2025.9.25.34.tar.gz
Algorithm Hash digest
SHA256 5ed9d9ad7a4d8f0ace17869e475ee5f89f05fe586c900ad774e2b83571365cfe
MD5 d10e41ad494ef478295880647635b2c3
BLAKE2b-256 db6ac12e9b0ba20fe639fcb0f14983e531d2c260c109aa7e6d25821b0a345cd2

See more details on using hashes here.

File details

Details for the file scalenx-2025.9.25.34-py3-none-any.whl.

File metadata

  • Download URL: scalenx-2025.9.25.34-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for scalenx-2025.9.25.34-py3-none-any.whl
Algorithm Hash digest
SHA256 fea52eebde0d8f32e752ba64fb204f905cde8f402fd82d34b4e14738922a22d1
MD5 b31dacf25196327fcd089b18ef5496d6
BLAKE2b-256 9eea43a8e826bc749cdf74c4e9a45804d73cdfd9a8b4968e2679d7a1c759b7e6

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