{"id":21150803,"url":"https://github.com/cedargrovestudios/circuitpython_paletteslice","last_synced_at":"2026-06-14T21:32:16.110Z","repository":{"id":139500745,"uuid":"577995592","full_name":"CedarGroveStudios/CircuitPython_PaletteSlice","owner":"CedarGroveStudios","description":"A CircuitPython wrapper class to add list slice capability to a displayio.Palette object while preserving transparency.","archived":false,"fork":false,"pushed_at":"2023-11-02T03:39:46.000Z","size":5404,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T19:02:00.632Z","etag":null,"topics":["circuitpython","circuitpython-community-bundle","displayio","list-slicing","palette-generator","proof-of-concept"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CedarGroveStudios.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-14T02:15:24.000Z","updated_at":"2023-03-19T23:12:04.000Z","dependencies_parsed_at":"2024-11-20T10:56:08.747Z","dependency_job_id":"b7b463c5-2841-4f61-9f9b-6caea5d18832","html_url":"https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/CedarGroveStudios/CircuitPython_PaletteSlice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteSlice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteSlice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteSlice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteSlice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CedarGroveStudios","download_url":"https://codeload.github.com/CedarGroveStudios/CircuitPython_PaletteSlice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteSlice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34339194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuitpython","circuitpython-community-bundle","displayio","list-slicing","palette-generator","proof-of-concept"],"created_at":"2024-11-20T10:08:25.330Z","updated_at":"2026-06-14T21:32:16.095Z","avatar_url":"https://github.com/CedarGroveStudios.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction\n============\n\nCedarGroveStudios/CircuitPython_PaletteSlice\n--------------------------------------------\n\n\n.. image:: https://img.shields.io/discord/327254708534116352.svg\n    :target: https://adafru.it/discord\n    :alt: Discord\n\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/workflows/Build%20CI/badge.svg\n    :target: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/actions\n    :alt: Build Status\n\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Code Style: Black\n\n*A CircuitPython wrapper class to add list slice and extended slice capability to a displayio.Palette object while preserving transparency.*\n\nThe default functionality of a ``displayio.Palette`` object is similar to a Python list object, but very limited. For example, the integer value of color elements of the palette can be modified but only one element can be changed at a time. The PaletteSlice wrapper class provides the ability to use a slice object to specify a subset of a palette to change or to create a new palette from a source palette. Both slice and extended slice objects are supported.\n\nIn addition to a palette property (``.palette``), PaletteSlice contains a list representation (``.reference_list``) of the source palette with color and transparency values stored as a tuple.\n\nThe ability to create and manipulate palettes using slicing allows for the use of a standardized palette to be used to provide a color scheme for multiple objects within a project framework, regardless of an object's color depth. For example, a standard color palette of 1024 individual colors could be used for a 64-color bitmap object by slicing the standard palette using an extended slice object:\n\n``bitmap_image.pixel_shader = source_palette[::16]``\n\n======\n\nNote that a PaletteSlice object behaves correctly only when a slice object is included in the syntax. For example,\n\n``bitmap_image.pixel_shader = source_palette``\n\nwill cause a type error:\n\n``TypeError: pixel_shader must be displayio.Palette or displayio.ColorConverter``\n\nAt a minimum, the PaletteSlice object must include the \"all\" slice object in order to return a displayio.Palette object:\n\n``bitmap_image.pixel_shader = source_palette[:]``\n\n======\n\n\nTwo Versions -- Minimal and Acme\n--------------------------------\n\nTwo versions of PaletteSlice are available. ``cedargrove_paletteslice.paletteslice`` is a minimal version that only supports palette slicing and the traditional palette functions:\n\n* ``.is_transparent(index)``\n* ``.make_transparent(index)``\n* ``.make_opaque(index)``\n* ``len(palette)``\n\nThe second version, ``cedargrove_paletteslice.paletteslice_acme`` currently extends the functionality of the minimal version with the additional functions:\n\n* ``__contains__(color)``  (usage: ``color in PaletteSlice.palette`` )\n* ``.append(color)``\n* ``.count(color)``\n* ``.index(color)``\n* ``.insert(key)``\n* ``.pop(key)``\n\nUnder consideration for a future \"acme\" version are:\n\n* ``.entend(new_palette)``\n* ``.remove(color)``\n* ``.reverse()``\n* ``.sort(key, reverse)``\n\nand perhaps the extended functions of:\n\n* ``min(palette)``\n* ``max(palette)``\n* ``enumerate(palette)``\n\nDependencies\n=============\nThis driver depends on:\n\n* `Adafruit CircuitPython \u003chttps://github.com/adafruit/circuitpython\u003e`_\n\nPlease ensure all dependencies are available on the CircuitPython filesystem.\nThis is easily achieved by downloading\n`the Adafruit library and driver bundle \u003chttps://circuitpython.org/libraries\u003e`_\nor individual libraries can be installed using\n`circup \u003chttps://github.com/adafruit/circup\u003e`_.\n\nInstalling to a Connected CircuitPython Device with Circup\n==========================================================\n\nMake sure that you have ``circup`` installed in your Python environment.\nInstall it with the following command if necessary:\n\n.. code-block:: shell\n\n    pip3 install circup\n\nWith ``circup`` installed and your CircuitPython device connected use the\nfollowing command to install:\n\n.. code-block:: shell\n\n    circup install cedargrove_paletteslice\n\nOr the following command to update an existing version:\n\n.. code-block:: shell\n\n    circup update\n\nUsage Example\n=============\n\n.. code-block:: python\n\n    from cedargrove_paletteslice.paletteslice import PaletteSlice\n    sliceable_palette = PaletteSlice(source_palette)\n\n    # Create a new palette from the sliceable palette\n    new_sliced_palette = sliceable_palette[0:124:2]\n\nUsing slice with narray Pseudocolor Palettes:\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/display_capture_composite.png\n    :alt: Using slice with narray Pseudocolor Palettes\n    :width: 600pt\n\n``paletteslice_simpletest.py``, ``paletteslice_acme_simpletest.py``, and ``paletteslice_ulab_test.py`` are contained in the ``examples`` folder.\n\nDocumentation\n=============\n`PaletteSlice API Documentation \u003chttps://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/pseudo_rtd_cedargrove_paletteslice.pdf\u003e`_\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/PaletteSlice_class_desc_minimal.png\n    :alt: Brainstorm Diagram\n    :width: 600pt\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/PaletteSlice_class_desc_acme.png\n    :alt: Brainstorm Diagram\n    :width: 600pt\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/PaletteSlice_class_internals.png\n    :alt: Brainstorm Diagram\n    :width: 600pt\n\nPaletteSlice Design Considerations\n----------------------------------\n\nCircuitPython classes such as PaletteSlice cannot inherit ``displayio.Palette`` or ``list`` attributes because of their specific core implementation. Therefore, PaletteSlice uses composition to appear to be a ``displayio.Palette`` object.\n\nThe PaletteSlice project began as a learning experience for the author but is also became a proof-of-concept for testing the usefulness of list slicing for ``displayio.Palette`` objects. It is hoped that this project will encourage list slice and extended slice capabilities be added to ``displayio.Palette`` in the CircuitPython core.\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteSlice/blob/main/media/PaletteSlice_design_brainstorm.png\n    :alt: Brainstorm Diagram\n    :width: 600pt\n\nFor information on building library documentation, please check out\n`this guide \u003chttps://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1\u003e`_.\n\nContributing\n============\n\nContributions are welcome! Please read our `Code of Conduct\n\u003chttps://github.com/CedarGroveStudios/Cedargrove_CircuitPython_PaletteSlice/blob/HEAD/CODE_OF_CONDUCT.md\u003e`_\nbefore contributing to help this project stay welcoming.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedargrovestudios%2Fcircuitpython_paletteslice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedargrovestudios%2Fcircuitpython_paletteslice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedargrovestudios%2Fcircuitpython_paletteslice/lists"}