Ticket #9772: cc608_colors_v1.patch
File cc608_colors_v1.patch, 9.4 KB (added by , 13 years ago) |
---|
-
mythtv/libs/libmythtv/cc608decoder.cpp
diff --git a/mythtv/libs/libmythtv/cc608decoder.cpp b/mythtv/libs/libmythtv/cc608decoder.cpp index 9e21e1f..f9e24cf 100644
a b void CC608Decoder::FormatCCField(int tc, int field, int data) 197 197 ccbuf[mode] += CharCC(b1); 198 198 len++; 199 199 col[mode]++; 200 if (b1 == '%') // specially encode the % character as "%%" 201 { 202 ccbuf[mode] += CharCC(b1); 203 len++; 204 } 200 205 if (b2 & 0x60) 201 206 { 202 207 ccbuf[mode] += CharCC(b2); 203 208 len++; 204 209 col[mode]++; 210 if (b2 == '%') // specially encode the % character as "%%" 211 { 212 ccbuf[mode] += CharCC(b2); 213 len++; 214 } 205 215 } 206 216 } 207 217 } … … void CC608Decoder::FormatCCField(int tc, int field, int data) 260 270 261 271 // row, indent settings are not final 262 272 // until text code arrives 273 if (b2 & 0x10) // indent with or without underline 274 { 275 if (b2 & 0x1) 276 { 277 VERBOSE(VB_VBI, 278 QString("cc608 preamble indent with underline, b2=%1") 279 .arg(b2, 2, 16)); 280 // XXX- Need to insert an underline code when the 281 // next real character arrives. 282 } 283 } 284 else // color with or without underline 285 { 286 if (b2 & 0xf) 287 { 288 VERBOSE(VB_VBI, 289 QString("cc608 preamble color change, b2=%1") 290 .arg(b2, 2, 16)); 291 // XXX- Need to insert color/underline/italics 292 // codes when the next real character arrives. 293 } 294 } 263 295 } 264 296 else 265 297 { … … void CC608Decoder::FormatCCField(int tc, int field, int data) 278 310 switch (b2 & 0x70) 279 311 { 280 312 case 0x20: //midrow attribute change 281 // TODO: we _do_ want colors, is that an attribute? 313 VERBOSE(VB_VBI, 314 QString("cc608 mid-row color change, b2=%1") 315 .arg(b2, 2, 16)); 316 // Encode as "%a" through "%p" for the 16 317 // possible values of b2. 282 318 ccbuf[mode] += ' '; 319 // Insert the space character before the 320 // control sequence, otherwise the space 321 // character will be lost due to the 322 // text.trimmed() operation in the 323 // MythUIText constructor, combined with 324 // the left-justification of captions. 325 ccbuf[mode] += '%'; 326 ccbuf[mode] += 'a' + (b2 & 0xf); 283 327 len = ccbuf[mode].length(); 284 328 col[mode]++; 285 329 break; -
mythtv/libs/libmythtv/subtitlescreen.cpp
diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp index 7c949f8..37482ce 100644
a b void SubtitleScreen::DisplayTextSubtitles(void) 339 339 changed = true; 340 340 int height = (m_safeArea.height() * m_textFontZoom) / 1800; 341 341 gTextSubFont->GetFace()->setPixelSize(height); 342 gTextSubFont->GetFace()->setItalic(false); 343 gTextSubFont->GetFace()->setUnderline(false); 342 344 gTextSubFont->SetColor(Qt::white); 343 345 } 344 346 } … … void SubtitleScreen::DisplayRawTextSubtitles(void) 424 426 { 425 427 int height = (m_safeArea.height() * m_textFontZoom) / 1800; 426 428 gTextSubFont->GetFace()->setPixelSize(height); 429 gTextSubFont->GetFace()->setItalic(false); 430 gTextSubFont->GetFace()->setUnderline(false); 427 431 gTextSubFont->SetColor(Qt::white); 428 432 } 429 433 } … … void SubtitleScreen::DisplayDVDButton(AVSubtitle* dvdButton, QRect &buttonPos) 576 580 AddScaledImage(fg_image, button); 577 581 } 578 582 583 // Extract everything from the cc buffer up until the next text format 584 // control sequence. Return that substring, and remove it from the cc 585 // buffer. The "%%" escape sequence is replaced with the original 586 // "%". Bogus control sequences are left unchanged. If the buffer 587 // starts with a valid control sequence, the output parameters are 588 // corresondingly updated (and the control sequence is stripped). 589 static QString GetNextCC608Chunk(CC608Text *cc, int &color, 590 bool &isItalic, bool &isUnderline) 591 { 592 QString result; 593 594 if (cc->teletextmode) 595 { 596 result = cc->text; 597 cc->text = QString::null; 598 return result; 599 } 600 601 // Handle an initial control sequence. 602 if (cc->text.length() >= 2 && cc->text[0] == '%' && 603 cc->text[1] >= 'a' && cc->text[1] < 'a' + 16) 604 { 605 int op = cc->text[1].unicode() - 'a'; 606 isUnderline = (op & 0x1); 607 if (op < 14) 608 { 609 isItalic = false; 610 color = op >> 1; 611 } 612 else 613 isItalic = true; // leave the color unchanged 614 cc->text = cc->text.mid(2); 615 } 616 617 // Copy the string into the result, up to the next control 618 // sequence. Convert any "%%" into "%". 619 int nextControl = cc->text.indexOf(QRegExp("%[a-p]")); 620 result = cc->text.left(nextControl).replace("%%", "%"); 621 cc->text = (nextControl < 0 ? QString::null : cc->text.mid(nextControl)); 622 623 return result; 624 } 625 579 626 void SubtitleScreen::DisplayCC608Subtitles(void) 580 627 { 581 628 static const QColor clr[8] = 582 629 { 583 Qt::white, Qt:: red, Qt::green, Qt::yellow,584 Qt:: blue, Qt::magenta, Qt::cyan,Qt::white,630 Qt::white, Qt::green, Qt::blue, Qt::cyan, 631 Qt::red, Qt::yellow, Qt::magenta, Qt::white, 585 632 }; 586 633 587 634 if (!InitialiseFont(m_fontStretch) || !m_608reader) … … void SubtitleScreen::DisplayCC608Subtitles(void) 621 668 int xscale = teletextmode ? 40 : 36; 622 669 int yscale = teletextmode ? 25 : 17; 623 670 gTextSubFont->GetFace()->setPixelSize(m_safeArea.height() / (yscale * 1.2)); 624 QFontMetrics font(*(gTextSubFont->GetFace()));625 671 QBrush bgfill = QBrush(QColor(0, 0, 0), Qt::SolidPattern); 626 int height = font.height() * (1 + PAD_HEIGHT);627 int pad_width = font.maxWidth() * PAD_WIDTH;628 672 629 673 for (; i != textlist->buffers.end(); i++) 630 674 { 631 675 CC608Text *cc = (*i); 676 int color = 0; 677 bool isItalic = false, isUnderline = false; 678 bool first = true; 679 int x = 0, width = 0; 632 680 633 if (cc && (cc->text != QString::null))681 for (int chunk = 0; cc && (cc->text != QString::null); first = false, chunk++) 634 682 { 635 int width = font.width(cc->text) + pad_width; 636 int x = teletextmode ? cc->y : (cc->x + 3); 683 QString captionText = GetNextCC608Chunk(cc, color, isItalic, isUnderline); 684 gTextSubFont->GetFace()->setItalic(isItalic); 685 gTextSubFont->GetFace()->setUnderline(isUnderline); 686 gTextSubFont->SetColor(clr[min(max(0, color), 7)]); 687 QFontMetrics font(*(gTextSubFont->GetFace())); 688 // XXX- could there be different heights across the same line? 689 int height = font.height() * (1 + PAD_HEIGHT); 690 if (first) 691 { 692 x = teletextmode ? cc->y : (cc->x + 3); 693 x = (int)(((float)x / (float)xscale) * (float)m_safeArea.width()); 694 } 695 else 696 { 697 x += width; // bump x by the previous width 698 } 699 int pad_width = font.maxWidth() * PAD_WIDTH; 700 width = font.width(captionText) + pad_width; 637 701 int y = teletextmode ? cc->x : cc->y; 638 x = (int)(((float)x / (float)xscale) * (float)m_safeArea.width());639 702 y = (int)(((float)y / (float)yscale) * (float)m_safeArea.height()); 640 703 QRect rect(x, y, width, height); 641 704 … … void SubtitleScreen::DisplayCC608Subtitles(void) 648 711 shape->SetArea(MythRect(bgrect)); 649 712 } 650 713 651 gTextSubFont->SetColor(clr[min(max(0, cc->color), 7)]);652 714 MythUIText *text = new MythUIText( 653 c c->text, *gTextSubFont, rect, rect, (MythUIType*)this,654 QString("cc608txt%1%2%3 ").arg(cc->x).arg(cc->y).arg(width));715 captionText, *gTextSubFont, rect, rect, (MythUIType*)this, 716 QString("cc608txt%1%2%3%4").arg(cc->x).arg(cc->y).arg(width).arg(chunk)); 655 717 if (text) 656 718 text->SetJustification(Qt::AlignLeft); 657 719 m_refreshArea = true; 658 VERBOSE(VB_VBI, QString("x %1 y %2 String: '%3'") 659 .arg(cc->x).arg(cc->y).arg(cc->text)); 720 VERBOSE(VB_VBI, QString("x %1 y %2 uline=%4 ital=%5 color=%6 coord=%7,%8 String: '%3'") 721 .arg(cc->x).arg(cc->y).arg(captionText) 722 .arg(isUnderline).arg(isItalic).arg(color).arg(x).arg(y)); 660 723 } 661 724 } 662 725 textlist->lock.unlock();