2 Copyright 2012 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, see <https://www.gnu.org/licenses/>.
24 #include "staticartwork.h"
25 #include "surfacevector.h"
27 SurfaceVector::SurfaceVector(OsdVector* vosd)
31 commands.reserve(2048);
34 SurfaceVector::~SurfaceVector()
36 osd->removeSurface(this);
37 std::vector<SVGCommand>::iterator itty = commands.begin();
39 while (itty != commands.end())
41 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
42 ImageIndex ii = (*itty).getImageIndex();
46 osd->removeImageRef(ii);
49 LoadIndex li = (*itty).getLoadIndex();
51 if (li) osd->removeLoadIndexRef(li);
58 int SurfaceVector::getFontHeight()
60 return (int)osd->getFontHeight();
63 float SurfaceVector::getCharWidth(wchar_t c)
65 return osd->getCharWidth(c);
69 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c)
71 return drawText(text, x, y, 0, c);
74 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
77 const char* run = text;
78 size_t length = strlen(text);
83 VectorHandle ref = osd->getStyleRef(c);
84 float* charwidtharray = osd->getCharWidthArray();
85 int commands_size = commands.size();
87 commands.resize(commands_size + strlen(text));
92 memset((void*)&state, 0, sizeof(state));
93 num_bytes = mbrtowc(&tempo, run, length, &state);
95 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
97 SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, tempo, ref);
100 float cur_shift = charwidtharray[tempo & 0xFF];
102 if (tempo && 0xFFFFFF00) cur_shift = osd->getCharWidth(tempo);
108 if (shift > width && width > 0)
110 command_mutex.unlock();
114 num_bytes = mbrtowc(&tempo, run, length, &state);
118 wchar_t* temptext = new wchar_t[length + 1];
119 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
120 temptext, length + 1) - 1;
122 for (int i = 0; i < real_length; i++)
124 SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, temptext[i], ref);
127 float cur_shift = charwidtharray[temptext[i] & 0xFF];
129 if (temptext[i] && 0xFFFFFF00) cur_shift = osd->getCharWidth(temptext[i]);
137 commands.resize(commands_size + chars);
138 command_mutex.unlock();
142 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
145 const char* run = text;
146 size_t length = strlen(text);
151 size_t num_bytes = 1;
152 memset((void*)&state, 0, sizeof(state));
153 num_bytes = mbrtowc(tempo, run, length, &state);
155 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
157 shift += osd->getCharWidth(*tempo);
160 num_bytes = mbrtowc(tempo, run, length, &state);
164 wchar_t* temptext = new wchar_t[length + 1];
165 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
166 temptext, length + 1) - 1;
168 for (int i = 0; i < real_length; i++)
170 shift += osd->getCharWidth(temptext[i]);
175 return drawText(text, (int)(x - shift), y, c);
178 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
181 const char* run = text;
182 size_t length = strlen(text);
187 size_t num_bytes = 1;
188 memset((void*)&state, 0, sizeof(state));
189 num_bytes = mbrtowc(tempo, run, length, &state);
191 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
193 shift += osd->getCharWidth(*tempo);
196 num_bytes = mbrtowc(tempo, run, length, &state);
200 wchar_t* temptext = new wchar_t[length + 1];
201 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
202 temptext, length + 1) - 1;
204 for (int i = 0; i < real_length; i++)
206 shift += osd->getCharWidth(temptext[i]);
212 return drawText(text, (int)(x - shift / 2.), y, c);
215 void SurfaceVector::drawJpeg(const char* fileName, int x, int y, int* width, int* height)
217 StaticArtwork index = sa_MAX; // This is for compatibility only
219 if (strcmp(fileName, "/vdr.jpg") == 0)
222 *height = 100; // this is faked so that the system does use the old coordinate system
223 *width = (int)ceil(190.f * osd->getPixelAspect());
225 else if (strcmp(fileName, "/wallpaperPAL.jpg") == 0)
227 index = sa_wallpaper;
228 *width = 720; // this is faked so that the system does use the old coordinate system
235 info.setStaticArtwork(index);
236 drawTVMedia(info, x, y, *width, *height, TopLeft);
241 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
243 command_mutex.lock();
244 ImageIndex image=osd->getJpegRef(fileName,width,height);
245 commands.push_back(SVGCommand::PaintImage(x,y,*width,*height,image,0));
246 command_mutex.unlock();
250 void SurfaceVector::drawTVMedia(TVMediaInfo& tvmedia, float x, float y, float width, float height, Corner corner)
252 command_mutex.lock();
253 ImageIndex image = 0;
254 LoadIndex load_index = osd->getTVMediaRef(tvmedia, image);
256 if (width != 0 && height != 0)
258 removeCommands(x, y, width, height);
263 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image %d %d", load_index,image);
264 commands.push_back(SVGCommand::PaintImage(x, y, width, height, image, 0, corner));
269 commands.push_back(SVGCommand::PaintImageLoading(load_index, x, y, width, height, 0, corner));
270 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image loading %d %d", load_index,image);
273 command_mutex.unlock();
276 void SurfaceVector::drawClippingRectangle(float x, float y, float w, float h)
278 command_mutex.lock();
279 commands.push_back(SVGCommand::PaintClipping((float)x, (float)y, (float)w, (float)h));
280 command_mutex.unlock();
283 int SurfaceVector::create(UINT width, UINT height)
289 void SurfaceVector::display()
291 //nothing this is really mvp specific
294 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
296 command_mutex.lock();
297 removeCommands(x, y, width, height); // remove commands below the box
298 VectorHandle ref = osd->getStyleRef(c);
299 commands.push_back(SVGCommand::PaintPath(x, y, width, height, PIRectangle, ref));
300 command_mutex.unlock();
304 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
306 command_mutex.lock();
307 VectorHandle ref = osd->getStyleRef(c);
308 commands.push_back(SVGCommand::PaintPath(x1, y, x2 - x1, 1, PIHorzLine, ref));
309 command_mutex.unlock();
312 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c)
314 command_mutex.lock();
315 VectorHandle ref = osd->getStyleRef(c);
316 commands.push_back(SVGCommand::PaintPath(x, y1, 1, y2 - y1, PIVertLine, ref));
317 command_mutex.unlock();
320 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm, const DisplayRegion& region)
322 //this is complicated
323 command_mutex.lock();
325 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth()*bm.getHeight());
326 for (UINT j = 0; j < bm.getHeight(); ++j){
327 for (UINT i = 0; i < bm.getWidth(); ++i)
329 data[i+j*bm.getHeight()]=bm.getColour(i,j);
332 ImageIndex image = osd->getImagePalette(bm.getWidth(), bm.getHeight(), &(bm.rawData()[0]),
333 (const unsigned int*)&bm.palette.getColourVector()[0]); // data is freed by the OSD
335 float tx = x + region.windowx;
336 float ty = y + region.windowy;
337 float th = bm.getHeight();
338 float tw = bm.getWidth();
340 float scalex = 720.f / ((float) (region.framewidth + 1));
341 float scaley = 576.f / ((float) (region.frameheight + 1));
346 SVGCommand temp = SVGCommand::PaintImage(tx, ty, tw, th, image, 0);
347 removeCommands(tx, ty, tw, th);
348 commands.push_back(temp);
349 command_mutex.unlock();
352 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw)
354 if (!fastdraw) command_mutex.lock();
356 VectorHandle ref = osd->getStyleRef(c);
357 commands.push_back(SVGCommand::PaintPath(x, y, 1, 1, PIPoint, ref));
359 if (!fastdraw) command_mutex.unlock();
361 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height, unsigned int width, DrawStyle& nextColour)
363 command_mutex.lock();
364 ImageIndex image = osd->getMonoBitmapRef(base, width, height);
365 VectorHandle ref = osd->getStyleRef(nextColour);
366 removeCommands(dx, dy, width, height);
367 commands.push_back(SVGCommand::PaintImage(dx, dy, height, width, image, ref));
368 command_mutex.unlock();
372 int SurfaceVector::removeCommands(float x, float y, float width, float height)
374 // we iterate through all old commands in order to remove commands hidden by this rectangle
375 std::vector<SVGCommand>::iterator itty = commands.begin();
376 std::vector<SVGCommand>::iterator remstart;
378 float cx, cy, cw, ch;
382 bool clipping_erases = false;
384 while (itty != commands.end())
386 if ((clipping_erases // test if clipping helps
387 || (*itty).Test(x, y, width, height) )
388 && (*itty).instr != DrawClipping)
390 //Log::getInstance()->log("OSD", Log::DEBUG, "Remove command %d %g %g %g %g %d %d",(*itty).instr,
391 //(*itty).x,(*itty).y,(*itty).w,(*itty).h,(*itty).reference,(*itty).target.image);
392 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
393 ImageIndex ii = (*itty).getImageIndex();
395 if (ii) osd->removeImageRef(ii);
397 LoadIndex li = (*itty).getLoadIndex();
399 if (li) osd->removeLoadIndexRef(li);
409 if ((*itty).instr == DrawClipping)
411 if ((*itty).w == 0.f && (*itty).h == 0.f)
426 clipping_erases = (cx >= x) && (cy >= y) && ((cx + cw) <= (x + width)) && ((cy + ch) <= (y + height));
431 itty = commands.erase(remstart, itty);
441 itty = commands.erase(remstart, itty);
448 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
450 // ok this method really works in a pixel oriented way
451 command_mutex.lock();
452 osd->updateOrAddSurface(this, dx - sx, dy - sy, swidth, sheight, commands);
453 command_mutex.unlock();
458 /* This is for systems which need a locking of the drawing surface to speed up drawing */
459 void SurfaceVector::startFastDraw()
461 command_mutex.lock();
463 void SurfaceVector::endFastDraw()
465 command_mutex.unlock();
469 void SurfaceVector::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c)
471 command_mutex.lock();
472 std::vector<SVGCommand>::iterator itty = commands.begin();
474 while (itty != commands.end())
476 if ((*itty).TTTest(ox, oy, x, y) )
478 itty = commands.erase(itty);
487 commands.push_back(SVGCommand::PaintTTchar(ox, oy, x, y, c.getInternal()));
488 command_mutex.unlock();