diff options
author | Anton Khirnov <wyskas@gmail.com> | 2010-02-24 18:08:30 +0000 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2010-02-24 18:08:30 +0000 |
commit | ae529ddb329952fa61aa1cbaae660580dc9f7c55 (patch) | |
tree | 51ef254efb5e8806c1c2bc1cd338187fb278b4ab /libavutil/common.h | |
parent | 01b35be14afb1bd2d295620410c8a96337aba345 (diff) | |
download | ffmpeg-ae529ddb329952fa61aa1cbaae660580dc9f7c55.tar.gz |
Add PUT_UTF16() macro.
Patch by Anton Khirnov <wyskas gmail com>.
Originally committed as revision 22030 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil/common.h')
-rw-r--r-- | libavutil/common.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libavutil/common.h b/libavutil/common.h index c91e658af7..4b757d1ca3 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -335,6 +335,36 @@ static inline av_const int av_ceil_log2(int x) }\ } +/*! + * \def PUT_UTF16(val, tmp, PUT_16BIT) + * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes). + * \param val is an input-only argument and should be of type uint32_t. It holds + * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If + * val is given as a function it is executed only once. + * \param tmp is a temporary variable and should be of type uint16_t. It + * represents an intermediate value during conversion that is to be + * output by PUT_16BIT. + * \param PUT_16BIT writes the converted UTF-16 data to any proper destination + * in desired endianness. It could be a function or a statement, and uses tmp + * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" + * PUT_BYTE will be executed 1 or 2 times depending on input character. + */ +#define PUT_UTF16(val, tmp, PUT_16BIT)\ + {\ + uint32_t in = val;\ + if (in < 0x10000) {\ + tmp = in;\ + PUT_16BIT\ + } else {\ + tmp = 0xD800 | ((in - 0x10000) >> 10);\ + PUT_16BIT\ + tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\ + PUT_16BIT\ + }\ + }\ + + + #include "mem.h" #ifdef HAVE_AV_CONFIG_H |