2 Copyright 2004-2005 Chris Tallon
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.
29 #include "teletxt/txtfont.h"
30 #include "staticartwork.h"
32 Surface* Surface::screen = NULL;
34 #ifndef GRADIENT_DRAWING
35 osd_font_t* Surface::font = &font_helvB18;
38 Surface::Surface(int id)
40 if (id == SCREEN) screen = this;
47 Surface* Surface::getScreen()
52 void Surface::initpol_tables()
57 if (Video::getInstance()->getFormat() == Video::PAL)
65 for (int py=0;py<charsizey;py++) {
66 float fposy=((float)(ttcharsizey))/((float)(charsizey))*((float)py);
67 float yweight=fposy-floor(fposy);
68 float yinvweight=1.-yweight;
69 interpol_upline[py]=std::min((int)(ceil(fposy)),9);
70 interpol_lowline[py]=std::max((int)(floor(fposy)),0);
71 for (int px=0;px<charsizex;px++) {
72 float fposx=((float)(ttcharsizex))/((float)(charsizex))*((float)px);
73 float xweight=fposx-floor(fposx);
74 float xinvweight=1.-xweight;
75 interpol_upbit[px]= (std::min((int)ceil(fposx),11));
76 interpol_lowbit[px]= (std::max((int)floor(fposx),0));
78 interpol_table_fac1[px][py]=(unsigned int)(xweight*yweight*256.);
79 interpol_table_fac2[px][py]=(unsigned int)(xinvweight*yweight*256.);
80 interpol_table_fac3[px][py]=(unsigned int)(xweight*yinvweight*256.);
81 interpol_table_fac4[px][py]=(unsigned int)(xinvweight*yinvweight*256.);
86 int Surface::drawText(const char* text, int x, int y, const DrawStyle& c)
88 return drawText(text, x, y, 2000, c);
90 #ifndef GRADIENT_DRAWING
91 int Surface::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
105 unsigned char ch = text[i];
106 unsigned long *character = &font->content[font->offset[ch]];
107 int w = font->width[ch];
110 for (X=0; (X<w) && (X + cx < width); X++)
114 if ((character[Y] >> (32 - X)) & 0x1)
116 drawPixel(x+X+cx, y+Y, rgba,true);
127 int Surface::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
134 for (i = 0; i < n; i++)
136 w += font->width[(unsigned char)text[i]];
142 else return drawText(text, x, y, c);
145 int Surface::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
152 for (i = 0; i < n; i++)
154 w += font->width[(unsigned char)text[i]]; //Characters bigger then 128 can appear
160 else return drawText(text, x, y, c);
163 float Surface::getCharWidth(wchar_t c)
165 return (float)font->width[(unsigned char) c];
168 int Surface::getFontHeight()
170 return font->spacing;
174 //Moved from Teletext view in order to allow device depend optimizations
176 Colour Surface::enumTeletextColorToCoulour(enumTeletextColor ttcol)
180 return Colour(0,0,0);
182 return Colour(255,0,0);
184 return Colour(0,255,0);
186 return Colour(255,255,0);
188 return Colour(0,0,255);
190 return Colour(255,0,255);
192 return Colour(0,255,255);
194 return Colour(255,255,255);
196 return Colour(0,0,0,0);
198 return Colour(127,0,0);
200 return Colour(0,127,0);
202 return Colour(127,127,0);
204 return Colour(0,0,127);
206 return Colour(127,0,127);
208 return Colour(0,127,127);
210 return Colour(127,127,127);
212 return Colour(0,0,0);
218 //Next function inspired by osdteletext plugin
219 void Surface::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c)
221 if (!pol_table_inited){
223 pol_table_inited=true;
225 unsigned int buffer [10];
226 unsigned int * charmap=GetFontChar(c,buffer);
227 if (!charmap) { //invalid char
228 memset(&buffer,0,10);
231 enumTeletextColor ttforegcolour=c.GetFGColor();
232 enumTeletextColor ttbackgcolour=c.GetBGColor();
233 if (c.GetBoxedOut()) {
234 ttforegcolour=ttcTransparent;
235 ttbackgcolour=ttcTransparent;
241 if (Video::getInstance()->getFormat() == Video::PAL)
247 //int ttcharsizex=12;
248 //int ttcharsizey=10;
249 int screenposx=charsizex*x+ox; //12*40= 480 250
250 int screenposy=y*charsizey+oy;
253 // Log::getInstance()->log("Surface", Log::ERR, "TTpos %d %d %d %d %d %d",x,y,ox,oy,screenposx,screenposy);
254 Colour fgcharcl=enumTeletextColorToCoulour(ttforegcolour);
255 Colour bgcharcl=enumTeletextColorToCoulour(ttbackgcolour);
258 for (int py=0;py<charsizey;py++) {
259 int upperbitline=charmap[interpol_upline[py]];
260 int lowerbitline=charmap[interpol_lowline[py]];
261 for (int px=0;px<charsizex;px++) {
262 int upperbit= interpol_upbit[px];
263 int lowerbit= interpol_lowbit[px];
264 Colour uuc=( upperbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
265 Colour ulc=( upperbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
266 Colour luc=( lowerbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl;
267 Colour llc=( lowerbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl;
268 unsigned int fac1,fac2,fac3,fac4;
269 fac1=interpol_table_fac1[px][py];
270 fac2=interpol_table_fac2[px][py];
271 fac3=interpol_table_fac3[px][py];
272 fac4=interpol_table_fac4[px][py];
274 Colour res((uuc.red*fac1+ulc.red*fac2+luc.red*fac3+llc.red*fac4)/256,
275 (uuc.green*fac1+ulc.green*fac2+luc.green*fac3+llc.green*fac4)/256,
276 (uuc.blue*fac1+ulc.blue*fac2+luc.blue*fac3+llc.blue*fac4)/256,
277 (uuc.alpha*fac1+ulc.alpha*fac2+luc.alpha*fac3+llc.alpha*fac4)/256); //if this is too slow make a table
278 int newcolour = ( (res.alpha << 24)
282 drawPixel(screenposx+px, screenposy+py, newcolour, true);
292 void Surface::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,
293 unsigned int width, DrawStyle& nextColour) {
296 unsigned int bytesIn, bitsIn;
297 int widthBytes=width/8;
298 for (y = 0; y < height; y++) {
299 for (x = 0; x < width; x++) {
300 bytesIn = (y * widthBytes) + (int) (x / 8);
303 if ((base[bytesIn] >> (7 - bitsIn)) & 0x01) {
304 drawPixel(dx+x, dy+y, nextColour, true);
311 void Surface::drawPoint(int x, int y, DrawStyle& c, bool fastdraw)
313 drawPixel(x,y,c,fastdraw);