{"id":16856444,"url":"https://github.com/vallentin/simplebmp","last_synced_at":"2025-12-18T12:12:28.288Z","repository":{"id":25319177,"uuid":"28746051","full_name":"vallentin/SimpleBMP","owner":"vallentin","description":"Small, simple and self-contained library for loading, saving and handling BMP (Bitmap) image files.","archived":false,"fork":false,"pushed_at":"2020-10-02T21:12:50.000Z","size":27,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T05:11:10.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://vallentinsource.com/simplebmp","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/vallentin.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":"2015-01-03T14:42:43.000Z","updated_at":"2021-10-17T12:07:21.000Z","dependencies_parsed_at":"2022-08-24T14:09:36.006Z","dependency_job_id":null,"html_url":"https://github.com/vallentin/SimpleBMP","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/vallentin%2FSimpleBMP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2FSimpleBMP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2FSimpleBMP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2FSimpleBMP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vallentin","download_url":"https://codeload.github.com/vallentin/SimpleBMP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248359118,"owners_count":21090476,"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-10-13T14:04:15.586Z","updated_at":"2025-12-18T12:12:23.022Z","avatar_url":"https://github.com/vallentin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# SimpleBMP\n\nSimpleBMP is a small, simple, self-contained and cross-platform C++ library for loading, saving and\nhandling [BMP (Bitmap) image files](http://en.wikipedia.org/wiki/BMP_file_format).\n\n*The only thing that SimpleBMP uses/requires is the standard library header `\u003cfstream\u003e`.*\n\n---\n\n*SimpleBMP is a young library, so any feedback for improvements and/or missing features are welcome!*\n\n---\n\n## Why SimpleBMP?\n\nBefore making SimpleBMP I was looking for a simple and upfront library for loading and saving BMP files. The only\nthing that I found was cluttered and complex libraries. BMP files are and they should have a simple library, when\nhaving to deal with them!\n\nSimpleBMP mainly has two functions `SimpleBMP::load()` and `SimpleBMP::save()`. SimpleBMP then also offers a class which\nis built around those two functions.\n\n---\n\n\n## Examples\n\n\u003e **There are a lot of examples on how SimpleBMP can be used, in\n\u003e the [\"examples\" directory](https://github.com/vallentin/SimpleBMP/tree/master/examples)!**\n\n- [Generating a Gradient](https://github.com/vallentin/SimpleBMP/blob/master/examples/gradient.cpp)\n- [Apply Grayscale Effect to an Image](https://github.com/vallentin/SimpleBMP/blob/master/examples/grayscale.cpp)\n- [OpenGL Load Texture](https://github.com/vallentin/SimpleBMP/blob/master/examples/opengl_load_texture.cpp)\n- [OpenGL Save Screenshot](https://github.com/vallentin/SimpleBMP/blob/master/examples/opengl_save_screenshot.cpp)\n- [Error Codes](https://github.com/vallentin/SimpleBMP/blob/master/examples/error_codes.cpp)\n- [Packed RGB Values](https://github.com/vallentin/SimpleBMP/blob/master/examples/packed_rgb_values.cpp)\n\nBut basically there are two general ways of using SimpleBMP.\n\n*The following example, is for loading an image, applying the [grayscale effect](http://en.wikipedia.org/wiki/Grayscale) to the loaded image and then save it again!*\n\nThe first way is, where you store and maintain the `width`, `height` and `pixels`.\n\n```cpp\nint width = 0, height = 0;\nunsigned char *pixels = nullptr;\n\nSimpleBMP::load(\u0026width, \u0026height, \u0026pixels, \"input.bmp\");\n\nfor (int i = 0; i \u003c width; i++)\n{\n\tfor (int j = 0; j \u003c height; j++)\n\t{\n\t\tunsigned char red = 0, green = 0, blue = 0;\n\n\t\tSimpleBMP::getPixel(width, height, pixels, i, j, \u0026red, \u0026green, \u0026blue);\n\n\t\tunsigned char gray = (red + green + blue) / 3;\n\n\t\tSimpleBMP::setPixel(width, height, pixels, i, j, gray, gray, gray);\n\t}\n}\n\nSimpleBMP::save(width, height, pixels, \"output.bmp\");\n```\n\nThe second way, is where you use and instanciate a SimpleBMP object.\n\n```cpp\nSimpleBMP bmp;\nbmp.load(\"input.bmp\");\n\nfor (int i = 0; i \u003c bmp.width; i++)\n{\n\tfor (int j = 0; j \u003c bmp.height; j++)\n\t{\n\t\tunsigned char red = 0, green = 0, blue = 0;\n\n\t\tbmp.getPixel(i, j, \u0026red, \u0026green, \u0026blue);\n\n\t\tunsigned char gray = (red + green + blue) / 3;\n\n\t\tbmp.setPixel(i, j, gray, gray, gray);\n\t}\n}\n\nbmp.save(\"output.bmp\");\n```\n\n\n## SimpleBMP + OpenGL\n\nSimpleBMP also has a simple wrapper function for use with OpenGL. But before you can use it, you need to define `SIMPLEBMP_OPENGL` before you include `simplebmp.h`.\n\n```cpp\n#define SIMPLEBMP_OPENGL\n#include \"simplebmp\\simplebmp.h\"\n```\n\nAgain you can both use it with or without having to instanciate a SimpleBMP object.\n\n```cpp\nSimpleBMP::glTexImage2D(width, height, pixels);\n```\n\nor\n\n```cpp\nbmp.glTexImage2D();\n```\n\n#### Complete OpenGL Example\n\n```cpp\n// Always remember that the texture must have\n// a width and height of Power of Two\n//\n// http://en.wikipedia.org/wiki/Power_of_two\n\nGLuint texture_handle;\nglGenTextures(1, \u0026texture_handle);\nglBindTexture(GL_TEXTURE_2D, texture_handle);\n\nbmp.glTexImage2D();\n```\n\n## OpenGL Save Screenshot\n\nSimpleBMP also allows for an easy way to save a screenshot!\n\n```cpp\nconst char *path = \"screenshot.bmp\";\n\n// The width and the height, would be the width\n// and height of your current scene.\nconst int width = 1280;\nconst int height = 720;\n\nSimpleBMP bmp(width, height);\n\nbmp.glReadPixels();\n\nif (!bmp.save(path))\n{\n\tprintf(\"Successfully Saved! \u003c%s\u003e\\n\", path);\n}\nelse\n{\n\tprintf(\"Save Failed! \u003c%s\u003e\\n\", path);\n}\n```\n\n\n\n## Error Codes\n\nThe `save` and `load` functions, return error codes. It is guaranteed that `0 (SIMPLEBMP_NO_ERROR)` is returned when\nno error has happened!\n\n```cpp\n#define SIMPLEBMP_NO_ERROR 0\n#define SIMPLEBMP_FOPEN_ERROR 1\n\n#define SIMPLEBMP_INVALID_SIGNATURE 2\n#define SIMPLEBMP_INVALID_BITS_PER_PIXEL 3\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallentin%2Fsimplebmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvallentin%2Fsimplebmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallentin%2Fsimplebmp/lists"}