{"id":13802151,"url":"https://github.com/jacklinquan/micropython-microbmp","last_synced_at":"2025-03-05T07:34:32.535Z","repository":{"id":57441488,"uuid":"438070307","full_name":"jacklinquan/micropython-microbmp","owner":"jacklinquan","description":"A small Python module for BMP image processing.","archived":false,"fork":false,"pushed_at":"2021-12-29T00:29:17.000Z","size":26,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-09T06:58:35.643Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jacklinquan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-14T00:48:33.000Z","updated_at":"2024-09-18T01:12:00.000Z","dependencies_parsed_at":"2022-09-06T02:21:56.214Z","dependency_job_id":null,"html_url":"https://github.com/jacklinquan/micropython-microbmp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-microbmp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-microbmp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-microbmp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklinquan%2Fmicropython-microbmp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacklinquan","download_url":"https://codeload.github.com/jacklinquan/micropython-microbmp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241989527,"owners_count":20053798,"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":[],"created_at":"2024-08-04T00:01:37.502Z","updated_at":"2025-03-05T07:34:32.515Z","avatar_url":"https://github.com/jacklinquan.png","language":"Python","readme":"# micropython-microbmp\n[![PayPal Donate][paypal_img]][paypal_link]\n[![PyPI version][pypi_img]][pypi_link]\n[![Downloads][downloads_img]][downloads_link]\n\n  [paypal_img]: https://github.com/jacklinquan/images/blob/master/paypal_donate_badge.svg\n  [paypal_link]: https://www.paypal.me/jacklinquan\n  [pypi_img]: https://badge.fury.io/py/micropython-microbmp.svg\n  [pypi_link]: https://badge.fury.io/py/micropython-microbmp\n  [downloads_img]: https://pepy.tech/badge/micropython-microbmp\n  [downloads_link]: https://pepy.tech/project/micropython-microbmp\n\nA small Python module for BMP image processing.\n \nIt supports BMP image of 1/2/4/8/24-bit colour depth.\n\nLoading supports compression method:\n\n- 0(BI_RGB, no compression)\n- 1(BI_RLE8, RLE 8-bit/pixel)\n- 2(BI_RLE4, RLE 4-bit/pixel)\n\nSaving only supports compression method 0(BI_RGB, no compression).\n\nThe [API][api_link] is compatible with the CPython version [microbmp][microbmp_link].\nAs a pure python module, it's not fast. But it opens up the possibility to save images.\nIt is especially useful for small IR cameras/sensors.\n\n  [api_link]: https://microbmp.readthedocs.io/en/latest/?badge=latest\n  [microbmp_link]: https://github.com/jacklinquan/microbmp\n\n## Where this module can be useful\nThis module can be useful in many scenarios, not limited to the list below:\n\n- To show BMP images on the screen.\n    It supports 1/2/4/8/24-bit colour depth and RLE compression(4-bit and 8-bit).\n    If the number of colours used in an image is small, it can be much compact.\n- To print the screen.\n    A screen or any `framebuf.FrameBuffer` object can be saved as a BMP image.\n- To save camera or IR thermal camera images.\n    For projects that involve MLX90640 or AMG88xx, the IR images can be saved.\n- To generate dynamic BMP images for web servers.\n    This module also can write BMP images to BytesIO.\n    So it does NOT have to save the images in the file system.\n    A combination of web server and IR camera can show IR image dynamically in the browser.\n\n## Installation\n``` Python\n\u003e\u003e\u003e import upip\n\u003e\u003e\u003e upip.install('micropython-microbmp')\n```\nAlternatively just copy microbmp.py to the MicroPython device.\n\n## Usage\n```Python\n\u003e\u003e\u003e from microbmp import MicroBMP\n\u003e\u003e\u003e img_24b_2x2 = MicroBMP(2, 2, 24)  # Create a 2(width) by 2(height) 24-bit image.\n\u003e\u003e\u003e img_24b_2x2.palette  # 24-bit image has no palette.\n\u003e\u003e\u003e img_24b_2x2.parray  # Pixels are arranged horizontally (top-down) in RGB order.\nbytearray(b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00')\n\u003e\u003e\u003e img_24b_2x2[1, 1] = 255, 255, 255  # Access 1 pixel (R, G, B): img[x, y]\n\u003e\u003e\u003e img_24b_2x2[0, 1, 0] = 255  # Access 1 primary colour of 1 pixel (Red): img[x, y, c]\n\u003e\u003e\u003e img_24b_2x2[1, 0, 1] = 255  # (Green)\n\u003e\u003e\u003e img_24b_2x2[0, 0, 2] = 255  # (Blue)\n\u003e\u003e\u003e img_24b_2x2.save(\"img_24b_2x2.bmp\")\n70\n\u003e\u003e\u003e new_img_24b_2x2 = MicroBMP().load(\"img_24b_2x2.bmp\")\n\u003e\u003e\u003e new_img_24b_2x2.palette\n\u003e\u003e\u003e new_img_24b_2x2.parray\nbytearray(b'\\x00\\x00\\xff\\x00\\xff\\x00\\xff\\x00\\x00\\xff\\xff\\xff')\n\u003e\u003e\u003e print(new_img_24b_2x2)\nBMP image, RGB, 24-bit, 2x2 pixels, 70 bytes\n\u003e\u003e\u003e img_1b_3x2 = MicroBMP(3, 2, 1)  # Create a 3(width) by 2(height) 1-bit image.\n\u003e\u003e\u003e img_1b_3x2.palette  # Each colour is in the order of (R, G, B)\n[bytearray(b'\\x00\\x00\\x00'), bytearray(b'\\xff\\xff\\xff')]\n\u003e\u003e\u003e img_1b_3x2.parray  # Each bit stores the colour index in HLSB format.\nbytearray(b'\\x00')\n\u003e\u003e\u003e \" \".join([\"{:0\u003e8}\".format(bin(byte)[2:]) for byte in img_1b_3x2.parray])\n'00000000'\n\u003e\u003e\u003e img_1b_3x2[1, 0] = 1  # Access 1 pixel (index): img[x, y]\n\u003e\u003e\u003e img_1b_3x2[1, 1] = 1\n\u003e\u003e\u003e img_1b_3x2[2, 1] = 1\n\u003e\u003e\u003e img_1b_3x2.save(\"img_1b_3x2.bmp\")\n70\n\u003e\u003e\u003e new_img_1b_3x2 = MicroBMP().load(\"img_1b_3x2.bmp\")\n\u003e\u003e\u003e new_img_1b_3x2.palette\n[bytearray(b'\\x00\\x00\\x00'), bytearray(b'\\xff\\xff\\xff')]\n\u003e\u003e\u003e new_img_1b_3x2.parray\nbytearray(b'L')\n\u003e\u003e\u003e \" \".join([\"{:0\u003e8}\".format(bin(byte)[2:]) for byte in new_img_1b_3x2.parray])\n'01001100'\n\u003e\u003e\u003e print(new_img_1b_3x2)\nBMP image, indexed, 1-bit, 3x2 pixels, 70 bytes\n```\n","funding_links":["https://www.paypal.me/jacklinquan"],"categories":["Libraries"],"sub_categories":["Display"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklinquan%2Fmicropython-microbmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacklinquan%2Fmicropython-microbmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklinquan%2Fmicropython-microbmp/lists"}