PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/System/Image/OSGImageFileType.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C Header | 390 lines | 136 code | 100 blank | 154 comment | 0 complexity | 42cbf3b3a37875cfe246aac6bc79fabf MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
  1. /*---------------------------------------------------------------------------*\
  2. * OpenSG *
  3. * *
  4. * *
  5. * Copyright (C) 2000-2002 by the OpenSG Forum *
  6. * *
  7. * www.opensg.org *
  8. * *
  9. * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
  10. * *
  11. \*---------------------------------------------------------------------------*/
  12. /*---------------------------------------------------------------------------*\
  13. * License *
  14. * *
  15. * This library is free software; you can redistribute it and/or modify it *
  16. * under the terms of the GNU Library General Public License as published *
  17. * by the Free Software Foundation, version 2. *
  18. * *
  19. * This library is distributed in the hope that it will be useful, but *
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  22. * Library General Public License for more details. *
  23. * *
  24. * You should have received a copy of the GNU Library General Public *
  25. * License along with this library; if not, write to the Free Software *
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
  27. * *
  28. \*---------------------------------------------------------------------------*/
  29. /*---------------------------------------------------------------------------*\
  30. * Changes *
  31. * *
  32. * *
  33. * *
  34. * *
  35. * *
  36. * *
  37. \*---------------------------------------------------------------------------*/
  38. #ifndef _OSGIMAGEFILETYPE_H_
  39. #define _OSGIMAGEFILETYPE_H_
  40. #include <list>
  41. #include "OSGIOFileTypeBase.h"
  42. #include "OSGImage.h"
  43. #include "OSGGeoReferenceAttachment.h"
  44. #include "boost/shared_ptr.hpp"
  45. OSG_BEGIN_NAMESPACE
  46. class ImageFileType;
  47. class OSG_SYSTEM_DLLMAPPING ImageBlockAccessor
  48. {
  49. /*========================== PUBLIC =================================*/
  50. public:
  51. /*---------------------------------------------------------------------*/
  52. /*! \name Destructor */
  53. /*! \{ */
  54. virtual ~ImageBlockAccessor(void);
  55. /*! \} */
  56. /*---------------------------------------------------------------------*/
  57. /*! \name Read/Write */
  58. /*! \{ */
  59. virtual bool isOpen(void) = 0;
  60. /*! \} */
  61. /*---------------------------------------------------------------------*/
  62. /*! \name Read/Write */
  63. /*! \{ */
  64. Vec2i getSize (void);
  65. Image::Type getType (void);
  66. Image::PixelFormat getFormat (void);
  67. Real64 getNoDataValue(void);
  68. /*! \} */
  69. /*---------------------------------------------------------------------*/
  70. /*! \name Read/Write */
  71. /*! \{ */
  72. GeoReferenceAttachment *getGeoRef(void);
  73. /*! \} */
  74. /*---------------------------------------------------------------------*/
  75. /*! \name Read/Write */
  76. /*! \{ */
  77. virtual bool readBlockA16(Vec2i vSampleOrigin,
  78. Int32 iTextureSize,
  79. UInt16 *pTarget,
  80. Int32 iTargetSizeBytes) = 0;
  81. virtual bool readBlockA16(Vec2i vSampleOrigin,
  82. Int32 iTextureSize,
  83. Int16 *pTarget,
  84. Int32 iTargetSizeBytes) = 0;
  85. /*! \} */
  86. /*========================= PROTECTED ===============================*/
  87. protected:
  88. GeoReferenceAttachmentUnrecPtr _pGeoRef;
  89. Vec2i _vSize;
  90. Image::Type _eImgType;
  91. Image::PixelFormat _eImgFormat;
  92. Real64 _fNoDataValue;
  93. /*---------------------------------------------------------------------*/
  94. /*! \name Default Constructor */
  95. /*! \{ */
  96. ImageBlockAccessor(void);
  97. /*! \} */
  98. /*========================== PRIVATE ================================*/
  99. private:
  100. };
  101. typedef boost::shared_ptr<ImageBlockAccessor> ImageBlockAccessorPtr;
  102. class OSG_SYSTEM_DLLMAPPING BlockAccessWrapper : public ImageBlockAccessor
  103. {
  104. /*========================== PUBLIC =================================*/
  105. public:
  106. typedef ImageBlockAccessor Inherited;
  107. /*---------------------------------------------------------------------*/
  108. /*! \name Destructor */
  109. /*! \{ */
  110. virtual ~BlockAccessWrapper(void);
  111. /*! \} */
  112. /*---------------------------------------------------------------------*/
  113. /*! \name Read/Write */
  114. /*! \{ */
  115. virtual bool isOpen(void);
  116. /*! \} */
  117. /*---------------------------------------------------------------------*/
  118. /*! \name Read/Write */
  119. /*! \{ */
  120. /*! \} */
  121. /*---------------------------------------------------------------------*/
  122. /*! \name Read/Write */
  123. /*! \{ */
  124. /*! \} */
  125. /*---------------------------------------------------------------------*/
  126. /*! \name Read/Write */
  127. /*! \{ */
  128. virtual bool readBlockA16(Vec2i vSampleOrigin,
  129. Int32 iTextureSize,
  130. UInt16 *pTarget,
  131. Int32 iTargetSizeBytes);
  132. virtual bool readBlockA16(Vec2i vSampleOrigin,
  133. Int32 iTextureSize,
  134. Int16 *pTarget,
  135. Int32 iTargetSizeBytes);
  136. /*! \} */
  137. /*========================= PROTECTED ===============================*/
  138. protected:
  139. ImageUnrecPtr _pImage;
  140. /*---------------------------------------------------------------------*/
  141. /*! \name Default Constructor */
  142. /*! \{ */
  143. BlockAccessWrapper(void);
  144. /*! \} */
  145. /*---------------------------------------------------------------------*/
  146. /*! \name Read/Write */
  147. /*! \{ */
  148. void open(const Char8 *szFilename);
  149. /*! \} */
  150. /*========================== PRIVATE ================================*/
  151. private:
  152. friend class ImageFileType;
  153. };
  154. typedef boost::shared_ptr<BlockAccessWrapper> BlockAccessWrapperPtr;
  155. /*! \brief Abstract Base ImageFileType. Defines the Interface for
  156. all concrete ImageFileTypes. See \ref PageSystemImage for detailed description.
  157. */
  158. class OSG_SYSTEM_DLLMAPPING ImageFileType : public IOFileTypeBase
  159. {
  160. /*========================== PUBLIC =================================*/
  161. public:
  162. /*---------------------------------------------------------------------*/
  163. /*! \name Public Types */
  164. /*! \{ */
  165. typedef IOFileTypeBase Inherited;
  166. typedef ImageFileType Self;
  167. /*! \} */
  168. /*---------------------------------------------------------------------*/
  169. /*! \name Flags */
  170. /*! \{ */
  171. enum
  172. {
  173. OSG_READ_SUPPORTED = 1,
  174. OSG_WRITE_SUPPORTED = 2
  175. };
  176. /*! \} */
  177. /*---------------------------------------------------------------------*/
  178. /*! \name Destructor */
  179. /*! \{ */
  180. virtual ~ImageFileType(void);
  181. /*! \} */
  182. /*---------------------------------------------------------------------*/
  183. /*! \name Get Methods */
  184. /*! \{ */
  185. const Char8 *getMimeType (void) const;
  186. const std::list<std::string> &getSuffixList(void) const;
  187. /*! \} */
  188. /*---------------------------------------------------------------------*/
  189. /*! \name Read/Write */
  190. /*! \{ */
  191. virtual bool read ( Image *pImage,
  192. const Char8 *fileName ) ;
  193. virtual bool write ( Image const *pImage,
  194. const Char8 *fileName ) ;
  195. virtual bool read ( Image *pImage,
  196. std::istream &is,
  197. const std::string &mimetype);
  198. virtual bool write ( Image const *pImage,
  199. std::ostream &os,
  200. const std::string &mimetype);
  201. virtual bool validateHeader(const Char8 *fileName,
  202. bool &implemented);
  203. /*! \} */
  204. /*---------------------------------------------------------------------*/
  205. /*! \name Read/Write */
  206. /*! \{ */
  207. virtual ImageBlockAccessorPtr open(const Char8 *fileName);
  208. /*! \} */
  209. /*---------------------------------------------------------------------*/
  210. /*! \name Type */
  211. /*! \{ */
  212. virtual std::string determineMimetypeFromStream(std::istream &is);
  213. /*! \} */
  214. /*---------------------------------------------------------------------*/
  215. /*! \name static store/restore */
  216. /*! \{ */
  217. static UInt64 restore( Image *pImage,
  218. const UChar8 *buffer,
  219. Int32 memSize = -1);
  220. static UInt64 store ( Image const *pImage,
  221. const Char8 *mimeType,
  222. UChar8 *buffer,
  223. Int32 memSize = -1);
  224. /*! \} */
  225. /*---------------------------------------------------------------------*/
  226. /*! \name Raw Store/Restore */
  227. /*! \{ */
  228. virtual UInt64 restoreData( Image *pImage,
  229. const UChar8 *buffer,
  230. Int32 memSize = -1);
  231. virtual UInt64 storeData ( Image const *pImage,
  232. UChar8 *buffer,
  233. Int32 memSize = -1);
  234. /*! \} */
  235. /*---------------------------------------------------------------------*/
  236. /*! \name store/restore */
  237. /*! \{ */
  238. UInt64 store (Image const *pImage,
  239. UChar8 *buffer,
  240. Int32 memSize = -1);
  241. virtual UInt64 maxBufferSize(Image const *pImage );
  242. /*! \} */
  243. /*---------------------------------------------------------------------*/
  244. /*! \name dump */
  245. /*! \{ */
  246. void dump(void);
  247. /*! \} */
  248. /*========================= PROTECTED ===============================*/
  249. protected:
  250. /*---------------------------------------------------------------------*/
  251. /*! \name MTD Header */
  252. /*! \{ */
  253. struct OSG_SYSTEM_DLLMAPPING Head
  254. {
  255. Char8 suffix[8];
  256. unsigned short pixelFormat;
  257. unsigned short width;
  258. unsigned short height;
  259. unsigned short depth;
  260. unsigned short mipmapCount;
  261. unsigned short frameCount;
  262. unsigned short frameDelay;
  263. unsigned short sideCount;
  264. unsigned short dataType;
  265. unsigned short _reserved3;
  266. unsigned short _reserved4;
  267. unsigned short attachmentSize;
  268. bool netToHost(void);
  269. bool hostToNet(void);
  270. };
  271. /*! \} */
  272. /*---------------------------------------------------------------------*/
  273. /*! \name Default Constructor */
  274. /*! \{ */
  275. ImageFileType(const Char8 *mimeType,
  276. const Char8 *suffixArray[],
  277. UInt16 suffixByteCount,
  278. UInt32 flags = OSG_READ_SUPPORTED);
  279. /*! \} */
  280. /*========================== PRIVATE ================================*/
  281. private:
  282. /* prohibit default function (move to 'public' if needed) */
  283. ImageFileType (const ImageFileType &obj);
  284. const ImageFileType &operator =(const ImageFileType &obj);
  285. std::list<std::string> _suffixList;
  286. std::string _mimeType;
  287. };
  288. typedef ImageFileType *ImageFileTypeP;
  289. OSG_END_NAMESPACE
  290. #endif // _OSGIMAGEFILETYPE_H_