Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PbmFile.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------+
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2002  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 #ifndef __PBMFILE_H_INCLUDED__
00029 #define __PBMFILE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     PbmFile.H
00034  * @brief    Header file of class qgar::PbmFile.
00035  *
00036  * @author   <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00037  * @date     Jul, 3  2001  17:11
00038  * @since    Qgar 1.0
00039  */
00040 
00041 // For RCS/CVS use: Do not delete
00042 /* $Id: PbmFile.H,v 1.14 2005/09/15 18:19:35 masini Exp $ */
00043 
00044 
00045 
00046 // QGAR
00047 #include <qgarlib/AbstractPbmPlusFile.H>
00048 #include <qgarlib/QgarErrorIO.H>
00049 
00050 
00051 
00052 namespace qgar
00053 {
00054 
00055 /**
00056  * @class PbmFile PbmFile.H "qgarlib/PbmFile.H"
00057  * @ingroup IO_FILE
00058  *
00059  * @brief File containing a binary image in PBM format.
00060  * 
00061  * Most of the code documented here is an adaptation of code from the PBM
00062  * software package. Here is the copyright notice of this package:
00063 @verbatim
00064  +------------------------------------------------------------------------+
00065  | Copyright (C) 1988 by Jef Poskanzer                                    |
00066  |                                                                        |
00067  | Permission to use, copy, modify, and distribute this software and its  |
00068  | documentation for any purpose and without fee is hereby granted,       |
00069  | provided that the above copyright notice appear in all copies and that |
00070  | both that copyright notice and this permission notice appear in        |
00071  | supporting documentation.  This software is provided "as is" without   |
00072  | express or implied warranty.                                           |
00073  +------------------------------------------------------------------------+
00074 @endverbatim
00075  *  For more information about PBM, see the
00076  *  <a href="http://www.bath.ac.uk/BUCS/Software/graphics/pbm/pbm.html">PBMPLUS home page</a>.
00077  *
00078  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00079  * @date   Jul, 3  2001  17:11
00080  * @since  Qgar 1.0
00081  */
00082 class PbmFile
00083 
00084   : public AbstractPbmPlusFile
00085 
00086 {
00087 // -------------------------------------------------------------------
00088 // P U B L I C    M E M B E R S
00089 // -------------------------------------------------------------------
00090 public:
00091 
00092   /** @name Constructors */
00093   //        ============
00094   //@{
00095 
00096   /**
00097    * @brief Initialize from file name and format.
00098    *
00099    * @param aFileName name of the new file
00100    * @param aFormat   format of the image contained in the file (default qgar::QGE_PBM_RAW)
00101    *
00102    * @warning
00103    * <ul>
00104    * <li>The number of rows and columns of the corresponding image
00105    *     are set to default (<b>0</b>).</li>
00106    * <li>Such a file cannot be opened
00107    *     in <b>write-only</b> or <b>read-write</b> modes.</li>
00108    * </ul>
00109    */
00110   PbmFile(const char* aFileName, QGEpbmFormat aFormat = QGE_PBM_RAW);
00111 
00112   /**
00113    * @brief Initialize from full data.
00114    *
00115    * @param aFileName name of the new file
00116    * @param aRowCnt   number of rows of the corresponding image
00117    * @param aColCnt   number of columns of the corresponding image
00118    * @param aFormat   format of the image contained in the file (default qgar::QGE_PBM_RAW)
00119    *
00120    * @warning Such a file is supposed to be used
00121    *   in <b>write-only</b> or <b>read-write</b> modes.
00122    */
00123   PbmFile(const char* aFileName,
00124           unsigned int aRowCnt,
00125           unsigned int aColCnt,
00126           QGEpbmFormat aFormat = QGE_PBM_RAW);
00127 
00128   //@}
00129 
00130 
00131   /** @name Input */
00132   //        =====
00133   //@{
00134 
00135   /**
00136    * @brief Read a row from the file.
00137    */
00138   void readRow();
00139 
00140   //@}
00141 
00142 
00143   /** @name Output */
00144   //        ======
00145   //@{
00146 
00147   /**
00148    * @brief Write a row into the file.
00149    */
00150   void writeRow();
00151 
00152   //@}
00153 
00154 
00155 // -------------------------------------------------------------------
00156 // P R O T E C T E D    M E M B E R S
00157 // -------------------------------------------------------------------
00158 protected:
00159 
00160   /** @name Magic numbers */
00161   //        =============
00162   //@{
00163 
00164   /**
00165    * @brief <b>PLAIN</b> format.
00166    */
00167   static const unsigned short _s_pbm_format;
00168 
00169   /**
00170    * @brief <b>PLAIN</b> format: Magic-1.
00171    */
00172   static const unsigned char  _s_pbm_magic1;
00173 
00174   /**
00175    * @brief <b>PLAIN</b> format: Magic-2.
00176    */
00177   static const unsigned char  _s_pbm_magic2;
00178 
00179   /**
00180    * @brief <b>RAW</b> format.
00181    */
00182   static const unsigned short _s_rpbm_format;
00183 
00184   /**
00185    * @brief <b>RAW</b> format: Magic-2.
00186    */
00187   static const unsigned char  _s_rpbm_magic2;
00188 
00189   //@}
00190 
00191 
00192   /** @name Input */
00193   //        =====
00194   //@{
00195 
00196   /**
00197    * @brief Read file header and allocate a new row.
00198    *
00199    * @exception qgar::QgarErrorIO (EOF while reading, bad magic number)
00200    *            
00201    */
00202   void readHeader() throw(QgarErrorIO);
00203 
00204   /**
00205    * @brief Return the next bit from the file.
00206    *
00207    * @exception qgar::QgarErrorIO (junk in file)
00208    */
00209   unsigned char getBit() throw(QgarErrorIO);
00210 
00211   //@}
00212 
00213 
00214   /** @name Output */
00215   //        ======
00216   //@{
00217 
00218   /**
00219    * @brief Write file header.
00220    */
00221   void writeHeader();
00222 
00223   /**
00224    * @brief Write file footer.
00225    */
00226   void writeFooter();
00227 
00228   //@}
00229 
00230 
00231 // -------------------------------------------------------------------
00232 
00233 }; // class PbmFile
00234 
00235 
00236 } // namespace qgar 
00237 
00238 #endif /* __PBMFILE_H_INCLUDED__ */