{"id":21150805,"url":"https://github.com/cedargrovestudios/circuitpython_palettefilter","last_synced_at":"2026-05-15T22:03:57.793Z","repository":{"id":139500732,"uuid":"540658837","full_name":"CedarGroveStudios/CircuitPython_PaletteFilter","owner":"CedarGroveStudios","description":"A CircuitPython helper class for replacing color index values in a displayio.Palette object.","archived":false,"fork":false,"pushed_at":"2023-11-02T03:29:33.000Z","size":950,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T08:09:45.138Z","etag":null,"topics":["circuitpython","circuitpython-community-bundle","greenscreen","palette-color-replacement","palette-filter"],"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}},"created_at":"2022-09-24T00:20:37.000Z","updated_at":"2023-10-09T01:55:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"17ac0ecf-9a35-4791-bb08-77f80c329095","html_url":"https://github.com/CedarGroveStudios/CircuitPython_PaletteFilter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteFilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteFilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteFilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CedarGroveStudios%2FCircuitPython_PaletteFilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CedarGroveStudios","download_url":"https://codeload.github.com/CedarGroveStudios/CircuitPython_PaletteFilter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243590515,"owners_count":20315696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","greenscreen","palette-color-replacement","palette-filter"],"created_at":"2024-11-20T10:08:25.737Z","updated_at":"2025-10-08T21:15:39.245Z","avatar_url":"https://github.com/CedarGroveStudios.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction\n============\n\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_PaletteFilter/workflows/Build%20CI/badge.svg\n    :target: https://github.com/CedarGroveStudios/CircuitPython_PaletteFilter/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\nPaletteFilter is a CircuitPython helper class for replacing color index values\nin a `displayio.Palette` object. A target color along with a tolerance parameter\ndetermine the range of color values to be replaced. The class creates a new\npalette object with the changes. The replacement color value (or `None` for\ntransparency) is substituted for the original palette entry and placed into the\nnew palette object, `PaletteFilter.palette`.\n\nThe filter uses a linear Euclidean comparison incorporating vision perception\n('redmean') approximation to test palette color values with the specified\ntarget color. https://en.wikipedia.org/wiki/Color_difference\n\nFor comparing a single color value, use the\n`cedargrove_palettefilter.compare_colors()` helper function.\n\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\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_palettefilter\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:: py\n\n    import displayio\n    from cedargrove_palettefilter import PaletteFilter\n\n    # Define the transparent color and tolerance values\n    TARGET_COLOR = 0x080808\n    FILL_COLOR = None\n    TOLERANCE = 4\n\n    # Make a displayio palette and set value(s) to transparent\n    SOURCE_COLORS = [\n        0x000000,\n        0x010101,\n        0x020202,\n        0x030303,\n        0x040404,\n        0x050505,\n        0x060606,\n        0x070707,\n        0x080808,\n        0x090909,\n    ]\n    SOURCE_PALETTE = displayio.Palette(len(SOURCE_COLORS))\n    for index, color in enumerate(SOURCE_COLORS):\n        SOURCE_PALETTE[index] = SOURCE_COLORS[index]\n\n    # Set a source palette value to transparent\n    SOURCE_PALETTE.make_transparent(3)\n\n    # Instantiate paletteFilter\n    filter = PaletteFilter(SOURCE_PALETTE, TARGET_COLOR, FILL_COLOR, TOLERANCE)\n    print(f\"target_color: {hex(filter.target_color)}\")\n\n    print(\"------\")\n    print(\"source palette:\")\n    print(\"index, color, transparency\")\n    for index, color in enumerate(SOURCE_PALETTE):\n        print(index, hex(color), SOURCE_PALETTE.is_transparent(index))\n\n    print(\"------\")\n    print(\"new palette:\")\n    print(\"index, color, transparency\")\n    for index, color in enumerate(filter.palette):\n        print(index, hex(color), filter.palette.is_transparent(index))\n\n    while True:\n        pass\n\n\nDocumentation\n=============\nAPI documentation for this library can be found in `PaletteFilter_API \u003chttps://github.com/CedarGroveStudios/CircuitPython_PaletteFilter/blob/main/media/pseudo_readthedocs_palettefilter.pdf\u003e`_.\n\n.. image:: https://github.com/CedarGroveStudios/CircuitPython_PaletteFilter/blob/main/media/flying_lars_test.png\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_PaletteFilter/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_palettefilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedargrovestudios%2Fcircuitpython_palettefilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedargrovestudios%2Fcircuitpython_palettefilter/lists"}