[MPlayer-dev-eng] [PATCH] Teletext support try3 (1/5, core)
Michael Niedermayer
michaelni at gmx.at
Mon Jul 16 14:22:41 CEST 2007
Hi
On Mon, Jul 16, 2007 at 03:33:03PM +0700, Vladimir Voroshilov wrote:
> 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?
what your code does
> 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) )
page += difference;
if(skip_hidden)
page= steppage(page);
difference can be +-1, +-0x10, +-0x100
a more generic solution which allows any direction value would be
static int steppage(int p, int direction, int skip_hidden){
if(skip_hidden)
p= (p&15) + ((p>>4)&15)*10 + (p>>8)*100;
p+= direction;
if(skip_hidden){
p= (p+800)%800;
p= (p%10) + ((p/10)%10)*16 + (p/100)*256;
}else
p&=0x7FF;
return p;
}
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20070716/e6d0fc64/attachment.pgp>
More information about the MPlayer-dev-eng
mailing list