A Portable Floating-Point-Based Image Format  1.0
Defines | Functions
pfi.c File Reference
#include "pfi.h"
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
Include dependency graph for pfi.c:

Go to the source code of this file.

Defines

#define SIZE_CHECK(type, size, name)   typedef type name[(sizeof (type) == size)*2-1]
#define PIXEL_PFIS   7
#define DPRINTF(x)

Functions

 SIZE_CHECK (pfiu32, 4, bar)
 SIZE_CHECK (pfiu16, 2, foobar)
static void double2pfi (double val, pfiu32 *results)
static int pfi2double (pfiu32 *coded, double *res)
static int numexpect (char *bufp, int expect)
static void skipwhite (char **pos)
static int skipcomments (FILE *stream)
static int pfi_read_internal (FILE *, int, int, int, double *)
int pfi_getv (FILE *stream, double *valp)
int pfi_putv (FILE *stream, double val)
int pfi_properties (FILE *stream, int *rows, int *cols, int *colors, int *colormodel)
double * pfi_read (FILE *stream, int *rows, int *cols, int *colors, int *colormodel)
int pfi_write (FILE *stream, double *buf, int rows, int cols, int colors, int colormodel, char *fname)
DLL_EXPORT int pfi_read_name (char *name, int rows, int cols, int colors, double *result)
DLL_EXPORT int pfi_write_name (char *name, double *buf, int rows, int cols, int colors, int colormodel)
DLL_EXPORT int pfi_properties_name (char *name, int *rows, int *cols, int *colors, int *colormodel)

Define Documentation

#define DPRINTF (   x)
#define PIXEL_PFIS   7

Definition at line 79 of file pfi.c.

Referenced by pfi_getv(), pfi_putv(), and pfi_read_internal().

#define SIZE_CHECK (   type,
  size,
  name 
)    typedef type name[(sizeof (type) == size)*2-1]

Definition at line 22 of file pfi.c.


Function Documentation

static void double2pfi ( double  val,
pfiu32 *  results 
) [static]

{enumerate}

The raw data consists of two 16 bit and six 32 bit unsigned integers in network byte ordering (byte-swapped on intel systems) per pixel color. We assume exponential notation, like with e in printf. The first two numbers contain the number left from the decimal point and the exponent respectively. For negative values the two- complement form is used. Every of six 32-bit numbers contains 9 digits of the number right from the decimal point, ordered from left to right, so a precision of 54 digits can be achieved.

Calculates 7 pfiu32 values to represent one double.

Parameters:
valThe double value.
resultsA reference to an array of 7 pfiu32 that will hold the result.

Definition at line 1051 of file pfi.c.

References DPRINTF.

Referenced by pfi_putv().

static int numexpect ( char *  bufp,
int  expect 
) [static]

Checks a string for the correct format of a given number of numbers.

Parameters:
bufpThe string that contains the number we want.
expectthe expected value
Returns:
The expected number or -1 on error.

Definition at line 1184 of file pfi.c.

References skipwhite().

Referenced by pfi_properties().

static int pfi2double ( pfiu32 *  coded,
double *  res 
) [static]

Calculates a double from 7 pfiu32 values.

Parameters:
codedA reference to an array of four pfiu32.
resA reference to the double representation of the four pfiu32.
Returns:
0 on succes, -1 on error.

Definition at line 1125 of file pfi.c.

References DPRINTF.

Referenced by pfi_getv().

int pfi_getv ( FILE *  stream,
double *  valp 
)

Reads a double value from an open pfi file

Parameters:
streamThe open file.
valpA reference to the value to be read.
Returns:
0 on success, else -1.

Definition at line 380 of file pfi.c.

References DPRINTF, pfi2double(), pfi_ftoh16, pfi_ftoh32, and PIXEL_PFIS.

Referenced by pfi_read_internal().

int pfi_properties ( FILE *  stream,
int *  rows,
int *  cols,
int *  colors,
int *  colormodel 
)

Gets the pfi image properties from an open file.

Parameters:
streamThe open file.
rowsA reference to the number of rows to be determined from the image header.
colsA reference to the number of cols to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colormodelA reference to an integer to represent the colormodel used in this image to be determined from the image header. We use 0 for none (greyscale), 1 for RGB etc.
Returns:
success: 0, else -1.

Definition at line 489 of file pfi.c.

References DPRINTF, numexpect(), and skipcomments().

Referenced by pfi_properties_name(), and pfi_read().

DLL_EXPORT int pfi_properties_name ( char *  name,
int *  rows,
int *  cols,
int *  colors,
int *  colormodel 
)

Gets the pfi image properties from an image file.

Parameters:
nameThe file name.
rowsA reference to the number of rows to be determined from the image header.
colsA reference to the number of cols to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colormodelA reference to an integer to represent the colormodel used in this image to be determined from the image header. We use 0 for none (greyscale), 1 for RGB etc.
Returns:
success: 0, else -1.

Definition at line 888 of file pfi.c.

References pfi_properties().

int pfi_putv ( FILE *  stream,
double  val 
)

Writes a double value into an open pfi file.

Parameters:
streamThe open file.
valThe value to be written.
Returns:
0 on success, else -1.

Definition at line 428 of file pfi.c.

References double2pfi(), DPRINTF, pfi_htof16, pfi_htof32, and PIXEL_PFIS.

Referenced by pfi_write().

double* pfi_read ( FILE *  stream,
int *  rows,
int *  cols,
int *  colors,
int *  colormodel 
)

Reads a pfi image from an open file.

Parameters:
streamThe open file.
rowsA reference to the number of rows to be determined from the image header.
colsA reference to the number of cols to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colormodelA reference to an integer to represent the colormodel used in this image to be determined from the image header. We use 0 for none (greyscale), 1 for RGB etc.
Returns:
A new double array containing the image. The colors are stored one after another, so we've got pixel one with all colors first, then pixel two etc. In case of error, NULL is returned

Definition at line 654 of file pfi.c.

References DPRINTF, pfi_properties(), and pfi_read_internal().

static int pfi_read_internal ( FILE *  stream,
int  rows,
int  cols,
int  colors,
double *  res 
) [static]

Reads a pfi image from an open file.

Parameters:
streamThe open file.
rowsthe number of rows
colsthe number of cols
colorsthe number of colors
resA double array containing the image. The colors are stored one after another, so we've got pixel one with all colors first, then pixel two etc.
Returns:
0 if successful, else -1

Definition at line 982 of file pfi.c.

References DPRINTF, pfi_getv(), and PIXEL_PFIS.

Referenced by pfi_read(), and pfi_read_name().

DLL_EXPORT int pfi_read_name ( char *  name,
int  rows,
int  cols,
int  colors,
double *  result 
)

Reads a pfi image.

Parameters:
nameThe file name.
rowsthe number of rows
colsthe number of cols
colorsthe number of colors
resultA double array containing the image. The colors are stored one after another, so we've got pixel one with all colors first, then pixel two etc.
Returns:
0 if successful, else -1

Definition at line 770 of file pfi.c.

References pfi_read_internal().

int pfi_write ( FILE *  stream,
double *  buf,
int  rows,
int  cols,
int  colors,
int  colormodel,
char *  fname 
)

Writes a pfi image to an open file.

Parameters:
streamThe open file.
bufA reference to the buffer containing the image. The colors are stored one after another, so we've got pixel one with all colors first, then pixel two etc.
rowsA reference to the number of rows to be determined from the image header.
colsA reference to the number of cols to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colormodelAn integer to represent the colormodel used in this image. We use 0 for none (greyscale), 1 for RGB etc.
fnameThe name which will be written to the file header.
Returns:
0 on success, else -1.

Definition at line 715 of file pfi.c.

References pfi_putv().

Referenced by pfi_write_name().

DLL_EXPORT int pfi_write_name ( char *  name,
double *  buf,
int  rows,
int  cols,
int  colors,
int  colormodel 
)

Opens and writes a pfi image.

Parameters:
nameThe file name.
bufA reference to the buffer containing the image. The colors are stored one after another, so we've got pixel one with all colors first, then pixel two etc.
rowsA reference to the number of rows to be determined from the image header.
colsA reference to the number of cols to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colorsA reference to the number of colors to be determined from the image header.
colormodelAn integer to represent the colormodel used in this image. We use 0 for none (greyscale), 1 for RGB etc.
Returns:
0 on success, else -1.

Definition at line 833 of file pfi.c.

References pfi_write().

SIZE_CHECK ( pfiu32  ,
,
bar   
)
SIZE_CHECK ( pfiu16  ,
,
foobar   
)
static int skipcomments ( FILE *  stream) [static]

Moves the file position pointer to the next line that is no comment line.

Parameters:
streamThe open file.
Returns:
The new line's first character or EOF at EOF.

Definition at line 927 of file pfi.c.

Referenced by pfi_properties().

static void skipwhite ( char **  pos) [static]

Returns the position of the first non whitespace character in a string.

Parameters:
posA string.
Returns:
The new position.

Definition at line 1214 of file pfi.c.

Referenced by numexpect().