• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkPackBits_DEFINED
18 #define SkPackBits_DEFINED
19 
20 #include "SkTypes.h"
21 
22 class SkPackBits {
23 public:
24     /** Given the number of 16bit values that will be passed to Pack16,
25         returns the worst-case size needed for the dst[] buffer.
26     */
27     static size_t ComputeMaxSize16(int count);
28 
29     /** Given the number of 8bit values that will be passed to Pack8,
30         returns the worst-case size needed for the dst[] buffer.
31     */
32     static size_t ComputeMaxSize8(int count);
33 
34     /** Write the src array into a packed format. The packing process may end
35         up writing more bytes than it read, so dst[] must be large enough.
36         @param src      Input array of 16bit values
37         @param count    Number of entries in src[]
38         @param dst      Buffer (allocated by caller) to write the packed data
39                         into
40         @return the number of bytes written to dst[]
41     */
42     static size_t Pack16(const uint16_t src[], int count, uint8_t dst[]);
43 
44     /** Write the src array into a packed format. The packing process may end
45         up writing more bytes than it read, so dst[] must be large enough.
46         @param src      Input array of 8bit values
47         @param count    Number of entries in src[]
48         @param dst      Buffer (allocated by caller) to write the packed data
49                         into
50         @return the number of bytes written to dst[]
51     */
52     static size_t Pack8(const uint8_t src[], int count, uint8_t dst[]);
53 
54     /** Unpack the data in src[], and expand it into dst[]. The src[] data was
55         written by a previous call to Pack16.
56         @param src  Input data to unpack, previously created by Pack16.
57         @param srcSize  Number of bytes of src to unpack
58         @param dst  Buffer (allocated by caller) to expand the src[] into.
59         @return the number of dst elements (not bytes) written into dst.
60     */
61     static int Unpack16(const uint8_t src[], size_t srcSize, uint16_t dst[]);
62 
63     /** Unpack the data in src[], and expand it into dst[]. The src[] data was
64         written by a previous call to Pack8.
65         @param src      Input data to unpack, previously created by Pack8.
66         @param srcSize  Number of bytes of src to unpack
67         @param dst      Buffer (allocated by caller) to expand the src[] into.
68         @return the number of bytes written into dst.
69     */
70     static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[]);
71 
72     /** Unpack the data from src[], skip the first dstSkip bytes, then write
73         dstWrite bytes into dst[]. The src[] data was written by a previous
74         call to Pack8. Return the number of bytes actually writtten into dst[]
75         @param src      Input data to unpack, previously created by Pack8.
76         @param dst      Buffer (allocated by caller) to expand the src[] into.
77         @param dstSkip  Number of bytes of unpacked src to skip before writing
78                         into dst
79         @param dstWrite Number of bytes of unpacked src to write into dst (after
80                         skipping dstSkip bytes)
81     */
82     static void Unpack8(uint8_t dst[], size_t dstSkip, size_t dstWrite,
83                         const uint8_t src[]);
84 };
85 
86 #endif
87