Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an assortment of grok parameters that can be set #2

Merged
merged 6 commits into from
Dec 13, 2023
Merged
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
9 changes: 1 addition & 8 deletions RELEASING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Announcing
Post-release actions
--------------------

- Edit *VERSION* symbols in blosc2_btune/__init__.py *and* pyproject.toml in main to increment the
- Edit *VERSION* symbols in blosc2_grok/__init__.py *and* pyproject.toml in main to increment the
version to the next minor one (i.e. X.Y.Z --> X.Y.(Z+1).dev).

- Create new headers for adding new features in ``RELEASE_NOTES.md``
Expand All @@ -73,10 +73,3 @@ Post-release actions
$ git push

That's all folks!


.. Local Variables:
.. mode: rst
.. coding: utf-8
.. fill-column: 70
.. End:
105 changes: 50 additions & 55 deletions blosc2_grok/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Blosc - Blocked Shuffling and Compression Library
##############################################################################
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (C) 2023 The Blosc Developers <[email protected]>
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: BSD 3-Clause (see LICENSE.txt)
#
# See LICENSE.txt for details about copyright and rights to use.
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

import ctypes
import os
Expand All @@ -17,22 +17,6 @@
__version__ = "0.0.2.dev"


class GrkProgOrder(Enum):
"""
Available grok progression orders.
`L` : layer
`R` : resolution
`C` : component
`P` : precinct
"""

LRCP = 0
RLCP = 1
RPCL = 2
PCRL = 3
CPRL = 4


class GrkFileFmt(Enum):
"""
Supported file formats in grok.
Expand Down Expand Up @@ -123,34 +107,30 @@ def destroy():
lib.blosc2_grok_destroy()


# TODO: change these for real defaults
# TODO: change these by the actual defaults
params_defaults = {
'tile_size_on': False,
'tx0': 0,
'ty0': 0,
't_width': 0,
't_height': 0,
'tile_size': (0, 0),
'tile_offset': (0, 0),
# 'numlayers': 0, # blosc2_grok C func set_params will still receive this param
'quality_mode': None,
'quality_layers': np.zeros(0, dtype=np.float64),
'csty': 0,
'numgbits': 2,
'prog_order': GrkProgOrder.LRCP,
'numpocs': 0,
'numresolution': 6,
'cblockw_init': 64,
'cblockh_init': 64,
'cblk_sty': 0,
'progression': "LRCP",
'num_resolutions': 6,
'codeblock_size': (64, 64),
# 10 - 19
'codeblock_style': 0,
# 'irreversible': False, # blosc2_grok C func set_params will still receive this param
'roi_compno': -1,
'roi_shift': 0,
'res_spec': 0,
'image_offset_x0': 0,
'image_offset_y0': 0,
'precinct_size': (0, 0),
'offset': (0, 0),
'subsampling_dx': 1,
'subsampling_dy': 1,
'decod_format': GrkFileFmt.GRK_FMT_UNK,
'cod_format': GrkFileFmt.GRK_FMT_UNK,
# 20 - 29
'enableTilePartGeneration': False,
'newTilePartProgressionDivider': 0,
'mct': 0,
Expand All @@ -159,14 +139,15 @@ def destroy():
'rsiz': GrkProfile.GRK_PROFILE_NONE,
'framerate': 0,
'apply_icc_': False,
'rateControlAlgorithm': GrkRateControl.PCRD_OPT,
'rateControlAlgorithm': GrkRateControl.BISECT,
'numThreads': 0,
# 30 - 37
'deviceId': 0,
'duration': 0,
'kernelBuildOptions': 0,
'repeats': 1,
'writePLT': False,
'writeTLM': False,
'plt': False,
'tlm': False,
'verbose': False,
'sharedMemoryInterface': False,
}
Expand All @@ -183,25 +164,39 @@ def set_params_defaults(**kwargs):
params.update(kwargs)
args = params.values()
args = list(args)
if args[5] is not None:
args[5] = args[5].encode('utf-8')
# Get number of layers
args.insert(5, args[6].shape[0])
else:
args.insert(5, 0)

args.insert(16, False) # irreversible param is deactivated for now
# Get number of layers
args.insert(2, 0)
if args[3] is not None:
args[3] = args[3].encode('utf-8')
args[2] = args[4].shape[0]

args[10] = args[10].value
args[24] = args[24].value
args[25] = args[25].value
args[31] = args[31].value
args[34] = args[34].value
args.insert(11, False) # irreversible param is deactivated for now

args[7] = args[7].encode('utf-8')

lib.blosc2_grok_set_default_params.argtypes = ([ctypes.c_bool] + [ctypes.c_int] * 5 + [ctypes.c_char_p] +
[np.ctypeslib.ndpointer(dtype=np.float64)] +
[ctypes.c_int] * 8 + [ctypes.c_bool] + [ctypes.c_int] * 9 +
[ctypes.c_bool] + [ctypes.c_int] * 6 + [ctypes.c_bool] +
# Convert tuples to desired NumPy arrays
args[0] = np.array(args[0], dtype=np.int64)
args[1] = np.array(args[1], dtype=np.int64)
args[9] = np.array(args[9], dtype=np.int64)
args[14] = np.array(args[14], dtype=np.int64)
args[15] = np.array(args[15], dtype=np.int64)

# Get value of enumerate
args[18] = args[18].value
args[19] = args[19].value
args[25] = args[25].value
args[28] = args[28].value

lib.blosc2_grok_set_default_params.argtypes = ([np.ctypeslib.ndpointer(dtype=np.int64)] * 2 +
[ctypes.c_int] + [ctypes.c_char_p] + [np.ctypeslib.ndpointer(dtype=np.float64)] +
[ctypes.c_int] * 2 + [ctypes.c_char_p] +
[ctypes.c_int] + [np.ctypeslib.ndpointer(dtype=np.int64)] + [ctypes.c_int] +
[ctypes.c_bool] + [ctypes.c_int] * 2 + [np.ctypeslib.ndpointer(dtype=np.int64)] +
[np.ctypeslib.ndpointer(dtype=np.int64)] + [ctypes.c_int] +
[ctypes.c_int] * 2 +
[ctypes.c_int] + [ctypes.c_bool] +
[ctypes.c_int] * 6 + [ctypes.c_bool] +
[ctypes.c_int] * 6 + [ctypes.c_bool] * 4)
lib.blosc2_grok_set_default_params(*args)

Expand Down
9 changes: 8 additions & 1 deletion examples/params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
##############################################################################
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

import blosc2
import blosc2_grok
import argparse
from pathlib import Path
import numpy as np
from PIL import Image

Expand Down
9 changes: 8 additions & 1 deletion examples/roundtrip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
##############################################################################
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

import blosc2
import blosc2_grok
import argparse
from pathlib import Path
import numpy as np
from PIL import Image

Expand Down
26 changes: 19 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
##############################################################################
# Btune for Blosc2 - Automatically choose the best codec/filter for your data
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (c) 2023 The Blosc Developers <[email protected]>
# https://btune.blosc.org
# License: GNU Affero General Public License v3.0
# See LICENSE.txt for details about copyright and rights to use.
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

[build-system]
Expand All @@ -18,17 +17,21 @@ readme = "README.md"
authors = [
{name = "Blosc Development Team", email = "[email protected]"},
]
description = "Grok plugin for Blosc2. jpeg2000 for grayscale."
description = "Grok (JPEG2000 codec) plugin for Blosc2."
keywords = ["plugin", "blosc2"]
license = {text = "GNU Affero General Public License version 3"}
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: C",
"Programming Language :: C++",
"Development Status :: 5 - Production/Stable",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Image Processing",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Scientific/Engineering :: Image Processing",
"Topic :: System :: Archiving :: Compression",
"Operating System :: Microsoft :: Windows",
"Operating System :: Unix",
]
Expand All @@ -37,6 +40,15 @@ dependencies = [
"blosc2"
]

[project.optional-dependencies]
h5py-test = [
"pytest", # to run tests
]

[project.urls]
Homepage = "https://github.com/Blosc/blosc2_grok"
Issues = "https://github.com/Blosc/blosc2_grok/issues"

[tool.setuptools]
platforms = [ "any" ]
zip-safe = false
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
addopts = --doctest-modules
testpaths =
tests
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
##############################################################################
# Btune for Blosc2 - Automatically choose the best codec/filter for your data
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (c) 2023 The Blosc Developers <[email protected]>
# https://btune.blosc.org
# License: GNU Affero General Public License v3.0
# See LICENSE.txt for details about copyright and rights to use.
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

from skbuild import setup
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Blosc - Blocked Shuffling and Compression Library
##############################################################################
# blosc2_grok: Grok (JPEG2000 codec) plugin for Blosc2
#
# Copyright (C) 2023 The Blosc Developers <[email protected]>
# Copyright (c) 2023 The Blosc Development Team <[email protected]>
# https://blosc.org
# License: GNU Affero General Public License v3.0 (see LICENSE.txt)
##############################################################################

set(GRK_BUILD_LIBPNG OFF)
set(GRK_BUILD_JPEG OFF)
Expand Down
Loading