ImageFile.h 7.2 KB

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