reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #ifndef SkPackBits_DEFINED |
| 10 | #define SkPackBits_DEFINED |
| 11 | |
| 12 | #include "SkTypes.h" |
| 13 | |
| 14 | class SkPackBits { |
| 15 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | /** Given the number of 8bit values that will be passed to Pack8, |
| 17 | returns the worst-case size needed for the dst[] buffer. |
| 18 | */ |
bungeman | ccb74b8 | 2016-02-23 12:55:20 -0800 | [diff] [blame] | 19 | static size_t ComputeMaxSize8(size_t srcSize); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | |
| 21 | /** Write the src array into a packed format. The packing process may end |
| 22 | up writing more bytes than it read, so dst[] must be large enough. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | @param src Input array of 8bit values |
jschuh | 699b852 | 2015-06-04 15:10:37 -0700 | [diff] [blame] | 24 | @param srcSize Number of entries in src[] |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | @param dst Buffer (allocated by caller) to write the packed data |
| 26 | into |
jschuh | 699b852 | 2015-06-04 15:10:37 -0700 | [diff] [blame] | 27 | @param dstSize Number of bytes in the output buffer. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | @return the number of bytes written to dst[] |
| 29 | */ |
jschuh | 699b852 | 2015-06-04 15:10:37 -0700 | [diff] [blame] | 30 | static size_t Pack8(const uint8_t src[], size_t srcSize, uint8_t dst[], |
| 31 | size_t dstSize); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | |
| 33 | /** Unpack the data in src[], and expand it into dst[]. The src[] data was |
| 34 | written by a previous call to Pack8. |
| 35 | @param src Input data to unpack, previously created by Pack8. |
| 36 | @param srcSize Number of bytes of src to unpack |
| 37 | @param dst Buffer (allocated by caller) to expand the src[] into. |
jschuh | 699b852 | 2015-06-04 15:10:37 -0700 | [diff] [blame] | 38 | @param dstSize Number of bytes in the output buffer. |
Mike Reed | fca3d0a | 2018-01-09 15:13:59 -0500 | [diff] [blame^] | 39 | @return the number of bytes written into dst, or 0 if srcSize or dstSize are too small. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | */ |
jschuh | 699b852 | 2015-06-04 15:10:37 -0700 | [diff] [blame] | 41 | static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[], |
| 42 | size_t dstSize); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #endif |