Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions =2.3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Using version ^2.27.0 for imageio

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 2 installs, 0 updates, 0 removals

• Installing pillow (9.5.0)
• Installing imageio (2.27.0)
8 changes: 8 additions & 0 deletions =3.2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Using version ^9.5.0 for Pillow

Updating dependencies
Resolving dependencies...

Writing lock file

No dependencies to install or update
156 changes: 156 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion pylibdmtx/pylibdmtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
32: DmtxPackOrder.DmtxPack32bppRGBX,
}

FNC1_VAL = '\xe8'


@contextmanager
def _image(pixels, width, height, pack):
Expand Down Expand Up @@ -313,7 +315,7 @@ def _encoder():
dmtxEncodeDestroy(byref(encoder))


def encode(data, scheme=None, size=None):
def encode(data, scheme=None, size=None, fnc1=False, module=1, margin=0):
"""
Encodes `data` in a DataMatrix image.

Expand All @@ -325,6 +327,9 @@ def encode(data, scheme=None, size=None):
If `None`, defaults to 'Ascii'.
size: image dimensions - one of `ENCODING_SIZE_NAMES`, or `None`.
If `None`, defaults to 'ShapeAuto'.
fnc1: (T/F) whether to generate GS1 datamatrix
module: pixels per module
margin: pixels on margin (blank)

Returns:
Encoded: with properties `(width, height, bpp, pixels)`.
Expand Down Expand Up @@ -356,9 +361,16 @@ def encode(data, scheme=None, size=None):
)
scheme = getattr(DmtxScheme, scheme_name)

if fnc1:
data = b'\xe8' + data

with _encoder() as encoder:
dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropScheme, scheme)
dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropSizeRequest, size)
if fnc1:
dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropFnc1, 0xe8)
dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropModuleSize, module)
dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropMarginSize, margin)

if dmtxEncodeDataMatrix(encoder, len(data), cast(data, c_ubyte_p)) == 0:
raise PyLibDMTXError(
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "pylibdmtx"
version = "0.1.1"
description = "Pylibdmtx fork, with FNC1, margin, and module size exposure."
authors = ["matt <matt@appliedinvention.com>"]
readme = "README.rst"

[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.24.2"
imageio = "^2.27.0"
Pillow = "^9.5.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"