[MPlayer-dev-eng] [PATCH] Windows1250 to ISO8859-2 subtitles conversion patch

Bartek Bergier berdzi at ksnet.dhs.org
Mon Mar 25 14:33:08 CET 2002


Hello

I've recently wrote a small patch to Mplayer that could be pretty useful
for Poles. Its purpose is to convert at playing time subtitles coded is
Windows 1250 format to ISO-8859-2. Most Polish subtitles are coded in
Windows 1250 and I always had to convert them with external software to
ISO. I include version for today CVS (20020325).

I tested it and I hope it will be useful

Regards, Berdzi.

PS: Sorry for sending it third time but I've got some encoding problem
-------------------------------------------------------
-------------- next part --------------
--- ./MPlayer-20020325/subreader.c	Thu Feb 28 03:37:13 2002
+++ ./subreader.c	Mon Mar 25 12:39:02 2002
@@ -144,10 +144,46 @@
     return current;
 }
 
+//win-1250 to ISO8859-2 subtitle conversion
+//written by Berdzi
+char *win2iso2(unsigned char *str)
+{
+ //char codes of Polish letters in win-1250 and ISO-8859-2 formats
+
+  unsigned char win[]={185,230,234,179,241,243,156,159,191,
+              165,198,202,163,209,211,140,143,175};
+  unsigned char iso2[]={177,230,234,179,241,243,182,188,191,
+               161,198,202,163,209,211,166,172,175};
+     
+  int i,n=0,code; //code - ASCII char code
+  char lineout[LINE_LEN+1]; //converted to ISO line of text
+  char *plineout; //pointer to lineout
+     
+  while(!eol(*str))
+   { code=(int)*str;
+     if (code>127) //convert only if code>127 (faster)
+      { for (i=0; i<=17; i++)
+         {
+           //if charcode is in win1250 format , change it to ISO8859-2 else change nothing
+           if (*str==win[i]) { lineout[n]=iso2[i]; break;} else { lineout[n]=*str; }
+         }
+      }
+     else
+      { lineout[n]=*str; }
+  
+     n++;
+     str++;
+   }
+     
+ lineout[n++]='\0';
+ plineout=lineout;
+ return plineout;
+}
 
 char *sub_readtext(char *source, char **dest) {
+    char *srciso=win2iso2(source); //later, instead of source we've got ISO coded srciso
     int len=0;
-    char *p=source;
+    char *p=srciso;
     
     while ( !eol(*p) && *p!= '|' ) {
 	p++,len++;
@@ -156,7 +192,7 @@
     *dest= (char *)malloc (len+1);
     if (!dest) {return ERR;}
     
-    strncpy(*dest, source, len);
+    strncpy(*dest, srciso, len);
     (*dest)[len]=0;
     
     while (*p=='\r' || *p=='\n' || *p=='|') p++;


More information about the MPlayer-dev-eng mailing list