Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2008 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkPackBits_DEFINED
     11 #define SkPackBits_DEFINED
     12 
     13 #include "SkTypes.h"
     14 
     15 class SkPackBits {
     16 public:
     17     /** Given the number of 16bit values that will be passed to Pack16,
     18         returns the worst-case size needed for the dst[] buffer.
     19     */
     20     static size_t ComputeMaxSize16(int count);
     21 
     22     /** Given the number of 8bit values that will be passed to Pack8,
     23         returns the worst-case size needed for the dst[] buffer.
     24     */
     25     static size_t ComputeMaxSize8(int count);
     26 
     27     /** Write the src array into a packed format. The packing process may end
     28         up writing more bytes than it read, so dst[] must be large enough.
     29         @param src      Input array of 16bit values
     30         @param count    Number of entries in src[]
     31         @param dst      Buffer (allocated by caller) to write the packed data
     32                         into
     33         @return the number of bytes written to dst[]
     34     */
     35     static size_t Pack16(const uint16_t src[], int count, uint8_t dst[]);
     36 
     37     /** Write the src array into a packed format. The packing process may end
     38         up writing more bytes than it read, so dst[] must be large enough.
     39         @param src      Input array of 8bit values
     40         @param count    Number of entries in src[]
     41         @param dst      Buffer (allocated by caller) to write the packed data
     42                         into
     43         @return the number of bytes written to dst[]
     44     */
     45     static size_t Pack8(const uint8_t src[], int count, uint8_t dst[]);
     46 
     47     /** Unpack the data in src[], and expand it into dst[]. The src[] data was
     48         written by a previous call to Pack16.
     49         @param src  Input data to unpack, previously created by Pack16.
     50         @param srcSize  Number of bytes of src to unpack
     51         @param dst  Buffer (allocated by caller) to expand the src[] into.
     52         @return the number of dst elements (not bytes) written into dst.
     53     */
     54     static int Unpack16(const uint8_t src[], size_t srcSize, uint16_t dst[]);
     55 
     56     /** Unpack the data in src[], and expand it into dst[]. The src[] data was
     57         written by a previous call to Pack8.
     58         @param src      Input data to unpack, previously created by Pack8.
     59         @param srcSize  Number of bytes of src to unpack
     60         @param dst      Buffer (allocated by caller) to expand the src[] into.
     61         @return the number of bytes written into dst.
     62     */
     63     static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[]);
     64 
     65     /** Unpack the data from src[], skip the first dstSkip bytes, then write
     66         dstWrite bytes into dst[]. The src[] data was written by a previous
     67         call to Pack8. Return the number of bytes actually writtten into dst[]
     68         @param src      Input data to unpack, previously created by Pack8.
     69         @param dst      Buffer (allocated by caller) to expand the src[] into.
     70         @param dstSkip  Number of bytes of unpacked src to skip before writing
     71                         into dst
     72         @param dstWrite Number of bytes of unpacked src to write into dst (after
     73                         skipping dstSkip bytes)
     74     */
     75     static void Unpack8(uint8_t dst[], size_t dstSkip, size_t dstWrite,
     76                         const uint8_t src[]);
     77 };
     78 
     79 #endif
     80