|
A Portable Floating-Point-Based Image Format
1.0
|
#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>
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 DPRINTF | ( | x | ) |
Definition at line 81 of file pfi.c.
Referenced by double2pfi(), pfi2double(), pfi_getv(), pfi_properties(), pfi_putv(), pfi_read(), and pfi_read_internal().
| #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] |
| 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.
| val | The double value. |
| results | A 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.
| bufp | The string that contains the number we want. |
| expect | the expected value |
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.
| coded | A reference to an array of four pfiu32. |
| res | A reference to the double representation of the four pfiu32. |
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
| stream | The open file. |
| valp | A reference to the value to be read. |
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.
| stream | The open file. |
| rows | A reference to the number of rows to be determined from the image header. |
| cols | A reference to the number of cols to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colormodel | A 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. |
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.
| name | The file name. |
| rows | A reference to the number of rows to be determined from the image header. |
| cols | A reference to the number of cols to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colormodel | A 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. |
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.
| stream | The open file. |
| val | The value to be written. |
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.
| stream | The open file. |
| rows | A reference to the number of rows to be determined from the image header. |
| cols | A reference to the number of cols to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colormodel | A 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. |
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.
| stream | The open file. |
| rows | the number of rows |
| cols | the number of cols |
| colors | the number of colors |
| res | A 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. |
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.
| name | The file name. |
| rows | the number of rows |
| cols | the number of cols |
| colors | the number of colors |
| result | A 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. |
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.
| stream | The open file. |
| buf | A 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. |
| rows | A reference to the number of rows to be determined from the image header. |
| cols | A reference to the number of cols to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colormodel | An integer to represent the colormodel used in this image. We use 0 for none (greyscale), 1 for RGB etc. |
| fname | The name which will be written to the file header. |
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.
| name | The file name. |
| buf | A 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. |
| rows | A reference to the number of rows to be determined from the image header. |
| cols | A reference to the number of cols to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colors | A reference to the number of colors to be determined from the image header. |
| colormodel | An integer to represent the colormodel used in this image. We use 0 for none (greyscale), 1 for RGB etc. |
Definition at line 833 of file pfi.c.
References pfi_write().
| SIZE_CHECK | ( | pfiu32 | , |
| 4 | , | ||
| bar | |||
| ) |
| SIZE_CHECK | ( | pfiu16 | , |
| 2 | , | ||
| foobar | |||
| ) |
| static int skipcomments | ( | FILE * | stream | ) | [static] |
Moves the file position pointer to the next line that is no comment line.
| stream | The open file. |
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.
| pos | A string. |
Definition at line 1214 of file pfi.c.
Referenced by numexpect().
1.7.6.1