ImageFile.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. /*****************************************************************************/
  7. /*! \file ImageFile.h
  8. \brief ImageFile class declaration
  9. */
  10. /*****************************************************************************/
  11. /*
  12. * $Author: koch $
  13. * $Date: 2009/08/03 15:23:49 $
  14. * $Revision: 1.5 $
  15. */
  16. /*****************************************************************************/
  17. #ifndef _IMAGEFILE_IMAGE_H
  18. #define _IMAGEFILE_IMAGE_H
  19. #include <string>
  20. #include <core/basics/types.h>
  21. #ifdef NICE_USELIB_PNG
  22. #include <png.h>
  23. #endif
  24. namespace NICE {
  25. template<class P> class GrayColorImageCommonImplementationT;
  26. /**
  27. * This class is used to write images in various formats.
  28. */
  29. class ImageFile
  30. {
  31. public:
  32. typedef enum{FormatUnknown,
  33. PBM_IMAGE_TEXT, PGM_IMAGE_TEXT, PPM_IMAGE_TEXT,
  34. PBM_RAW, PGM_RAW, PPM_RAW, PAM_RAW,
  35. PNG, JPG} Format;
  36. class Header
  37. {
  38. public:
  39. int width;
  40. int height;
  41. int bitdepth;
  42. int channel;
  43. Header() : width(-1), height(-1),
  44. bitdepth(-1), channel(-1) {};
  45. };
  46. private:
  47. std::string filename;
  48. ImageFile::Format fileformat;
  49. ImageFile::Header fileheader;
  50. int datapos;
  51. /**
  52. * Read specific PXM file header.
  53. */
  54. void getPXMHeader();
  55. #ifdef NICE_USELIB_PNG
  56. /**
  57. * Read specific PNG file header.
  58. */
  59. void getPNGHeader();
  60. #endif
  61. #ifdef NICE_USELIB_JPG
  62. /**
  63. * Read specific JPG file header.
  64. */
  65. void getJPGHeader();
  66. #endif
  67. //! get fileformat specific header
  68. void getMyHeader();
  69. public:
  70. //! Default constructor
  71. ImageFile();
  72. //! Constructor with name and optional format specifier.
  73. /*! \param filename name of the file to write or read an image
  74. * \param type format of the image if none, file format will be automatically detected \see ImageFile::Format
  75. */
  76. ImageFile(const std::string &filename, Format type=FormatUnknown);
  77. //! Copy-Constructor
  78. /*! \param arg class to copy
  79. */
  80. ImageFile(const ImageFile& arg);
  81. //! Destructor of ImageFile
  82. virtual ~ImageFile();
  83. //! Assignment operator
  84. /*! \param ex class to copy
  85. * \return a reference to this class
  86. */
  87. ImageFile& operator=(const ImageFile& ex);
  88. /**
  89. * Get file name.
  90. * @return image filename
  91. */
  92. const std::string &fileName() const { return filename; }
  93. /**
  94. * Get file format.
  95. * @return image filetype
  96. */
  97. ImageFile::Format fileType() const { return fileformat; }
  98. /**
  99. * Return if image file is a graylevel image.
  100. */
  101. bool isGray() const;
  102. /**
  103. * Get file header.
  104. * @return image header
  105. */
  106. const ImageFile::Header &getHeader();
  107. uint height();
  108. uint width();
  109. /**
  110. * Get file comment.
  111. * @return image comment
  112. */
  113. std::string getComment();
  114. /**
  115. * Read image from file
  116. * @param image GrayColorImageCommonImplementationT to read in
  117. */
  118. template<class P>
  119. void reader(GrayColorImageCommonImplementationT<P> *image);
  120. /**
  121. * Write image to file
  122. * @param image GrayColorImageCommonImplementationT to be written
  123. */
  124. template<class P>
  125. void writer(const GrayColorImageCommonImplementationT<P> *image) const;
  126. /**
  127. * read pxm image from file
  128. * @param image GrayColorImageCommonImplementationT to read in
  129. */
  130. template <class P>
  131. void readerPXM(GrayColorImageCommonImplementationT<P> *image);
  132. /**
  133. * write pxm image to file
  134. * @param image GrayColorImageCommonImplementationT to be written
  135. */
  136. template <class P>
  137. void writerPXM(const GrayColorImageCommonImplementationT<P> *image) const;
  138. #ifdef NICE_USELIB_PNG
  139. /**
  140. * Read png image from file
  141. * @param image GrayColorImageCommonImplementationT to read in
  142. */
  143. template<class P>
  144. void readerPNG(GrayColorImageCommonImplementationT<P> *image);
  145. /**
  146. * Write png image to file
  147. * @param image GrayColorImageCommonImplementationT to be written
  148. */
  149. template<class P>
  150. void writerPNG(const GrayColorImageCommonImplementationT<P> *image) const;
  151. #endif
  152. #ifdef NICE_USELIB_JPG
  153. /**
  154. * Read jpg image from file
  155. * @param image GrayColorImageCommonImplementationT to read in
  156. */
  157. template<class P>
  158. void readerJPG(GrayColorImageCommonImplementationT<P> *image);
  159. /**
  160. * Write jpg image to file
  161. * @param image GrayColorImageCommonImplementationT to be written
  162. * @param quality output qualtiy of the GrayColorImageCommonImplementationT to be written (default=100)
  163. */
  164. template<class P>
  165. void writerJPG(const GrayColorImageCommonImplementationT<P> *image, const int quality=100) const;
  166. #endif
  167. #ifdef NICE_USELIB_LIBMAGICK
  168. template<class P>
  169. void readerMagick(GrayColorImageCommonImplementationT<P> *image);
  170. template<class P>
  171. void writerMagick(const GrayColorImageCommonImplementationT<P> *image) const;
  172. #endif
  173. /**
  174. * Check the format of a image file
  175. * @param filename full path and name of the file
  176. * @return image format
  177. */
  178. static ImageFile::Format name2Format(const std::string &filename);
  179. };
  180. } // namespace NICE
  181. #include <core/image/GrayColorImageCommonImplementationT.h>
  182. //#ifdef __GNUC__
  183. #include "core/image/ImageFile.tcc"
  184. //#endif
  185. #endif /* _IMAGEFILE_IMAGE_H */
  186. /*****************************************************************************/
  187. /*
  188. * $Log: ImageFile.h,v $
  189. * Revision 1.5 2009/08/03 15:23:49 koch
  190. * deleted unnecessary .h
  191. *
  192. * Revision 1.4 2009/07/22 12:12:01 rodner
  193. * - added ImageMagick functionality
  194. *
  195. * Revision 1.3 2009/06/10 08:06:34 rodner
  196. * - getHeader support for png/jpg without system("identify ..");
  197. *
  198. * Revision 1.2 2009/05/28 11:36:30 bajramov
  199. * renamed a few things for consistency
  200. *
  201. * Revision 1.1.1.1 2007/05/22 19:26:35 bajramov
  202. * limun2
  203. *
  204. * Revision 1.14 2007/02/01 15:58:18 bajramov
  205. * improved interface for writing image files
  206. * added format choice to ImageFileListWriter (to be renamed)
  207. *
  208. * Revision 1.13 2007/01/19 12:27:15 bajramov
  209. * moved include from h to tcc
  210. *
  211. * Revision 1.12 2006/10/23 11:30:40 zimmermann
  212. * * more general jpg io
  213. *
  214. * Revision 1.11 2006/10/20 17:14:04 zimmermann
  215. * * improved jpg io / test
  216. *
  217. * Revision 1.10 2006/10/06 13:21:39 mattern
  218. * .
  219. *
  220. * Revision 1.9 2006/08/22 13:35:55 zimmermann
  221. * *fixed a little error
  222. *
  223. * Revision 1.8 2006/08/21 15:55:28 mattern
  224. * - is gray implemented
  225. *
  226. * Revision 1.7 2006/07/13 12:50:09 mattern
  227. * - small fixes
  228. *
  229. * Revision 1.6 2006/05/24 13:22:44 mattern
  230. * - extern C fix
  231. *
  232. * Revision 1.5 2006/05/24 13:03:43 mattern
  233. * - jpg bugfix
  234. * - unsigned signed errors fixed
  235. *
  236. * Revision 1.4 2006/05/22 16:13:24 zimmermann
  237. * * added jpeg io to ColorImage/Image/ImageFile
  238. *
  239. * Revision 1.3 2006/03/02 21:11:33 mattern
  240. * - bugfixes
  241. *
  242. * Revision 1.2 2006/03/02 14:54:54 mattern
  243. * - documenation improved
  244. *
  245. * Revision 1.1 2006/03/02 14:50:33 mattern
  246. * - ImageFile added
  247. * - more template methods
  248. * - ippwrapper improved
  249. * - png support
  250. *
  251. */