/* pbmio
 *
 * A library of portable bitmap (PBM) routines for use with libnetpbm
 *
 * Jerod Weinman
 */
#ifndef __PBMIO_H__
#define __PBMIO_H__

/* Make libnetpbm play nicely with C++, which is necessary to link with CUDA */
extern "C" {
#include <ppm.h>
}

typedef struct {
     bit **bits; /* 2D array is a pointer to an array of pointers */
     int rows;
     int cols;
} pbm_t;

/* Read a pbm file from disk.
 *
 * If there is any failure, an error is printed to STDERR and a
 * negative value is returned. Otherwise zero is returned and the
 * pbm_t is filled in.
 *
 * Uses a libnetpbm function that may cause program abort upon failure.
 */
int pbmread( const char *file, pbm_t *im);

/* Write a pbm file to disk.
 *
 * If there is any failure, an error is printed to STDERR and a
 * negative value is returned. Otherwise zero is returned and the
 * pbm_t is filled in.
 *
 * Uses a libnetpbm function that may cause program abort upon failure.
 */
int pbmwrite( const char *file,  pbm_t *im);

/* Allocate memory for the pbm_t
 * If there is any failure, an error is printed to STDERR and a
 * negative value is returned. Otherwise zero is returned and the
 * pbm_t is filled in.
 */
int pbmalloc( pbm_t *im, int rows, int cols);

/* Free a pbm structure */
void pbmfree( pbm_t *im);

/* Copy the data from one pbm_t to another.
 * Assumes the buffers are the same size.
 * Returns a negative value if dst has a size different from src, and
 * zero otherwise. 
 */
int pbmcopy( pbm_t *dst, const pbm_t *src);

#endif
