integerCoding.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // Copyright 2017 Pixar
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "Apache License")
  5. // with the following modification; you may not use this file except in
  6. // compliance with the Apache License and the following modification to it:
  7. // Section 6. Trademarks. is deleted and replaced with:
  8. //
  9. // 6. Trademarks. This License does not grant permission to use the trade
  10. // names, trademarks, service marks, or product names of the Licensor
  11. // and its affiliates, except as required to comply with Section 4(c) of
  12. // the License and to reproduce the content of the NOTICE file.
  13. //
  14. // You may obtain a copy of the Apache License at
  15. //
  16. // http://www.apache.org/licenses/LICENSE-2.0
  17. //
  18. // Unless required by applicable law or agreed to in writing, software
  19. // distributed under the Apache License with the above modification is
  20. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21. // KIND, either express or implied. See the Apache License for the specific
  22. // language governing permissions and limitations under the Apache License.
  23. //
  24. #ifndef USD_INTEGERCODING_H
  25. #define USD_INTEGERCODING_H
  26. //#include "pxr/pxr.h"
  27. //#include "pxr/usd/usd/api.h"
  28. #include <cstdint>
  29. #include <memory>
  30. #define USD_API
  31. //PXR_NAMESPACE_OPEN_SCOPE
  32. namespace tinyusdz {
  33. class Usd_IntegerCompression
  34. {
  35. public:
  36. // Return the max compression buffer size required for \p numInts 32-bit
  37. // integers.
  38. USD_API
  39. static size_t GetCompressedBufferSize(size_t numInts);
  40. // Return the max decompression working space size required for \p numInts
  41. // 32-bit integers.
  42. USD_API
  43. static size_t GetDecompressionWorkingSpaceSize(size_t numInts);
  44. // Compress \p numInts ints from \p ints to \p compressed. The
  45. // \p compressed space must point to at least
  46. // GetCompressedBufferSize(numInts) bytes. Return the actual number
  47. // of bytes written to \p compressed.
  48. USD_API
  49. static size_t CompressToBuffer(
  50. int32_t const *ints, size_t numInts, char *compressed, std::string *err);
  51. // Compress \p numInts ints from \p ints to \p compressed. The
  52. // \p compressed space must point to at least
  53. // GetCompressedBufferSize(numInts) bytes. Return the actual number
  54. // of bytes written to \p compressed.
  55. USD_API
  56. static size_t CompressToBuffer(
  57. uint32_t const *ints, size_t numInts, char *compressed, std::string *err);
  58. // Decompress \p compressedSize bytes from \p compressed to produce
  59. // \p numInts 32-bit integers into \p ints. Clients may supply
  60. // \p workingSpace to save allocations if several decompressions will be
  61. // done but it isn't required. If supplied it must point to at least
  62. // GetDecompressionWorkingSpaceSize(numInts) bytes.
  63. USD_API
  64. static size_t DecompressFromBuffer(
  65. char const *compressed, size_t compressedSize,
  66. int32_t *ints, size_t numInts, std::string *err,
  67. char *workingSpace=nullptr);
  68. // Decompress \p compressedSize bytes from \p compressed to produce
  69. // \p numInts 32-bit integers into \p ints. Clients may supply
  70. // \p workingSpace to save allocations if several decompressions will be
  71. // done but it isn't required. If supplied it must point to at least
  72. // GetDecompressionWorkingSpaceSize(numInts) bytes.
  73. USD_API
  74. static size_t DecompressFromBuffer(
  75. char const *compressed, size_t compressedSize,
  76. uint32_t *ints, size_t numInts, std::string *err,
  77. char *workingSpace=nullptr);
  78. };
  79. class Usd_IntegerCompression64
  80. {
  81. public:
  82. // Return the max compression buffer size required for \p numInts 64-bit
  83. // integers.
  84. USD_API
  85. static size_t GetCompressedBufferSize(size_t numInts);
  86. // Return the max decompression working space size required for \p numInts
  87. // 64-bit integers.
  88. USD_API
  89. static size_t GetDecompressionWorkingSpaceSize(size_t numInts);
  90. // Compress \p numInts ints from \p ints to \p compressed. The
  91. // \p compressed space must point to at least
  92. // GetCompressedBufferSize(numInts) bytes. Return the actual number
  93. // of bytes written to \p compressed.
  94. USD_API
  95. static size_t CompressToBuffer(
  96. int64_t const *ints, size_t numInts, char *compressed, std::string *err);
  97. // Compress \p numInts ints from \p ints to \p compressed. The
  98. // \p compressed space must point to at least
  99. // GetCompressedBufferSize(numInts) bytes. Return the actual number
  100. // of bytes written to \p compressed.
  101. USD_API
  102. static size_t CompressToBuffer(
  103. uint64_t const *ints, size_t numInts, char *compressed, std::string *err);
  104. // Decompress \p compressedSize bytes from \p compressed to produce
  105. // \p numInts 64-bit integers into \p ints. Clients may supply
  106. // \p workingSpace to save allocations if several decompressions will be
  107. // done but it isn't required. If supplied it must point to at least
  108. // GetDecompressionWorkingSpaceSize(numInts) bytes.
  109. USD_API
  110. static size_t DecompressFromBuffer(
  111. char const *compressed, size_t compressedSize,
  112. int64_t *ints, size_t numInts, std::string *err,
  113. char *workingSpace=nullptr);
  114. // Decompress \p compressedSize bytes from \p compressed to produce
  115. // \p numInts 64-bit integers into \p ints. Clients may supply
  116. // \p workingSpace to save allocations if several decompressions will be
  117. // done but it isn't required. If supplied it must point to at least
  118. // GetDecompressionWorkingSpaceSize(numInts) bytes.
  119. USD_API
  120. static size_t DecompressFromBuffer(
  121. char const *compressed, size_t compressedSize,
  122. uint64_t *ints, size_t numInts, std::string *err,
  123. char *workingSpace=nullptr);
  124. };
  125. //PXR_NAMESPACE_CLOSE_SCOPE
  126. } // namespace tinyusdz
  127. #endif // USD_INTEGERCODING_H