include/it/io.h

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2008 Francois Cayre, Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   I/O functions for the libit library
00022   Copyright (C) 2005 Herve Jegou
00023 */
00024 
00025 #ifndef __it_io_h
00026 #define __it_io_h
00027 
00028 #include <stdarg.h>
00029 #include <assert.h>
00030 #include <it/mat.h>
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /*! \defgroup io I/O functions                                               */
00034 /* @{                                                                        */
00035 /*---------------------------------------------------------------------------*/
00036 
00037 /*----------------------------------------------------------------------*/
00038 /* Extending printing of formatted string (includes vector and matrix)  */
00039 void it_vprintf (char *fmt, va_list args);
00040 void it_fprintf (FILE * output, char *fmt, ...);
00041 void it_printf (char *fmt, ...);
00042 void it_vfprintf (FILE * output, char *fmt, va_list ap);
00043 
00044 /* Error functions                                                      */
00045 void it_warning (char *fmt, ...);
00046 void it_error (char *fmt, ...);
00047 
00048 void __it_assert (int a, const char *filename, int line, char *message);
00049 #ifdef NDEBUG
00050 #define it_assert(a,expr) ((void) (0))
00051 #else
00052 #if defined(__GNUC__)
00053 #define it_assert(a,expr) __it_assert((long)(a), __FILE__, __LINE__, expr)
00054 #else
00055 #define it_assert(a,expr) __it_assert((long)(a), "", 0, expr)
00056 #endif
00057 #endif
00058 
00059 /* Modify the default format for vector printing (called by format $v)  */
00060 void it_set_vec_default_fmt (char *fmt);
00061 
00062 /* Modify the default format for matrix printing (called by format #m)  */
00063 void it_set_mat_default_fmt (char *fmt);
00064 
00065 
00066 /* Read integers and double from an NOT null-terminated string */
00067 char *it_read_int (char *s, int *p_val);
00068 char *it_read_float (char *s, float *p_val);
00069 char *it_read_double (char *s, double *p_val);
00070 char *it_read_cplx (char *s, cplx * p_val);
00071 
00072 /* Read a vector from a string and return the position after the vector */
00073 char *it_read_vec (char *s, vec * v);
00074 char *it_read_fvec (char *s, vec * v);
00075 char *it_read_ivec (char *s, ivec * v);
00076 char *it_read_bvec (char *s, bvec * v);
00077 char *it_read_cvec (char *s, cvec * v);
00078 
00079 /* Read a matrix from a string and return the position after the matrix */
00080 char *it_read_mat (char *s, mat * m);
00081 char *it_read_fmat (char *s, mat * m);
00082 char *it_read_imat (char *s, imat * m);
00083 char *it_read_bmat (char *s, bmat * m);
00084 char *it_read_cmat (char *s, cmat * m);
00085 
00086 /* Create a vector from a string */
00087 vec  vec_new_string (char *s);
00088 vec  fvec_new_string (char *s);
00089 ivec ivec_new_string (char *s);
00090 bvec bvec_new_string (char *s);
00091 cvec cvec_new_string (char *s);
00092 
00093 /* Create a matrix from a string */
00094 mat  mat_new_string (char *s);
00095 mat  fmat_new_string (char *s);
00096 imat imat_new_string (char *s);
00097 bmat bmat_new_string (char *s);
00098 cmat cmat_new_string (char *s);
00099 
00100 /*----------------------------------------------------------------------*/
00101 /* Determines the type of a PNM file, based on magic numbers.
00102    The returned value is a character between '1' and '6'.
00103    If an error occured, the returned value the value 0                  */
00104 char pnm_type (const char *filename);
00105 
00106 /* Retrieve some information about an pnm file.                         
00107    String comments must be pre-allocated                                */
00108 int  pnm_info (const char *filename, char *p_pnm_type, int *p_width,
00109          int *p_height, int *p_max_val, char *comments, int length);
00110 
00111 /* Read a pgm file and return the corresponding matrix of double values */
00112 mat  mat_pgm_read (const char *filename);
00113 
00114 /* Read a pgm file and return the corresponding matrix of int values */
00115 imat imat_pgm_read (const char *filename);
00116 
00117 /* Write a matrix of double as a pgm image file                         */
00118 int  mat_pgm_write (const char *filename, mat m);
00119 
00120 /* Write a matrix of integers as a pgm file                             */
00121 int  imat_pgm_write (const char *filename, imat m);
00122 
00123 /*----------------------------------------------------------------------*/
00124 /* WAV file handling functions                                          */
00125 int  wav_info (const char *filename, int *p_channels, int *p_srate,
00126          int *p_depth, int *p_length);
00127 mat  mat_wav_read (const char *filename);
00128 imat imat_wav_read (const char *filename);
00129 void mat_wav_write (const char *filename, mat m, int srate, int depth);
00130 void imat_wav_write (const char *filename, imat m, int srate, int depth);
00131 
00132 
00133 /*----------------------------------------------------------------------*/
00134 /* Write and read matrix in a pack format (dimension+data)              */
00135 
00136 void vec_fwrite (FILE * stream, vec v);
00137 void fvec_fwrite (FILE * stream, vec v);
00138 void bvec_fwrite (FILE * stream, bvec v);
00139 void ivec_fwrite (FILE * stream, ivec v);
00140 void cvec_fwrite (FILE * stream, cvec v);
00141 
00142 
00143 /* Return 1 if the vector is successfully read, 0 otherwise */
00144 int  vec_fread (FILE * stream, vec v);
00145 int  fvec_fread (FILE * stream, vec v);
00146 int  bvec_fread (FILE * stream, bvec v);
00147 int  ivec_fread (FILE * stream, ivec v);
00148 int  cvec_fread (FILE * stream, cvec v);
00149 
00150 /* return NULL if the vector can't be read */
00151 vec  vec_new_fread (FILE * stream);
00152 vec  fvec_new_fread (FILE * stream);
00153 bvec bvec_new_fread (FILE * stream);
00154 ivec ivec_new_fread (FILE * stream);
00155 cvec cvec_new_fread (FILE * stream);
00156 
00157 void mat_fwrite (FILE * stream, mat m);
00158 void fmat_fwrite (FILE * stream, mat m);
00159 void bmat_fwrite (FILE * stream, bmat m);
00160 void imat_fwrite (FILE * stream, imat m);
00161 void cmat_fwrite (FILE * stream, cmat m);
00162 
00163 /* Read a vector in a binary format from a buffer. 
00164    The function returns the number of bytes read */
00165 int vec_sread (void * buffer, vec v);
00166 int fvec_sread (void * buffer, vec v);
00167 int ivec_sread (void * buffer, ivec v);
00168 
00169 mat  mat_new_fread (FILE * stream);
00170 bmat bmat_new_fread (FILE * stream);
00171 imat imat_new_fread (FILE * stream);
00172 cmat cmat_new_fread (FILE * stream);
00173 
00174 
00175 /*----------------------------------------------------------------------*/
00176 /* Read files                                                           */
00177 
00178 /* Read a binary vector from a file. If the parameter nb_max is > 0, 
00179    then the number of bits read is bounded to this quantity.              */
00180 bvec bvec_file_read_bits (const char *filename, int nb_max);
00181 
00182 /* Write a vector of bits in a file */
00183 void bvec_file_write_bits (const char *filename, bvec v);
00184 
00185 /* @} */
00186 
00187 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau