[MPlayer-dev-eng] [PATCH] Teletext support try3 (1/5, core)

Vladimir Voroshilov voroshil at gmail.com
Mon Jul 16 10:33:03 CEST 2007


2007/7/15, Michael Niedermayer <michaelni at gmx.at>:
> Hi
>
> On Sun, Jul 15, 2007 at 06:01:13PM +0700, Vladimir Voroshilov wrote:
> > +
> > +/**
> > + * \brief convert 123 --> 0x123
> > + * \param dec decimal value
> > + * \return apropriate hexadecimal value
> > + *
> > + */
> > +static inline int vbi_dec2bcd(int dec){
> > +    unsigned char c1,c2,c3;
> > +    int ret;
> > +    c1=dec%10;
> > +    c2=(dec/10)%10;
> > +    c3=(dec/100)%10;
> > +    ret=(c3<<8)|(c2<<4)|c1;
> > +    mp_msg(MSGT_TV,MSGL_DBG3,"vbi_dec2bcd: %d -> 0x%03x\n",dec,ret);
> > +    return ret;
> > +}
> > +
> > +/**
> > + * \brief convert 0x123 --> 123
> > + * \param bcd hexadecimal value
> > + * \return apropriate decimal value
> > + *
> > + */
> > +static inline int vbi_bcd2dec(int bcd){
> > +    unsigned char c1,c2,c3;
> > +    int ret;
> > +
> > +    c1=(bcd>>8)&0xf;
> > +    c2=(bcd>>4)&0xf;
> > +    c3=(bcd)&0xf;
> > +
> > +    if(c1>9 || c2>9 || c3>9)
> > +        return 0;
> > +
> > +    ret=(c1*100+c2*10+c3);
> > +    mp_msg(MSGT_TV,MSGL_DBG3,"vbi_bcd2dec:0x%03x -> %d \n",bcd,ret);
> > +    return ret;
> > +}
> > +
> > +/**
> > + * \brief calculate increased/decreased by given value page number
> > + * \param curr  current page number in hexadecimal for
> > + * \param direction decimal value (can be negative) to add to value or curr parameter
> > + * \return new page number in hexadecimal form
> > + *
> > + * VBI page numbers are represented in special hexadecimal form, e.g.
> > + * page with number 123 (as seen by user) internally has number 0x123.
> > + * and equation 0x123+8 should be equal to 0x131 instead of regular 0x12b.
> > + *
> > + *
> > + * Page numbers 0xYYY (where Y is not belongs to (0..9) and pages below 0x100 and
> > + * higher 0x799 are reserved for internal use.
> > + *
> > + */
> > +static int steppage(int curr, int direction)
> > +{
> > +    int newpage = vbi_dec2bcd(vbi_bcd2dec(curr) + direction);
> > +    if (newpage < 0x0)
> > +        newpage = 0x799;
> > +    if (newpage > 0x799)
> > +        newpage = 0x0;
> > +    mp_msg(MSGT_TV,MSGL_DBG3,"steppage is called: curr:0x%03x, direction: %d, newpage: 0x%03x\n",curr,direction,newpage);
> > +    return newpage;
> > +}
>
> ohh my god is this a mess, please use something like the following
> (note, its untested)
>
> static int todec(unsigned int p){
>     int d= p&15;
>     if     (d==15) p-=6;
>     else if(d==10) p+=6;
>     return p;
> }
> static int steppage(unsigned int p){
>     p= todec(p & 0x7FF);
>     p=     (p& 15) + (todec(p>>4)<<4);
>     return ((p&255) + (todec(p>>8)<<8)) & 0x7FF;
> }
What this code intend to do?
I didn't undestand it.
How will it calculate expression below (note: 10 is decimal value)
0x123+10 => 0x133 (in my code: 0x133=steppage(0x123,10) )



-- 
Regards,
Vladimir Voroshilov     mailto:voroshil at gmail.com
JID: voroshil at gmail.com, voroshil at jabber.ru
ICQ: 95587719



More information about the MPlayer-dev-eng mailing list