PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llimage/llimagedxt.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 141 lines | 93 code | 22 blank | 26 comment | 1 complexity | e65db01d8c5dbb874bdf4de64c98af71 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llimagedxt.h
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #ifndef LL_LLIMAGEDXT_H
  26. #define LL_LLIMAGEDXT_H
  27. #include "llimage.h"
  28. #include "llpointer.h"
  29. // This class decodes and encodes LL DXT files (which may unclude uncompressed RGB or RGBA mipped data)
  30. class LLImageDXT : public LLImageFormatted
  31. {
  32. public:
  33. enum EFileFormat
  34. {
  35. FORMAT_UNKNOWN = 0,
  36. FORMAT_I8 = 1,
  37. FORMAT_A8,
  38. FORMAT_RGB8,
  39. FORMAT_RGBA8,
  40. FORMAT_DXT1,
  41. FORMAT_DXT2,
  42. FORMAT_DXT3,
  43. FORMAT_DXT4,
  44. FORMAT_DXT5,
  45. FORMAT_DXR1,
  46. FORMAT_DXR2,
  47. FORMAT_DXR3,
  48. FORMAT_DXR4,
  49. FORMAT_DXR5,
  50. FORMAT_NOFILE = 0xff,
  51. };
  52. struct dxtfile_header_old_t
  53. {
  54. S32 format;
  55. S32 maxlevel;
  56. S32 maxwidth;
  57. S32 maxheight;
  58. };
  59. struct dxtfile_header_t
  60. {
  61. S32 fourcc;
  62. // begin DDSURFACEDESC2 struct
  63. S32 header_size; // size of the header
  64. S32 flags; // flags - unused
  65. S32 maxheight;
  66. S32 maxwidth;
  67. S32 image_size; // size of the compressed image
  68. S32 depth;
  69. S32 num_mips;
  70. S32 reserved[11];
  71. struct pixel_format
  72. {
  73. S32 struct_size; // size of this structure
  74. S32 flags;
  75. S32 fourcc;
  76. S32 bit_count;
  77. S32 r_mask;
  78. S32 g_mask;
  79. S32 b_mask;
  80. S32 a_mask;
  81. } pixel_fmt;
  82. S32 caps[4];
  83. S32 reserved2;
  84. };
  85. protected:
  86. /*virtual*/ ~LLImageDXT();
  87. private:
  88. BOOL encodeDXT(const LLImageRaw* raw_image, F32 decode_time, bool explicit_mips);
  89. public:
  90. LLImageDXT();
  91. /*virtual*/ std::string getExtension() { return std::string("dxt"); }
  92. /*virtual*/ BOOL updateData();
  93. /*virtual*/ BOOL decode(LLImageRaw* raw_image, F32 decode_time);
  94. /*virtual*/ BOOL encode(const LLImageRaw* raw_image, F32 encode_time);
  95. /*virtual*/ S32 calcHeaderSize();
  96. /*virtual*/ S32 calcDataSize(S32 discard_level = 0);
  97. BOOL getMipData(LLPointer<LLImageRaw>& raw, S32 discard=-1);
  98. void setFormat();
  99. S32 getMipOffset(S32 discard);
  100. EFileFormat getFileFormat() { return mFileFormat; }
  101. bool isCompressed() { return (mFileFormat >= FORMAT_DXT1 && mFileFormat <= FORMAT_DXR5); }
  102. bool convertToDXR(); // convert from DXT to DXR
  103. static void checkMinWidthHeight(EFileFormat format, S32& width, S32& height);
  104. static S32 formatBits(EFileFormat format);
  105. static S32 formatBytes(EFileFormat format, S32 width, S32 height);
  106. static S32 formatOffset(EFileFormat format, S32 width, S32 height, S32 max_width, S32 max_height);
  107. static S32 formatComponents(EFileFormat format);
  108. static EFileFormat getFormat(S32 fourcc);
  109. static S32 getFourCC(EFileFormat format);
  110. static void calcDiscardWidthHeight(S32 discard_level, EFileFormat format, S32& width, S32& height);
  111. static S32 calcNumMips(S32 width, S32 height);
  112. private:
  113. static void extractMip(const U8 *indata, U8* mipdata, int width, int height,
  114. int mip_width, int mip_height, EFileFormat format);
  115. private:
  116. EFileFormat mFileFormat;
  117. S32 mHeaderSize;
  118. };
  119. #endif