All Projects → raysan5 → rpng

raysan5 / rpng

Licence: Zlib License
A simple and easy-to-use library to manage png chunks

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to rpng

kha-tutorial-series
source code from kha tutorial series
Stars: ✭ 56 (-22.22%)
Mutual labels:  gamedev
Open2Nord
A Python script that makes connecting to NordVPN servers through OpenVPN GUI a lot easier, and adds extra functionality
Stars: ✭ 22 (-69.44%)
Mutual labels:  gamedev
js13k-ecs
A 1kb entity component system, designed for Js13kGames
Stars: ✭ 76 (+5.56%)
Mutual labels:  gamedev
ure
the unRogueEngine
Stars: ✭ 111 (+54.17%)
Mutual labels:  gamedev
CategoryTool
Unity Editor tool to create Categories in the Hierarchy. The Categories work as dividers between GameObjects.
Stars: ✭ 47 (-34.72%)
Mutual labels:  gamedev
saddy-graphics-engine-2d
Saddy is an open-source crossplatform 2D graphic engine, based on OpenGL, which can be used for creating 2D games. like platformers or RPGs.
Stars: ✭ 51 (-29.17%)
Mutual labels:  gamedev
unity-plumber
A component to procedurally generate pipe-like meshes in Unity
Stars: ✭ 55 (-23.61%)
Mutual labels:  gamedev
FNA-VSCode-Template
Template, build tasks, and easy-install scripts for making FNA + Nez games with VSCode
Stars: ✭ 28 (-61.11%)
Mutual labels:  gamedev
SimpleTilemap
A fast, easy way to generate runtime tilemaps in Unity
Stars: ✭ 37 (-48.61%)
Mutual labels:  gamedev
FlaxSamples
Collection of example projects for Flax Engine
Stars: ✭ 50 (-30.56%)
Mutual labels:  gamedev
ToolKit
2d - 3d game and interactive application develepment kit
Stars: ✭ 26 (-63.89%)
Mutual labels:  gamedev
SDL.zig
A shallow wrapper around SDL that provides object API and error handling
Stars: ✭ 102 (+41.67%)
Mutual labels:  gamedev
SimpleIncremental
A simple Unity project that introduces many of Unity's cooler advanced concepts.
Stars: ✭ 51 (-29.17%)
Mutual labels:  gamedev
cage
Cage (Ain't a Game Engine) - write 2D games using plain C
Stars: ✭ 40 (-44.44%)
Mutual labels:  gamedev
awesome-gamejam
This is a curated list that contains helpful links and resources for game jams and game development.
Stars: ✭ 38 (-47.22%)
Mutual labels:  gamedev
Entitas-Java
Entity Component System (ECS) in Java 8
Stars: ✭ 37 (-48.61%)
Mutual labels:  gamedev
PICO-EC
A tiny scene-entity-component library created for the PICO-8 fantasty console.
Stars: ✭ 37 (-48.61%)
Mutual labels:  gamedev
tuile
Tuile (french for tile) is a 2D graphics engine inspired from old hardware and based on layers, tiles sets, tile maps and sprites. Its scanline rendering pipeline makes it perfect for raster effects.
Stars: ✭ 19 (-73.61%)
Mutual labels:  gamedev
RamenEngine
A game engine written in SwiftForth.
Stars: ✭ 53 (-26.39%)
Mutual labels:  gamedev
UnityDebug
A wrapper script for Unity debug calls to use conditional attributes in order to avoid debug code being compiled into release builds.
Stars: ✭ 29 (-59.72%)
Mutual labels:  gamedev

rpng is a simple and easy-to-use library to manage png chunks.

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.

rpng implements internally the DEFLATE algorithm to allow reading and writing PNG images when required.



features

  • Load/Save png files from raw image data
  • Count/read/write/remove png chunks
  • Operates on file or memory-buffer
  • Chunks data abstraction (png_chunk type)
  • Minimal libc usage and RPNG_NO_STDIO supported

basic functions

// Load/Save a PNG file from image data (IHDR, IDAT, IEND)
char *rpng_load_image(const char *filename, int *width, int *height, int *color_channels, int *bit_depth);
void rpng_save_image(const char *filename, const char *data, int width, int height, int color_channels, int bit_depth);

// Read and write chunks from file
int rpng_chunk_count(const char *filename);                                  // Count the chunks in a PNG image
rpng_chunk rpng_chunk_read(const char *filename, const char *chunk_type);    // Read one chunk type
rpng_chunk *rpng_chunk_read_all(const char *filename, int *count);           // Read all chunks
void rpng_chunk_remove(const char *filename, const char *chunk_type);        // Remove one chunk type
void rpng_chunk_remove_ancillary(const char *filename);                      // Remove all chunks except: IHDR-PLTE-IDAT-IEND
void rpng_chunk_write(const char *filename, rpng_chunk data);                // Write one new chunk after IHDR (any kind)

// Chunk utilities
void rpng_chunk_print_info(const char *filename);                            // Output info about the chunks
bool rpng_chunk_check_all_valid(const char *filename);                       // Check chunks CRC is valid
void rpng_chunk_combine_image_data(const char *filename);                    // Combine multiple IDAT chunks into a single one
void rpng_chunk_split_image_data(const char *filename, int split_size);      // Split one IDAT chunk into multiple ones

design notes

rpng includes an advanced API to work directly on memory buffers, to avoid direct file access or allow virtual file systems. Those 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:

rpng_chunk rpng_chunk_read(const char *filename, const char *chunk_type);            // Read one chunk type
rpng_chunk rpng_chunk_read_from_memory(const char *buffer, const char *chunk_type);  // Read one chunk type from memory

Note an important detail: memory functions do not receive the size of the buffer. It was a design decision. Data is validated following PNG specs (png magic number, chunks data, IEND closing chunk) but it's expected that user provides valid data.

Memory 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 32MB, redefine that number if dealing with bigger PNG images.

usage example

Write a custom data chunk into a png file:

#define RPNG_IMPLEMENTATION
#include "rpng.h"

int main()
{
    CustomDataType customData = { 0 };

    // TODO: Fill your custom data

    rpng_chunk chunk = { 0 };
    memcpy(chunk.type, "cSTm", 4);
    chunk.length = sizeof(CustomDataType);
    chunk.data = &customData;
    chunk.crc = 0;   // Automatically computed on writing

    rpng_chunk_write("my_image.png", chunk);  // Write custom chunk
}

Several chunk operations on a command line input file:

#define RPNG_IMPLEMENTATION
#include "rpng.h"

int main(int argc, char *argv[])
{
    if (argc > 1)
    {
        // TEST: Print chunks info
        rpng_chunk_print_info(argv[1]);

        // TEST: Write tEXt chunk
        rpng_chunk_write_text(argv[1], "Description", "rpng, library to manage png chunks");

        // TEST: Remove tEXt chunk
        rpng_chunk_remove(argv[1], "tEXt");
        
        // TEST: Remove all ancillary chunks
        rpng_chunk_remove_ancillary(argv[1]);
    }
    else printf("WARNING: No input file provided.\n");

    return 0;
}

There is a complete example here.

license

rpng 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 for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].