Skip to content

Commit c62e68e

Browse files
committed
PyPNG 0.20231004.0
1 parent c311b1f commit c62e68e

File tree

2 files changed

+41
-49
lines changed

2 files changed

+41
-49
lines changed

pypng/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
"""Type `from pypng import pnglpng` to get access to functions."""
1+
"""
2+
Type::
3+
4+
from pypng import pnglpng
5+
6+
or::
7+
8+
from pypng.pnglpng import list2png, png2list
9+
10+
to get access to functions.
11+
12+
"""

pypng/pnglpng.py

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,48 @@
88
Joint between PyPNG and other programs
99
--------------------------------------
1010
11-
Created by: `Ilya Razmanov<mailto:ilyarazmanov@gmail.com>`_
12-
aka `Ilyich the Toad<mailto:amphisoft@gmail.com>`_.
13-
1411
Overview
15-
---------
12+
--------
1613
1714
**pnglpng** (png-list-png) is a suitable joint between `PyPNG`_
1815
and other Python programs, providing data conversion from/to used by PyPNG
1916
to/from understandable by ordinary average human.
2017
2118
Functions included are:
2219
23-
:png2list: reading PNG file and returning all data;
24-
:list2png: getting data and writing PNG file;
25-
:create_image: creating empty nested 3D list for image representation.
20+
- ``png2list``: reading PNG file and returning all data;
21+
- ``list2png``: getting data and writing PNG file;
22+
- ``create_image``: creating empty nested 3D list for image representation.
2623
2724
Installation
28-
-------------
25+
------------
2926
3027
Should be kept together with ``png.py`` module. See ``import`` for detail.
3128
3229
Usage
33-
------
34-
35-
After ``import pnglpng``, use something like
30+
-----
3631
37-
::
32+
After ``import pnglpng``, use something like::
3833
3934
X, Y, Z, maxcolors, list_3d, info = pnglpng.png2list(in_filename)
4035
41-
for reading data from ``in_filename`` PNG, where:
42-
43-
:X, Y, Z: image dimensions (int);
44-
:maxcolors: number of colors per channel for current image (int);
45-
:list_3d: image pixel data as list(list(list(int)));
46-
:info: PNG chunks like resolution etc (dictionary);
36+
for reading data from PNG file, where:
4737
48-
and
38+
- ``X``, ``Y``, ``Z``: PNG image dimensions (int);
39+
- ``maxcolors``: number of colors per channel for current image (int), either 1, or 255, or 65535, for 1 bpc, 8 bpc and 16 bpc PNG respectively;
40+
- ``list_3d``: Y * X * Z list (image) of lists (rows) of lists (pixels) of ints (channels), from PNG iDAT;
41+
- ``info``: dictionary of PNG chunks like resolution etc., as they are accessible by PyPNG.
4942
50-
::
43+
and ::
5144
5245
pnglpng.list2png(out_filename, list_3d, info)
5346
54-
for writing data to ``out_filename`` PNG.
47+
for writing data as listed above to ``out_filename`` PNG.
5548
56-
Prerequisites and References
57-
----------------------------
49+
References
50+
----------
5851
59-
1. `PyPNG`_
52+
1. `PyPNG`_ download
6053
2. `PyPNG docs`_
6154
6255
.. _PyPNG: https://gitlab.com/drj11/pypng
@@ -84,19 +77,13 @@
8477
def png2list(in_filename):
8578
"""Take PNG filename and return PNG data in a human-friendly form.
8679
87-
Usage
88-
89-
::
90-
91-
X, Y, Z, maxcolors, list_3d, info = pnglpng.png2list(in_filename)
80+
:param str in_filename: input file name;
81+
:return X, Y, Z, maxcolors, list_3d, info: tuple, consisting of:
9282
93-
Takes PNG filename ``in_filename`` and return the following tuple
94-
95-
:X, Y, Z: PNG image dimensions (int);
96-
:maxcolors: number of colors per channel for current image (int),
97-
either 1, or 255, or 65535, for 1 bpc, 8 bpc and 16 bpc PNG respectively;
98-
:list_3d: Y * X * Z list (image) of lists (rows) of lists (pixels) of ints (channels), from PNG iDAT;
99-
:info: dictionary from PNG chunks like resolution etc. as they are accessible by PyPNG.
83+
- ``X``, ``Y``, ``Z``: PNG image dimensions (int);
84+
- ``maxcolors``: number of colors per channel for current image (int), either 1, or 255, or 65535, for 1 bpc, 8 bpc and 16 bpc PNG respectively;
85+
- ``list_3d``: Y * X * Z list (image) of lists (rows) of lists (pixels) of ints (channels), from PNG iDAT;
86+
- ``info``: dictionary of PNG chunks like resolution etc., as they are accessible by PyPNG.
10087
10188
"""
10289

@@ -128,18 +115,12 @@ def png2list(in_filename):
128115
def list2png(out_filename, list_3d, info):
129116
"""Take filename and image data, and create PNG file.
130117
131-
Usage
132-
133-
::
134-
135-
pnglpng.list2png(out_filename, list_3d, info)
136-
137-
Take data described below and write PNG file `out_filename` out of it.
138-
139-
:list_3d: Y * X * Z list (image) of lists (rows) of lists (pixels) of ints (channels);
140-
:info: dictionary, chunks like resolution etc. as you want them to be present in PNG.
118+
:param list_3d: Y * X * Z list (image) of lists (rows) of lists (pixels) of ints (channels);
119+
:param info: dictionary, chunks like resolution etc. as you want them to be present in PNG;
120+
:param str out_filename: output PNG file name (str).
141121
142-
Note that ``X``, ``Y`` and ``Z`` detected from the list structure override those set in ``info``.
122+
.. note:: ``X``, ``Y`` and ``Z`` detected from the list structure override those set in ``info``.
123+
.. warning:: Correct ``info['bitdepth']`` is **critical** because it cannot be detected from the list structure.
143124
144125
"""
145126

@@ -177,7 +158,7 @@ def flatten_2d(list_3d):
177158

178159
yield from ([list_3d[y][x][z] for x in range(X) for z in range(Z)] for y in range(Y))
179160

180-
# ↓ Writing PNG with `.write` method (row by row),
161+
# ↓ Writing PNG with `.write` method (row by row),
181162
# using `flatten_2d` generator to save memory
182163
writer = png.Writer(X, Y, **info)
183164
with open(out_filename, 'wb') as result_png:

0 commit comments

Comments
 (0)