llimagej2c.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @file llimagej2c.h
  3. * @brief Image implementation for jpeg2000.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLIMAGEJ2C_H
  33. #define LL_LLIMAGEJ2C_H
  34. #include "llerror.h"
  35. #include "llimage.h"
  36. #include "llassettype.h"
  37. class LLImageJ2C final : public LLImageFormatted
  38. {
  39. protected:
  40. LOG_CLASS(LLImageJ2C);
  41. ~LLImageJ2C() override = default;
  42. public:
  43. LLImageJ2C();
  44. // Base class overrides
  45. std::string getExtension() override { return "j2c"; }
  46. bool updateData() override;
  47. LL_INLINE bool decode(LLImageRaw* raw_imagep) override
  48. {
  49. return decodeChannels(raw_imagep, 0, 4);
  50. }
  51. bool decodeChannels(LLImageRaw* raw_imagep, S32 first_channel,
  52. S32 max_channel_count) override;
  53. LL_INLINE bool encode(const LLImageRaw* raw_imagep) override
  54. {
  55. return raw_imagep && encode(raw_imagep, NULL);
  56. }
  57. LL_INLINE S32 calcHeaderSize() override
  58. {
  59. // *HACK: just needs to be >= actual header size...
  60. return FIRST_PACKET_SIZE;
  61. }
  62. S32 calcDataSize(S32 discard_level = 0) override;
  63. S32 calcDiscardLevelBytes(S32 bytes) override;
  64. LL_INLINE S8 getRawDiscardLevel() override { return mRawDiscardLevel; }
  65. // Override these so that we do not try to set a global variable from a DLL
  66. LL_INLINE void resetLastError() override { mLastError.clear(); }
  67. void setLastError(const std::string& message,
  68. const std::string& filename = std::string()) override;
  69. // Encode with comment text
  70. bool encode(const LLImageRaw* raw_imagep, const char* comment_text);
  71. bool validate(U8* data, U32 file_size);
  72. bool loadAndValidate(const std::string& filename);
  73. // Encode accessors
  74. // Use non-lossy ?
  75. LL_INLINE void setReversible(bool b) { mReversible = b; }
  76. LL_INLINE void setRate(F32 rate) { mRate = rate; }
  77. LL_INLINE void setMaxBytes(S32 max_bytes) { mMaxBytes = max_bytes; }
  78. LL_INLINE S32 getMaxBytes() const { return mMaxBytes; }
  79. static S32 calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level,
  80. F32 rate = 0.f);
  81. static std::string getEngineInfo();
  82. protected:
  83. void updateRawDiscardLevel();
  84. // Finds out the image size and number of channels. Returns true if image
  85. // size and number of channels was determined, false otherwise.
  86. bool getMetadata();
  87. // Fast header-based scan method.
  88. bool getMetadataFast(S32& width, S32& height, S32& comps);
  89. bool decodeImpl(LLImageRaw& raw_image, S32 first_channel,
  90. S32 max_channel_count);
  91. bool encodeImpl(const LLImageRaw& raw_image, const char* comment_text);
  92. static void eventMgrCallback(const char* msg, void*);
  93. static void initEventManager();
  94. protected:
  95. std::string mLastError;
  96. F32 mRate;
  97. S32 mMaxBytes; // Maximum number of bytes of data to use.
  98. S8 mRawDiscardLevel;
  99. bool mReversible;
  100. };
  101. #endif