Skip to content

Commit d1a3d6e

Browse files
committed
Usage documentation
1 parent 1120177 commit d1a3d6e

8 files changed

Lines changed: 94 additions & 6 deletions

File tree

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quirc

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
# The theme to use for HTML and HTML Help pages. See the documentation for
9292
# a list of builtin themes.
93-
html_theme = 'default'
93+
html_theme = 'nature'
9494

9595
# Theme options are theme-specific and customize the look and feel of a theme
9696
# further. For a list of options available for each theme, see the

docs/source/usage/high-level.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
High-level API
2+
==============
3+
4+
It is very simple in use::
5+
6+
import quirc
7+
from PIL import Image
8+
9+
for code in quirc.decode(Image.open('images/qr-code.png')):
10+
print code['text']
11+
12+
`quirc.decode` function returns generator, which contains results of QR codes recognition.
13+
Each item is `dict` object with those keys:
14+
15+
corners
16+
Tuple with the four corners of the QR code, from top left, clockwise
17+
size
18+
The number of cells across in the QR code
19+
version
20+
QR code version
21+
ecc_level
22+
The percentage of unreadable codewords can be restored in a QR Code symbol without data loss
23+
data_type
24+
QR code type
25+
text
26+
Encoded text

docs/source/usage/index.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Usage
22
=====
33

4-
.. automodule:: quirc
5-
:members:
4+
Library usage splits into two parts: *high-level* and *low-level* API.
5+
6+
In a sunny and beautiful world you will need only a *high-level* API.
7+
But if you are have not so much free memory or want to control whole the process, use a *low-level* API.
8+
9+
.. toctree::
10+
:maxdepth: 1
11+
12+
high-level
13+
low-level

docs/source/usage/low-level.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Low-level API
2+
==============
3+
4+
Low-level API fully copies the C API and contains all in the `quirc.api` module.
5+
6+
.. automodule:: quirc.api
7+
8+
9+
Usage
10+
-----
11+
12+
::
13+
14+
from quirc import api
15+
from PIL import Image
16+
17+
image = Image.open('images/qr-code.png')
18+
width, height = image.size
19+
20+
# Convert image to the grayscale mode
21+
if not image.mode in ('L', '1'):
22+
image = image.convert('L')
23+
pixels = image.load()
24+
25+
obj = api.new()
26+
api.resize(obj, width, height)
27+
28+
buffer = api.begin(obj, width, height)
29+
30+
# Fill buffer with a image pixels. One cell, one pixel.
31+
idx = 0
32+
for i in range(width):
33+
for j in range(height):
34+
buffer[idx] = ctypes.c_uint8(pixels[j, i])
35+
idx += 1
36+
37+
# Finish image recognition
38+
api.end(obj)
39+
40+
code = api.structures.Code()
41+
data = api.structures.Data()
42+
43+
for i in range(api.count(obj)):
44+
api.extract(obj, i, code)
45+
api.decode(code, data)
46+
47+
print ctypes.string_at(data.payload, data.payload_len)
48+
49+
api.destroy(obj)

quirc/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ def decode(image):
6161
'size': code.size,
6262
'version': data.version,
6363
'ecc_level': data.ecc_level,
64-
'mask': data.mask,
6564
'data_type': data.data_type,
6665
'text': ctypes.string_at(data.payload, data.payload_len),
67-
}
66+
}
6867

6968
api.destroy(obj)

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
99
This library is fast, small, easy to use, have a very small memory usage,
1010
and optionally requires one of the image processing libraries.
11+
12+
Links
13+
------
14+
15+
* `Documentation <http://python-quirc.readthedocs.org>`_
16+
1117
"""
1218

1319
from setuptools import setup

tests/test_quirc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def test_pil(self):
3434
code = result[0]
3535

3636
self.assertEqual(code['data_type'], 4)
37-
self.assertEqual(code['mask'], 6)
3837
self.assertEqual(code['ecc_level'], 0)
3938
self.assertEqual(code['size'], 29)
4039

0 commit comments

Comments
 (0)