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()
58 if (Video::getInstance()->getFormat() == Video::PAL)
70 for (int py = 0; py < charsizey; py++)
72 float fposy = ((float)(ttcharsizey)) / ((float)(charsizey)) * ((float)py);
73 float yweight = fposy - floor(fposy);
74 float yinvweight = 1. - yweight;
75 interpol_upline[py] = std::min((int)(ceil(fposy)), 9);
76 interpol_lowline[py] = std::max((int)(floor(fposy)), 0);
78 for (int px = 0; px < charsizex; px++)
80 float fposx = ((float)(ttcharsizex)) / ((float)(charsizex)) * ((float)px);
81 float xweight = fposx - floor(fposx);
82 float xinvweight = 1. - xweight;
83 interpol_upbit[px] = (std::min((int)ceil(fposx), 11));
84 interpol_lowbit[px] = (std::max((int)floor(fposx), 0));
86 interpol_table_fac1[px][py] = (unsigned int)(xweight * yweight * 256.);
87 interpol_table_fac2[px][py] = (unsigned int)(xinvweight * yweight * 256.);
88 interpol_table_fac3[px][py] = (unsigned int)(xweight * yinvweight * 256.);
89 interpol_table_fac4[px][py] = (unsigned int)(xinvweight * yinvweight * 256.);
94 int Surface::drawText(const char* text, int x, int y, const DrawStyle& c)
96 return drawText(text, x, y, 2000, c);
98 #ifndef GRADIENT_DRAWING
99 int Surface::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
109 ULONG rgba = c.rgba();
112 for (i = 0; i < n; i++)
114 unsigned char ch = text[i];
115 unsigned long* character = &font->content[font->offset[ch]];
116 int w = font->width[ch];
119 for (X = 0; (X < w) && (X + cx < width); X++)
121 for (Y = 0; Y < h; Y++)
123 if ((character[Y] >> (32 - X)) & 0x1)
125 drawPixel(x + X + cx, y + Y, rgba, true);
138 int Surface::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
145 for (i = 0; i < n; i++)
147 w += font->width[(unsigned char)text[i]];
153 else return drawText(text, x, y, c);
156 int Surface::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
163 for (i = 0; i < n; i++)
165 w += font->width[(unsigned char)text[i]]; //Characters bigger then 128 can appear
171 else return drawText(text, x, y, c);
174 float Surface::getCharWidth(wchar_t c)
176 return (float)font->width[(unsigned char) c];
179 int Surface::getFontHeight()
181 return font->spacing;
185 //Moved from Teletext view in order to allow device depend optimizations
187 Colour Surface::enumTeletextColorToCoulour(enumTeletextColor ttcol)
192 return Colour(0, 0, 0);
195 return Colour(255, 0, 0);
198 return Colour(0, 255, 0);
201 return Colour(255, 255, 0);
204 return Colour(0, 0, 255);
207 return Colour(255, 0, 255);
210 return Colour(0, 255, 255);
213 return Colour(255, 255, 255);
216 return Colour(0, 0, 0, 0);
219 return Colour(127, 0, 0);
222 return Colour(0, 127, 0);
225 return Colour(127, 127, 0);
228 return Colour(0, 0, 127);
231 return Colour(127, 0, 127);
234 return Colour(0, 127, 127);
237 return Colour(127, 127, 127);
240 return Colour(0, 0, 0);
246 //Next function inspired by osdteletext plugin
247 void Surface::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c)
249 if (!pol_table_inited)
252 pol_table_inited = true;
255 unsigned int buffer [10];
256 unsigned int* charmap = GetFontChar(c, buffer);
258 if (!charmap) //invalid char
260 memset(&buffer, 0, 10);
264 enumTeletextColor ttforegcolour = c.GetFGColor();
265 enumTeletextColor ttbackgcolour = c.GetBGColor();
269 ttforegcolour = ttcTransparent;
270 ttbackgcolour = ttcTransparent;
277 if (Video::getInstance()->getFormat() == Video::PAL)
286 //int ttcharsizex=12;
287 //int ttcharsizey=10;
288 int screenposx = charsizex * x + ox; //12*40= 480 250
289 int screenposy = y * charsizey + oy;
292 // Log::getInstance()->log("Surface", Log::ERR, "TTpos %d %d %d %d %d %d",x,y,ox,oy,screenposx,screenposy);
293 Colour fgcharcl = enumTeletextColorToCoulour(ttforegcolour);
294 Colour bgcharcl = enumTeletextColorToCoulour(ttbackgcolour);
298 for (int py = 0; py < charsizey; py++)
300 int upperbitline = charmap[interpol_upline[py]];
301 int lowerbitline = charmap[interpol_lowline[py]];
303 for (int px = 0; px < charsizex; px++)
305 int upperbit = interpol_upbit[px];
306 int lowerbit = interpol_lowbit[px];
307 Colour uuc = ( upperbitline & (0x8000 >> upperbit)) ? fgcharcl : bgcharcl;
308 Colour ulc = ( upperbitline & (0x8000 >> lowerbit)) ? fgcharcl : bgcharcl;
309 Colour luc = ( lowerbitline & (0x8000 >> upperbit)) ? fgcharcl : bgcharcl;
310 Colour llc = ( lowerbitline & (0x8000 >> lowerbit)) ? fgcharcl : bgcharcl;
311 unsigned int fac1, fac2, fac3, fac4;
312 fac1 = interpol_table_fac1[px][py];
313 fac2 = interpol_table_fac2[px][py];
314 fac3 = interpol_table_fac3[px][py];
315 fac4 = interpol_table_fac4[px][py];
317 Colour res((uuc.red * fac1 + ulc.red * fac2 + luc.red * fac3 + llc.red * fac4) / 256,
318 (uuc.green * fac1 + ulc.green * fac2 + luc.green * fac3 + llc.green * fac4) / 256,
319 (uuc.blue * fac1 + ulc.blue * fac2 + luc.blue * fac3 + llc.blue * fac4) / 256,
320 (uuc.alpha * fac1 + ulc.alpha * fac2 + luc.alpha * fac3 + llc.alpha * fac4) / 256); //if this is too slow make a table
321 int newcolour = ( (res.alpha << 24)
325 drawPixel(screenposx + px, screenposy + py, newcolour, true);
335 void Surface::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,
336 unsigned int width, DrawStyle& nextColour)
340 unsigned int bytesIn, bitsIn;
341 int widthBytes = width / 8;
343 for (y = 0; y < height; y++)
345 for (x = 0; x < width; x++)
347 bytesIn = (y * widthBytes) + (int) (x / 8);
350 if ((base[bytesIn] >> (7 - bitsIn)) & 0x01)
352 drawPixel(dx + x, dy + y, nextColour, true);
360 void Surface::drawPoint(int x, int y, DrawStyle& c, bool fastdraw)
362 drawPixel(x, y, c, fastdraw);