Classes | Typedefs
pgm.h File Reference

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

#include "generic.h"
#include "mathop.h"
#include <stdio.h>
Include dependency graph for pgm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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.

Functions

Core operations
VL_EXPORT int vl_pgm_extract_head (FILE *f, VlPgmImage *im)
 Extract PGM header from stream.
VL_EXPORT int vl_pgm_extract_data (FILE *f, VlPgmImage const *im, void *data)
 Extract PGM data from stream.
VL_EXPORT int vl_pgm_insert (FILE *f, VlPgmImage const *im, void const *data)
 Insert a PGM image into a stream.
VL_EXPORT vl_size vl_pgm_get_npixels (VlPgmImage const *im)
 Get PGM image number of pixels.
VL_EXPORT vl_size vl_pgm_get_bpp (VlPgmImage const *im)
 Get PGM image bytes per pixel.
Helper functions
VL_EXPORT int vl_pgm_write (char const *name, vl_uint8 const *data, int width, int height)
 Write bytes to a PGM file.
VL_EXPORT int vl_pgm_write_f (char const *name, float const *data, int width, int height)
 Write floats to PGM file.
VL_EXPORT int vl_pgm_read_new (char const *name, VlPgmImage *im, vl_uint8 **data)
 Read a PGM file.
VL_EXPORT int vl_pgm_read_new_f (char const *name, VlPgmImage *im, float **data)
 Read floats from a PGM file.

Detailed Description

Portable graymap format (PGM) parser.

This module implements basic input and ouptut of images in PGM format.

Extracting an image encoded in PGM format from an imput file stream involves the following steps:

Writing an image in PGM format to an ouptut file stream can be done by using vl_pgm_insert.

To quickly read/write a PGM image from/to a given file, use vl_pgm_read_new() and vl_pgm_write(). To to the same from a buffer in floating point format use vl_pgm_read_new_f() and vl_pgm_write_f().

Author:
Andrea Vedaldi

Definition in file pgm.h.


Define Documentation

#define VL_ERR_PGM_INV_DATA   103

Invalid PGM data section.

Definition at line 25 of file pgm.h.

#define VL_ERR_PGM_INV_HEAD   101

Invalid PGM header section.

Definition at line 23 of file pgm.h.

#define VL_ERR_PGM_INV_META   102

Invalid PGM meta section.

Definition at line 24 of file pgm.h.

#define VL_ERR_PGM_IO   104

Generic I/O error.

Definition at line 26 of file pgm.h.


Typedef Documentation

typedef struct _VlPgmImage VlPgmImage

PGM image meta data.

A PGM image is a 2-D array of pixels of width #width and height #height. Each pixel is an integer one or two bytes wide, depending whether #max_value is smaller than 256.


Function Documentation

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

Extract PGM data from stream.

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

Parameters:
finput file.
imPGM image descriptor.
datadata buffer to fill.
Returns:
error code.

The function extracts from the file f the data section of an image encoded in PGM format. The function fills the buffer data according. The buffer data should be vl_pgm_get_npixels() by vl_pgm_get_bpp() bytes large.

Definition at line 263 of file pgm.c.

VL_EXPORT int vl_pgm_extract_head ( FILE *  f,
VlPgmImage im 
)

Extract PGM header from stream.

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

Parameters:
finput file.
imimage structure to fill.
Returns:
error code.

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

The error may be either VL_ERR_PGM_INV_HEAD or VL_ERR_PGM_INV_META depending whether the error occurred in decoding the header or meta section of the PGM file.

Definition at line 161 of file pgm.c.

VL_EXPORT vl_size vl_pgm_get_bpp ( VlPgmImage const *  im)

Get PGM image bytes per pixel.

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

Parameters:
imPGM image descriptor.
Returns:
number of bytes per pixel.

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

Definition at line 140 of file pgm.c.

VL_EXPORT vl_size vl_pgm_get_npixels ( VlPgmImage const *  im)

Get PGM image number of pixels.

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

Parameters:
imPGM image descriptor.
Returns:
number of pixels of the image.

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()).

Definition at line 125 of file pgm.c.

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

Insert a PGM image into a stream.

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

Parameters:
foutput file.
imPGM image meta-data.
dataimage data.
Returns:
error code.

Definition at line 337 of file pgm.c.

VL_EXPORT int vl_pgm_read_new ( char const *  name,
VlPgmImage im,
vl_uint8 **  data 
)

Read a PGM file.

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

Parameters:
namefile name.
ima pointer to the PGM image structure to fill.
dataa pointer to the pointer to the allocated buffer.
Returns:
error code.

The function reads a PGM image from file name and initializes the structure im and the buffer data accordingly.

The ownership of the buffer data is transfered to the caller. data should be freed by means of vl_free().

Bug:
Only PGM files with 1 BPP are supported.

Definition at line 394 of file pgm.c.

VL_EXPORT int vl_pgm_read_new_f ( char const *  name,
VlPgmImage im,
float **  data 
)

Read floats from a PGM file.

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

Parameters:
namefile name.
ima pointer to the PGM image structure to fill.
dataa pointer to the pointer to the allocated buffer.
Returns:
error code.

The function reads a PGM image from file name and initializes the structure im and the buffer data accordingly. The buffer data is an array of floats in the range [0, 1].

The ownership of the buffer data is transfered to the caller. data should be freed by means of vl_free().

Bug:
Only PGM files with 1 BPP are supported.

Definition at line 443 of file pgm.c.

VL_EXPORT int vl_pgm_write ( char const *  name,
vl_uint8 const *  data,
int  width,
int  height 
)

Write bytes to a PGM file.

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

Parameters:
namefile name.
datadata to write.
widthwidth of the image.
heightheight of the image.
Returns:
error code.

The function dumps the image data to the PGM file of the specified name. This is an helper function simplifying the usage of vl_pgm_insert().

Definition at line 480 of file pgm.c.

VL_EXPORT int vl_pgm_write_f ( char const *  name,
float const *  data,
int  width,
int  height 
)

Write floats to PGM file.

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

Parameters:
namefile name.
datadata to write.
widthwidth of the image.
heightheight of the image.
Returns:
error code.

The function dumps the image data to the PGM file of the specified name. The data is re-scaled to fit in the range 0-255. This is an helper function simplifying the usage of vl_pgm_insert().

Definition at line 517 of file pgm.c.



libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:52