michael@0: michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkPackBits_DEFINED michael@0: #define SkPackBits_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: class SkPackBits { michael@0: public: michael@0: /** Given the number of 16bit values that will be passed to Pack16, michael@0: returns the worst-case size needed for the dst[] buffer. michael@0: */ michael@0: static size_t ComputeMaxSize16(int count); michael@0: michael@0: /** Given the number of 8bit values that will be passed to Pack8, michael@0: returns the worst-case size needed for the dst[] buffer. michael@0: */ michael@0: static size_t ComputeMaxSize8(int count); michael@0: michael@0: /** Write the src array into a packed format. The packing process may end michael@0: up writing more bytes than it read, so dst[] must be large enough. michael@0: @param src Input array of 16bit values michael@0: @param count Number of entries in src[] michael@0: @param dst Buffer (allocated by caller) to write the packed data michael@0: into michael@0: @return the number of bytes written to dst[] michael@0: */ michael@0: static size_t Pack16(const uint16_t src[], int count, uint8_t dst[]); michael@0: michael@0: /** Write the src array into a packed format. The packing process may end michael@0: up writing more bytes than it read, so dst[] must be large enough. michael@0: @param src Input array of 8bit values michael@0: @param count Number of entries in src[] michael@0: @param dst Buffer (allocated by caller) to write the packed data michael@0: into michael@0: @return the number of bytes written to dst[] michael@0: */ michael@0: static size_t Pack8(const uint8_t src[], int count, uint8_t dst[]); michael@0: michael@0: /** Unpack the data in src[], and expand it into dst[]. The src[] data was michael@0: written by a previous call to Pack16. michael@0: @param src Input data to unpack, previously created by Pack16. michael@0: @param srcSize Number of bytes of src to unpack michael@0: @param dst Buffer (allocated by caller) to expand the src[] into. michael@0: @return the number of dst elements (not bytes) written into dst. michael@0: */ michael@0: static int Unpack16(const uint8_t src[], size_t srcSize, uint16_t dst[]); michael@0: michael@0: /** Unpack the data in src[], and expand it into dst[]. The src[] data was michael@0: written by a previous call to Pack8. michael@0: @param src Input data to unpack, previously created by Pack8. michael@0: @param srcSize Number of bytes of src to unpack michael@0: @param dst Buffer (allocated by caller) to expand the src[] into. michael@0: @return the number of bytes written into dst. michael@0: */ michael@0: static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[]); michael@0: michael@0: /** Unpack the data from src[], skip the first dstSkip bytes, then write michael@0: dstWrite bytes into dst[]. The src[] data was written by a previous michael@0: call to Pack8. Return the number of bytes actually writtten into dst[] michael@0: @param src Input data to unpack, previously created by Pack8. michael@0: @param dst Buffer (allocated by caller) to expand the src[] into. michael@0: @param dstSkip Number of bytes of unpacked src to skip before writing michael@0: into dst michael@0: @param dstWrite Number of bytes of unpacked src to write into dst (after michael@0: skipping dstSkip bytes) michael@0: */ michael@0: static void Unpack8(uint8_t dst[], size_t dstSkip, size_t dstWrite, michael@0: const uint8_t src[]); michael@0: }; michael@0: michael@0: #endif