pgm.c File Reference
Detailed Description
Definition in file pgm.c.
#include "pgm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Functions | |
static int | remove_line (FILE *f) |
Remove all characters to the next new-line. | |
static int | remove_blanks (FILE *f) |
Remove white-spaces and comments. | |
VL_EXPORT int | vl_pgm_get_npixels (VlPgmImage const *im) |
Get PGM image number of pixels. | |
VL_EXPORT int | vl_pgm_get_bpp (VlPgmImage const *im) |
Get PGM image bytes per pixel. | |
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 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. | |
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. |
Function Documentation
static int remove_blanks | ( | FILE * | f | ) | [static] |
For internal use only.
- Parameters:
-
f file to strip.
- Returns:
- number of characters removed.
Definition at line 74 of file pgm.c.
References remove_line().
Referenced by vl_pgm_extract_head().
static int remove_line | ( | FILE * | f | ) | [static] |
For internal use only.
- Parameters:
-
f file to strip.
- Returns:
- number of characters removed.
Definition at line 44 of file pgm.c.
Referenced by remove_blanks().
VL_EXPORT 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.
- Returns:
- error code.
Definition at line 270 of file pgm.c.
References _VlPgmImage::is_raw, vl_err_msg, VL_ERR_MSG_LEN, vl_err_no, VL_ERR_PGM_INV_DATA, vl_pgm_get_bpp(), and vl_pgm_get_npixels().
Referenced by vl_pgm_read_new().
VL_EXPORT int vl_pgm_extract_head | ( | FILE * | f, | |
VlPgmImage * | im | |||
) |
- Parameters:
-
f input file. im image structure to fill.
- Returns:
- error code. The function sets vl_err_no to VL_PGM_INV_HEAD or VL_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.
References remove_blanks(), vl_err_no, VL_ERR_PGM_INV_HEAD, and VL_ERR_PGM_INV_META.
Referenced by vl_pgm_read_new().
VL_EXPORT int vl_pgm_get_bpp | ( | VlPgmImage const * | im | ) |
- Parameters:
-
im PGM image descriptor.
- Returns:
- number of bytes per pixel.
Definition at line 139 of file pgm.c.
References _VlPgmImage::max_value.
Referenced by vl_pgm_extract_data(), vl_pgm_insert(), and vl_pgm_read_new().
VL_EXPORT int vl_pgm_get_npixels | ( | VlPgmImage const * | im | ) |
- Parameters:
-
im PGM image descriptor.
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.
Definition at line 121 of file pgm.c.
References _VlPgmImage::height, and _VlPgmImage::width.
Referenced by vl_pgm_extract_data(), vl_pgm_insert(), vl_pgm_read_new(), and vl_pgm_read_new_f().
VL_EXPORT int vl_pgm_insert | ( | FILE * | f, | |
VlPgmImage const * | im, | |||
void const * | data | |||
) |
- Parameters:
-
f output file. im PGM image meta-data. data image data.
- Returns:
- error code.
Definition at line 348 of file pgm.c.
References _VlPgmImage::height, _VlPgmImage::max_value, vl_err_msg, VL_ERR_MSG_LEN, vl_err_no, VL_ERR_PGM_IO, vl_free(), vl_malloc(), vl_pgm_get_bpp(), vl_pgm_get_npixels(), and _VlPgmImage::width.
Referenced by vl_pgm_write().
VL_EXPORT int vl_pgm_read_new | ( | char const * | name, | |
VlPgmImage * | im, | |||
vl_uint8 ** | data | |||
) |
- Parameters:
-
name file name. im a pointer to the PGM image structure to fill. data a pointer to the pointer to the allocated buffer.
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.
- Returns:
- error code.
Definition at line 410 of file pgm.c.
References VL_ERR_BAD_ARG, vl_err_msg, VL_ERR_MSG_LEN, vl_err_no, VL_ERR_PGM_IO, vl_free(), vl_malloc(), vl_pgm_extract_data(), vl_pgm_extract_head(), vl_pgm_get_bpp(), and vl_pgm_get_npixels().
Referenced by vl_pgm_read_new_f().
VL_EXPORT int vl_pgm_read_new_f | ( | char const * | name, | |
VlPgmImage * | im, | |||
float ** | data | |||
) |
- Parameters:
-
name file name. im a pointer to the PGM image structure to fill. data a pointer to the pointer to the allocated buffer.
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.
- Returns:
- error code.
Definition at line 468 of file pgm.c.
References _VlPgmImage::max_value, vl_free(), vl_malloc(), vl_pgm_get_npixels(), and vl_pgm_read_new().
VL_EXPORT int vl_pgm_write | ( | char const * | name, | |
vl_uint8 const * | data, | |||
int | width, | |||
int | height | |||
) |
- Parameters:
-
name file name. data data to write. width width of the image. height height of the image.
- Returns:
- error code.
Definition at line 507 of file pgm.c.
References _VlPgmImage::height, _VlPgmImage::is_raw, _VlPgmImage::max_value, vl_err_msg, VL_ERR_MSG_LEN, vl_err_no, VL_ERR_PGM_IO, vl_pgm_insert(), and _VlPgmImage::width.
Referenced by vl_pgm_write_f().
VL_EXPORT int vl_pgm_write_f | ( | char const * | name, | |
float const * | data, | |||
int | width, | |||
int | height | |||
) |
- Parameters:
-
name file name. data data to write. width width of the image. height height of the image.
- Returns:
- error code.
Definition at line 549 of file pgm.c.
References VL_EPSILON_F, vl_free(), VL_INFINITY_F, vl_malloc(), VL_MAX, VL_MIN, and vl_pgm_write().