PageRenderTime 38ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llimage/llimagej2c.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 166 lines | 89 code | 25 blank | 52 comment | 0 complexity | a9124e85835bc408f7c6d1fa7866b3a3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llimagej2c.h
  3. * @brief Image implmenation for jpeg2000.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLIMAGEJ2C_H
  27. #define LL_LLIMAGEJ2C_H
  28. #include "llimage.h"
  29. #include "llassettype.h"
  30. #include "llmetricperformancetester.h"
  31. class LLImageJ2CImpl;
  32. class LLImageCompressionTester ;
  33. class LLImageJ2C : public LLImageFormatted
  34. {
  35. protected:
  36. virtual ~LLImageJ2C();
  37. public:
  38. LLImageJ2C();
  39. // Base class overrides
  40. /*virtual*/ std::string getExtension() { return std::string("j2c"); }
  41. /*virtual*/ BOOL updateData();
  42. /*virtual*/ BOOL decode(LLImageRaw *raw_imagep, F32 decode_time);
  43. /*virtual*/ BOOL decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 first_channel, S32 max_channel_count);
  44. /*virtual*/ BOOL encode(const LLImageRaw *raw_imagep, F32 encode_time);
  45. /*virtual*/ S32 calcHeaderSize();
  46. /*virtual*/ S32 calcDataSize(S32 discard_level = 0);
  47. /*virtual*/ S32 calcDiscardLevelBytes(S32 bytes);
  48. /*virtual*/ S8 getRawDiscardLevel();
  49. // Override these so that we don't try to set a global variable from a DLL
  50. /*virtual*/ void resetLastError();
  51. /*virtual*/ void setLastError(const std::string& message, const std::string& filename = std::string());
  52. BOOL initDecode(LLImageRaw &raw_image, int discard_level, int* region);
  53. BOOL initEncode(LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels);
  54. // Encode with comment text
  55. BOOL encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time=0.0);
  56. BOOL validate(U8 *data, U32 file_size);
  57. BOOL loadAndValidate(const std::string &filename);
  58. // Encode accessors
  59. void setReversible(const BOOL reversible); // Use non-lossy?
  60. void setRate(F32 rate);
  61. void setMaxBytes(S32 max_bytes);
  62. S32 getMaxBytes() const { return mMaxBytes; }
  63. static S32 calcHeaderSizeJ2C();
  64. static S32 calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 rate = 0.f);
  65. static std::string getEngineInfo();
  66. protected:
  67. friend class LLImageJ2CImpl;
  68. friend class LLImageJ2COJ;
  69. friend class LLImageJ2CKDU;
  70. friend class LLImageCompressionTester;
  71. void decodeFailed();
  72. void updateRawDiscardLevel();
  73. S32 mMaxBytes; // Maximum number of bytes of data to use...
  74. S32 mDataSizes[MAX_DISCARD_LEVEL+1]; // Size of data required to reach a given level
  75. U32 mAreaUsedForDataSizeCalcs; // Height * width used to calculate mDataSizes
  76. S8 mRawDiscardLevel;
  77. F32 mRate;
  78. BOOL mReversible;
  79. LLImageJ2CImpl *mImpl;
  80. std::string mLastError;
  81. // Image compression/decompression tester
  82. static LLImageCompressionTester* sTesterp;
  83. };
  84. // Derive from this class to implement JPEG2000 decoding
  85. class LLImageJ2CImpl
  86. {
  87. public:
  88. virtual ~LLImageJ2CImpl();
  89. protected:
  90. // Find out the image size and number of channels.
  91. // Return value:
  92. // true: image size and number of channels was determined
  93. // false: error on decode
  94. virtual BOOL getMetadata(LLImageJ2C &base) = 0;
  95. // Decode the raw image optionally aborting (to continue later) after
  96. // decode_time seconds. Decode at most max_channel_count and start
  97. // decoding channel first_channel.
  98. // Return value:
  99. // true: decoding complete (even if it failed)
  100. // false: time expired while decoding
  101. virtual BOOL decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count) = 0;
  102. virtual BOOL encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time=0.0,
  103. BOOL reversible=FALSE) = 0;
  104. virtual BOOL initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level = -1, int* region = NULL) = 0;
  105. virtual BOOL initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size = -1, int precincts_size = -1, int levels = 0) = 0;
  106. friend class LLImageJ2C;
  107. };
  108. #define LINDEN_J2C_COMMENT_PREFIX "LL_"
  109. //
  110. // This class is used for performance data gathering only.
  111. // Tracks the image compression / decompression data,
  112. // records and outputs them to the log file.
  113. //
  114. class LLImageCompressionTester : public LLMetricPerformanceTesterBasic
  115. {
  116. public:
  117. LLImageCompressionTester();
  118. ~LLImageCompressionTester();
  119. void updateDecompressionStats(const F32 deltaTime) ;
  120. void updateDecompressionStats(const S32 bytesIn, const S32 bytesOut) ;
  121. void updateCompressionStats(const F32 deltaTime) ;
  122. void updateCompressionStats(const S32 bytesIn, const S32 bytesOut) ;
  123. protected:
  124. /*virtual*/ void outputTestRecord(LLSD* sd);
  125. private:
  126. //
  127. // Data size
  128. //
  129. U32 mTotalBytesInDecompression; // Total bytes fed to decompressor
  130. U32 mTotalBytesOutDecompression; // Total bytes produced by decompressor
  131. U32 mTotalBytesInCompression; // Total bytes fed to compressor
  132. U32 mTotalBytesOutCompression; // Total bytes produced by compressor
  133. U32 mRunBytesInDecompression; // Bytes fed to decompressor in this run
  134. U32 mRunBytesInCompression; // Bytes fed to compressor in this run
  135. //
  136. // Time
  137. //
  138. F32 mTotalTimeDecompression; // Total time spent in computing decompression
  139. F32 mTotalTimeCompression; // Total time spent in computing compression
  140. };
  141. #endif