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)
30 commands.reserve(2048);
33 SurfaceVector::~SurfaceVector()
35 osd->removeSurface(this);
37 for (SVGCommand& command : commands)
39 osd->decrementStyleRefCount(command.getRef()); // We remove the Style reference, so that osd can free stuff
41 ImageIndex ii = command.getImageIndex();
42 if (ii) osd->removeImageRef(ii);
44 LoadIndex li = command.getLoadIndex();
45 if (li) osd->removeLoadIndexRef(li);
49 int SurfaceVector::getFontHeight()
51 return (int)osd->getFontHeight();
54 float SurfaceVector::getCharWidth(wchar_t c)
56 return osd->getCharWidth(c);
59 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c)
61 return drawText(text, x, y, 0, c);
64 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
67 const char* run = text;
68 size_t length = strlen(text);
73 VectorHandle ref = osd->getStyleRef(c);
74 float* charwidtharray = osd->getCharWidthArray();
75 int commands_size = commands.size();
77 commands.resize(commands_size + strlen(text));
82 memset((void*)&state, 0, sizeof(state));
83 num_bytes = mbrtowc(&tempo, run, length, &state);
85 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
87 SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, tempo, ref);
90 float cur_shift = charwidtharray[tempo & 0xFF];
92 if (tempo && 0xFFFFFF00) cur_shift = osd->getCharWidth(tempo);
98 if (shift > width && width > 0)
100 command_mutex.unlock();
104 num_bytes = mbrtowc(&tempo, run, length, &state);
108 wchar_t* temptext = new wchar_t[length + 1];
109 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
110 temptext, length + 1) - 1;
112 for (int i = 0; i < real_length; i++)
114 SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, temptext[i], ref);
117 float cur_shift = charwidtharray[temptext[i] & 0xFF];
119 if (temptext[i] && 0xFFFFFF00) cur_shift = osd->getCharWidth(temptext[i]);
127 commands.resize(commands_size + chars);
128 command_mutex.unlock();
132 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
135 const char* run = text;
136 size_t length = strlen(text);
141 size_t num_bytes = 1;
142 memset((void*)&state, 0, sizeof(state));
143 num_bytes = mbrtowc(tempo, run, length, &state);
145 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
147 shift += osd->getCharWidth(*tempo);
150 num_bytes = mbrtowc(tempo, run, length, &state);
154 wchar_t* temptext = new wchar_t[length + 1];
155 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
156 temptext, length + 1) - 1;
158 for (int i = 0; i < real_length; i++)
160 shift += osd->getCharWidth(temptext[i]);
165 return drawText(text, (int)(x - shift), y, c);
168 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
171 const char* run = text;
172 size_t length = strlen(text);
177 size_t num_bytes = 1;
178 memset((void*)&state, 0, sizeof(state));
179 num_bytes = mbrtowc(tempo, run, length, &state);
181 while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0)
183 shift += osd->getCharWidth(*tempo);
186 num_bytes = mbrtowc(tempo, run, length, &state);
190 wchar_t* temptext = new wchar_t[length + 1];
191 int real_length = MultiByteToWideChar(CP_UTF8, 0, text, -1,
192 temptext, length + 1) - 1;
194 for (int i = 0; i < real_length; i++)
196 shift += osd->getCharWidth(temptext[i]);
202 return drawText(text, (int)(x - shift / 2.), y, c);
205 void SurfaceVector::drawJpeg(const char* fileName, int x, int y, int* width, int* height)
207 StaticArtwork index = sa_MAX; // This is for compatibility only
209 if (strcmp(fileName, "/vdr.jpg") == 0)
212 *height = 100; // this is faked so that the system does use the old coordinate system
213 *width = (int)ceil(190.f * osd->getPixelAspect());
215 else if (strcmp(fileName, "/wallpaperPAL.jpg") == 0)
217 index = sa_wallpaper;
218 *width = 720; // this is faked so that the system does use the old coordinate system
225 info.setStaticArtwork(index);
226 drawTVMedia(info, x, y, *width, *height, TopLeft);
231 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
233 command_mutex.lock();
234 ImageIndex image=osd->getJpegRef(fileName,width,height);
235 commands.push_back(SVGCommand::PaintImage(x,y,*width,*height,image,0));
236 command_mutex.unlock();
240 void SurfaceVector::drawTVMedia(TVMediaInfo& tvmedia, float x, float y, float width, float height, Corner corner)
242 command_mutex.lock();
243 ImageIndex image = 0;
244 LoadIndex load_index = osd->getTVMediaRef(tvmedia, image);
246 if (width != 0 && height != 0)
248 removeCommands(x, y, width, height);
253 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image %d %d", load_index,image);
254 commands.push_back(SVGCommand::PaintImage(x, y, width, height, image, 0, corner));
259 commands.push_back(SVGCommand::PaintImageLoading(load_index, x, y, width, height, 0, corner));
260 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image loading %d %d", load_index,image);
263 command_mutex.unlock();
266 void SurfaceVector::drawClippingRectangle(float x, float y, float w, float h)
268 command_mutex.lock();
269 commands.push_back(SVGCommand::PaintClipping((float)x, (float)y, (float)w, (float)h));
270 command_mutex.unlock();
273 int SurfaceVector::create(UINT width, UINT height)
279 void SurfaceVector::display()
281 //nothing this is really mvp specific
284 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
286 command_mutex.lock();
287 removeCommands(x, y, width, height); // remove commands below the box
288 VectorHandle ref = osd->getStyleRef(c);
289 commands.push_back(SVGCommand::PaintPath(x, y, width, height, PIRectangle, ref));
290 command_mutex.unlock();
294 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
296 command_mutex.lock();
297 VectorHandle ref = osd->getStyleRef(c);
298 commands.push_back(SVGCommand::PaintPath(x1, y, x2 - x1, 1, PIHorzLine, ref));
299 command_mutex.unlock();
302 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c)
304 command_mutex.lock();
305 VectorHandle ref = osd->getStyleRef(c);
306 commands.push_back(SVGCommand::PaintPath(x, y1, 1, y2 - y1, PIVertLine, ref));
307 command_mutex.unlock();
310 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm, const DisplayRegion& region)
312 //this is complicated
313 command_mutex.lock();
315 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth()*bm.getHeight());
316 for (UINT j = 0; j < bm.getHeight(); ++j){
317 for (UINT i = 0; i < bm.getWidth(); ++i)
319 data[i+j*bm.getHeight()]=bm.getColour(i,j);
322 ImageIndex image = osd->getImagePalette(bm.getWidth(), bm.getHeight(), &(bm.rawData()[0]),
323 (const unsigned int*)&bm.palette.getColourVector()[0]); // data is freed by the OSD
325 float tx = x + region.windowx;
326 float ty = y + region.windowy;
327 float th = bm.getHeight();
328 float tw = bm.getWidth();
330 float scalex = 720.f / ((float) (region.framewidth + 1));
331 float scaley = 576.f / ((float) (region.frameheight + 1));
336 SVGCommand temp = SVGCommand::PaintImage(tx, ty, tw, th, image, 0);
337 removeCommands(tx, ty, tw, th);
338 commands.push_back(temp);
339 command_mutex.unlock();
342 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw)
344 if (!fastdraw) command_mutex.lock();
346 VectorHandle ref = osd->getStyleRef(c);
347 commands.push_back(SVGCommand::PaintPath(x, y, 1, 1, PIPoint, ref));
349 if (!fastdraw) command_mutex.unlock();
351 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height, unsigned int width, DrawStyle& nextColour)
353 command_mutex.lock();
354 ImageIndex image = osd->getMonoBitmapRef(base, width, height);
355 VectorHandle ref = osd->getStyleRef(nextColour);
356 removeCommands(dx, dy, width, height);
357 commands.push_back(SVGCommand::PaintImage(dx, dy, height, width, image, ref));
358 command_mutex.unlock();
362 int SurfaceVector::removeCommands(float x, float y, float width, float height)
364 // we iterate through all old commands in order to remove commands hidden by this rectangle
365 std::vector<SVGCommand>::iterator itty = commands.begin();
366 std::vector<SVGCommand>::iterator remstart;
368 float cx, cy, cw, ch;
372 bool clipping_erases = false;
374 while (itty != commands.end())
376 if ((clipping_erases // test if clipping helps
377 || (*itty).Test(x, y, width, height) )
378 && (*itty).instr != DrawClipping)
380 //Log::getInstance()->log("OSD", Log::DEBUG, "Remove command %d %g %g %g %g %d %d",(*itty).instr,
381 //(*itty).x,(*itty).y,(*itty).w,(*itty).h,(*itty).reference,(*itty).target.image);
382 osd->decrementStyleRefCount((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
383 ImageIndex ii = (*itty).getImageIndex();
385 if (ii) osd->removeImageRef(ii);
387 LoadIndex li = (*itty).getLoadIndex();
389 if (li) osd->removeLoadIndexRef(li);
399 if ((*itty).instr == DrawClipping)
401 if ((*itty).w == 0.f && (*itty).h == 0.f)
416 clipping_erases = (cx >= x) && (cy >= y) && ((cx + cw) <= (x + width)) && ((cy + ch) <= (y + height));
421 itty = commands.erase(remstart, itty);
431 itty = commands.erase(remstart, itty);
438 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
440 // ok this method really works in a pixel oriented way
441 command_mutex.lock();
442 osd->updateOrAddSurface(this, dx - sx, dy - sy, swidth, sheight, commands);
443 command_mutex.unlock();
448 /* This is for systems which need a locking of the drawing surface to speed up drawing */
449 void SurfaceVector::startFastDraw()
451 command_mutex.lock();
453 void SurfaceVector::endFastDraw()
455 command_mutex.unlock();
459 void SurfaceVector::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c)
461 command_mutex.lock();
462 std::vector<SVGCommand>::iterator itty = commands.begin();
464 while (itty != commands.end())
466 if ((*itty).TTTest(ox, oy, x, y) )
468 itty = commands.erase(itty);
477 commands.push_back(SVGCommand::PaintTTchar(ox, oy, x, y, c.getInternal()));
478 command_mutex.unlock();