- Main Page
- Data Structures
- Files
- Related Pages

# pgm.h File Reference

Portable graymap format (PGM) parser. More...

`#include "generic.h"`
`#include <stdio.h>`

Go to the source code of this file.

## Data Structures
struct | _VlPgmImage
| PGM image meta data. More...
## Defines
PGM parser error codes
#define | VL_ERR_PGM_INV_HEAD 101
#define | VL_ERR_PGM_INV_META 102
#define | VL_ERR_PGM_INV_DATA 103
#define | VL_ERR_PGM_IO 104
## Typedefs
typedef struct _VlPgmImage | VlPgmImage
| PGM image meta data type.
## Functions
int | vl_pgm_extract_head (FILE *f, VlPgmImage *im)
| Read PGM header.
int | vl_pgm_extract_data (FILE *f, VlPgmImage const *im, void *data)
| Read PGM data.
int | vl_pgm_insert (FILE *f, VlPgmImage const *im, void *data)
| Write a PGM image.
int | vl_pgm_get_data_size (VlPgmImage const *im)
| Get PGM image data size.
int | vl_pgm_get_bpp (VlPgmImage const *im)
| Get PGM image bytes per pixel.

## Detailed Description

Author:
  Andrea Vedaldi

To read a PGM image, first call vl_pgm_extract_head() to extract the image meta data (size and bit-depth). Then allocate the appropriate buffer and call vl_pgm_extract_data().

To write a PGM image use vl_pgm_insert().

## Define Documentation

#define VL_ERR_PGM_INV_DATA 103

Invalid PGM data section.

#define VL_ERR_PGM_INV_HEAD 101

Invalid PGM heder serction.

#define VL_ERR_PGM_INV_META 102

Invalid PGM meta section.

#define VL_ERR_PGM_IO 104

Generic I/O error.

## Typedef Documentation

typedef struct _VlPgmImage VlPgmImage

See also:
  _VlPgmImage.

## Function Documentation

int vl_pgm_extract_data | ( | FILE * | f,
|  | VlPgmImage const * | im,
|  | void * | data |
| ) |  |  |

Parameters:

  | f | input file.
  | im | PGM image descriptor.
  | data | data buffer to fill.

The function extracts from the file f the data section of an image encoded in PGM format. The function fills the buffer data according.

Returns:
  error code.

int vl_pgm_extract_head | ( | FILE * | f,
|  | VlPgmImage * | im |
| ) |  |  |

----------------------------------------------------------------

Parameters:

  | f | input file.
  | im | image structure to fill.

The function extracts from the file f the meta-data section of an image encoded in PGM format. The function fills the structure VlPgmImage according.

Returns:
  error code. The function sets vl_err_no to VL_PGM_INV_HEAD or VL_PGM_INV_META depending wether the error occurred in decoding the header or meta section of the PGM file.

int vl_pgm_get_bpp | ( | VlPgmImage const * | im | ) |

Parameters:

  | im | PGM image descriptor.

The functions returns the number of bytes for each pixel of the PGM image im.

Returns:
  number of bytes per pixel.

int vl_pgm_get_data_size | ( | VlPgmImage const * | im | ) |

Parameters:

  | im | PGM image descriptor.

The functions returns the number of pixels of the PGM image im.

To calculate the image data size in bytes, this value must be multiplied by the number of byte per pixels (see vl_pgm_get_bpp()).

Returns:
  number of pixels of the image.

int vl_pgm_insert | ( | FILE * | f,
|  | VlPgmImage const * | im,
|  | void * | data |
| ) |  |  |

Parameters:

  | f | output file.
  | im | PGM image meta-data.
  | data | image data.

Returns:
  error code.