{"id":19382613,"url":"https://github.com/marklagodych/bmp_c","last_synced_at":"2025-06-21T08:34:40.493Z","repository":{"id":119760903,"uuid":"308008168","full_name":"MarkLagodych/BMP_C","owner":"MarkLagodych","description":"A simple C library for operating on images and working with BMP files","archived":false,"fork":false,"pushed_at":"2020-10-31T21:27:36.000Z","size":728,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T17:14:39.708Z","etag":null,"topics":["bmp","c","image-processing"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarkLagodych.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-10-28T12:24:15.000Z","updated_at":"2023-07-23T09:44:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"9d35a19d-6204-431a-aa85-91cc9652e32b","html_url":"https://github.com/MarkLagodych/BMP_C","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MarkLagodych/BMP_C","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkLagodych%2FBMP_C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkLagodych%2FBMP_C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkLagodych%2FBMP_C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkLagodych%2FBMP_C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarkLagodych","download_url":"https://codeload.github.com/MarkLagodych/BMP_C/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkLagodych%2FBMP_C/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261093583,"owners_count":23108680,"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":["bmp","c","image-processing"],"created_at":"2024-11-10T09:22:26.742Z","updated_at":"2025-06-21T08:34:35.483Z","avatar_url":"https://github.com/MarkLagodych.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BMP_C\n## A simple C library for operating on images and working with BMP files\n\n`images.c`, `images.h` include functions, needed to operate on images\n\n`bmp.c`, `bmp.h` include functions, needed to read/write simple 24-bit RGB .bmp files\n\n\n# Example\n\n```c\n#include \"images.h\"\n#include \"bmp.h\"\n\nint main() {\n\n    // Read a few .bmp images\n    Image *img1 = BMP_Read(\"1.bmp\");\n    Image *img2 = BMP_Read(\"2.bmp\");\n\n    // Create image with the same size as img1\n    Image *img3 = CreateCompatible(img1);\n\n    // Overlay img2 on the img3 (black by default)\n    //  starting from point(0;0)\n    // Saturation ratio img3:img2 -- 1:2\n    OverlayImage(img3, 0, 0, img2, 1, 2);\n\n    CopyFragment(img3, 130, 130, img1, 130, 130, img1-\u003ewidth-260, img1-\u003eheight-260);\n\n    ResizeImage(img3, 300, 200, RESIZE_AVERAGE);\n\n    BMP_Write(img3, \"result.bmp\");\n\n    // Free all the memory\n    DeleteImage(img1);\n    DeleteImage(img2);\n    DeleteImage(img3);\n\n    return errno;\n}\n```\n\nSource images\n\n![](https://raw.githubusercontent.com/MarkLagodych/assets/main/BMP_C/1.bmp?raw=true)\n![](https://raw.githubusercontent.com/MarkLagodych/assets/main/BMP_C/2.bmp?raw=true)\n\nResult\n\n![](https://raw.githubusercontent.com/MarkLagodych/assets/main/BMP_C/result.bmp?raw=true)\n\n## Brief description of main types\n\n```c\ntypedef uint8_t Color;\ntypedef uint32_t uint;\n```\n`Color` is a minimal type to store a pixel channel.\n`uint` is a type, enough to store image width/height\n\n\nHere is the declaration of `Pixel`:\n```c\ntypedef struct {\n    Color B, G, R;\n} Pixel;\n```\n\nHere is the declaration of `Image`:\n```c\ntypedef struct {\n    uint width, height;\n    Pixel *data;\n} Image;\n```\n\nSo, when declaring `Image *img;` we declare a pointer to an image container that has a pointer to pixel data.\nWhy so complicated? The thing is it is easier to call functions that change images.\nAnd because of so many pointers, we have several `Delete..` functions:\n\n```c\n// Frees allocated memory\nvoid DeleteImage(Image *image);     // Both functions below\nvoid DeleteData(Image *image);      // Frees only pixel data\nvoid DeleteContainer(Image *image); // Frees only image structure, not its pixel data\n```\n\n`DeleteImage` may be called in the end of using your image.\n\n`DeleteContainer` and `DeleteData` may be called inside your functions that operate on images.\n\n## Brief description of main macros/functions\n\n- `pix(r, g, b)` macro is a shortcut to create a `Pixel` structure from given R, G and B values\n\n- `pixi(image, x, y)` macro gets an access to an image pixel.\n    Example:\n    ```c\n    pixi(img1, 10, 34) = pix(255, 255, 0);\n    ```\n    This code sets a pixel of img1 with coordinates (10;34) to yellow color.\n\n- ```Pixel avgpix(Pixel pixel1, Pixel pixel2, uint a, uint b);```\n  This function makes an avarage from two pixels with ratio a:b\n  \n- ```Image *CreateImage(uint width, uint height);```\n  Allocates memory to store an image with given size\n\n- ```Image *CreateCompatible(Image *image);```\n  Creates an image with the same size\n\n\n## Further reading\n\nTake a look at `bmp.h` and `images.h` files.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarklagodych%2Fbmp_c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarklagodych%2Fbmp_c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarklagodych%2Fbmp_c/lists"}