PageRenderTime 72ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/System/Image/ES/OSGImage.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C Header | 436 lines | 208 code | 78 blank | 150 comment | 3 complexity | 3a543e3ab2fc39a908d24bf24b91f534 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 _OSGIMAGE_H_
  39. #define _OSGIMAGE_H_
  40. #ifdef __sgi
  41. #pragma once
  42. #endif
  43. #include "OSGConfig.h"
  44. #include "OSGImageBase.h"
  45. #include "OSGGLEXT.h"
  46. #include "OSGReal16.h"
  47. OSG_BEGIN_NAMESPACE
  48. /*! \brief Image class. See \ref PageSystemImage
  49. for a description.
  50. */
  51. class OSG_SYSTEM_DLLMAPPING Image : public ImageBase
  52. {
  53. private:
  54. /*========================== PUBLIC =================================*/
  55. public:
  56. typedef ImageBase Inherited;
  57. enum PixelFormat
  58. {
  59. OSG_INVALID_PF = 0,
  60. OSG_A_PF = GL_ALPHA,
  61. #if !defined(OSG_EMBEDDED) || OSG_GL_ES_VERSION > 100
  62. OSG_I_PF = GL_INTENSITY,
  63. #endif
  64. OSG_L_PF = GL_LUMINANCE,
  65. OSG_LA_PF = GL_LUMINANCE_ALPHA,
  66. /*** BGR ***/
  67. #if defined(GL_BGR)
  68. OSG_BGR_PF = GL_BGR,
  69. #elif defined(GL_BGR_EXT)
  70. OSG_BGR_PF = GL_BGR_EXT,
  71. #else
  72. OSG_BGR_PF = 0,
  73. #endif
  74. /*** BGRA ***/
  75. #if defined(GL_BGRA)
  76. OSG_BGRA_PF = GL_BGRA,
  77. #elif defined(GL_BGRA_EXT)
  78. OSG_BGRA_PF = GL_BGRA_EXT,
  79. #else
  80. OSG_BGRA_PF = 0,
  81. #endif
  82. /*** RGB_DXT1 ***/
  83. #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
  84. OSG_RGB_DXT1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
  85. #else
  86. OSG_RGB_DXT1 = 0,
  87. #endif
  88. /*** RGBA_DXT1 ***/
  89. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
  90. OSG_RGBA_DXT1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
  91. #else
  92. OSG_RGBA_DXT1 = 0,
  93. #endif
  94. /*** RGBA_DXT3 ***/
  95. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
  96. OSG_RGBA_DXT3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
  97. #else
  98. OSG_RGBA_DXT3 = 0,
  99. #endif
  100. /*** RGBA_DXT5 ***/
  101. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
  102. OSG_RGBA_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
  103. #else
  104. OSG_RGBA_DXT5 = 0,
  105. #endif
  106. OSG_RGB_PF = GL_RGB,
  107. OSG_RGBA_PF = GL_RGBA
  108. };
  109. enum Type
  110. {
  111. OSG_INVALID_IMAGEDATATYPE = GL_FALSE,
  112. OSG_UINT8_IMAGEDATA = GL_UNSIGNED_BYTE,
  113. #if defined(GL_UNSIGNED_SHORT)
  114. OSG_UINT16_IMAGEDATA = GL_UNSIGNED_SHORT,
  115. #endif
  116. #if defined(GL_UNSIGNED_INT)
  117. OSG_UINT32_IMAGEDATA = GL_UNSIGNED_INT,
  118. #endif
  119. #if !defined(OSG_EMBEDDED)
  120. OSG_FLOAT16_IMAGEDATA = GL_HALF_FLOAT_NV,
  121. #endif
  122. OSG_FLOAT32_IMAGEDATA = GL_FLOAT
  123. };
  124. /*---------------------------------------------------------------------*/
  125. /*! \name Sync */
  126. /*! \{ */
  127. virtual void changed(ConstFieldMaskArg whichField,
  128. UInt32 origin,
  129. BitVector details);
  130. /*! \} */
  131. /*---------------------------------------------------------------------*/
  132. /*! \name Output */
  133. /*! \{ */
  134. virtual void dump( UInt32 uiIndent = 0,
  135. const BitVector bvFlags = 0) const;
  136. /*! \} */
  137. /*---------------------------------------------------------------------*/
  138. /*! \name Set Object Data */
  139. /*! \{ */
  140. bool set ( UInt32 pixelFormat,
  141. Int32 width,
  142. Int32 height = 1,
  143. Int32 depth = 1,
  144. Int32 mipmapCount = 1,
  145. Int32 frameCount = 1,
  146. Time frameDelay = 0.0,
  147. const UInt8 *data = 0,
  148. Int32 type = OSG_UINT8_IMAGEDATA,
  149. bool allocMem = true,
  150. Int32 sidecount = 1 );
  151. bool set ( ImagePtr image );
  152. bool setData (const UInt8 *data = 0 );
  153. void clearData ( void );
  154. bool setSubData ( Int32 offX,
  155. Int32 offY,
  156. Int32 offZ,
  157. Int32 srcW,
  158. Int32 srcH,
  159. Int32 srcD,
  160. const UInt8 *data );
  161. bool flipDepthFrameData( void );
  162. /*! \} */
  163. /*---------------------------------------------------------------------*/
  164. /*! \name Add Value */
  165. /*! \{ */
  166. bool addValue(const Char8 *value);
  167. /*! \} */
  168. /*---------------------------------------------------------------------*/
  169. /*! \name Reformate */
  170. /*! \{ */
  171. bool reformat(const PixelFormat pixelFormat,
  172. ImagePtr destination = NullFC);
  173. /*! \} */
  174. /*---------------------------------------------------------------------*/
  175. /*! \name Convert dataType */
  176. /*! \{ */
  177. void swapDataEndian (void );
  178. bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
  179. /*! \} */
  180. /*---------------------------------------------------------------------*/
  181. /*! \name Scale */
  182. /*! \{ */
  183. bool scale (Int32 width,
  184. Int32 height = 1,
  185. Int32 depth = 1,
  186. ImagePtr destination = NullFC );
  187. bool scaleNextPower2(ImagePtr destination = NullFC );
  188. /*! \} */
  189. /*---------------------------------------------------------------------*/
  190. /*! \name SubImage */
  191. /*! \{ */
  192. bool subImage(Int32 offX,
  193. Int32 offY,
  194. Int32 offZ,
  195. Int32 destW,
  196. Int32 destH,
  197. Int32 destD,
  198. ImagePtr destination = NullFC);
  199. /*! \} */
  200. /*---------------------------------------------------------------------*/
  201. /*! \name Slice */
  202. /*! \{ */
  203. bool slice(Int32 offX = -1,
  204. Int32 offY = -1,
  205. Int32 offZ = -1,
  206. ImagePtr destination = NullFC);
  207. /*! \} */
  208. /*---------------------------------------------------------------------*/
  209. /*! \name Mipmap */
  210. /*! \{ */
  211. bool createMipmap(Int32 level = -1,
  212. ImagePtr destination = NullFC);
  213. /*! \} */
  214. /*---------------------------------------------------------------------*/
  215. /*! \name Read/Write */
  216. /*! \{ */
  217. bool write(const Char8 *fileName);
  218. bool read (const Char8 *fileName);
  219. /*! \} */
  220. /*---------------------------------------------------------------------*/
  221. /*! \name Storage/Restore */
  222. /*! \{ */
  223. UInt64 store (const Char8 *mimeType,
  224. UInt8 *mem,
  225. Int32 memSize = -1);
  226. UInt64 restore(const UInt8 *mem,
  227. Int32 memSize = -1);
  228. /*! \} */
  229. /*---------------------------------------------------------------------*/
  230. /*! \name Comparison/Assign */
  231. /*! \{ */
  232. Image &operator = (const Image &image);
  233. bool operator < (const Image &image);
  234. bool operator == (const Image &image);
  235. bool operator != (const Image &image);
  236. /*! \} */
  237. /*---------------------------------------------------------------------*/
  238. /*! \name Get Methods */
  239. /*! \{ */
  240. bool isValid (void) const;
  241. bool hasAlphaChannel (void);
  242. bool isAlphaBinary (void);
  243. bool hasColorChannel (void);
  244. bool hasCompressedData(void);
  245. UInt8 getComponents (void) const;
  246. bool calcIsAlphaBinary(void);
  247. /*! \} */
  248. /*---------------------------------------------------------------------*/
  249. /*! \name Size */
  250. /*! \{ */
  251. unsigned long getSize(bool withMipmap = true,
  252. bool withFrames = true,
  253. bool withSides = true) const;
  254. /*! \} */
  255. /*---------------------------------------------------------------------*/
  256. /*! \name Get Methods */
  257. /*! \{ */
  258. const UInt8 *getData (UInt32 mipmapNum = 0,
  259. UInt32 frameNum = 0,
  260. UInt32 sidecount = 0) const;
  261. UInt8 *editData (UInt32 mipmapNum = 0,
  262. UInt32 frameNum = 0,
  263. UInt32 sidecount = 0);
  264. const UInt8 *getDataByTime (Time time,
  265. UInt32 mipmapNum = 1) const;
  266. UInt8 *editDataByTime(Time time,
  267. UInt32 mipmapNum = 1);
  268. /*! \} */
  269. /*---------------------------------------------------------------------*/
  270. /*! \name Calculate */
  271. /*! \{ */
  272. void calcMipmapGeometry (UInt32 mipmapNum,
  273. UInt32 &width,
  274. UInt32 &height,
  275. UInt32 &depth ) const;
  276. UInt32 calcMipmapLevelCount(void ) const;
  277. UInt32 calcFrameNum (Time time,
  278. bool loop = true) const;
  279. /*! \} */
  280. /*---------------------------------------------------------------------*/
  281. /*! \name Clear Image */
  282. /*! \{ */
  283. virtual void clear (UChar8 pixelValue = 0 );
  284. virtual void clearFloat(Real32 pixelValue = 0.0 );
  285. virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
  286. /*! \} */
  287. /*---------------------------------------------------------------------*/
  288. /*! \name attachment handling */
  289. /*! \{ */
  290. bool hasAttachment ( void ) const;
  291. UInt32 attachmentCount ( void ) const;
  292. void setAttachmentField (const std::string &key,
  293. const std::string &data);
  294. const std::string *findAttachmentField(const std::string &key ) const;
  295. /*! \} */
  296. /*---------------------------------------------------------------------*/
  297. /*! \name Calculate Mipmap Size */
  298. /*! \{ */
  299. UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
  300. UInt32 w,
  301. UInt32 h,
  302. UInt32 d ) const;
  303. UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
  304. UInt32 calcMipmapSumSize (UInt32 mipmapNum,
  305. UInt32 w,
  306. UInt32 h,
  307. UInt32 d ) const;
  308. UInt32 calcMipmapSumSize (UInt32 mipmapNum) const;
  309. /*! \} */
  310. /*========================= PROTECTED ===============================*/
  311. protected:
  312. /*---------------------------------------------------------------------*/
  313. /*! \name static element */
  314. /*! \{ */
  315. static Int32 _formatDic[][2];
  316. static Int32 _typeDic [][2];
  317. /*! \} */
  318. /*---------------------------------------------------------------------*/
  319. /*! \name Constructors */
  320. /*! \{ */
  321. Image(void);
  322. Image(const Image &source);
  323. /*! \} */
  324. /*---------------------------------------------------------------------*/
  325. /*! \name Destructors */
  326. /*! \{ */
  327. virtual ~Image(void);
  328. /*! \} */
  329. /*---------------------------------------------------------------------*/
  330. /*! \name Init */
  331. /*! \{ */
  332. static void initMethod(InitPhase ePhase);
  333. /*! \} */
  334. /*========================== PRIVATE ================================*/
  335. private:
  336. /*---------------------------------------------------------------------*/
  337. /*! \name Image Data */
  338. /*! \{ */
  339. bool createData(const UInt8 *data,
  340. bool allocMem = true);
  341. bool scaleData ( UInt8 *srcData,
  342. Int32 srcW,
  343. Int32 srcH,
  344. Int32 srcD,
  345. UInt8 *destData,
  346. Int32 destW,
  347. Int32 destH,
  348. Int32 destD );
  349. /*! \} */
  350. /*---------------------------------------------------------------------*/
  351. friend class FieldContainer;
  352. friend class ImageBase;
  353. };
  354. typedef Image *ImageP;
  355. OSG_END_NAMESPACE
  356. #include "OSGImageBase.inl"
  357. #include "OSGImage.inl"
  358. #endif /* _OSGIMAGE_H_ */