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

Justin Ruggles jruggle
Sun Jul 9 02:58:36 CEST 2006


Michael Niedermayer wrote:
> 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)
> 
> [...]

Here is an updated patch with both Michael's and Mans' suggestions.

-Justin


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: utf8.diff
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20060708/f9b258f0/attachment.asc>



More information about the ffmpeg-devel mailing list