PageRenderTime 57ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llkdu/llkdumem.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 145 lines | 102 code | 17 blank | 26 comment | 2 complexity | 79d48c2253e16f3f591660e6b167c054 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llkdumem.h
  3. * @brief Helper class for kdu memory management
  4. *
  5. * $LicenseInfo:firstyear=2010&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_LLKDUMEM_H
  27. #define LL_LLKDUMEM_H
  28. // Support classes for reading and writing from memory buffers in KDU
  29. #include "kdu_image.h"
  30. #include "kdu_elementary.h"
  31. #include "kdu_messaging.h"
  32. #include "kdu_params.h"
  33. #include "kdu_compressed.h"
  34. #include "kdu_sample_processing.h"
  35. #include "image_local.h"
  36. #include "stdtypes.h"
  37. class LLKDUMemSource: public kdu_compressed_source
  38. {
  39. public:
  40. LLKDUMemSource(U8 *input_buffer, U32 size)
  41. {
  42. mData = input_buffer;
  43. mSize = size;
  44. mCurPos = 0;
  45. }
  46. ~LLKDUMemSource()
  47. {
  48. }
  49. int read(kdu_byte *buf, int num_bytes)
  50. {
  51. U32 num_out;
  52. num_out = num_bytes;
  53. if ((mSize - mCurPos) < (U32)num_bytes)
  54. {
  55. num_out = mSize -mCurPos;
  56. }
  57. memcpy(buf, mData + mCurPos, num_out);
  58. mCurPos += num_out;
  59. return num_out;
  60. }
  61. void reset()
  62. {
  63. mCurPos = 0;
  64. }
  65. private:
  66. U8 *mData;
  67. U32 mSize;
  68. U32 mCurPos;
  69. };
  70. class LLKDUMemTarget: public kdu_compressed_target
  71. {
  72. public:
  73. LLKDUMemTarget(U8 *output_buffer, U32 &output_size, const U32 buffer_size)
  74. {
  75. mData = output_buffer;
  76. mSize = buffer_size;
  77. mCurPos = 0;
  78. mOutputSize = &output_size;
  79. }
  80. ~LLKDUMemTarget()
  81. {
  82. }
  83. bool write(const kdu_byte *buf, int num_bytes)
  84. {
  85. U32 num_out;
  86. num_out = num_bytes;
  87. if ((mSize - mCurPos) < (U32)num_bytes)
  88. {
  89. num_out = mSize - mCurPos;
  90. memcpy(mData + mCurPos, buf, num_out);
  91. return false;
  92. }
  93. memcpy(mData + mCurPos, buf, num_out);
  94. mCurPos += num_out;
  95. *mOutputSize = mCurPos;
  96. return true;
  97. }
  98. private:
  99. U8 *mData;
  100. U32 mSize;
  101. U32 mCurPos;
  102. U32 *mOutputSize;
  103. };
  104. class LLKDUMemIn : public kdu_image_in_base
  105. {
  106. public:
  107. LLKDUMemIn(const U8 *data,
  108. const U32 size,
  109. const U16 rows,
  110. const U16 cols,
  111. U8 in_num_components,
  112. siz_params *siz);
  113. ~LLKDUMemIn();
  114. bool get(int comp_idx, kdu_line_buf &line, int x_tnum);
  115. private:
  116. const U8 *mData;
  117. int first_comp_idx;
  118. int num_components;
  119. int rows, cols;
  120. int alignment_bytes; // Number of 0's at end of each line.
  121. int precision[3];
  122. image_line_buf *incomplete_lines; // Each "sample" represents a full pixel
  123. image_line_buf *free_lines;
  124. int num_unread_rows;
  125. U32 mCurPos;
  126. U32 mDataSize;
  127. };
  128. #endif