Home

Awesome

Bitmap API

GitHub GitHub commit activity GitHub code size in bytes

A C library for manipulating bitmap/raster graphics in memory and on disk.

#include <stdio.h>
#include "bmp.h"

int main(int argc, char *argv[]) {
    Bitmap *b = bm_create(128,128);

    bm_set_color(b, bm_atoi("white"));
    bm_puts(b, 30, 60, "Hello World");

    bm_save(b, "out.gif");
    bm_free(b);
    return 0;
}

The code is licensed under the terms of the MIT-0 License. See the file LICENSE for details.

Attribution is appreciated, but not required.

Features:

The fonts/ directory contains some 8-bit style bitmap fonts in XBM format.

Getting Started

Copy bmp.c and bmp.h to your project directory, and add bmp.c to your list of files to compile.

To enable PNG support you need zlib and libpng (the development versions) installed. If you are using GCC, do the following:

Other compilers might have diffent flags. See the libpng documentation for your platform.

Likewise, to enable JPEG support, you need libjpeg installed and specify the -DUSEJPG command line option when compiling and add -ljpeg to your linker options.

To use stb_image, put the stb_image.h file in the same directory as bmp.c (or use your compiler's -I option to point it to stb_image.h's path), and add -DUSESTB to your compiler flags.

Similarly, to use stb_image_write, put the stb_image_write.h file in the same directory as bmp.c, and add -DUSESTBW to your compiler flags.

Use bm_create() to create Bitmap objects and bm_free() to destroy them.

bm_bind() can be used to wrap a Bitmap object around an existing buffer of bytes, such as OpenGL textures and SDL surfaces.

The Makefile generates HTML documentation from bmp.h through the d.awk script. Type make docs to create the documentation.

A basic CMakeLists.txt file is also provided for CMake, but you might need to adapt it to your specific needs. To build with CMake, use the following commands:

mkdir build; cd build
cmake -G "Unix Makefiles" ..
make

Additional Utilities

References

TODO