blosc2-grok


Nameblosc2-grok JSON
Version 0.3.3 PyPI version JSON
download
home_pageNone
SummaryGrok (JPEG2000 codec) plugin for Blosc2.
upload_time2024-04-04 11:44:42
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseGNU Affero General Public License version 3
keywords plugin blosc2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Blosc2 grok

A plugin of the excellent [grok library](https://github.com/GrokImageCompression/grok) for Blosc2.  grok is a JPEG2000 codec, and with this plugin, you can use it as yet another codec in applications using Blosc2.  See an example of use at: https://github.com/Blosc/blosc2_grok/blob/main/examples/params.py

## Installation

For using `blosc2_grok` you will first have to install its wheel:

```shell
pip install blosc2-grok -U
```

## Usage

```python
import blosc2
import numpy as np
import blosc2_grok
from PIL import Image

# Set the params for the grok codec
kwargs = {}
kwargs['cod_format'] = blosc2_grok.GrkFileFmt.GRK_FMT_JP2
kwargs['quality_mode'] = "dB"
kwargs['quality_layers'] = np.array([5], dtype=np.float64)
blosc2_grok.set_params_defaults(**kwargs)

# Define the compression and decompression parameters for Blosc2.
# Disable the filters and do not split blocks (these won't work with grok).
cparams = {
    'codec': blosc2.Codec.GROK,
    'filters': [],
    'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}

# Read the image
im = Image.open("examples/kodim23.png")
# Convert the image to a numpy array
np_array = np.asarray(im)

# Transform the numpy array to a blosc2 array. This is where compression happens, and
# the HTJ2K codec is called.
bl_array = blosc2.asarray(
    np_array,
    chunks=np_array.shape,
    blocks=np_array.shape,
    cparams=cparams,
    urlpath="examples/kodim23.b2nd",
    mode="w",
)

# Print information about the array, see the compression ratio (cratio)
print(bl_array.info)
```

## Parameters for compression

The following parameters are available for compression for grok, with their defaults.  Most of them are named after the ones in the [Pillow library](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg-2000-saving) and have the same meaning.  The ones that are not in Pillow are marked with a `*` and you can get more information about them in the [grok documentation](https://github.com/GrokImageCompression/grok/wiki/3.-grk_compress), or by following the provided links.  For those marked with a ``**``, you can get more information in the [grok.h header](https://github.com/GrokImageCompression/grok/blob/a84ac2592e581405a976a00cf9e6f03cab7e2481/src/lib/core/grok.h#L975
).

    'tile_size': (0, 0),
    'tile_offset': (0, 0),
    'quality_mode': None,
    'quality_layers': np.zeros(0, dtype=np.float64),
    'progression': "LRCP",
    'num_resolutions': 6,
    'codeblock_size': (64, 64),
    'irreversible': False,
    'precinct_size': (0, 0),
    'offset': (0, 0),
    'mct': 0,
    * 'numgbits': 2,  # Equivalent to -N, -guard_bits
    * 'roi_compno': -1,  # Together with 'roi_shift' it is equivalent to -R, -ROI
    * 'roi_shift': 0,
    * 'decod_format': GrkFileFmt.GRK_FMT_UNK,
    * 'cod_format': GrkFileFmt.GRK_FMT_UNK,
    * 'rsiz': GrkProfile.GRK_PROFILE_NONE,  # Equivalent to -Z, -rsiz
    * 'framerate': 0,
    * 'apply_icc_': False,  # Equivalent to -f, -apply_icc
    * 'rateControlAlgorithm': GrkRateControl.BISECT,
    * 'num_threads': 0,
    * 'deviceId': 0,  # Equivalent to -G, -device_id
    * 'duration': 0,  # Equivalent to -J, -duration
    * 'repeats': 1,  # Equivalent to -e, -repetitions
    * 'mode': GrkMode.DEFAULT,  # Equivalent to -M, -mode
    * 'verbose': False,  # Equivalent to -v, -verbose
    ** 'enableTilePartGeneration': False,  # See header of grok.h above
    ** 'max_cs_size': 0,  # See header of grok.h above
    ** 'max_comp_size': 0,  # See header of grok.h above


### codec_meta as rates quality mode

As a simpler way to activate the rates quality mode, if you set the `codec_meta` from the `cparams` to an
integer different from 0, the rates quality mode will be activated with a rate value equal to `codec_meta` / 10. If 
`cod_format` is not specified, the default will be used. The `codec_meta` has priority to the `rates` param set with the 
`blosc2_grok.set_params_defaults()`.
```python
import blosc2


cparams = {
    'codec': blosc2.Codec.GROK,
    'codec_meta': 5 * 10,  # cratio will be 5
    'filters': [],
    'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}
```

## More examples

See the [examples](examples/) directory for more examples.

## Thanks

Thanks to Marta Iborra, from the Blosc Development Team, for doing most of the job in making this plugin possible, and J. David Ibáñez and Francesc Alted for the initial contributions.  Also, thanks to Aaron Boxer, the original author of the [grok library](https://github.com/GrokImageCompression/grok), for his help in ironing out issues for making this interaction possible. 

That's all folks!

The Blosc Development Team

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "blosc2-grok",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "plugin blosc2",
    "author": null,
    "author_email": "Blosc Development Team <contact@blosc.org>",
    "download_url": null,
    "platform": null,
    "description": "# Blosc2 grok\n\nA plugin of the excellent [grok library](https://github.com/GrokImageCompression/grok) for Blosc2.  grok is a JPEG2000 codec, and with this plugin, you can use it as yet another codec in applications using Blosc2.  See an example of use at: https://github.com/Blosc/blosc2_grok/blob/main/examples/params.py\n\n## Installation\n\nFor using `blosc2_grok` you will first have to install its wheel:\n\n```shell\npip install blosc2-grok -U\n```\n\n## Usage\n\n```python\nimport blosc2\nimport numpy as np\nimport blosc2_grok\nfrom PIL import Image\n\n# Set the params for the grok codec\nkwargs = {}\nkwargs['cod_format'] = blosc2_grok.GrkFileFmt.GRK_FMT_JP2\nkwargs['quality_mode'] = \"dB\"\nkwargs['quality_layers'] = np.array([5], dtype=np.float64)\nblosc2_grok.set_params_defaults(**kwargs)\n\n# Define the compression and decompression parameters for Blosc2.\n# Disable the filters and do not split blocks (these won't work with grok).\ncparams = {\n    'codec': blosc2.Codec.GROK,\n    'filters': [],\n    'splitmode': blosc2.SplitMode.NEVER_SPLIT,\n}\n\n# Read the image\nim = Image.open(\"examples/kodim23.png\")\n# Convert the image to a numpy array\nnp_array = np.asarray(im)\n\n# Transform the numpy array to a blosc2 array. This is where compression happens, and\n# the HTJ2K codec is called.\nbl_array = blosc2.asarray(\n    np_array,\n    chunks=np_array.shape,\n    blocks=np_array.shape,\n    cparams=cparams,\n    urlpath=\"examples/kodim23.b2nd\",\n    mode=\"w\",\n)\n\n# Print information about the array, see the compression ratio (cratio)\nprint(bl_array.info)\n```\n\n## Parameters for compression\n\nThe following parameters are available for compression for grok, with their defaults.  Most of them are named after the ones in the [Pillow library](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg-2000-saving) and have the same meaning.  The ones that are not in Pillow are marked with a `*` and you can get more information about them in the [grok documentation](https://github.com/GrokImageCompression/grok/wiki/3.-grk_compress), or by following the provided links.  For those marked with a ``**``, you can get more information in the [grok.h header](https://github.com/GrokImageCompression/grok/blob/a84ac2592e581405a976a00cf9e6f03cab7e2481/src/lib/core/grok.h#L975\n).\n\n    'tile_size': (0, 0),\n    'tile_offset': (0, 0),\n    'quality_mode': None,\n    'quality_layers': np.zeros(0, dtype=np.float64),\n    'progression': \"LRCP\",\n    'num_resolutions': 6,\n    'codeblock_size': (64, 64),\n    'irreversible': False,\n    'precinct_size': (0, 0),\n    'offset': (0, 0),\n    'mct': 0,\n    * 'numgbits': 2,  # Equivalent to -N, -guard_bits\n    * 'roi_compno': -1,  # Together with 'roi_shift' it is equivalent to -R, -ROI\n    * 'roi_shift': 0,\n    * 'decod_format': GrkFileFmt.GRK_FMT_UNK,\n    * 'cod_format': GrkFileFmt.GRK_FMT_UNK,\n    * 'rsiz': GrkProfile.GRK_PROFILE_NONE,  # Equivalent to -Z, -rsiz\n    * 'framerate': 0,\n    * 'apply_icc_': False,  # Equivalent to -f, -apply_icc\n    * 'rateControlAlgorithm': GrkRateControl.BISECT,\n    * 'num_threads': 0,\n    * 'deviceId': 0,  # Equivalent to -G, -device_id\n    * 'duration': 0,  # Equivalent to -J, -duration\n    * 'repeats': 1,  # Equivalent to -e, -repetitions\n    * 'mode': GrkMode.DEFAULT,  # Equivalent to -M, -mode\n    * 'verbose': False,  # Equivalent to -v, -verbose\n    ** 'enableTilePartGeneration': False,  # See header of grok.h above\n    ** 'max_cs_size': 0,  # See header of grok.h above\n    ** 'max_comp_size': 0,  # See header of grok.h above\n\n\n### codec_meta as rates quality mode\n\nAs a simpler way to activate the rates quality mode, if you set the `codec_meta` from the `cparams` to an\ninteger different from 0, the rates quality mode will be activated with a rate value equal to `codec_meta` / 10. If \n`cod_format` is not specified, the default will be used. The `codec_meta` has priority to the `rates` param set with the \n`blosc2_grok.set_params_defaults()`.\n```python\nimport blosc2\n\n\ncparams = {\n    'codec': blosc2.Codec.GROK,\n    'codec_meta': 5 * 10,  # cratio will be 5\n    'filters': [],\n    'splitmode': blosc2.SplitMode.NEVER_SPLIT,\n}\n```\n\n## More examples\n\nSee the [examples](examples/) directory for more examples.\n\n## Thanks\n\nThanks to Marta Iborra, from the Blosc Development Team, for doing most of the job in making this plugin possible, and J. David Ib\u00e1\u00f1ez and Francesc Alted for the initial contributions.  Also, thanks to Aaron Boxer, the original author of the [grok library](https://github.com/GrokImageCompression/grok), for his help in ironing out issues for making this interaction possible. \n\nThat's all folks!\n\nThe Blosc Development Team\n",
    "bugtrack_url": null,
    "license": "GNU Affero General Public License version 3",
    "summary": "Grok (JPEG2000 codec) plugin for Blosc2.",
    "version": "0.3.3",
    "project_urls": {
        "Homepage": "https://github.com/Blosc/blosc2_grok",
        "Issues": "https://github.com/Blosc/blosc2_grok/issues"
    },
    "split_keywords": [
        "plugin",
        "blosc2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e4c794339f1297bb8ecc4a9ed68242d13a3afd37c8148f1feed899285643783b",
                "md5": "448863ab4e8d5622974cec72b8df902e",
                "sha256": "58c7de1184d78adf85a48dd79364480a7594f9fb5e509fab5ed6d1919847eb96"
            },
            "downloads": -1,
            "filename": "blosc2_grok-0.3.3-py3-none-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "448863ab4e8d5622974cec72b8df902e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 1934474,
            "upload_time": "2024-04-04T11:44:42",
            "upload_time_iso_8601": "2024-04-04T11:44:42.898210Z",
            "url": "https://files.pythonhosted.org/packages/e4/c7/94339f1297bb8ecc4a9ed68242d13a3afd37c8148f1feed899285643783b/blosc2_grok-0.3.3-py3-none-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a06c2c5437b49b2cf441e870ef5114568d79746422de18a04d3f8088926beff8",
                "md5": "b1c0faf939309d32376b8a856c4b9db5",
                "sha256": "9da834d835d60163e532bbe6cb6a0fc38111aa2a4bfb9113de7eaffc162dc74c"
            },
            "downloads": -1,
            "filename": "blosc2_grok-0.3.3-py3-none-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "b1c0faf939309d32376b8a856c4b9db5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 1632321,
            "upload_time": "2024-04-04T11:44:44",
            "upload_time_iso_8601": "2024-04-04T11:44:44.844494Z",
            "url": "https://files.pythonhosted.org/packages/a0/6c/2c5437b49b2cf441e870ef5114568d79746422de18a04d3f8088926beff8/blosc2_grok-0.3.3-py3-none-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45c37daf6c64a80a2d882ccf3352607322f1de7f55f5a67b87ee11dc4582283d",
                "md5": "19fde23bd0657fa06fe060fc5b588c26",
                "sha256": "cb2a3f77d53cfbedac744293350ea56accf279a298bc3f0d8bc6b0317a2a5422"
            },
            "downloads": -1,
            "filename": "blosc2_grok-0.3.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "19fde23bd0657fa06fe060fc5b588c26",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 2173712,
            "upload_time": "2024-04-04T11:44:46",
            "upload_time_iso_8601": "2024-04-04T11:44:46.766511Z",
            "url": "https://files.pythonhosted.org/packages/45/c3/7daf6c64a80a2d882ccf3352607322f1de7f55f5a67b87ee11dc4582283d/blosc2_grok-0.3.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6522a4b85a0c78e60e1e67f4bc4e89dfce9d9fc54885f405c0817e0805c60aa9",
                "md5": "6e3ff4d0294e84a1e1c50b3dc0b6fd5a",
                "sha256": "7d10b70396fb08ba0b573bfbbc16e6f1096f12681c21952e26b014c9cde31e22"
            },
            "downloads": -1,
            "filename": "blosc2_grok-0.3.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "6e3ff4d0294e84a1e1c50b3dc0b6fd5a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 2288814,
            "upload_time": "2024-04-04T11:44:49",
            "upload_time_iso_8601": "2024-04-04T11:44:49.244798Z",
            "url": "https://files.pythonhosted.org/packages/65/22/a4b85a0c78e60e1e67f4bc4e89dfce9d9fc54885f405c0817e0805c60aa9/blosc2_grok-0.3.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86fa6548e16a554cbdf9aba8ccc8f0bb147dfd51c72b635bd3c02f4027620949",
                "md5": "2e81ba0202174684c9f7a3ba6acf2d9a",
                "sha256": "b6b8bf360b2927b242ddf705714e70d87f845f8eb96ec40eba28a49b76280b85"
            },
            "downloads": -1,
            "filename": "blosc2_grok-0.3.3-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "2e81ba0202174684c9f7a3ba6acf2d9a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3978715,
            "upload_time": "2024-04-04T11:44:51",
            "upload_time_iso_8601": "2024-04-04T11:44:51.826545Z",
            "url": "https://files.pythonhosted.org/packages/86/fa/6548e16a554cbdf9aba8ccc8f0bb147dfd51c72b635bd3c02f4027620949/blosc2_grok-0.3.3-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-04 11:44:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Blosc",
    "github_project": "blosc2_grok",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "blosc2-grok"
}
        
Elapsed time: 0.22969s