Coder Social home page Coder Social logo

fpng_py's Introduction

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]
    """
    ...

fpng_py's People

Contributors

k0lb3 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.