apngasm_python._apngasm_python

Classes

APNGAsm

Class representing APNG file, storing APNGFrame(s) and other metadata.

APNGFrame

Class representing a frame in APNG.

IAPNGAsmListener

Class for APNGAsmListener. Meant to be used internally.

rgb

Class for RGB object. Meant to be used internally.

rgba

Class for RGBA object. Meant to be used internally.

Functions

create_frame_from_rgb()], width, height, delay_num, ...)

Creates an APNGFrame from a bitmapped array of RBG pixel data.

create_frame_from_rgb_trns()], width, height, ...)

Creates an APNGFrame from a bitmapped array of RBG pixel data, with one color treated as transparent.

create_frame_from_rgba()], width, height, delay_num, ...)

Creates an APNGFrame from a bitmapped array of RBGA pixel data.

Module Contents

class apngasm_python._apngasm_python.APNGAsm
class apngasm_python._apngasm_python.APNGAsm(frames: collections.abc.Sequence[APNGFrame])

Class representing APNG file, storing APNGFrame(s) and other metadata.

add_frame(frame: APNGFrame) int

Adds an APNGFrame object to the frame vector.

Parameters:
frame : apngasm_python._apngasm_python.APNGFrame

The APNGFrame object to be added.

Returns:

The new number of frames/the number of this frame on the frame vector.

Return type:

int

add_frame_from_file(file_path: str, delay_num: int = 100, delay_den: int = 1000) int

Adds a frame from a PNG file or frames from a APNG file to the frame vector.

Parameters:
file_path : str

The relative or absolute path to an image file.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR).

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR).

Returns:

The new number of frames/the number of this frame on the frame vector.

Return type:

int

add_frame_from_rgb(pixels_rgb: rgb, width: int, height: int, trns_color: rgb | None, delay_num: int = 100, delay_den: int = 1000) int

Adds an APNGFrame object to the vector. Not possible to use in Python. As alternative, Use create_frame_from_rgb() or create_frame_from_rgba(). Or manually, First create an empty APNGFrame with frame = APNGFrame(), then set frame.width, frame.height, frame.color_type, frame.pixels, frame.palette, frame.delay_num, frame.delay_den manually.

Parameters:
pixels_rgb : apngasm_python._apngasm_python.rgb

The RGB pixel data.

width : int

The width of the pixel data.

height : int

The height of the pixel data.

trns_color : apngasm_python._apngasm_python.rgb

The color [r, g, b] to be treated as transparent.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR).

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR).

Returns:

The new number of frames/the number of this frame on the frame vector.

Return type:

int

add_frame_from_rgba(pixels_rgba: rgba, width: int, height: int, delay_num: int = 100, delay_den: int = 1000) int

Adds an APNGFrame object to the vector. Not possible to use in Python. As alternative, Use create_frame_from_rgb() or create_frame_from_rgba(). Or manually, First create an empty APNGFrame with frame = APNGFrame(), then set frame.width, frame.height, frame.color_type, frame.pixels, frame.palette, frame.delay_num, frame.delay_den manually.

Parameters:
pixels_rgba : apngasm_python._apngasm_python.rgba

The RGBA pixel data.

width : int

The width of the pixel data.

height : int

The height of the pixel data.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR).

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR).

Returns:

The new number of frames/the number of this frame on the frame vector.

Return type:

int

assemble(output_path: str) bool

Assembles and outputs an APNG file.

Parameters:
output_path : str

The output file path.

Returns:

true if assemble completed succesfully.

Return type:

bool

disassemble(file_path: str) list[APNGFrame]

Disassembles an APNG file.

Parameters:
file_path : str

The file path to the PNG image to be disassembled.

Returns:

A vector containing the frames of the disassembled PNG.

Return type:

list[apngasm_python._apngasm_python.APNGFrame]

save_pngs(output_dir: str) bool

Saves individual PNG files of the frames in the frame vector.

Parameters:
output_dir : str

The directory where the PNG fils will be saved.

Returns:

true if all files were saved successfully.

Return type:

bool

load_animation_spec(file_path: str) list[APNGFrame]

Loads an animation spec from JSON or XML. Loaded frames are added to the end of the frame vector. For more details on animation specs see: https://github.com/Genshin/PhantomStandards

Parameters:
file_path : str

The path of JSON or XML file.

Returns:

A vector containing the frames

Return type:

list[apngasm_python._apngasm_python.APNGFrame]

save_json(output_path: str, image_dir: str) bool

Saves a JSON animation spec file.

Parameters:
output_path : str

Path to save the file to.

image_dir : str

Directory where frame files are to be saved if not the same path as the animation spec.

Returns:

true if save was successful.

Return type:

bool

save_xml(output_path: str, image_dir: str) bool

Saves an XML animation spec file.

Parameters:
file_path : str

Path to save the file to.

image_dir : str

Directory where frame files are to be saved if not the same path as the animation spec.

Returns:

true if save was successful.

Return type:

bool

set_apngasm_listener(listener: IAPNGAsmListener | None = None) None

Sets a listener.

Parameters:
listener : Optional[apngasm_python._apngasm_python.IAPNGAsmListener]

A pointer to the listener object. If the argument is NULL a default APNGAsmListener will be created and assigned.

set_loops(loops: int = 0) None

Set loop count of animation.

Parameters:
loops : int

Loop count of animation. If the argument is 0 a loop count is infinity.

set_skip_first(skip_first: bool) None

Set flag of skip first frame.

Parameters:
skip_first : int

Flag of skip first frame.

get_frames() list[APNGFrame]

Returns the frame vector.

Returns:

frame vector.

Return type:

list[apngasm_python._apngasm_python.APNGFrame]

get_loops() int

Returns the loop count.

Returns:

loop count.

Return type:

int

is_skip_first() bool

Returns the flag of skip first frame.

Returns:

flag of skip first frame.

Return type:

bool

frame_count() int

Returns the number of frames.

Returns:

number of frames.

Return type:

int

reset() int

Destroy all frames in memory/dispose of the frame vector. Leaves the apngasm object in a clean state. Returns number of frames disposed of.

Returns:

number of frames disposed of.

Return type:

int

version() str

Returns the version of APNGAsm.

Returns:

the version of APNGAsm.

Return type:

str

class apngasm_python._apngasm_python.APNGFrame
class apngasm_python._apngasm_python.APNGFrame(file_path: str, delay_num: int = 100, delay_den: int = 1000)
class apngasm_python._apngasm_python.APNGFrame(pixels: rgb, width: int, height: int, trns_color: rgb, delay_num: int = 100, delay_den: int = 1000)
class apngasm_python._apngasm_python.APNGFrame(pixels: rgba, width: int, height: int, delay_num: int = 100, delay_den: int = 1000)

Class representing a frame in APNG.

save(out_path: str) bool

Saves this frame as a single PNG file.

Parameters:
out_path : str

The relative or absolute path to save the image file to.

Returns:

true if save was successful.

Return type:

bool

property pixels : Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=None, None, None)]

The raw pixel data of frame, expressed as a 3D numpy array in Python. Note that setting this value will also set the variable ‘rows’ internally. This should be set AFTER you set the width, height and color_type.

property width : int

The width of frame.

property height : int

The height of frame.

property color_type : int

The color_type of the frame.

0: Grayscale (Pillow mode=’L’) 2: RGB (Pillow mode=’RGB’) 3: Palette (Pillow mode=’P’) 4: Grayscale + Alpha (Pillow mode=’LA’) 6: RGBA (Pillow mode=’RGBA’)

property palette : Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=256, 3)]

The palette data of frame. Only applies to ‘P’ mode Image (i.e. Not RGB, RGBA). Expressed as 2D numpy array in format of [[r0, g0, b0], [r1, g1, b1], …, [r255, g255, b255]] in Python.

property transparency : Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=None)]

The transparency color of frame that is treated as transparent, expressed as 1D numpy array. For more info, refer to ‘tRNS Transparency’ in http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html

property palette_size : int

The palette data size of frame.

property transparency_size : int

The transparency data size of frame.

property delay_num : int

The nominator of the duration of frame. Duration of time is delay_num / delay_den seconds.

property delay_den : int

The denominator of the duration of frame. Duration of time is delay_num / delay_den seconds.

class apngasm_python._apngasm_python.IAPNGAsmListener

Class for APNGAsmListener. Meant to be used internally.

apngasm_python._apngasm_python.create_frame_from_rgb(pixels: Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=None, None, 3)], width: int, height: int, delay_num: int = 100, delay_den: int = 1000) APNGFrame

Creates an APNGFrame from a bitmapped array of RBG pixel data.

Parameters:
pixels : numpy.typing.NDArray

The RGB pixel data, expressed as 3D numpy array.

width : int

The width of the pixel data.

height : int

The height of the pixel data.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR).

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR).

Returns:

A APNGFrame object.

Return type:

apngasm_python._apngasm_python.APNGFrame

apngasm_python._apngasm_python.create_frame_from_rgb_trns(pixels: Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=None, None, 3)], width: int, height: int, trns_color: Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=3)], delay_num: int = 100, delay_den: int = 1000) APNGFrame

Creates an APNGFrame from a bitmapped array of RBG pixel data, with one color treated as transparent.

Parameters:
pixels : numpy.typing.NDArray

The RGB pixel data, expressed as 3D numpy array.

width : int

The width of the pixel data.

height : int

The height of the pixel data.

trns_color : numpy.typing.NDArray

The color [r, g, b] to be treated as transparent, expressed as 1D numpy array.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR).

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR).

Returns:

A APNGFrame object.

Return type:

apngasm_python._apngasm_python.APNGFrame

apngasm_python._apngasm_python.create_frame_from_rgba(pixels: Annotated[numpy.typing.ArrayLike, dict(dtype='uint8', shape=None, None, 4)], width: int, height: int, delay_num: int = 100, delay_den: int = 1000) APNGFrame

Creates an APNGFrame from a bitmapped array of RBGA pixel data.

Parameters:
pixels : numpy.typing.NDArray

The RGBA pixel data, expressed as 3D numpy array.

width : int

The width of the pixel data.

height : int

The height of the pixel data.

delay_num : int

The delay numerator for this frame (defaults to DEFAULT_FRAME_NUMERATOR)

delay_den : int

The delay denominator for this frame (defaults to DEFAULT_FRAME_DENMINATOR)

Returns:

A APNGFrame object.

Return type:

apngasm_python._apngasm_python.APNGFrame

class apngasm_python._apngasm_python.rgb
class apngasm_python._apngasm_python.rgb(arg0: int, arg1: int, arg2: int, /)

Class for RGB object. Meant to be used internally.

property r : int
property g : int
property b : int
class apngasm_python._apngasm_python.rgba
class apngasm_python._apngasm_python.rgba(arg0: int, arg1: int, arg2: int, arg3: int, /)

Class for RGBA object. Meant to be used internally.

property r : int
property g : int
property b : int
property a : int