2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "surface.h"
\r
28 #include "teletxt/txtfont.h"
\r
30 unsigned int interpol_table_fac1[16][22];
\r
31 unsigned int interpol_table_fac2[16][22];
\r
32 unsigned int interpol_table_fac3[16][22];
\r
33 unsigned int interpol_table_fac4[16][22];
\r
34 int interpol_lowbit[16];
\r
35 int interpol_upbit[16];
\r
36 int interpol_lowline[22];
\r
37 int interpol_upline[22];
\r
38 bool pol_table_inited=false;
\r
40 void initpol_tables(){
\r
44 if (Video::getInstance()->getFormat() == Video::PAL)
\r
52 for (int py=0;py<charsizey;py++) {
\r
53 float fposy=((float)(ttcharsizey))/((float)(charsizey))*((float)py);
\r
54 float yweight=fposy-floor(fposy);
\r
55 float yinvweight=1.-yweight;
\r
56 interpol_upline[py]=min((unsigned int)ceil(fposy),9);
\r
57 interpol_lowline[py]=max((unsigned int)floor(fposy),0);
\r
58 for (int px=0;px<charsizex;px++) {
\r
59 float fposx=((float)(ttcharsizex))/((float)(charsizex))*((float)px);
\r
60 float xweight=fposx-floor(fposx);
\r
61 float xinvweight=1.-xweight;
\r
62 interpol_upbit[px]= (min((unsigned int)ceil(fposx),11));
\r
63 interpol_lowbit[px]= (max((unsigned int)floor(fposx),0));
\r
65 interpol_table_fac1[px][py]=xweight*yweight*256.;
\r
66 interpol_table_fac2[px][py]=xinvweight*yweight*256.;
\r
67 interpol_table_fac3[px][py]=xweight*yinvweight*256.;
\r
68 interpol_table_fac4[px][py]=xinvweight*yinvweight*256.;
\r
75 Surface* Surface::screen = NULL;
\r
76 osd_font_t* Surface::font = &font_helvB18;
\r
78 Surface::Surface(int id)
\r
80 if (id == SCREEN) screen = this;
\r
87 Surface* Surface::getScreen()
\r
92 int Surface::drawText(const char* text, int x, int y, ULONG rgba)
\r
94 return drawText(text, x, y, 2000, rgba);
\r
97 int Surface::drawText(const char* text, int x, int y, int width, ULONG rgba)
\r
108 for (i=0; i<n; i++)
\r
110 unsigned char c = text[i];
\r
111 unsigned long *character = &font->content[font->offset[c]];
\r
112 int w = font->width[c];
\r
115 for (X=0; (X<w) && (X + cx < width); X++)
\r
117 for (Y=0; Y<h; Y++)
\r
119 if ((character[Y] >> (32 - X)) & 0x1)
\r
121 drawPixel(x+X+cx, y+Y, rgba,true);
\r
132 int Surface::drawTextRJ(const char* text, int x, int y, ULONG rgba)
\r
139 for (i = 0; i < n; i++)
\r
141 w += font->width[(unsigned char)text[i]];
\r
146 if (x < 0) return 0;
\r
147 else return drawText(text, x, y, rgba);
\r
150 int Surface::drawTextCentre(const char* text, int x, int y, ULONG rgba)
\r
157 for (i = 0; i < n; i++)
\r
159 w += font->width[(unsigned char)text[i]]; //Characters bigger then 128 can appear
\r
164 if (x < 0) return 0;
\r
165 else return drawText(text, x, y, rgba);
\r
168 int Surface::getCharWidth(char c)
\r
170 return font->width[(unsigned char) c];
\r
173 int Surface::getFontHeight()
\r
175 return font->spacing;
\r
178 //Moved from Teletext view in order to allow device depend optimizations
\r
180 Colour Surface::enumTeletextColorToCoulour(enumTeletextColor ttcol)
\r
184 return Colour(0,0,0);
\r
186 return Colour(255,0,0);
\r
188 return Colour(0,255,0);
\r
190 return Colour(255,255,0);
\r
192 return Colour(0,0,255);
\r
194 return Colour(255,0,255);
\r
196 return Colour(0,255,255);
\r
198 return Colour(255,255,255);
\r
199 case ttcTransparent:
\r
200 return Colour(0,0,0,0);
\r
202 return Colour(127,0,0);
\r
204 return Colour(0,127,0);
\r
205 case ttcHalfYellow:
\r
206 return Colour(127,127,0);
\r
208 return Colour(0,0,127);
\r
209 case ttcHalfMagenta:
\r
210 return Colour(127,0,127);
\r
212 return Colour(0,127,127);
\r
214 return Colour(127,127,127);
\r
216 return Colour(0,0,0);
\r
222 //Next function inspired by osdteletext plugin
\r
223 void Surface::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c)
\r
225 if (!pol_table_inited){
\r
227 pol_table_inited=true;
\r
229 unsigned int buffer [10];
\r
230 unsigned int * charmap=GetFontChar(c,buffer);
\r
231 if (!charmap) { //invalid char
\r
232 memset(&buffer,0,10);
\r
235 enumTeletextColor ttforegcolour=c.GetFGColor();
\r
236 enumTeletextColor ttbackgcolour=c.GetBGColor();
\r
237 if (c.GetBoxedOut()) {
\r
238 ttforegcolour=ttcTransparent;
\r
239 ttbackgcolour=ttcTransparent;
\r
245 if (Video::getInstance()->getFormat() == Video::PAL)
\r
251 int ttcharsizex=12;
\r
252 int ttcharsizey=10;
\r
253 int screenposx=charsizex*x+ox; //12*40= 480 250
\r
254 int screenposy=y*charsizey+oy;
\r
257 // Log::getInstance()->log("Surface", Log::ERR, "TTpos %d %d %d %d %d %d",x,y,ox,oy,screenposx,screenposy);
\r
258 Colour fgcharcl=enumTeletextColorToCoulour(ttforegcolour);
\r
259 Colour bgcharcl=enumTeletextColorToCoulour(ttbackgcolour);
\r
262 for (int py=0;py<charsizey;py++) {
\r
263 int upperbitline=charmap[interpol_upline[py]];
\r
264 int lowerbitline=charmap[interpol_lowline[py]];
\r
265 for (int px=0;px<charsizex;px++) {
\r
266 int upperbit= interpol_upbit[px];
\r
267 int lowerbit= interpol_lowbit[px];
\r
268 Colour uuc=( upperbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
\r
269 Colour ulc=( upperbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
\r
270 Colour luc=( lowerbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
\r
271 Colour llc=( lowerbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
\r
272 unsigned int fac1,fac2,fac3,fac4;
\r
273 fac1=interpol_table_fac1[px][py];
\r
274 fac2=interpol_table_fac2[px][py];
\r
275 fac3=interpol_table_fac3[px][py];
\r
276 fac4=interpol_table_fac4[px][py];
\r
278 Colour res((uuc.red*fac1+ulc.red*fac2+luc.red*fac3+llc.red*fac4)/256,
\r
279 (uuc.green*fac1+ulc.green*fac2+luc.green*fac3+llc.green*fac4)/256,
\r
280 (uuc.blue*fac1+ulc.blue*fac2+luc.blue*fac3+llc.blue*fac4)/256,
\r
281 (uuc.alpha*fac1+ulc.alpha*fac2+luc.alpha*fac3+llc.alpha*fac4)/256); //if this is too slow make a table
\r
282 int c = ( (res.alpha << 24 )
\r
286 drawPixel(screenposx+px,screenposy+py,c, true);
\r