Ticket #1899: 1899-v1.patch

File 1899-v1.patch, 28.7 KB (added by danielk, 18 years ago)

Fix for segfault

  • libs/libmythtv/osdtypeteletext.h

     
    9696class TeletextMagazine
    9797{
    9898  public:
    99     QMutex lock;
     99    mutable QMutex lock;
    100100    int current_page;
    101101    int current_subpage;
    102102    std::map<int, TeletextPage> pages;
     
    112112        : OSDType(other.m_name), TeletextViewer() {}
    113113    virtual ~OSDTypeTeletext() {}
    114114
    115 
    116115    void Reinit(float wmult, float hmult);
    117116
     117    // Teletext Drawing methods
    118118    void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
     119    void DrawBackground(OSDSurface *surface, int x, int y) const;
     120    void DrawRect(OSDSurface *surface, const QRect) const;
     121    void DrawCharacter(OSDSurface *surface, int x, int y,
     122                       QChar ch, int doubleheight = 0) const;
     123    void DrawMosaic(OSDSurface *surface, int x, int y,
     124                    int code, int doubleheight) const;
     125    void DrawLine(OSDSurface *surface, const uint8_t *page,
     126                  uint row, int lang) const;
     127    void DrawHeader(OSDSurface *surface, const uint8_t *page, int lang) const;
     128    void DrawStatus(OSDSurface *surface) const;
     129    void DrawPage(OSDSurface *surface) const;
    119130
    120     void SetForegroundColor(int color);
    121     void SetBackgroundColor(int color);
    122 
    123     void DrawBackground(int x, int y);
    124     void DrawRect(int x, int y, int dx, int dy);
    125     void DrawCharacter(int x, int y, QChar ch, int doubleheight = 0);
    126     void DrawMosaic(int x, int y, int code, int doubleheight);
    127 
    128     void DrawLine(const uint8_t* page, uint row, int lang);
    129     void DrawHeader(const uint8_t* page, int lang);
    130     void DrawPage(void);
    131 
    132     void NewsFlash(void) {};
    133 
    134     void PageUpdated(int page, int subpage);
    135     void HeaderUpdated(uint8_t* page, int lang);
    136     void StatusUpdated(void);
    137 
    138     // Teletext Viewer methods
     131    // TeletextViewer interface methods
    139132    void KeyPress(uint key);
    140133    void SetPage(int page, int subpage);
    141134    void SetDisplaying(bool display) { m_displaying = display; };
     
    146139    void AddTeletextData(int magazine, int row,
    147140                         const uint8_t* buf, int vbimode);
    148141
     142    static const QColor kColorBlack;
     143    static const QColor kColorRed;
     144    static const QColor kColorGreen;
     145    static const QColor kColorYellow;
     146    static const QColor kColorBlue;
     147    static const QColor kColorMagenta;
     148    static const QColor kColorCyan;
     149    static const QColor kColorWhite;
     150    static const int    kTeletextColumns;
     151    static const int    kTeletextRows;
     152
    149153  private:
    150     char CharConversion(char ch, int lang);
    151     TeletextSubPage *FindSubPage(int page, int subpage, int direction = 0);
    152     TeletextPage    *FindPage(int page, int direction = 0);
     154    // Internal Teletext Sets
     155    void SetForegroundColor(int color) const;
     156    void SetBackgroundColor(int color) const;
    153157
     158    // Internal Teletext Commands
     159    void NewsFlash(void) {};
     160    void PageUpdated(int page, int subpage);
     161    void HeaderUpdated(uint8_t *page, int lang);
     162
     163    const TeletextSubPage *FindSubPage(int page,int subpage,int dir = 0) const;
     164    const TeletextPage *FindPage(int page, int direction = 0) const;
     165
     166    TeletextSubPage *FindSubPage(int page, int subpage, int direction = 0)
     167        { return (TeletextSubPage*) FindSubPage(page, subpage, direction); }
     168    TeletextPage *FindPage(int page, int direction = 0)
     169        { return (TeletextPage*) FindPage(page, direction); }
     170
    154171  private:
    155172    QMutex       m_lock;
    156173    QRect        m_displayrect;
    157174    QRect        m_unbiasedrect;
    158175
    159     TTFFont     *m_font;
    160     OSDSurface  *m_surface;
    161176    OSDTypeBox  *m_box;
    162177
    163178    int          m_tt_colspace;
    164179    int          m_tt_rowspace;
    165180
    166     uint8_t      m_bgcolor_y;
    167     uint8_t      m_bgcolor_u;
    168     uint8_t      m_bgcolor_v;
    169     uint8_t      m_bgcolor_a;
    170 
    171181    // last fetched page
    172182    int          m_fetchpage;
    173183    int          m_fetchsubpage;
    174184
     185    // needs to mutable so we can change color character by character.
     186    mutable TTFFont *m_font;
     187
     188    // current character background
     189    mutable uint8_t  m_bgcolor_y;
     190    mutable uint8_t  m_bgcolor_u;
     191    mutable uint8_t  m_bgcolor_v;
     192    mutable uint8_t  m_bgcolor_a;
     193
    175194    // currently displayed page:
    176     int          m_curpage;
    177     int          m_cursubpage;
     195    mutable int  m_curpage;
     196    mutable int  m_cursubpage;
     197    mutable bool m_curpage_showheader;
     198    mutable bool m_curpage_issubtitle;
     199
    178200    int          m_pageinput[3];
    179     bool         m_curpage_showheader;
    180     bool         m_curpage_issubtitle;
    181201
    182202    bool         m_transparent;
    183203    bool         m_revealHidden;
     
    186206
    187207    TeletextMagazine m_magazines[8];
    188208    unsigned char    bitswap[256];
    189 
    190     static const QColor kColorBlack;
    191     static const QColor kColorRed;
    192     static const QColor kColorGreen;
    193     static const QColor kColorYellow;
    194     static const QColor kColorBlue;
    195     static const QColor kColorMagenta;
    196     static const QColor kColorCyan;
    197     static const QColor kColorWhite;
    198     static const int    kTeletextColumns;
    199     static const int    kTeletextRows;
    200209};
    201210
    202211#endif
  • libs/libmythtv/osdtypeteletext.cpp

     
    5050                                 QRect displayrect, float wmult, float hmult)
    5151    : OSDType(name),
    5252      m_displayrect(displayrect),       m_unbiasedrect(0,0,0,0),
    53       m_font(font),                     m_surface(NULL),
    5453      m_box(NULL),
    5554
    5655      m_tt_colspace(m_displayrect.width()  / kTeletextColumns),
    5756      m_tt_rowspace(m_displayrect.height() / kTeletextRows),
    5857
    59       m_bgcolor_y(0),                   m_bgcolor_u(0),
    60       m_bgcolor_v(0),                   m_bgcolor_a(0),
    6158      // last fetched page
    6259      m_fetchpage(0),                   m_fetchsubpage(0),
    63       // currently displayed page:
     60
     61      // current font
     62      m_font(font),
     63
     64      // current character background
     65      m_bgcolor_y(0),                   m_bgcolor_u(0),
     66      m_bgcolor_v(0),                   m_bgcolor_a(0),
     67
     68      // currently displayed page
    6469      m_curpage(0x100),                 m_cursubpage(-1),
    6570      m_curpage_showheader(true),       m_curpage_issubtitle(false),
    6671
     
    115120    m_pageinput[2] = '0';
    116121}
    117122
    118 /** \fn OSDTypeTeletext::CharConversion(char, int)
    119  *  \brief converts the given character to the given language
    120  */
    121 char OSDTypeTeletext::CharConversion(char ch, int lang)
    122 {
    123     int c = 0;
    124     for (int j = 0; j < 14; j++)
    125     {
    126         c = ch & 0x7F;
    127         if (c == lang_chars[0][j])
    128             ch = lang_chars[lang + 1][j];
    129     }
    130     return ch;
    131 }
    132 
    133123/** \fn OSDTypeTeletext::AddPageHeader(int,int,const unsigned char*,int,int,int)
    134124 *  \brief Adds a new page header
    135125 *         (page=0 if none)
     
    298288    }
    299289}
    300290
    301 /** \fn OSDTypeTeletext::PageUpdated(int)
     291/** \fn OSDTypeTeletext::PageUpdated(int,int)
    302292 *  \brief Updates the page, if given pagenumber is the same
    303293 *         as the current shown page
    304294 */
     
    313303    if (subpage != m_cursubpage && m_cursubpage != -1)
    314304        return;
    315305
    316 
    317     if (m_surface != NULL)
     306#if 1
     307#warning TODO PageUpdated() may need to schedule redraw....
     308#else
     309    if (surface != NULL)
    318310    {
    319         m_surface->SetChanged(true);
    320         m_surface->ClearUsed();
    321         DrawPage();
     311        surface->SetChanged(true);
     312        surface->ClearUsed();
     313        DrawPage(surface);
    322314    }
     315#endif
    323316}
    324317
    325318/** \fn OSDTypeTeletext::HeaderUpdated(unsigned char*,int)
     
    340333    if (m_curpage_showheader == false)
    341334        return;
    342335
    343     if (m_surface != NULL)
    344         DrawHeader(page, lang);
     336#if 1
     337#warning TODO HeaderUpdated() may need to schedule redraw....
     338    (void) lang;
     339#else
     340    if (surface != NULL)
     341        DrawHeader(surface, page, lang);
     342#endif
    345343}
    346344
    347345/** \fn OSDTypeTeletext::FindPage(int, int)
     
    351349 *  \param direction find page before or after the given page
    352350 *  \return TeletextPage (NULL if not found)
    353351 */
    354 TeletextPage* OSDTypeTeletext::FindPage(int page, int direction)
     352const TeletextPage *OSDTypeTeletext::FindPage(int page, int direction) const
    355353{
    356     TeletextPage *res = NULL;
    357354    int mag = MAGAZINE(page);
    358355
    359356    if (mag > 8 || mag < 1)
     
    361358
    362359    QMutexLocker lock(&m_magazines[mag - 1].lock);
    363360
    364     std::map<int, TeletextPage>::iterator pageIter;
     361    std::map<int, TeletextPage>::const_iterator pageIter;
    365362    pageIter = m_magazines[mag - 1].pages.find(page);
    366363    if (pageIter == m_magazines[mag - 1].pages.end())
    367364        return NULL;
    368365
    369     res = &pageIter->second;
     366    const TeletextPage *res = &pageIter->second;
    370367    if (direction == -1)
    371368    {
    372369        --pageIter;
    373370        if (pageIter == m_magazines[mag - 1].pages.end())
    374371        {
    375             std::map<int, TeletextPage>::reverse_iterator iter;
     372            std::map<int, TeletextPage>::const_reverse_iterator iter;
    376373            iter = m_magazines[mag - 1].pages.rbegin();
    377374            res = &iter->second;
    378375        }
     
    395392    return res;
    396393}
    397394
    398 /** \fn OSDTypeTeletext::FindSubPage(int, int, int)
     395/** \fn OSDTypeTeletext::FindSubPage(int, int, int) const
    399396 *  \brief Finds the given page
    400397 *
    401398 *  \param page Page number
     
    404401 *         (only if Subpage is not -1)
    405402 *  \return TeletextSubPage (NULL if not found)
    406403 */
    407 TeletextSubPage* OSDTypeTeletext::FindSubPage(int page, int subpage, int direction)
     404const TeletextSubPage *OSDTypeTeletext::FindSubPage(int page, int subpage,
     405                                                    int direction) const
    408406{
    409     TeletextSubPage *res = NULL;
    410407    int mag = MAGAZINE(page);
    411408
    412409    if (mag > 8 || mag < 1)
     
    414411
    415412    QMutexLocker lock(&m_magazines[mag - 1].lock);
    416413
    417     if (subpage == -1)
    418     {
    419         // return the first subpage found
    420         std::map<int, TeletextPage>::iterator pageIter;
    421         pageIter = m_magazines[mag - 1].pages.find(page);
    422         if (pageIter == m_magazines[mag - 1].pages.end())
    423             return NULL;
     414    std::map<int, TeletextPage>::const_iterator pageIter;
     415    pageIter = m_magazines[mag - 1].pages.find(page);
     416    if (pageIter == m_magazines[mag - 1].pages.end())
     417        return NULL;
    424418
    425         TeletextPage *page = &pageIter->second;
    426         std::map<int, TeletextSubPage>::iterator subpageIter;
    427         subpageIter = page->subpages.begin();
    428         if (subpageIter == page->subpages.end())
    429             return NULL;
     419    const TeletextPage *ttpage = &(pageIter->second);
     420    std::map<int, TeletextSubPage>::const_iterator subpageIter =
     421        ttpage->subpages.begin();
    430422
    431         return &subpageIter->second;
    432     }
    433     else
    434     {
    435         // try to find the subpage given
    436         std::map<int, TeletextPage>::iterator pageIter;
    437         pageIter = m_magazines[mag - 1].pages.find(page);
    438         if (pageIter == m_magazines[mag - 1].pages.end())
    439             return NULL;
     423    // try to find the subpage given, or first if subpage == -1
     424    if (subpage != -1)
     425        subpageIter = ttpage->subpages.find(subpage);
    440426
    441         TeletextPage *page = &pageIter->second;
    442         std::map<int, TeletextSubPage>::iterator subpageIter;
    443         subpageIter = page->subpages.find(subpage);
    444         if (subpageIter == page->subpages.end())
    445             return NULL;
     427    if (subpageIter == ttpage->subpages.end())
     428        return NULL;
    446429
    447         res = &subpageIter->second;
    448         if (direction == -1)
    449         {
    450             --subpageIter;
    451             if (subpageIter == page->subpages.end())
    452             {
    453                 std::map<int, TeletextSubPage>::reverse_iterator iter;
    454                 iter = page->subpages.rbegin();
    455                 res = &iter->second;
    456             }
    457             else
    458                 res = &subpageIter->second;
    459         }
     430    if (subpage == -1)
     431        return &(subpageIter->second);
    460432
    461         if (direction == 1)
     433    const TeletextSubPage *res = &(subpageIter->second);
     434    if (direction == -1)
     435    {
     436        --subpageIter;
     437        if (subpageIter == ttpage->subpages.end())
    462438        {
    463             ++subpageIter;
    464             if (subpageIter == page->subpages.end())
    465             {
    466                 subpageIter = page->subpages.begin();
    467                 res = &subpageIter->second;
    468             }
    469             else
    470                 res = &subpageIter->second;
     439            std::map<int, TeletextSubPage>::const_reverse_iterator iter =
     440                ttpage->subpages.rbegin();
     441            res = &(iter->second);
    471442        }
     443        else
     444            res = &(subpageIter->second);
    472445    }
    473446
     447    if (direction == 1)
     448    {
     449        ++subpageIter;
     450        if (subpageIter == ttpage->subpages.end())
     451            subpageIter = ttpage->subpages.begin();
     452
     453        res = &(subpageIter->second);
     454    }
     455
    474456    return res;
    475457}
    476458
     
    677659    PageUpdated(m_curpage, m_cursubpage);
    678660}
    679661
    680 /** \fn OSDTypeTeletext::SetForegroundColor(int)
     662QColor color_tt2qt(int ttcolor)
     663{
     664    QColor color;
     665
     666    switch (ttcolor & ~TTColor::TRANSPARENT)
     667    {
     668        case TTColor::BLACK:   color = OSDTypeTeletext::kColorBlack;   break;
     669        case TTColor::RED:     color = OSDTypeTeletext::kColorRed;     break;
     670        case TTColor::GREEN:   color = OSDTypeTeletext::kColorGreen;   break;
     671        case TTColor::YELLOW:  color = OSDTypeTeletext::kColorYellow;  break;
     672        case TTColor::BLUE:    color = OSDTypeTeletext::kColorBlue;    break;
     673        case TTColor::MAGENTA: color = OSDTypeTeletext::kColorMagenta; break;
     674        case TTColor::CYAN:    color = OSDTypeTeletext::kColorCyan;    break;
     675        case TTColor::WHITE:   color = OSDTypeTeletext::kColorWhite;   break;
     676    }
     677
     678    return color;
     679}
     680
     681/** \fn OSDTypeTeletext::SetForegroundColor(int) const
    681682 *  \brief Set the font color to the given color.
    682683 *
    683684 *   NOTE: TTColor::TRANSPARENT does not do anything!
    684685 *  \sa TTColor
    685686 */
    686 void OSDTypeTeletext::SetForegroundColor(int color)
     687void OSDTypeTeletext::SetForegroundColor(int ttcolor) const
    687688{
    688     switch (color & ~TTColor::TRANSPARENT)
    689     {
    690         case TTColor::BLACK:   m_font->setColor(kColorBlack);   break;
    691         case TTColor::RED:     m_font->setColor(kColorRed);     break;
    692         case TTColor::GREEN:   m_font->setColor(kColorGreen);   break;
    693         case TTColor::YELLOW:  m_font->setColor(kColorYellow);  break;
    694         case TTColor::BLUE:    m_font->setColor(kColorBlue);    break;
    695         case TTColor::MAGENTA: m_font->setColor(kColorMagenta); break;
    696         case TTColor::CYAN:    m_font->setColor(kColorCyan);    break;
    697         case TTColor::WHITE:   m_font->setColor(kColorWhite);   break;
    698     }
    699 
     689    m_font->setColor(color_tt2qt(ttcolor));
    700690    m_font->setShadow(0,0);
    701691    m_font->setOutline(0);
    702692}
    703693
    704 /** \fn OSDTypeTeletext:SetBackgroundColor(int)
     694/** \fn OSDTypeTeletext:SetBackgroundColor(int) const
    705695 *  \brief Set the background color to the given color
    706696 *
    707697 *  \sa TTColor
    708698 */
    709 void OSDTypeTeletext::SetBackgroundColor(int ttcolor)
     699void OSDTypeTeletext::SetBackgroundColor(int ttcolor) const
    710700{
    711     QColor color;
     701    const QColor color = color_tt2qt(ttcolor);
    712702
    713     switch (ttcolor & ~TTColor::TRANSPARENT)
    714     {
    715         case TTColor::BLACK:   color = kColorBlack;   break;
    716         case TTColor::RED:     color = kColorRed;     break;
    717         case TTColor::GREEN:   color = kColorGreen;   break;
    718         case TTColor::YELLOW:  color = kColorYellow;  break;
    719         case TTColor::BLUE:    color = kColorBlue;    break;
    720         case TTColor::MAGENTA: color = kColorMagenta; break;
    721         case TTColor::CYAN:    color = kColorCyan;    break;
    722         case TTColor::WHITE:   color = kColorWhite;   break;
    723     }
     703    const int r = color.red();
     704    const int g = color.green();
     705    const int b = color.blue();
    724706
    725     int r = color.red();
    726     int g = color.green();
    727     int b = color.blue();
     707    const float y = (0.299*r) + (0.587*g) + (0.114*b);
     708    const float u = (0.564*(b - y)); // = -0.169R-0.331G+0.500B
     709    const float v = (0.713*(r - y)); // = 0.500R-0.419G-0.081B
    728710
    729     float y = (0.299*r) + (0.587*g) + (0.114*b);
    730     float u = (0.564*(b - y)); // = -0.169R-0.331G+0.500B
    731     float v = (0.713*(r - y)); // = 0.500R-0.419G-0.081B
    732 
    733711    m_bgcolor_y = (uint8_t)(y);
    734712    m_bgcolor_u = (uint8_t)(127 + u);
    735713    m_bgcolor_v = (uint8_t)(127 + v);
     714
    736715    m_bgcolor_a = (ttcolor & TTColor::TRANSPARENT) ? 0x00 : 0xff;
    737716}
    738717
    739 /** \fn OSDTypeTeletext::DrawBackground(int, int)
    740  *  \brief draws background in the color set in setBackgroundColor
     718/** \fn OSDTypeTeletext::DrawBackground(OSDSurface*,int,int) const
     719 *  \brief draws background in the color set in SetBackgroundColor().
    741720 *
    742721 *  \param x X position (40 cols)
    743722 *  \param y Y position (25 rows)
    744723 */
    745 void OSDTypeTeletext::DrawBackground(int x, int y)
     724void OSDTypeTeletext::DrawBackground(OSDSurface *surface, int x, int y) const
    746725{
    747726    x *= m_tt_colspace;
    748727    x += m_displayrect.left();
     
    750729    y *= m_tt_rowspace;
    751730    y += m_displayrect.top();
    752731
    753     DrawRect(x, y, m_tt_colspace, m_tt_rowspace);
     732    DrawRect(surface, QRect(x, y, m_tt_colspace, m_tt_rowspace));
    754733}
    755734
    756 /** \fn OSDTypeteletext::drawRect(int, int, int, int)
    757  *  \brief draws a Rectangle at position x and y (width dx, height dy)
    758  *         with the color set in setBackgroundColor
    759  *
    760  *  \param x X position at the screen
    761  *  \param y Y position at the screen
    762  *  \param dx width
    763  *  \param dy height
     735/** \fn OSDTypeteletext::DrawRect(OSDSurface*,const QRect) const
     736 *  \brief Draws a Rectangle with the color set in SetBackgroundColor().
    764737 */
    765 void OSDTypeTeletext::DrawRect(int x, int y, int dx, int dy)
     738void OSDTypeTeletext::DrawRect(OSDSurface *surface, const QRect rect) const
    766739{
    767     QRect all(x, y, dx, dy);
    768     m_surface->AddRect(all);
     740    QRect tmp = rect;
     741    surface->AddRect(tmp);
    769742
    770     int luma_stride = m_surface->width;
    771     int chroma_stride = m_surface->width >> 1;
    772     int ye = y + dy;
     743    const int luma_stride   = surface->width;
     744    const int chroma_stride = surface->width >> 1;
     745    const int y  = rect.top(),    x  = rect.left();
     746    const int dy = rect.height(), dx = rect.width();
     747    const int ye = y + dy;
    773748
    774     unsigned char *buf_y = m_surface->y + (luma_stride * y) + x;
    775     unsigned char *buf_u = m_surface->u + (chroma_stride * (y>>1)) + (x>>1);
    776     unsigned char *buf_v = m_surface->v + (chroma_stride * (y>>1)) + (x>>1);
    777     unsigned char *buf_a = m_surface->alpha + (luma_stride * y) + x;
     749    unsigned char *buf_y = surface->y + (luma_stride * y) + x;
     750    unsigned char *buf_u = surface->u + (chroma_stride * (y>>1)) + (x>>1);
     751    unsigned char *buf_v = surface->v + (chroma_stride * (y>>1)) + (x>>1);
     752    unsigned char *buf_a = surface->alpha + (luma_stride * y) + x;
    778753
    779     for (; y<ye; ++y)
     754    for (int j = y; j < ye; j++)
    780755    {
    781         for (int i=0; i<dx; ++i)
     756        for (int i = 0; i < dx; i++)
    782757        {
    783758            buf_y[i] = m_bgcolor_y;
    784759            buf_a[i] = m_bgcolor_a;
    785760        }
    786761
    787         if ((y & 1) == 0)
     762        if (!(y & 1))
    788763        {
    789             for (int i=0; i<dx; ++i)
     764            for (int k = 0; k < dx; k++)
    790765            {
    791                 buf_u[i>>1] = m_bgcolor_u;
    792                 buf_v[i>>1] = m_bgcolor_v;
     766                buf_u[k>>1] = m_bgcolor_u;
     767                buf_v[k>>1] = m_bgcolor_v;
    793768            }
    794769
    795770            buf_u += chroma_stride;
     
    801776    }
    802777}
    803778
    804 /** \fn OSDTypeTeletext::DrawCharacter(int, int, QChar, int)
     779/** \fn OSDTypeTeletext::DrawCharacter(OSDSurface*,int,int,QChar,int) const
    805780 *  \brief Draws a character at posistion x, y
    806781 *
    807782 *  \param x X position (40 cols)
     
    809784 *  \param ch Character
    810785 *  \param doubleheight if different to 0, draw doubleheighted character
    811786 */
    812 void OSDTypeTeletext::DrawCharacter(int x, int y, QChar ch, int doubleheight)
     787void OSDTypeTeletext::DrawCharacter(OSDSurface *surface,
     788                                    int x, int y,
     789                                    QChar ch, int doubleheight) const
    813790{
    814791    if (!m_font)
    815792        return;
     
    822799    y *= m_tt_rowspace;
    823800    y += m_displayrect.top();
    824801
    825     m_font->DrawString(m_surface, x, y, line,
    826                        m_surface->width, m_surface->height,
     802    m_font->DrawString(surface, x, y, line,
     803                       surface->width, surface->height,
    827804                       255, doubleheight);
    828805}
    829806
     
    833810 *  \param x X position (40 cols)
    834811 *  \param y Y position (25 rows)
    835812 *  \param code Code
    836  *  \param doubleheight if different to 0, draw doubleheighted mosaic)
     813 *  \param doubleheight if different to 0, draw doubleheighted mosaic) const
    837814 */
    838 void OSDTypeTeletext::DrawMosaic(int x, int y, int code, int doubleheight)
     815void OSDTypeTeletext::DrawMosaic(OSDSurface *surface, int x, int y,
     816                                 int code, int doubleheight) const
    839817{
    840     (void)x;
    841     (void)y;
    842     (void)code;
    843 
    844818    x *= m_tt_colspace;
    845819    x += m_displayrect.left();
    846820
    847821    y *= m_tt_rowspace;
    848822    y += m_displayrect.top();
    849823
    850     int dx = (int)round(m_tt_colspace / 2)+1;
    851     int dy = (int)round(m_tt_rowspace / 3)+1;
     824    int dx = (int)round(m_tt_colspace / 2) + 1;
     825    int dy = (int)round(m_tt_rowspace / 3) + 1;
     826    dy = (doubleheight) ? (2 * dy) : dy;
    852827
    853     if (doubleheight != 0)
    854         dy *= 2;
     828    if (code & 0x10)
     829        DrawRect(surface, QRect(x,      y + 2*dy, dx, dy));
     830    if (code & 0x40)
     831        DrawRect(surface, QRect(x + dx, y + 2*dy, dx, dy));
     832    if (code & 0x01)
     833        DrawRect(surface, QRect(x,      y,        dx, dy));
     834    if (code & 0x02)
     835        DrawRect(surface, QRect(x + dx, y,        dx, dy));
     836    if (code & 0x04)
     837        DrawRect(surface, QRect(x,      y + dy,   dx, dy));
     838    if (code & 0x08)
     839        DrawRect(surface, QRect(x + dx, y + dy,   dx, dy));
     840}
    855841
    856     if (code & 0x10) DrawRect(x,      y + 2*dy, dx, dy);
    857     if (code & 0x40) DrawRect(x + dx, y + 2*dy, dx, dy);
    858     if (code & 0x01) DrawRect(x,      y,        dx, dy);
    859     if (code & 0x02) DrawRect(x + dx, y,        dx, dy);
    860     if (code & 0x04) DrawRect(x,      y + dy,   dx, dy);
    861     if (code & 0x08) DrawRect(x + dx, y + dy,   dx, dy);
     842/** \fn cvt_char(char,int)
     843 *  \brief converts the given character to the given language
     844 */
     845static char cvt_char(char ch, int lang)
     846{
     847    int c = 0;
     848    for (int j = 0; j < 14; j++)
     849    {
     850        c = ch & 0x7F;
     851        if (c == lang_chars[0][j])
     852            ch = lang_chars[lang + 1][j];
     853    }
     854    return ch;
    862855}
    863856
    864 void OSDTypeTeletext::DrawLine(const unsigned char* page, uint row, int lang)
     857void OSDTypeTeletext::DrawLine(OSDSurface *surface, const unsigned char *page,
     858                               uint row, int lang) const
    865859{
    866860    bool mosaic;
    867861    bool conceal;
     
    903897    if (row == 1)
    904898    {
    905899        for (uint x = 0; x < 8; x++)
    906             DrawBackground(x, 1);
     900            DrawBackground(surface, x, 1);
    907901    }
    908902
    909903    for (uint x = (row == 1 ? 8 : 0); x < (uint)kTeletextColumns; ++x)
     
    10061000            if (m_transparent)
    10071001                SetBackgroundColor(TTColor::TRANSPARENT);
    10081002
    1009             DrawBackground(x, row);
     1003            DrawBackground(surface, x, row);
    10101004            if (doubleheight && row < (uint)kTeletextRows)
    1011                 DrawBackground(x, row + 1);
     1005                DrawBackground(surface, x, row + 1);
    10121006
    10131007            if ((mosaic) && (ch < 0x40 || ch > 0x5F))
    10141008            {
    10151009                SetBackgroundColor(newfgcolor);
    1016                 DrawMosaic(x, row, ch, doubleheight);
     1010                DrawMosaic(surface, x, row, ch, doubleheight);
    10171011            }
    10181012            else
    10191013            {
    1020                 char c2 = CharConversion(ch, lang);
     1014                char c2 = cvt_char(ch, lang);
    10211015                bool dh = doubleheight && row < (uint)kTeletextRows;
    10221016                int  rw = (dh) ? row + 1 : row;
    1023                 DrawCharacter(x, rw, c2, dh);
     1017                DrawCharacter(surface, x, rw, c2, dh);
    10241018            }
    10251019        }
    10261020    }
    10271021}
    10281022
    1029 void OSDTypeTeletext::DrawHeader(const unsigned char* page, int lang)
     1023void OSDTypeTeletext::DrawHeader(OSDSurface *surface,
     1024                                 const unsigned char* page, int lang) const
    10301025{
    10311026    if (!m_displaying)
    10321027        return;
    10331028
    10341029    if (page != NULL)
    1035         DrawLine(page, 1, lang);
    1036    
    1037     StatusUpdated();
     1030        DrawLine(surface, page, 1, lang);
     1031
     1032    DrawStatus(surface);
    10381033}
    10391034
    1040 void OSDTypeTeletext::DrawPage(void)
     1035void OSDTypeTeletext::DrawPage(OSDSurface *surface) const
    10411036{
    10421037    if (!m_displaying)
    10431038        return;
    10441039
    1045     TeletextSubPage *ttpage = FindSubPage(m_curpage, m_cursubpage);
     1040    const TeletextSubPage *ttpage = FindSubPage(m_curpage, m_cursubpage);
    10461041
    1047     if (ttpage == NULL)
     1042    if (!ttpage)
    10481043    {
    1049         DrawHeader(NULL,0);
     1044        DrawHeader(surface, NULL, 0);
    10501045        return;
    10511046    }
    10521047
    10531048    m_cursubpage = ttpage->subpagenum;
    10541049
    10551050    int a = 0;
    1056     if ((ttpage->subtitle) || (ttpage->flags &
    1057             (TP_SUPPRESS_HEADER + TP_NEWSFLASH + TP_SUBTITLE)))
     1051    if ((ttpage->subtitle) ||
     1052        (ttpage->flags & (TP_SUPPRESS_HEADER | TP_NEWSFLASH | TP_SUBTITLE)))
    10581053    {
    10591054        a = 1;
    10601055        m_curpage_showheader = false;
     
    10641059    {
    10651060        m_curpage_issubtitle = false;
    10661061        m_curpage_showheader = true;
    1067         DrawHeader(ttpage->data[0], ttpage->lang);
     1062        DrawHeader(surface, ttpage->data[0], ttpage->lang);
    10681063    }
    10691064
    1070     for (int y = kTeletextRows-a; y >= 2; y--)
    1071         DrawLine(ttpage->data[y-1], y, ttpage->lang);
     1065    for (int y = kTeletextRows - a; y >= 2; y--)
     1066        DrawLine(surface, ttpage->data[y-1], y, ttpage->lang);
    10721067}
    10731068
    10741069void OSDTypeTeletext::Reinit(float wmult, float hmult)
     
    10781073    m_tt_rowspace = m_displayrect.height() / kTeletextRows;
    10791074}
    10801075
    1081 void OSDTypeTeletext::Draw(OSDSurface *surface, int fade, int maxfade,
    1082                            int xoff, int yoff)
     1076void OSDTypeTeletext::Draw(OSDSurface *surface,
     1077                           int /*fade*/, int /*maxfade*/,
     1078                           int /*xoff*/, int /*yoff*/)
    10831079{
    1084     (void)surface;
    1085     (void)fade;
    1086     (void)maxfade;
    1087     (void)xoff;
    1088     (void)yoff;
    1089 
    1090     m_surface = surface;
    1091     DrawPage();
     1080    DrawPage(surface);
    10921081}
    10931082
    1094 void OSDTypeTeletext::StatusUpdated(void)
     1083void OSDTypeTeletext::DrawStatus(OSDSurface *surface) const
    10951084{
    10961085    SetForegroundColor(TTColor::WHITE);
    10971086    SetBackgroundColor(TTColor::BLACK);
    10981087
    10991088    if (!m_transparent)
    11001089        for (int i = 0; i < 40; ++i)
    1101             DrawBackground(i, 0);
     1090            DrawBackground(surface, i, 0);
    11021091
    1103     DrawCharacter(1, 0, 'P', 0);
    1104     DrawCharacter(2, 0, m_pageinput[0], 0);
    1105     DrawCharacter(3, 0, m_pageinput[1], 0);
    1106     DrawCharacter(4, 0, m_pageinput[2], 0);
     1092    DrawCharacter(surface, 1, 0, 'P', 0);
     1093    DrawCharacter(surface, 2, 0, m_pageinput[0], 0);
     1094    DrawCharacter(surface, 3, 0, m_pageinput[1], 0);
     1095    DrawCharacter(surface, 4, 0, m_pageinput[2], 0);
    11071096
    1108     TeletextSubPage *ttpage = FindSubPage(m_curpage, m_cursubpage);
     1097    const TeletextSubPage *ttpage = FindSubPage(m_curpage, m_cursubpage);
    11091098
    11101099    if (!ttpage)
    11111100    {
     
    11141103
    11151104        if (!m_transparent)
    11161105            for (int i = 7; i < 40; i++)
    1117                 DrawBackground(i, 0);
     1106                DrawBackground(surface, i, 0);
    11181107
    11191108        char *str = "Page Not Available";
    11201109        for (unsigned int i = 0; i < strlen(str); ++i)
    1121             DrawCharacter(i+10, 0, str[i], 0);
     1110            DrawCharacter(surface, i+10, 0, str[i], 0);
    11221111
    11231112        return;
    11241113    }
     
    11261115    // get list of available sub pages
    11271116    QString str = "";
    11281117    int count = 1, selected = 0;
    1129     TeletextPage *page = FindPage(m_curpage);
     1118    const TeletextPage *page = FindPage(m_curpage);
    11301119    if (page)
    11311120    {
    1132         std::map<int, TeletextSubPage>::iterator subpageIter;
     1121        std::map<int, TeletextSubPage>::const_iterator subpageIter;
    11331122        subpageIter = page->subpages.begin();
    11341123        while (subpageIter != page->subpages.end())
    11351124        {
    1136             TeletextSubPage *subpage = &subpageIter->second;
     1125            const TeletextSubPage *subpage = &subpageIter->second;
    11371126
    11381127            if (subpage->subpagenum == m_cursubpage)
    11391128            {
     
    11801169        else
    11811170            SetBackgroundColor(TTColor::BLACK);
    11821171
    1183         DrawBackground(x * 3 + 7, 0);
     1172        DrawBackground(surface, x * 3 + 7, 0);
    11841173
    11851174        if (str[x * 3] == '*')
    11861175        {
     
    11881177            SetBackgroundColor(TTColor::RED);
    11891178        }
    11901179
    1191         DrawBackground(x * 3 + 8, 0);
    1192         DrawBackground(x * 3 + 9, 0);
     1180        DrawBackground(surface, x * 3 + 8, 0);
     1181        DrawBackground(surface, x * 3 + 9, 0);
    11931182
    1194         DrawCharacter(x * 3 + 7, 0, str[x * 3], 0);
    1195         DrawCharacter(x * 3 + 8, 0, str[x * 3 + 1], 0);
    1196         DrawCharacter(x * 3 + 9, 0, str[x * 3 + 2], 0);
     1183        DrawCharacter(surface, x * 3 + 7, 0, str[x * 3], 0);
     1184        DrawCharacter(surface, x * 3 + 8, 0, str[x * 3 + 1], 0);
     1185        DrawCharacter(surface, x * 3 + 9, 0, str[x * 3 + 2], 0);
    11971186    }
    11981187}
    11991188