2 Copyright 2005-2008 Chris Tallon, Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vteletextview.h"
26 #include "teletxt/txtfont.h"
28 float interpol_table_fac1[16][22];
29 float interpol_table_fac2[16][22];
30 float interpol_table_fac3[16][22];
31 float interpol_table_fac4[16][22];
32 int interpol_lowbit[16];
33 int interpol_upbit[16];
34 int interpol_lowline[22];
35 int interpol_upline[22];
37 void initpol_tables(){
41 if (Video::getInstance()->getFormat() == Video::PAL)
49 for (int py=0;py<charsizey;py++) {
50 float fposy=((float)(ttcharsizey))/((float)(charsizey))*((float)py);
51 float yweight=fposy-floor(fposy);
52 float yinvweight=1.-yweight;
53 interpol_upline[py]=min((unsigned int)ceil(fposy),9);
54 interpol_lowline[py]=max((unsigned int)floor(fposy),0);
55 for (int px=0;px<charsizex;px++) {
56 float fposx=((float)(ttcharsizex))/((float)(charsizex))*((float)px);
57 float xweight=fposx-floor(fposx);
58 float xinvweight=1.-xweight;
59 interpol_upbit[px]= (min((unsigned int)ceil(fposx),11));
60 interpol_lowbit[px]= (max((unsigned int)floor(fposx),0));
62 interpol_table_fac1[px][py]=xweight*yweight;
63 interpol_table_fac2[px][py]=xinvweight*yweight;
64 interpol_table_fac3[px][py]=xweight*yinvweight;
65 interpol_table_fac4[px][py]=xinvweight*yinvweight;
71 VTeletextView::VTeletextView(TeletextDecoderVBIEBU* TTdecoder,Boxx* playerview)
79 if (Video::getInstance()->getFormat() == Video::PAL)
82 setSize(680,22); //Only first line
89 setSize(680,18);//only first line
97 VTeletextView::~VTeletextView ()
99 // Make sure the timer is deleted
101 BoxStack::getInstance()->update(pv);
102 Timers::getInstance()->cancelTimer(this, 1);
103 ttdecoder->unRegisterTeletextView(this);
107 void VTeletextView::draw(bool completedraw, bool onlyfirstline)
114 if (ttdecoder->isDirty(x,y) || completedraw) {
115 cTeletextChar c=ttdecoder->getChar(x,y);
117 //Skip Blinking and conceal
119 ttdecoder->setChar(x,y,c);
122 if (onlyfirstline) break;
128 Colour VTeletextView::enumTeletextColorToCoulour(enumTeletextColor ttcol)
132 return Colour(0,0,0);
134 return Colour(255,0,0);
136 return Colour(0,255,0);
138 return Colour(255,255,0);
140 return Colour(0,0,255);
142 return Colour(255,0,255);
144 return Colour(0,255,255);
146 return Colour(255,255,255);
148 return Colour(0,0,0,0);
150 return Colour(127,0,0);
152 return Colour(0,127,0);
154 return Colour(127,127,0);
156 return Colour(0,0,127);
158 return Colour(127,0,127);
160 return Colour(0,127,127);
162 return Colour(127,127,127);
164 return Colour(0,0,0);
168 //Next function inspired by osdteletext plugin
169 void VTeletextView::drawChar(int x, int y, cTeletextChar c)
171 unsigned int buffer [10];
172 unsigned int * charmap=GetFontChar(c,buffer);
173 if (!charmap) { //invalid char
174 memset(&buffer,0,10);
177 enumTeletextColor ttforegcolour=c.GetFGColor();
178 enumTeletextColor ttbackgcolour=c.GetBGColor();
179 if (c.GetBoxedOut()) {
180 ttforegcolour=ttcTransparent;
181 ttbackgcolour=ttcTransparent;
186 bool firstline=false;
187 if (y==0) firstline=true;
188 if (Video::getInstance()->getFormat() == Video::PAL)
196 int screenposx=charsizex*x; //12*40= 480 250
197 int screenposy=y*charsizey;
198 Boxx* drawtarget=this;
202 screenposy+=this->getScreenY();
203 screenposx+=this->getScreenX();
207 Colour fgcharcl=enumTeletextColorToCoulour(ttforegcolour);
208 Colour bgcharcl=enumTeletextColorToCoulour(ttbackgcolour);
210 drawtarget->startFastDraw();
211 for (int py=0;py<charsizey;py++) {
212 int upperbitline=charmap[interpol_upline[py]];
213 int lowerbitline=charmap[interpol_lowline[py]];
214 for (int px=0;px<charsizex;px++) {
215 int upperbit= interpol_upbit[px];
216 int lowerbit= interpol_lowbit[px];
217 Colour uuc=( upperbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
218 Colour ulc=( upperbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
219 Colour luc=( lowerbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
220 Colour llc=( lowerbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
221 float fac1,fac2,fac3,fac4;
222 fac1=interpol_table_fac1[px][py];
223 fac2=interpol_table_fac2[px][py];
224 fac3=interpol_table_fac3[px][py];
225 fac4=interpol_table_fac4[px][py];
227 Colour res(uuc.red*fac1+ulc.red*fac2+luc.red*fac3+llc.red*fac4,
228 uuc.green*fac1+ulc.green*fac2+luc.green*fac3+llc.green*fac4,
229 uuc.blue*fac1+ulc.blue*fac2+luc.blue*fac3+llc.blue*fac4,
230 uuc.alpha*fac1+ulc.alpha*fac2+luc.alpha*fac3+llc.alpha*fac4); //if this is too slow make a table
231 drawtarget->drawPixelAlpha(screenposx+px,screenposy+py,res, true);
236 drawtarget->endFastDraw();
241 int VTeletextView::handleCommand(int command) {
242 if (subtitlemode) return 0; //Ok we are in subtitle mode, we are a slave of the player
259 // key in teletext page
269 void VTeletextView::doKey(int command)
273 if (command==9) return; //not allowed
275 pagenums[0]=command+ 48;
279 } else if (keyindigit==2) {
281 pagenums[0]=48+((page &0xF00)>>8);
282 pagenums[1]=command+ 48;
285 } else if (keyindigit==3) {
287 pagenums[0]=48+((page &0xF00)>>8);
288 pagenums[1]=48+((page &0x0F0)>>4);
289 pagenums[2]=48+command;
291 ttdecoder->setPage(page);
293 ttdecoder->setKeyinDigits(pagenums,true);
296 if (Video::getInstance()->getFormat() == Video::PAL) {
307 BoxStack::getInstance()->update(this,&toupdate);
311 void VTeletextView::timercall(int clientReference)
316 void VTeletextView::processMessage(Message* m)
318 if (m->message == Message::TELETEXTUPDATE)
321 BoxStack::getInstance()->update(this);
322 BoxStack::getInstance()->update(pv);
324 } else if (m->message == Message::TELETEXTUPDATEFIRSTLINE)
328 if (Video::getInstance()->getFormat() == Video::PAL) {
341 BoxStack::getInstance()->update(this,&toupdate);