SkPackBits.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2008 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkPackBits_DEFINED
  8. #define SkPackBits_DEFINED
  9. #include "include/core/SkTypes.h"
  10. class SkPackBits {
  11. public:
  12. /** Given the number of 8bit values that will be passed to Pack8,
  13. returns the worst-case size needed for the dst[] buffer.
  14. */
  15. static size_t ComputeMaxSize8(size_t srcSize);
  16. /** Write the src array into a packed format. The packing process may end
  17. up writing more bytes than it read, so dst[] must be large enough.
  18. @param src Input array of 8bit values
  19. @param srcSize Number of entries in src[]
  20. @param dst Buffer (allocated by caller) to write the packed data
  21. into
  22. @param dstSize Number of bytes in the output buffer.
  23. @return the number of bytes written to dst[]
  24. */
  25. static size_t Pack8(const uint8_t src[], size_t srcSize, uint8_t dst[],
  26. size_t dstSize);
  27. /** Unpack the data in src[], and expand it into dst[]. The src[] data was
  28. written by a previous call to Pack8.
  29. @param src Input data to unpack, previously created by Pack8.
  30. @param srcSize Number of bytes of src to unpack
  31. @param dst Buffer (allocated by caller) to expand the src[] into.
  32. @param dstSize Number of bytes in the output buffer.
  33. @return the number of bytes written into dst, or 0 if srcSize or dstSize are too small.
  34. */
  35. static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[],
  36. size_t dstSize);
  37. };
  38. #endif