{"id":24617757,"url":"https://github.com/jacoblincool/cimple-bmp","last_synced_at":"2026-03-02T12:38:36.977Z","repository":{"id":42447290,"uuid":"477778692","full_name":"JacobLinCool/cimple-bmp","owner":"JacobLinCool","description":"Simple BMP Library in C. A 600 lines implementation of reading/writing 16, 24, 32 bits BMP and their drawing utilities.","archived":false,"fork":false,"pushed_at":"2024-08-29T15:48:31.000Z","size":1169,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-30T16:24:09.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/JacobLinCool.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-04T16:15:00.000Z","updated_at":"2024-08-29T15:48:34.000Z","dependencies_parsed_at":"2024-08-29T16:07:32.747Z","dependency_job_id":"47b19bcc-b882-4ec1-a036-2f23e9d399e6","html_url":"https://github.com/JacobLinCool/cimple-bmp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fcimple-bmp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fcimple-bmp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fcimple-bmp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fcimple-bmp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JacobLinCool","download_url":"https://codeload.github.com/JacobLinCool/cimple-bmp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235519909,"owners_count":19003201,"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":"2025-01-24T23:40:38.904Z","updated_at":"2025-10-06T10:31:31.322Z","avatar_url":"https://github.com/JacobLinCool.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Cimple BMP\n\n![plot](./img/plot.png)\n\nSimple BMP Library in C.\n\n[Read / Write BMP](#read--write-bmp) ． [Create Empty BMP](#create-empty-bmp)\n\n[Fill](#fill) ．\n[Copy](#copy) ．\n[Rect](#rect) ．\n[Circle](#circle) ．\n[Line](#line) ．\n[Custom](#custom-drawing)\n\n[Pixel Blend](#pixel)\n\n\u003c/div\u003e\n\n## Features\n\n### Read / Write BMP\n\n```c\nu8 read_bmp(string path, BMP* bmp);\n```\n\nThis library should be able to read 16, 24, 32 bit BMP files.\n\n```c\nu8 write_bmp(BMP* bmp, string path, u8 red_bits, u8 green_bits, u8 blue_bits, u8 alpha_bits);\n```\n\nThe following exporting formats are supported:\n\n- 16 bit (RGB 555)\n- 16 bit (RGB 565)\n- 24 bit (RGB 888)\n- 32 bit (RGBA 8888)\n\n### Create Empty BMP\n\n```c\nBMP* create_bmp(u64 width, u64 height, Pixel pixel);\n```\n\nIt will create a BMP with the specified width and height, and fill it with the specified pixel.\n\n### Fill\n\n```c\n// as a method-like member of BMP\nu64(*fill)(BMP* bmp, Pixel pixel);\n\n// usage\nBMP* bmp = create_bmp(100, 100, PIXEL_BLUE);\nu64 count = Bmp.fill(bmp, PIXEL_RED);\n```\n\n### Copy\n\n```c\nu64 bmp_copy(BMP* bmp, i64 from_x, i64 from_y, i64 width, i64 height, BMP* source, i64 source_x, i64 source_y);\n```\n\nThis function will copy a rectangular area from the source BMP to the destination BMP.\n\n### Rect\n\n```c\n// as a method-like member of BMP\nu64(*rect)(BMP* bmp, i64 from_x, i64 from_y, i64 width, i64 height, Pixel pixel);\n\n// usage\nBMP* bmp = create_bmp(100, 100, PIXEL_BLUE);\nu64 count = Bmp.rect(bmp, 0, 0, 50, 100, PIXEL_RED);\n```\n\nThis function will draw a rectangle on the BMP.\n\n### Circle\n\n```c\n// as a method-like member of BMP\nu64(*circle)(BMP* bmp, i64 center_x, i64 center_y, i64 radius, Pixel pixel);\n\n// usage\nBMP* bmp = create_bmp(100, 100, PIXEL_BLUE);\nu64 count = Bmp.circle(bmp, 50, 50, 30, PIXEL_RED);\n```\n\nThis function will draw a filled circle on the BMP.\n\n### Line\n\n```c\n// as a method-like member of BMP\nu64(*line)(BMP* bmp, i64 from_x, i64 from_y, i64 to_x, i64 to_y, u64 width, Pixel pixel);\n\n// usage\nBMP* bmp = create_bmp(100, 100, PIXEL_BLUE);\nu64 count = Bmp.line(bmp, 20, 20, 80, 80, 5, PIXEL_RED);\n```\n\n### Custom Drawing\n\nThis library provides a simple but powerful way to draw custom shapes on the BMP.\n\n```c\n// as a method-like member of BMP\nu64(*draw)(BMP* bmp, Pixel pixel, bool (*condition)(struct BMP*, i64 x, i64 y));\n\n// usage\nbool do_draw(struct BMP* bmp, i64 x, i64 y) {\n    return x % 2 == 0 \u0026\u0026 y % 2 == 0;\n}\n\nBMP* bmp = create_bmp(100, 100, PIXEL_BLUE);\nu64 count = Bmp.draw(bmp, PIXEL_RED, \u0026do_draw);\n```\n\nPassing a function pointer to the draw function will draw a pixel on the position if the condition is true.\n\n### Pixel\n\nEvery BMP is composed of pixels.\n\n```c\ntypedef struct Pixel {\n    u8 red;\n    u8 green;\n    u8 blue;\n    u8 alpha;\n} Pixel;\n```\n\nThere are some predefined pixel types:\n\n```c\n#define PIXEL_BLACK ((Pixel){ 0, 0, 0, 0xFF })\n#define PIXEL_WHITE ((Pixel){ 0xFF, 0xFF, 0xFF, 0xFF })\n#define PIXEL_RED ((Pixel){ 0xFF, 0, 0, 0xFF })\n#define PIXEL_GREEN ((Pixel){ 0, 0xFF, 0, 0xFF })\n#define PIXEL_BLUE ((Pixel){ 0, 0, 0xFF, 0xFF })\n#define PIXEL_YELLOW ((Pixel){ 0xFF, 0xFF, 0, 0xFF })\n#define PIXEL_CYAN ((Pixel){ 0, 0xFF, 0xFF, 0xFF })\n#define PIXEL_MAGENTA ((Pixel){ 0xFF, 0, 0xFF, 0xFF })\n#define PIXEL_BLACK_TRANSPARENT ((Pixel){ 0, 0, 0, 0 })\n#define PIXEL_WHITE_TRANSPARENT ((Pixel){ 0xFF, 0xFF, 0xFF, 0 })\n#define PIXEL_RED_TRANSPARENT ((Pixel){ 0xFF, 0, 0, 0 })\n#define PIXEL_GREEN_TRANSPARENT ((Pixel){ 0, 0xFF, 0, 0 })\n#define PIXEL_BLUE_TRANSPARENT ((Pixel){ 0, 0, 0xFF, 0 })\n#define PIXEL_YELLOW_TRANSPARENT ((Pixel){ 0xFF, 0xFF, 0, 0 })\n#define PIXEL_CYAN_TRANSPARENT ((Pixel){ 0, 0xFF, 0xFF, 0 })\n#define PIXEL_MAGENTA_TRANSPARENT ((Pixel){ 0xFF, 0, 0xFF, 0 })\n#define PIXEL_TRANSPARENT PIXEL_BLACK_TRANSPARENT\n```\n\n![colors](./img/colors_888.png)\n\nYou can also use this to make your pixel:\n\n```c\n// Royal Blue, RGB: (0, 35, 102)\nBmp.fill(bmp, (Pixel){ 0, 35, 102, 0 });\n```\n\n### Pixel Blend\n\n```c\nPixel blend(Pixel a, Pixel b, f64 weight);\n\n// usage\nPixel PIXEL_GRAY = blend(PIXEL_BLACK, PIXEL_WHITE, 0.5);\n```\n\nThis function will blend the two source pixels and return the result.\n\n### Pixel Over\n\n```c\nPixel pixel_over(Pixel front, Pixel back);\n```\n\nThe function will return the result of the pixel over operation (alpha blending).\n\n### `RGB` \u0026 `RGBA`\n\n```c\nPixel RGBA(u32 hex);\nPixel RGB(u32 hex);\n\n// usage\nPixel PIXEL_RED = RGB(0xFF0000);\nPixel PIXEL_GREEN_TRANSPARENT = RGBA(0x00FF0080);\n```\n\nThese two functions will convert the hexadecimal color value to a pixel.\n\n## Images\n\n![Plot](img/plot.png)\n\n![Colors](img/colors_888.png)\n\n![Maldives](img/maldives_555.png)\n\n![Random Blocks](img/random_blocks.png)\n\n![Random Circles](img/random_circles.png)\n\n\u003e The images in this README are PNG files, which are converted from the BMP files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fcimple-bmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacoblincool%2Fcimple-bmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fcimple-bmp/lists"}