PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/System/Image/WS/OSGImage.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C Header | 490 lines | 242 code | 90 blank | 158 comment | 2 complexity | 8bb9f3bad01d7623e0138d9ff473ee48 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. OSG_I_PF = GL_INTENSITY,
  62. OSG_L_PF = GL_LUMINANCE,
  63. OSG_LA_PF = GL_LUMINANCE_ALPHA,
  64. /*** BGR ***/
  65. #if defined(GL_BGR)
  66. OSG_BGR_PF = GL_BGR,
  67. #elif defined(GL_BGR_EXT)
  68. OSG_BGR_PF = GL_BGR_EXT,
  69. #else
  70. OSG_BGR_PF = 0,
  71. #endif
  72. /*** BGRA ***/
  73. #if defined(GL_BGRA)
  74. OSG_BGRA_PF = GL_BGRA,
  75. #elif defined(GL_BGRA_EXT)
  76. OSG_BGRA_PF = GL_BGRA_EXT,
  77. #else
  78. OSG_BGRA_PF = 0,
  79. #endif
  80. /*** RGB_DXT1 ***/
  81. #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
  82. OSG_RGB_DXT1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
  83. #else
  84. OSG_RGB_DXT1 = 0,
  85. #endif
  86. /*** RGBA_DXT1 ***/
  87. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
  88. OSG_RGBA_DXT1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
  89. #else
  90. OSG_RGBA_DXT1 = 0,
  91. #endif
  92. /*** RGBA_DXT3 ***/
  93. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
  94. OSG_RGBA_DXT3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
  95. #else
  96. OSG_RGBA_DXT3 = 0,
  97. #endif
  98. /*** RGBA_DXT5 ***/
  99. #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
  100. OSG_RGBA_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
  101. #else
  102. OSG_RGBA_DXT5 = 0,
  103. #endif
  104. OSG_RGB_PF = GL_RGB,
  105. OSG_RGBA_PF = GL_RGBA,
  106. OSG_ALPHA_INTEGER_PF = GL_ALPHA_INTEGER_EXT,
  107. OSG_RGB_INTEGER_PF = GL_RGB_INTEGER_EXT,
  108. OSG_RGBA_INTEGER_PF = GL_RGBA_INTEGER_EXT,
  109. OSG_BGR_INTEGER_PF = GL_BGR_INTEGER_EXT,
  110. OSG_BGRA_INTEGER_PF = GL_BGRA_INTEGER_EXT,
  111. OSG_LUMINANCE_INTEGER_PF = GL_LUMINANCE_INTEGER_EXT,
  112. OSG_LUMINANCE_ALPHA_INTEGER_PF = GL_LUMINANCE_ALPHA_INTEGER_EXT
  113. };
  114. enum Type
  115. {
  116. OSG_INVALID_IMAGEDATATYPE = GL_NONE,
  117. OSG_UINT8_IMAGEDATA = GL_UNSIGNED_BYTE,
  118. OSG_UINT16_IMAGEDATA = GL_UNSIGNED_SHORT,
  119. OSG_UINT32_IMAGEDATA = GL_UNSIGNED_INT,
  120. OSG_FLOAT16_IMAGEDATA = GL_HALF_FLOAT_NV,
  121. OSG_FLOAT32_IMAGEDATA = GL_FLOAT,
  122. OSG_INT16_IMAGEDATA = GL_SHORT,
  123. OSG_INT32_IMAGEDATA = GL_INT
  124. };
  125. enum ResUnit
  126. {
  127. OSG_RESUNIT_INVALID = 0,
  128. OSG_RESUNIT_NONE = 1,
  129. OSG_RESUNIT_INCH = 2
  130. };
  131. /*---------------------------------------------------------------------*/
  132. /*! \name Sync */
  133. /*! \{ */
  134. virtual void changed(ConstFieldMaskArg whichField,
  135. UInt32 origin,
  136. BitVector details);
  137. /*! \} */
  138. /*---------------------------------------------------------------------*/
  139. /*! \name Output */
  140. /*! \{ */
  141. virtual void dump( UInt32 uiIndent = 0,
  142. const BitVector bvFlags = 0) const;
  143. /*! \} */
  144. /*---------------------------------------------------------------------*/
  145. /*! \name Set Object Data */
  146. /*! \{ */
  147. bool set ( UInt32 pixelFormat,
  148. Int32 width,
  149. Int32 height = 1,
  150. Int32 depth = 1,
  151. Int32 mipmapCount = 1,
  152. Int32 frameCount = 1,
  153. Time frameDelay = 0.0,
  154. const UInt8 *data = 0,
  155. Int32 type = OSG_UINT8_IMAGEDATA,
  156. bool allocMem = true,
  157. Int32 sidecount = 1 );
  158. bool set ( Image *image );
  159. bool setData (const UInt8 *data = 0 );
  160. void clearData ( void );
  161. bool setSubData ( Int32 offX,
  162. Int32 offY,
  163. Int32 offZ,
  164. Int32 srcW,
  165. Int32 srcH,
  166. Int32 srcD,
  167. const UInt8 *data );
  168. bool flipDepthFrameData( void );
  169. /*! \} */
  170. /*---------------------------------------------------------------------*/
  171. /*! \name Add Value */
  172. /*! \{ */
  173. bool addValue(const Char8 *value);
  174. /*! \} */
  175. /*---------------------------------------------------------------------*/
  176. /*! \name Reformate */
  177. /*! \{ */
  178. bool reformat(const PixelFormat pixelFormat,
  179. Image *destination = NULL,
  180. Int32 iCompressionFlags = 0);
  181. /*! \} */
  182. /*---------------------------------------------------------------------*/
  183. /*! \name Convert dataType */
  184. /*! \{ */
  185. void swapDataEndian (void );
  186. bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
  187. /*! \} */
  188. /*---------------------------------------------------------------------*/
  189. /*! \name Scale */
  190. /*! \{ */
  191. bool scale (Int32 width,
  192. Int32 height = 1,
  193. Int32 depth = 1,
  194. Image *destination = NULL);
  195. bool scaleNextPower2(Image *destination = NULL);
  196. /*! \} */
  197. /*---------------------------------------------------------------------*/
  198. /*! \name Mirror */
  199. /*! \{ */
  200. bool mirror (bool horizontal,
  201. bool vertical,
  202. bool flipDepth = false,
  203. Image *destination = NULL );
  204. /*! \} */
  205. /*---------------------------------------------------------------------*/
  206. /*! \name SubImage */
  207. /*! \{ */
  208. bool subImage(Int32 offX,
  209. Int32 offY,
  210. Int32 offZ,
  211. Int32 destW,
  212. Int32 destH,
  213. Int32 destD,
  214. Image *destination = NULL);
  215. /*! \} */
  216. /*---------------------------------------------------------------------*/
  217. /*! \name Slice */
  218. /*! \{ */
  219. bool slice(Int32 offX = -1,
  220. Int32 offY = -1,
  221. Int32 offZ = -1,
  222. Image *destination = NULL);
  223. /*! \} */
  224. /*---------------------------------------------------------------------*/
  225. /*! \name Mipmap */
  226. /*! \{ */
  227. bool createMipmap(Int32 level = -1,
  228. Image *destination = NULL);
  229. bool removeMipmap(void );
  230. /*! \} */
  231. /*---------------------------------------------------------------------*/
  232. /*! \name Read/Write */
  233. /*! \{ */
  234. bool write(const Char8 *fileName);
  235. bool read (const Char8 *fileName);
  236. /*! \} */
  237. /*---------------------------------------------------------------------*/
  238. /*! \name Storage/Restore */
  239. /*! \{ */
  240. UInt64 store (const Char8 *mimeType,
  241. UInt8 *mem,
  242. Int32 memSize = -1);
  243. UInt64 restore(const UInt8 *mem,
  244. Int32 memSize = -1);
  245. /*! \} */
  246. /*---------------------------------------------------------------------*/
  247. /*! \name Comparison/Assign */
  248. /*! \{ */
  249. Image &operator = (const Image &image);
  250. bool operator < (const Image &image);
  251. bool operator == (const Image &image);
  252. bool operator != (const Image &image);
  253. /*! \} */
  254. /*---------------------------------------------------------------------*/
  255. /*! \name Get Methods */
  256. /*! \{ */
  257. bool isValid (void) const;
  258. bool hasAlphaChannel (void);
  259. bool isAlphaBinary (void);
  260. bool hasColorChannel (void);
  261. bool hasCompressedData(void);
  262. UInt8 getComponents (void) const;
  263. bool calcIsAlphaBinary(void);
  264. /*! \} */
  265. /*---------------------------------------------------------------------*/
  266. /*! \name Size */
  267. /*! \{ */
  268. unsigned long getSize(bool withMipmap = true,
  269. bool withFrames = true,
  270. bool withSides = true) const;
  271. /*! \} */
  272. /*---------------------------------------------------------------------*/
  273. /*! \name Get Methods */
  274. /*! \{ */
  275. const UInt8 *getData (UInt32 mipmapNum = 0,
  276. UInt32 frameNum = 0,
  277. UInt32 sidecount = 0) const;
  278. UInt8 *editData (UInt32 mipmapNum = 0,
  279. UInt32 frameNum = 0,
  280. UInt32 sidecount = 0);
  281. const UInt8 *getDataFast (UInt32 mipmapNum = 0,
  282. UInt32 frameNum = 0,
  283. UInt32 sidecount = 0) const;
  284. UInt8 *editDataFast (UInt32 mipmapNum = 0,
  285. UInt32 frameNum = 0,
  286. UInt32 sidecount = 0);
  287. const UInt8 *getDataByTime (Time time,
  288. UInt32 mipmapNum = 1) const;
  289. UInt8 *editDataByTime(Time time,
  290. UInt32 mipmapNum = 1);
  291. /*! \} */
  292. /*---------------------------------------------------------------------*/
  293. /*! \name Calculate */
  294. /*! \{ */
  295. void calcMipmapGeometry (UInt32 mipmapNum,
  296. UInt32 &width,
  297. UInt32 &height,
  298. UInt32 &depth ) const;
  299. UInt32 calcMipmapLevelCount(void ) const;
  300. UInt32 calcFrameNum (Time time,
  301. bool loop = true) const;
  302. /*! \} */
  303. /*---------------------------------------------------------------------*/
  304. /*! \name Clear Image */
  305. /*! \{ */
  306. virtual void clear (UChar8 pixelValue = 0 );
  307. virtual void clearFloat(Real32 pixelValue = 0.0 );
  308. virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
  309. /*! \} */
  310. /*---------------------------------------------------------------------*/
  311. /*! \name attachment handling */
  312. /*! \{ */
  313. bool hasAttachment ( void ) const;
  314. UInt32 attachmentCount ( void ) const;
  315. void setAttachmentField (const std::string &key,
  316. const std::string &data);
  317. const std::string *findAttachmentField(const std::string &key ) const;
  318. /*! \} */
  319. /*---------------------------------------------------------------------*/
  320. /*! \name Calculate Mipmap Size */
  321. /*! \{ */
  322. UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
  323. UInt32 w,
  324. UInt32 h,
  325. UInt32 d ) const;
  326. UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
  327. UInt32 calcMipmapSumSize (UInt32 mipmapNum,
  328. UInt32 w,
  329. UInt32 h,
  330. UInt32 d ) const;
  331. UInt32 calcMipmapSumSize (UInt32 mipmapNum) const;
  332. /*! \} */
  333. /*---------------------------------------------------------------------*/
  334. /*! \name Don't know yet */
  335. /*! \{ */
  336. #if 0
  337. void imageContentChanged(Int32 minX = -1, Int32 maxX = -1,
  338. Int32 minY = -1, Int32 maxY = -1,
  339. Int32 minZ = -1, Int32 maxZ = -1 );
  340. #endif
  341. /*! \} */
  342. /*========================= PROTECTED ===============================*/
  343. protected:
  344. std::vector<Int32> _mipmapOffset;
  345. /*---------------------------------------------------------------------*/
  346. /*! \name static element */
  347. /*! \{ */
  348. static UInt32 _formatDic[][2];
  349. static Int32 _typeDic [][2];
  350. /*! \} */
  351. /*---------------------------------------------------------------------*/
  352. /*! \name Constructors */
  353. /*! \{ */
  354. Image(void);
  355. Image(const Image &source);
  356. /*! \} */
  357. /*---------------------------------------------------------------------*/
  358. /*! \name Destructors */
  359. /*! \{ */
  360. virtual ~Image(void);
  361. /*! \} */
  362. /*---------------------------------------------------------------------*/
  363. /*! \name Init */
  364. /*! \{ */
  365. static void initMethod(InitPhase ePhase);
  366. /*! \} */
  367. /*========================== PRIVATE ================================*/
  368. private:
  369. /*---------------------------------------------------------------------*/
  370. /*! \name Image Data */
  371. /*! \{ */
  372. bool createData (const UInt8 *data,
  373. bool allocMem = true );
  374. bool scaleData (const UInt8 *srcData,
  375. Int32 srcW,
  376. Int32 srcH,
  377. Int32 srcD,
  378. UInt8 *destData,
  379. Int32 destW,
  380. Int32 destH,
  381. Int32 destD );
  382. void calcMipmapOffsets( void );
  383. bool mirrorData (const UInt8 *srcData,
  384. UInt8 *destData,
  385. Int32 width,
  386. Int32 height,
  387. Int32 depth,
  388. bool horizontal,
  389. bool vertical,
  390. bool flipDepth = false);
  391. /*! \} */
  392. /*---------------------------------------------------------------------*/
  393. friend class FieldContainer;
  394. friend class ImageBase;
  395. };
  396. typedef Image *ImageP;
  397. OSG_END_NAMESPACE
  398. #include "OSGImageBase.inl"
  399. #include "OSGImage.inl"
  400. #endif /* _OSGIMAGE_H_ */