[Ffmpeg-devel] [PATCH] move utf8 writing to libavutil

Michael Niedermayer michaelni
Sat Jul 8 20:04:13 CEST 2006


Hi

On Sat, Jul 08, 2006 at 01:21:56PM -0400, Justin Ruggles wrote:
> Hello,
> 
> This patch moves UTF-8 writing to libavutil.  It is an extension of
> Michael's commit yesterday which did the same to UTF-8 reading.
> 
> -Justin
> 

> Index: libavutil/common.h
> ===================================================================
> --- libavutil/common.h	(revision 5675)
> +++ libavutil/common.h	(working copy)
> @@ -518,6 +518,22 @@
>          }\
>      }
>  
> +#define PUT_UTF8(val, PUT_BYTE, OUTBYTE)\
> +    if(val < 0x80){\
> +        OUTBYTE = val;\
> +        PUT_BYTE\
> +    } else {\
> +        int bytes = (av_log2(val)+4) / 5;\
> +        int shift = (bytes - 1) * 6;\
> +        OUTBYTE = (256 - (256>>bytes)) | (val >> shift);\
> +        PUT_BYTE\
> +        while(shift >= 6){\
> +            shift -= 6;\
> +            OUTBYTE = 0x80 | ((val >> shift) & 0x3F);\
> +            PUT_BYTE\
> +        }\
> +    }\
> +

iam not sure if its cleaner, but the follwing is simpler:

#define PUT_UTF8(val)\
    if(val < 0x80){\
        PUT_BYTE(val)\
    } else {\
        int bytes = (av_log2(val)+4) / 5;\
        int shift = (bytes - 1) * 6;\
        PUT_BYTE((256 - (256>>bytes)) | (val >> shift));\
...

#define PUT_BYTE(v) put_bits(pb, 8, v);
    PUT_UTF8(val)



[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is




More information about the ffmpeg-devel mailing list