{"id":16811681,"url":"https://github.com/raysan5/rpng","last_synced_at":"2025-04-13T06:33:36.940Z","repository":{"id":49351501,"uuid":"267284987","full_name":"raysan5/rpng","owner":"raysan5","description":"A simple and easy-to-use library to load/save png images and manage png chunks","archived":false,"fork":false,"pushed_at":"2024-09-03T10:56:47.000Z","size":3433,"stargazers_count":169,"open_issues_count":1,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-14T10:19:30.771Z","etag":null,"topics":["c","data-structures","fileformat","gamedev"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raysan5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"raysan5","patreon":"raylib","open_collective":null,"ko_fi":"raysan","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-05-27T10:06:23.000Z","updated_at":"2024-10-08T01:52:28.000Z","dependencies_parsed_at":"2022-09-07T04:00:51.381Z","dependency_job_id":"156a141a-ac85-41ed-b601-9c6206604da8","html_url":"https://github.com/raysan5/rpng","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Frpng","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Frpng/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Frpng/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raysan5%2Frpng/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raysan5","download_url":"https://codeload.github.com/raysan5/rpng/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674677,"owners_count":21143760,"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":["c","data-structures","fileformat","gamedev"],"created_at":"2024-10-13T10:19:26.721Z","updated_at":"2025-04-13T06:33:36.915Z","avatar_url":"https://github.com/raysan5.png","language":"C","funding_links":["https://github.com/sponsors/raysan5","https://patreon.com/raylib","https://ko-fi.com/raysan"],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"left\" src=\"https://github.com/raysan5/rpng/blob/master/logo/rpng_256x256.png\" width=256\u003e\n\n**rpng is a simple and easy-to-use library to load/save png images and manage png chunks.**\n\n`rpng` is provided as a self-contained portable single-file header-only library with no external dependencies. Its only dependency, the standard C library, can also be replaced with a custom implementation if required.\n\n`rpng` implements internally the `DEFLATE` algorithm to allow reading and writing PNG images when required.\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## features\n\n - Load/save png files from raw image data\n - Load/save png indexed data and palette\n - Count/read/write/remove png chunks\n - Operates on file or memory-buffer\n - Chunks data abstraction (`png_chunk` type)\n - Minimal `libc` usage and `RPNG_NO_STDIO` supported\n \n## basic functions\n```c\n// Load/Save a PNG file from image data (IHDR, IDAT, PLTE, tRNS IEND)\nchar *rpng_load_image(const char *filename, int *width, int *height, int *color_channels, int *bit_depth);\nchar *rpng_load_image_indexed(const char *filename, int *width, int *height, rpng_palette *palette);\nint rpng_save_image(const char *filename, const char *data, int width, int height, int color_channels, int bit_depth);\nint rpng_save_image_indexed(const char *filename, const char *indexed_data, int width, int height, rpng_palette palette);\n\n// Read and write chunks from file\nint rpng_chunk_count(const char *filename);                                  // Count the chunks in a PNG image\nrpng_chunk rpng_chunk_read(const char *filename, const char *chunk_type);    // Read one chunk type\nrpng_chunk *rpng_chunk_read_all(const char *filename, int *count);           // Read all chunks\nvoid rpng_chunk_remove(const char *filename, const char *chunk_type);        // Remove one chunk type\nvoid rpng_chunk_remove_ancillary(const char *filename);                      // Remove all chunks except: IHDR-PLTE-IDAT-IEND\nvoid rpng_chunk_write(const char *filename, rpng_chunk data);                // Write one new chunk after IHDR (any kind)\n\n// Chunk utilities\nvoid rpng_chunk_print_info(const char *filename);                            // Output info about the chunks\nbool rpng_chunk_check_all_valid(const char *filename);                       // Check chunks CRC is valid\nvoid rpng_chunk_combine_image_data(const char *filename);                    // Combine multiple IDAT chunks into a single one\nvoid rpng_chunk_split_image_data(const char *filename, int split_size);      // Split one IDAT chunk into multiple ones\n```\n\n## design notes\n`rpng` includes an advanced API to work directly on memory buffers, to avoid direct file access or allow virtual file systems.\nThose functions share the same signature than file functions but add a `_from_memory()` suffix and receive the memory buffer instead of the filename, some of them also return the file output size. Here an example:\n```c\nrpng_chunk rpng_chunk_read(const char *filename, const char *chunk_type);            // Read one chunk type\n```\n```c\nrpng_chunk rpng_chunk_read_from_memory(const char *buffer, const char *chunk_type);  // Read one chunk type from memory\n```\n*Note an important detail:* memory functions do not receive the size of the buffer. It was a design decision.\nData is validated following PNG specs (png magic number, chunks data, IEND closing chunk) but it's expected that user provides valid data.\n\nMemory functions that require writing data, return the output buffer size as a parameter: `int *output_size` and are limited in size by `RPNG_MAX_OUTPUT_SIZE` definition, by default **64MB**, redefine that number if dealing with bigger PNG images.\n\n## usage example\n\nWrite a custom data chunk into a png file:\n```c\n#define RPNG_IMPLEMENTATION\n#include \"rpng.h\"\n\nint main()\n{\n    CustomDataType customData = { 0 };\n\n    // TODO: Fill your custom data\n\n    rpng_chunk chunk = { 0 };\n    memcpy(chunk.type, \"cSTm\", 4);\n    chunk.length = sizeof(CustomDataType);\n    chunk.data = \u0026customData;\n    chunk.crc = 0;   // Automatically computed on writing\n\n    rpng_chunk_write(\"my_image.png\", chunk);  // Write custom chunk\n}\n```\n\nSeveral chunk operations on a command line input file:\n```c\n#define RPNG_IMPLEMENTATION\n#include \"rpng.h\"\n\nint main(int argc, char *argv[])\n{\n    if (argc \u003e 1)\n    {\n        // TEST: Print chunks info\n        rpng_chunk_print_info(argv[1]);\n\n        // TEST: Write tEXt chunk\n        rpng_chunk_write_text(argv[1], \"Description\", \"rpng, library to manage png chunks\");\n\n        // TEST: Remove tEXt chunk\n        rpng_chunk_remove(argv[1], \"tEXt\");\n        \n        // TEST: Remove all ancillary chunks\n        rpng_chunk_remove_ancillary(argv[1]);\n    }\n    else printf(\"WARNING: No input file provided.\\n\");\n\n    return 0;\n}\n```\n\nThere is a complete example [here](https://github.com/raysan5/rpng/blob/master/examples/rpng_test_suite.c).\n\n## license\n\nrpng is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraysan5%2Frpng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraysan5%2Frpng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraysan5%2Frpng/lists"}