Skip to main content

No project description provided

Project description

fpng_py

A C-Python wrapper for fpng, "a very fast C++ .PNG image reader/writer for 24/32bpp images."

Installation

fpng_py is available via pypi, with pre-build wheels for macOS and Windows with SSE enabled. There are no pre-build wheels for Linux, as they would require building without SSE, which would decrease the performance by a fair bit.

via pypi

pip install fpng_py

via git

pip install git+https://github.com/K0lb3/fpng_py.git

via source

pip install .

Functions

def fpng_cpu_supports_sse41() -> bool:
    """
    Returns true if the CPU supports SSE 4.1, and SSE support wasn't disabled by setting FPNG_NO_SSE=1.
    """
    ...


def fpng_crc32(data: bytes, prev_crc32: int = 0) -> int:
    """
    Computes the CRC32 of the given data.
    Fast CRC-32 SSE4.1+pclmul or a scalar fallback (slice by 4)

    Parameters
    ----------
    data : bytes
        The data to compute the CRC32 of.
    prev_crc32 : int, optional
        The previous CRC32 value. Defaults to 0.
    """
    ...


def fpng_adler32(data: bytes, adler: int = 1):
    """
    Computes the Adler32 of the given data.
    Fast Adler32 SSE4.1 Adler-32 with a scalar fallback.

    Parameters
    ----------
    data : bytes
        The data to compute the Adler32 of.
    adler : int, optional
        The previous Adler32 value. Defaults to 1.
    """
    ...


def fpng_encode_image_to_memory(
    image: bytes,
    w: int,
    h: int,
    num_chans: int = 0,
    flags: CompressionFlags = CompressionFlags.NONE,
) -> bytes:
    """
    Encodes the given image into a PNG file in memory.
    Fast PNG encoding. The resulting file can be decoded either using a standard PNG decoder or by the fpng_decode_memory() function below.

    Parameters
    ----------
    image : bytes
        binary data of RGB or RGBA image pixels, R first in memory, B/A last.
        w: int
        width of the image
    h: int
        height of the image
    num_chans: int, optional
        number of channels in the image, 3 for RGB, 4 for RGBA
        if num_chans is 0, it will be inferred from the image data.
        image's row pitch in bytes must is w*num_chans.
    flags: CompressionFlags, optional
        flags for the encoder. Defaults to 0.
    """
    ...


def fpng_encode_image_to_file(
    filename: str,
    image: bytes,
    w: int,
    h: int,
    num_chans: int = 0,
    flags: CompressionFlags = CompressionFlags.NONE,
) -> None:
    """
    Encodes the given image into a PNG file.
    Fast PNG encoding. The resulting file can be decoded either using a standard PNG decoder or by the fpng_decode_memory() function below.

    Parameters
    ----------
    filename : str
        path to the file to write the PNG to.
    image : bytes
        binary data of RGB or RGBA image pixels, R first in memory, B/A last.
    w: int
        width of the image
    h: int
        height of the image
    num_chans: int, optional
        number of channels in the image, 3 for RGB, 4 for RGBA
        if num_chans is 0, it will be inferred from the image data.
        image's row pitch in bytes must is w*num_chans.
    flags: CompressionFlags, optional
        flags for the encoder. Defaults to 0.
    """
    ...


def fpng_get_info(image: bytes) -> Tuple[int, int, int]:
    """
    Returns the width, height and number of channels of the given image.
    Fast PNG decoding of files ONLY created by fpng_encode_image_to_memory() or fpng_encode_image_to_file().
    If fpng_get_info() or fpng_decode_memory() returns FPNG_DECODE_NOT_FPNG, you should decode the PNG by falling back to a general purpose decoder.
    fpng_get_info() parses the PNG header and iterates through all chunks to determine if it's a file written by FPNG, but does not decompress the actual image data so it's relatively fast.

    Parameters
    ----------
    image : bytes
        binary data of RGB or RGBA image pixels, R first in memory, B/A last.

    Returns
    -------
    (width, height, num_chans) : Tuple[int, int, int]
    """
    ...


def fpng_decode_from_memory(
    image: bytes, desired_channels: int
) -> Tuple[bytes, int, int, int]:
    """
    Decodes the given image from memory.
    fpng_decode_memory decompresses 24/32bpp PNG files ONLY encoded by this module.
    If the image is 24bpp and 32bpp is requested, the alpha values will be set to 0xFF.
    If the image is 32bpp and 24bpp is requested, the alpha values will be discarded.

    Parameters
    ----------
    image : bytes
        binary data of RGB or RGBA image pixels, R first in memory, B/A last.
    desired_channels : int
        number of channels to decode the image to.
        3 for RGB, 4 for RGBA

    Returns
    -------
    (image, width, height, num_chans) : Tuple[bytes, int, int, int]
    """
    ...


def fpng_decode_from_file(
    filename: str, desired_channels: int
) -> Tuple[bytes, int, int, int]:
    """
    Decodes the given image from a file.

    fpng_decode_file decompresses 24/32bpp PNG files ONLY encoded by this module.
    If the image is 24bpp and 32bpp is requested, the alpha values will be set to 0xFF.
    If the image is 32bpp and 24bpp is requested, the alpha values will be discarded.

    Parameters
    ----------
    filename : str
        path to the file to decode.
    desired_channels : int
        number of channels to decode the image to.
        3 for RGB, 4 for RGBA

    Returns
    -------
    (image, width, height, num_chans) : Tuple[bytes, int, int, int]
    """
    ...

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

fpng_py_fix-0.0.3.tar.gz (285.1 kB view details)

Uploaded Source

Built Distributions

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

fpng_py_fix-0.0.3-cp313-cp313-win_amd64.whl (34.9 kB view details)

Uploaded CPython 3.13Windows x86-64

fpng_py_fix-0.0.3-cp313-cp313-macosx_15_0_arm64.whl (35.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

File details

Details for the file fpng_py_fix-0.0.3.tar.gz.

File metadata

  • Download URL: fpng_py_fix-0.0.3.tar.gz
  • Upload date:
  • Size: 285.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for fpng_py_fix-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8b48f640795a744b1d4ca4286f5be264defa651ab8af5c03398d5f64f727ae5d
MD5 d7e413c15fdb6c849d372867d721945c
BLAKE2b-256 a268bea25a1dce93de8beb91bff32ba6abfb45cb37ebec64555edbfde79e5161

See more details on using hashes here.

File details

Details for the file fpng_py_fix-0.0.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fpng_py_fix-0.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5ca572e7a20dd42edc8fef5d0574030e578f5f1ffc58addc5af1d1862b9f8612
MD5 530615632214ff4124f94f92dad9036c
BLAKE2b-256 b04dc3b9d9d53705326dc4548eb52c87089c6fda173843f7a2d9900b32489e56

See more details on using hashes here.

File details

Details for the file fpng_py_fix-0.0.3-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for fpng_py_fix-0.0.3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a66888cea3eb0430ebec51a08480f9d52d4e840031cee1c27a92555e7e7fcb96
MD5 0b0767b9cd4c8a670e6a71f9608887a1
BLAKE2b-256 3947662f93969753d81b915ad676e8bbbd47222719ede5ef7ee2a3d4bc859578

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