- Main Page
- Data Structures
- Files
- Related Pages

# pgm.c File Reference

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

`#include "pgm.h"`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`

## Functions
static int | remove_line (FILE *f)
| Reremove all characters to the next new-line.
static int | remove_blanks (FILE *f)
| Reremove white-spaces and comments.
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.
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.

## Detailed Description

Author:
  Andrea Vedaldi

## Function Documentation

static int remove_blanks | ( | FILE * | f | ) | `[static]`

For internal use only.

Parameters:

  | f | file to strip.

Returns:
  number of characted removed.

static int remove_line | ( | FILE * | f | ) | `[static]`

For internal use only.

Parameters:

  | f | file to strip.

Returns:
  number of characted removed.

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.