Giter Site home page Giter Site logo

bitmap's Introduction

Bitmap API

A C library for manipulating bitmap 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 License. See the file LICENSE for details.

Features:

  • Supported formats:
    • Windows BMP, GIF, PCX and TGA files can be loaded and saved without third-party dependencies.
    • PNG through libpng
    • JPEG through libjpeg
    • Alternatively, PNG and JPEG files can be loaded through the Sean Barrett's stb_image image loader library. stb_image supports a couple of additional formats, such as PSD, PIC and PNM binary formats. See bm_load_stb() for more information.
  • Supports manipulation of OpenGL textures, SDL surfaces, GDI contexts. See the bm_bind() function. It can also serve as a back end for Cairo graphics
  • Support for SDL2's SDL_RWops file manipulation routines for loading images in the supported formats.
  • Primitives: Lines, circles, elipses, bezier curves, polygons, etc.
    • Clipping rectangles are obeyed.
  • Floodfill and filled primitives.
  • Image resizing: nearest neighbour, bilinear and bicubic.
  • Blitting, blitting with color masks, scaled and rotated blitting.
  • Text rendering: FreeType support and built-in 8-bit style raster fonts.
  • Filtering with kernels and smoothing.
  • CSS-style colors.
  • Loading images from XBM and X PixMap data.
  • Cross platform. It's been known to compile under Windows (MinGW), Linux, Android and Web via Emscripten.

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:

  • Use these flags -DUSEPNG `libpng-config --cflags` when compiling.
  • Add `libpng-config --ldflags` -lz when linking.

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, and add -DUSESTB 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][dawk] script. Type make docs to create the documentation.

Additional Utilities

  • The fonts/ directory contains some 8ร—8 bitmap fonts in XBM format that can be loaded via the bm_make_xbm_font() function.
  • The ftypefont/ directory contains a wrapper for FreeType to allow rendering of freetype-supported fonts on Bitmap structures.
  • The misc/ directory contains
    • gif.c and gif.h - code for programmatically manipulating animated GIFs. It originates from the file I used to develop the GIF encoder/decoder originally.
    • cairoback.c - A demo of how the bitmap objects can be used as a back-end for the Cairo graphics library
    • The palette/ subdirectory contains a utility for generating palettes and converting images to those palettes.
    • pbm.c and xpm.c: Samples on how to use the module with PBM and XPM file formats. to_xbm.c contains a function that can output a bitmap as a XBM.
    • The kmeans/ subdirectory contains a program that uses K-means clustering to identify the dominant colors in an image.
    • imgdup.c is a program that scans directories for duplicate images using the dHash algorithm.

References

bitmap's People

Contributors

wernsey avatar

Watchers

James Cloos avatar Vardan Mikayelyan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.