apngasm_python._apngasm_python¶
Classes¶
Class representing APNG file, storing APNGFrame(s) and other metadata. |
|
Class representing a frame in APNG. |
|
Class for APNGAsmListener. Meant to be used internally. |
|
Class for RGB object. Meant to be used internally. |
|
Class for RGBA object. Meant to be used internally. |
Functions¶
|
Creates an APNGFrame from a bitmapped array of RBG pixel data. |
|
Creates an APNGFrame from a bitmapped array of RBG pixel data, with one color treated as transparent. |
|
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.
-
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.
- disassemble(file_path: str) list[APNGFrame]¶
Disassembles an APNG file.
- save_pngs(output_dir: str) bool¶
Saves individual PNG files of the frames in the frame vector.
- 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
- save_json(output_path: str, image_dir: str) bool¶
Saves a JSON animation spec file.
- save_xml(output_path: str, image_dir: str) bool¶
Saves an XML animation spec file.
-
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_skip_first(skip_first: bool) None¶
Set flag of skip first frame.
- is_skip_first() bool¶
Returns the flag of skip first frame.
- 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.
- 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.
- 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.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.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:¶