Windows Bitmap Library

Contents:

Introduction

This is a simple library for importing and manipulating windows bitmap files.

Currently only 24 bit uncompressed bitmaps are supported.

I developed this library for the purpose of teaching myself some image processing methods. So, the API will most likely change in the future as I add new stuff.

There is a lot of space for code optimiztion - most of the algorithms are trivially parallel - excellent use case for things like pthreads, openMP, CUDA or x86 vector instructions.

Quickstart

These sample programs illustrate how to access and manipulate pixel data in the bitmap:

Example 1

Brightness adjustment:

_images/lena.jpg _images/frob.jpg
#include <libwinbmp.c>
#include <stdio.h>
#define STEP 64

int main(void)
{
    bmp_t *bmp;
    bmp = bmp_load("/home/jakub/bmp-parser/lena.bmp");
    unsigned int row_size = bmp->info.width * 3;
    unsigned int x;
    unsigned int y;
    int d;

    for (y = 0; y < bmp->info.height; y++) {
        for (x = 0; x < row_size; x++) {
            d = (int)bmp->data[y][x] + STEP;
            if (d > 255) {
                d = 255;
            } else if (d < 0) {
                d = 0;
            }
            bmp->data[y][x] = (unsigned char)d;
        }
    }

    bmp_write(bmp,"/home/jakub/bmp-parser/frob.bmp");
    bmp_destroy(bmp);
    return 0;
}

Example 2

Averaging two images:

_images/lena.jpg _images/beach.jpg _images/frob2.jpg
#include <libwinbmp.c>
#include <stdio.h>


int main(void)
{
    bmp_t *bmp;
    bmp_t *other;
    bmp = bmp_load("/home/jakub/bmp-parser/lena.bmp");
    other = bmp_load("/home/jakub/bmp-parser/beach.bmp");

    bmp_average(bmp, other);

    bmp_write(bmp,"/home/jakub/bmp-parser/frob.bmp");
    bmp_destroy(bmp);
    bmp_destroy(other);
    return 0;
}

libwinbmp.h

Structures

`bmp_file_header_t`_
Bitmap file info.
`bmp_bitmap_info_header_t`_
Bitmap data info.
`bmp_t`_
Bitmap structure.

Utility Functions

`bmp_t *bmp_load(const char *path)`_
Loads bitmap file from the path into bmp_t structure.
`int bmp_write(bmp_t *bmp, const char *path)`_
Writes in-memory bitmap to a file.
`void bmp_destroy(bmp_t *bmp)`_
Deallocates memory taken up by the bitmap.
`unsigned int get_row_size(bmp_t *bmp)`_
Calculates row size including 4-byte alignment padding.
`unsigned int get_pixel_array_size(bmp_t *bmp)`_
Calculates pixel array size including 4-byte alignment padding.

Image Functions

Just a bunch of simple functions.

Image Arithmetic
`bmp_t *bmp_add(bmp_t *bmp, const bmp_t *other)`_
Adds two bitmaps.
`bmp_t *bmp_subtract(bmp_t *bmp, const bmp_t *other)`_
Subtracts two bitmaps.
`bmp_t *bmp_difference(bmp_t *bmp, const bmp_t *other)`_
Subtracts two bitmaps (absolute pixel distance is returned).
`bmp_t *bmp_multiply(bmp_t *bmp, const bmp_t *other)`_
Multiplies two bitmaps.
`bmp_t *bmp_average(bmp_t *bmp, const bmp_t *other)`_
Returns minimum of two pixels.
`bmp_t *bmp_min(bmp_t *bmp, const bmp_t *other)`_
Returns maximum of two pixels.
Convolution Filters
`bmp_t *bmp_blur(bmp_t *bmp)`_
Blurs the bitmap.
`bmp_t *bmp_edges(bmp_t *bmp)`_
Detects the edges.
`bmp_t *bmp_sharpen(bmp_t *bmp)`_
Sharpens the image.
`bmp_t *bmp_emboss(bmp_t *bmp)`_
Creates emboss effect.
`bmp_t *bmp_mean(bmp_t *bmp)`_
Mean blur filter.

Indices and tables