Ticket #9772: cc608_colors_v5.patch
File cc608_colors_v5.patch, 14.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..9649c87 100644
a b CC608Decoder::CC608Decoder(CC608Input *ccr) 43 43 memset(lastrow, 0, sizeof(lastrow)); 44 44 memset(newrow, 0, sizeof(newrow)); 45 45 memset(newcol, 0, sizeof(newcol)); 46 memset(newattr, 0, sizeof(newattr)); 46 47 memset(timecode, 0, sizeof(timecode)); 47 48 memset(row, 0, sizeof(row)); 48 49 memset(col, 0, sizeof(col)); … … void CC608Decoder::FormatCCField(int tc, int field, int data) 254 255 newrow[mode] = lastrow[mode] + 1; 255 256 256 257 if (b2 & 0x10) //row contains indent flag 258 { 257 259 newcol[mode] = (b2 & 0x0E) << 1; 260 // Encode as 0x7020 or 0x7021 depending on the 261 // underline flag. 262 newattr[mode] = (b2 & 0x1) + 0x20; 263 LOG(VB_VBI, LOG_INFO, 264 QString("cc608 preamble indent, b2=%1") 265 .arg(b2, 2, 16)); 266 } 258 267 else 268 { 259 269 newcol[mode] = 0; 270 newattr[mode] = (b2 & 0xf) + 0x10; 271 // Encode as 0x7010 through 0x702f for the 16 possible 272 // values of b2. 273 LOG(VB_VBI, LOG_INFO, 274 QString("cc608 preamble color change, b2=%1") 275 .arg(b2, 2, 16)); 276 } 260 277 261 // row, indent settings are not final278 // row, indent, attribute settings are not final 262 279 // until text code arrives 263 280 } 264 281 else … … void CC608Decoder::FormatCCField(int tc, int field, int data) 278 295 switch (b2 & 0x70) 279 296 { 280 297 case 0x20: //midrow attribute change 281 // TODO: we _do_ want colors, is that an attribute? 282 ccbuf[mode] += ' '; 298 LOG(VB_VBI, LOG_INFO, 299 QString("cc608 mid-row color change, b2=%1") 300 .arg(b2, 2, 16)); 301 // Encode as 0x7000 through 0x700f for the 302 // 16 possible values of b2. 303 ccbuf[mode] += QChar(0x7000 + (b2 & 0xf)); 283 304 len = ccbuf[mode].length(); 284 305 col[mode]++; 285 306 break; … … void CC608Decoder::FormatCCField(int tc, int field, int data) 412 433 { 413 434 newrow[mode] = 1; 414 435 newcol[mode] = 0; 436 newattr[mode] = 0; 415 437 } 416 438 style[mode] = CC_STYLE_ROLLUP; 417 439 break; … … void CC608Decoder::FormatCCField(int tc, int field, int data) 474 496 // TXT starts at row 1 475 497 newrow[mode] = 1; 476 498 newcol[mode] = 0; 499 newattr[mode] = 0; 477 500 style[mode] = CC_STYLE_ROLLUP; 478 501 break; 479 502 … … void CC608Decoder::BufferCC(int mode, int len, int clr) 651 674 int i = 0; 652 675 while (i < dispbuf.length()) { 653 676 QChar cp = dispbuf.at(i); 654 switch (cp.unicode()) 677 int cpu = cp.unicode(); 678 switch (cpu) 655 679 { 656 680 case 0x2120 : vbuf += "(SM)"; break; 657 681 case 0x2122 : vbuf += "(TM)"; break; … … void CC608Decoder::BufferCC(int mode, int len, int clr) 665 689 case 0x2588 : vbuf += "[]"; break; 666 690 case 0x266A : vbuf += "o/~"; break; 667 691 case '\b' : vbuf += "\\b"; break; 668 default : vbuf += QString(cp.toLatin1()); 692 default : 693 if (cpu >= 0x7000 && cpu < 0x7000 + 0x30) 694 vbuf += QString("[%1]").arg(cpu - 0x7000, 2, 16); 695 else vbuf += QString(cp.toLatin1()); 669 696 } 670 697 i++; 671 698 } … … int CC608Decoder::NewRowCC(int mode, int len) 771 798 lastrow[mode] = newrow[mode]; 772 799 newrow[mode] = 0; 773 800 774 for (int x = 0; x < newcol[mode]; x++) 801 int limit = (newattr[mode] ? newcol[mode] - 1 : newcol[mode]); 802 for (int x = 0; x < limit; x++) 775 803 { 776 804 ccbuf[mode] += ' '; 777 805 len++; 778 806 col[mode]++; 779 807 } 808 if (newattr[mode]) 809 { 810 ccbuf[mode] += QChar(newattr[mode] + 0x7000); 811 len++; 812 col[mode]++; 813 } 780 814 newcol[mode] = 0; 815 newattr[mode] = 0; 781 816 782 817 return len; 783 818 } -
mythtv/libs/libmythtv/cc608decoder.h
diff --git a/mythtv/libs/libmythtv/cc608decoder.h b/mythtv/libs/libmythtv/cc608decoder.h index 1463144..b87bbf5 100644
a b class CC608Decoder 98 98 int lastrow[8]; 99 99 int newrow[8]; 100 100 int newcol[8]; 101 int newattr[8]; // color+italic+underline 101 102 int timecode[8]; 102 103 int row[8]; 103 104 int col[8]; -
mythtv/libs/libmythtv/cc608reader.cpp
diff --git a/mythtv/libs/libmythtv/cc608reader.cpp b/mythtv/libs/libmythtv/cc608reader.cpp index f430c65..f5cc1c5 100644
a b CC608Buffer* CC608Reader::GetOutputText(bool &changed) 74 74 inpos += sizeof(st); 75 75 76 76 CC608Text *cc = new CC608Text(QString((const char*) inpos), 77 st.row, st.col, st.fg,true);77 st.row, st.col, true); 78 78 m_outputBuffers.lock.lock(); 79 79 m_outputBuffers.buffers.push_back(cc); 80 80 m_outputBuffers.lock.unlock(); … … void CC608Reader::Update(unsigned char *inpos) 188 188 else 189 189 m_outputText = QString::fromUtf8((const char *)inpos, -1); 190 190 tmpcc = new CC608Text(m_outputText, m_outputCol, m_outputRow, 191 0,false);191 false); 192 192 ccbuf->push_back(tmpcc); 193 193 #if 0 194 194 if (ccbuf->size() > 4) -
mythtv/libs/libmythtv/cc608reader.h
diff --git a/mythtv/libs/libmythtv/cc608reader.h b/mythtv/libs/libmythtv/cc608reader.h index 5e020db..96a4507 100644
a b 14 14 class CC608Text 15 15 { 16 16 public: 17 CC608Text(QString T, int X, int Y, int C, intTT)18 : text(T), x(X), y(Y), color(C),teletextmode(TT) {}17 CC608Text(QString T, int X, int Y, int TT) 18 : text(T), x(X), y(Y), teletextmode(TT) {} 19 19 QString text; 20 20 int x; 21 21 int y; 22 int color;23 22 bool teletextmode; 24 23 }; 25 24 -
mythtv/libs/libmythtv/subtitlescreen.cpp
diff --git a/mythtv/libs/libmythtv/subtitlescreen.cpp b/mythtv/libs/libmythtv/subtitlescreen.cpp index 7c949f8..05804dc 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(bg_image, rect); 577 581 } 578 582 583 // Extract everything from the text buffer up until the next format 584 // control character. Return that substring, and remove it from the 585 // input string. Bogus control characters are left unchanged. If the 586 // buffer starts with a valid control character, the output parameters 587 // are corresondingly updated (and the control character is stripped). 588 static QString GetNextCC608Chunk(QString &text, bool teletextmode, 589 int &color, bool &isItalic, bool &isUnderline, 590 bool &showedNonControl) 591 { 592 QString result; 593 QString orig(text); 594 595 if (teletextmode) 596 { 597 result = text; 598 text = QString::null; 599 showedNonControl = true; 600 return result; 601 } 602 603 // Handle an initial control sequence. 604 if (text.length() >= 1 && text[0] >= 0x7000) 605 { 606 int op = text[0].unicode() - 0x7000; 607 isUnderline = (op & 0x1); 608 switch (op & ~1) 609 { 610 case 0x0e: 611 // color unchanged 612 isItalic = true; 613 break; 614 case 0x1e: 615 color = op >> 1; 616 isItalic = true; 617 break; 618 case 0x20: 619 // color unchanged 620 // italics unchanged 621 break; 622 default: 623 color = (op & 0xf) >> 1; 624 isItalic = false; 625 break; 626 } 627 text = text.mid(1); 628 } 629 630 // Copy the string into the result, up to the next control 631 // character. 632 int nextControl = text.indexOf(QRegExp("[\\x7000-\\x7fff]")); 633 if (nextControl < 0) 634 { 635 result = text; 636 text = QString::null; 637 showedNonControl = true; 638 } 639 else 640 { 641 result = text.left(nextControl); 642 // Print the space character before handling the next control 643 // character, otherwise the space character will be lost due 644 // to the text.trimmed() operation in the MythUIText 645 // constructor, combined with the left-justification of 646 // captions. 647 if (text[nextControl] < (0x7000 + 0x10)) 648 result += " "; 649 text = text.mid(nextControl); 650 if (nextControl > 0) 651 showedNonControl = true; 652 } 653 654 return result; 655 } 656 579 657 void SubtitleScreen::DisplayCC608Subtitles(void) 580 658 { 581 659 static const QColor clr[8] = 582 660 { 583 Qt::white, Qt:: red, Qt::green, Qt::yellow,584 Qt:: blue, Qt::magenta, Qt::cyan,Qt::white,661 Qt::white, Qt::green, Qt::blue, Qt::cyan, 662 Qt::red, Qt::yellow, Qt::magenta, Qt::white, 585 663 }; 586 664 587 665 if (!InitialiseFont(m_fontStretch) || !m_608reader) … … void SubtitleScreen::DisplayCC608Subtitles(void) 621 699 int xscale = teletextmode ? 40 : 36; 622 700 int yscale = teletextmode ? 25 : 17; 623 701 gTextSubFont->GetFace()->setPixelSize(m_safeArea.height() / (yscale * 1.2)); 624 QFontMetrics font(*(gTextSubFont->GetFace()));625 702 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 703 629 704 for (; i != textlist->buffers.end(); i++) 630 705 { 631 706 CC608Text *cc = (*i); 707 int color = 0; 708 bool isItalic = false, isUnderline = false; 709 bool first = true; 710 bool showedNonControl = false; 711 int x = 0, width = 0; 712 QString text(cc->text); 632 713 633 if (cc && (cc->text != QString::null))714 for (int chunk = 0; text != QString::null; first = false, chunk++) 634 715 { 635 int width = font.width(cc->text) + pad_width; 636 int x = teletextmode ? cc->y : (cc->x + 3); 716 QString captionText = 717 GetNextCC608Chunk(text, cc->teletextmode, 718 color, isItalic, isUnderline, 719 showedNonControl); 720 gTextSubFont->GetFace()->setItalic(isItalic); 721 gTextSubFont->GetFace()->setUnderline(isUnderline); 722 gTextSubFont->SetColor(clr[min(max(0, color), 7)]); 723 QFontMetrics font(*(gTextSubFont->GetFace())); 724 // XXX- could there be different heights across the same line? 725 int height = font.height() * (1 + PAD_HEIGHT); 726 if (first) 727 { 728 x = teletextmode ? cc->y : (cc->x + 3); 729 x = (int)(((float)x / (float)xscale) * (float)m_safeArea.width()); 730 } 731 else 732 { 733 x += width; // bump x by the previous width 734 } 735 int pad_width = font.maxWidth() * PAD_WIDTH; 736 width = font.width(captionText) + pad_width; 637 737 int y = teletextmode ? cc->x : cc->y; 638 x = (int)(((float)x / (float)xscale) * (float)m_safeArea.width());639 738 y = (int)(((float)y / (float)yscale) * (float)m_safeArea.height()); 739 // Sometimes a line of caption text begins with a mid-row 740 // format control like italics or a color change. The 741 // spec says the mid-row control also includes a space 742 // character. But this looks clumsy when using a 743 // background, so we suppress it after the placement is 744 // calculated. 745 if (!showedNonControl) 746 continue; 640 747 QRect rect(x, y, width, height); 641 748 642 749 if (!teletextmode && m_useBackground) … … void SubtitleScreen::DisplayCC608Subtitles(void) 648 755 shape->SetArea(MythRect(bgrect)); 649 756 } 650 757 651 gTextSubFont->SetColor(clr[min(max(0, cc->color), 7)]);652 758 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));759 captionText, *gTextSubFont, rect, rect, (MythUIType*)this, 760 QString("cc608txt%1%2%3%4").arg(cc->x).arg(cc->y).arg(width).arg(chunk)); 655 761 if (text) 656 762 text->SetJustification(Qt::AlignLeft); 657 763 m_refreshArea = true; 658 LOG(VB_VBI, LOG_INFO, QString("x %1 y %2 String: '%3'") 659 .arg(cc->x).arg(cc->y).arg(cc->text)); 764 LOG(VB_VBI, LOG_INFO, QString("x %1 y %2 uline=%4 ital=%5 color=%6 coord=%7,%8 String: '%3'") 765 .arg(cc->x).arg(cc->y).arg(captionText) 766 .arg(isUnderline).arg(isItalic).arg(color).arg(x).arg(y)); 660 767 } 661 768 } 662 769 textlist->lock.unlock();