All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
integerCoding.h
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 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 
30 #include <cstdint>
31 #include <memory>
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 class Usd_IntegerCompression
36 {
37 public:
38  // Return the max compression buffer size required for \p numInts 32-bit
39  // integers.
40  USD_API
41  static size_t GetCompressedBufferSize(size_t numInts);
42 
43  // Return the max decompression working space size required for \p numInts
44  // 32-bit integers.
45  USD_API
46  static size_t GetDecompressionWorkingSpaceSize(size_t numInts);
47 
48  // Compress \p numInts ints from \p ints to \p compressed. The
49  // \p compressed space must point to at least
50  // GetCompressedBufferSize(numInts) bytes. Return the actual number
51  // of bytes written to \p compressed.
52  USD_API
53  static size_t CompressToBuffer(
54  int32_t const *ints, size_t numInts, char *compressed);
55 
56  // Compress \p numInts ints from \p ints to \p compressed. The
57  // \p compressed space must point to at least
58  // GetCompressedBufferSize(numInts) bytes. Return the actual number
59  // of bytes written to \p compressed.
60  USD_API
61  static size_t CompressToBuffer(
62  uint32_t const *ints, size_t numInts, char *compressed);
63 
64  // Decompress \p compressedSize bytes from \p compressed to produce
65  // \p numInts 32-bit integers into \p ints. Clients may supply
66  // \p workingSpace to save allocations if several decompressions will be
67  // done but it isn't required. If supplied it must point to at least
68  // GetDecompressionWorkingSpaceSize(numInts) bytes.
69  USD_API
70  static size_t DecompressFromBuffer(
71  char const *compressed, size_t compressedSize,
72  int32_t *ints, size_t numInts,
73  char *workingSpace=nullptr);
74 
75  // Decompress \p compressedSize bytes from \p compressed to produce
76  // \p numInts 32-bit integers into \p ints. Clients may supply
77  // \p workingSpace to save allocations if several decompressions will be
78  // done but it isn't required. If supplied it must point to at least
79  // GetDecompressionWorkingSpaceSize(numInts) bytes.
80  USD_API
81  static size_t DecompressFromBuffer(
82  char const *compressed, size_t compressedSize,
83  uint32_t *ints, size_t numInts,
84  char *workingSpace=nullptr);
85 };
86 
87 class Usd_IntegerCompression64
88 {
89 public:
90  // Return the max compression buffer size required for \p numInts 64-bit
91  // integers.
92  USD_API
93  static size_t GetCompressedBufferSize(size_t numInts);
94 
95  // Return the max decompression working space size required for \p numInts
96  // 64-bit integers.
97  USD_API
98  static size_t GetDecompressionWorkingSpaceSize(size_t numInts);
99 
100  // Compress \p numInts ints from \p ints to \p compressed. The
101  // \p compressed space must point to at least
102  // GetCompressedBufferSize(numInts) bytes. Return the actual number
103  // of bytes written to \p compressed.
104  USD_API
105  static size_t CompressToBuffer(
106  int64_t const *ints, size_t numInts, char *compressed);
107 
108  // Compress \p numInts ints from \p ints to \p compressed. The
109  // \p compressed space must point to at least
110  // GetCompressedBufferSize(numInts) bytes. Return the actual number
111  // of bytes written to \p compressed.
112  USD_API
113  static size_t CompressToBuffer(
114  uint64_t const *ints, size_t numInts, char *compressed);
115 
116  // Decompress \p compressedSize bytes from \p compressed to produce
117  // \p numInts 64-bit integers into \p ints. Clients may supply
118  // \p workingSpace to save allocations if several decompressions will be
119  // done but it isn't required. If supplied it must point to at least
120  // GetDecompressionWorkingSpaceSize(numInts) bytes.
121  USD_API
122  static size_t DecompressFromBuffer(
123  char const *compressed, size_t compressedSize,
124  int64_t *ints, size_t numInts,
125  char *workingSpace=nullptr);
126 
127  // Decompress \p compressedSize bytes from \p compressed to produce
128  // \p numInts 64-bit integers into \p ints. Clients may supply
129  // \p workingSpace to save allocations if several decompressions will be
130  // done but it isn't required. If supplied it must point to at least
131  // GetDecompressionWorkingSpaceSize(numInts) bytes.
132  USD_API
133  static size_t DecompressFromBuffer(
134  char const *compressed, size_t compressedSize,
135  uint64_t *ints, size_t numInts,
136  char *workingSpace=nullptr);
137 };
138 
139 PXR_NAMESPACE_CLOSE_SCOPE
140 
141 #endif // USD_INTEGERCODING_H