Functions

Image I/O and Helpers

The input and output of PGM and CSV files. More...

Functions

NTTW_DLL_SYM int openFile_Read (const char *filename, FILE **inFilePtr, int binary)
 Opens the file for read mode.
NTTW_DLL_SYM int openFile_Write (const char *filename, FILE **inFilePtr, int binary)
 Opens the file for write mode.
NTTW_DLL_SYM int openFile_Append (const char *filename, FILE **inFilePtr, int binary)
 Opens the file for append mode.
NTTW_DLL_SYM int readCSV (nttw_integer **data, const int rows, const int cols, const char *filename)
 Reads a Comma Separated Value (CSV) file. Memory is internally allocated to the correct size.
NTTW_DLL_SYM int readPGMHeader (FILE *inFile, char *type, int *rows, int *cols, int *maxGrey)
 Reads the parameters in the header of a PGM file.
NTTW_DLL_SYM int readPGM (nttw_integer **data, int *rows, int *cols, const char *filename, int binary)
 Reads in an image which has a PGM format of name given.
NTTW_DLL_SYM int readSignedPGM (long **data, int *rows, int *cols, const char *filename, int binary)
 Inputs data as a PGM file with signed values.
NTTW_DLL_SYM int readUCharPGM (unsigned char **data, int *rows, int *cols, const char *filename, int binary)
 Inputs data as a PGM file with signed values.
NTTW_DLL_SYM int writePGM (nttw_integer *data, const int rows, const int cols, const int greyMax, const char *filename, int binary)
 Outputs data as a PGM file.
NTTW_DLL_SYM int writeSignedPGM (long *data, const int rows, const int cols, const int greyMax, const char *filename, int binary)
 Outputs data as a PGM file with signed values.
NTTW_DLL_SYM int writeUCharPGM (unsigned char *data, const int rows, const int cols, const char *filename, int binary)
 Outputs data as a PGM file with unsigned character values.

Detailed Description

The input and output of PGM and CSV files.

Read a PGM file by using readPGM() and write using writePGM(). CSV files can be read using readCSV(). All functions read and write 32-bit integers.


Function Documentation

openFile_Append ( const char *  filename,
FILE **  inFilePtr,
int  binary 
)

Opens the file for append mode.

< Open Binary File.

< Open ASCII File.

Definition at line 71 of file image.c.

openFile_Read ( const char *  filename,
FILE **  inFilePtr,
int  binary 
)

Opens the file for read mode.

< Open Binary File.

< Open ASCII File.

Definition at line 27 of file image.c.

openFile_Write ( const char *  filename,
FILE **  inFilePtr,
int  binary 
)

Opens the file for write mode.

< Open Binary File.

< Open ASCII File.

Definition at line 49 of file image.c.

readCSV ( nttw_integer **  data,
const int  rows,
const int  cols,
const char *  filename 
)

Reads a Comma Separated Value (CSV) file. Memory is internally allocated to the correct size.

Allocate Memory for Image appropriately

Read Data according to size and type provided in header

Close File

Definition at line 93 of file image.c.

readPGM ( nttw_integer **  data,
int *  rows,
int *  cols,
const char *  filename,
int  binary 
)

Reads in an image which has a PGM format of name given.

Takes a reference to a 1D pointer, and reads the file as a 2D array into the 1D array.

Memory is handled internally, no prior allocation is required.

Parameters:
data - This is an array passed by reference, or &(image) where "image" is a 1D array declared with array_1D().
rows - number of rows that the file has. Passed by reference. Prior knowledge of file size is not required. This will contain the number of rows in file.
cols - number of columns that the file has. Passed by reference. Prior knowledge of file size is not required. This will contain the number of columns in file.
filename - The name of the PGM to be opened.
binary - Boolean for reading binary file.
Returns:
TRUE if read is successful.

Allocate Memory for Image appropriately

Read Data according to size and type provided in header

Close File

Definition at line 165 of file image.c.

readPGMHeader ( FILE *  inFile,
char *  type,
int *  rows,
int *  cols,
int *  maxGrey 
)

Reads the parameters in the header of a PGM file.

Read PGM Header Read Filetype and File comment

See if Comment not present

If so, Start again and dont read comment

Read Filetype

Else read comments until none left

Read Image Characteristics

Allocate Memory for Image appropriately

Definition at line 119 of file image.c.

readSignedPGM ( long **  data,
int *  rows,
int *  cols,
const char *  filename,
int  binary 
)

Inputs data as a PGM file with signed values.

Returns:
TRUE if successful.

Allocate Memory for Image appropriately

Read Data according to size and type provided in header

Close File

Definition at line 207 of file image.c.

readUCharPGM ( unsigned char **  data,
int *  rows,
int *  cols,
const char *  filename,
int  binary 
)

Inputs data as a PGM file with signed values.

Returns:
TRUE if successful.

Allocate Memory for Image appropriately

Read Data according to size and type provided in header

Close File

Definition at line 249 of file image.c.

writePGM ( nttw_integer data,
const int  rows,
const int  cols,
const int  greyMax,
const char *  filename,
int  binary 
)

Outputs data as a PGM file.

Returns:
TRUE if successful.

Definition at line 291 of file image.c.

writeSignedPGM ( long *  data,
const int  rows,
const int  cols,
const int  greyMax,
const char *  filename,
int  binary 
)

Outputs data as a PGM file with signed values.

Returns:
TRUE if successful.

Definition at line 316 of file image.c.

writeUCharPGM ( unsigned char *  data,
const int  rows,
const int  cols,
const char *  filename,
int  binary 
)

Outputs data as a PGM file with unsigned character values.

Returns:
TRUE if successful.

Definition at line 341 of file image.c.