]> git.vomp.tv Git - vompclient.git/blob - osdopenvg.cc
Fix segfault in boxstack.cc
[vompclient.git] / osdopenvg.cc
1 /*\r
2     Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter\r
3 \r
4     This file is part of VOMP.\r
5 \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
10 \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
15 \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
19 */\r
20 \r
21 \r
22 #include "osdopenvg.h"\r
23 #include "mtd.h"\r
24 #include "videoomx.h"\r
25 #include "surface.h"\r
26 #include <Magick++.h>\r
27 \r
28 #include "message.h"\r
29 #include "command.h"\r
30 #include "teletxt/txtfont.h"\r
31 \r
32 #include <sys/syscall.h>\r
33 #include <vector>\r
34 #include <math.h>\r
35 \r
36 using namespace Magick;\r
37 \r
38 extern uint8_t font_data[]     asm("_binary_fonts_sourcesans_ttf_start");\r
39 extern uint8_t font_data_end[] asm("_binary_fonts_sourcesans_ttf_end");\r
40 extern uint8_t vdr_data[]     asm("_binary_other_vdrhires_jpg_start");\r
41 extern uint8_t vdr_data_end[] asm("_binary_other_vdrhires_jpg_end");\r
42 extern uint8_t wallpaper_data[]     asm("_binary_other_wallpaper720p_jpg_start");\r
43 extern uint8_t wallpaper_data_end[] asm("_binary_other_wallpaper720p_jpg_end");\r
44 \r
45 \r
46 #define  BACKBUFFER_WIDTH 1280\r
47 #define  BACKBUFFER_HEIGHT 720\r
48 \r
49 \r
50 OsdOpenVG::OsdOpenVG()\r
51 {\r
52   vgmutex.Lock();\r
53   taskmutex.Lock();\r
54   lastrendertime=getTimeMS();\r
55   display_height=0;\r
56   display_width=0;\r
57   mode=0;\r
58   aspect_correction=1.;\r
59 \r
60   wait_id=1;\r
61 \r
62 }\r
63 \r
64 OsdOpenVG::~OsdOpenVG()\r
65 {\r
66 \r
67   if (initted)\r
68   {\r
69                 shutdown();\r
70   }\r
71 \r
72 \r
73   vgmutex.Unlock();\r
74   taskmutex.Unlock();\r
75 }\r
76 \r
77 \r
78 \r
79 int OsdOpenVG::init(void* device)\r
80 {\r
81   if (initted) return 0;\r
82   Video* video = Video::getInstance();\r
83    //window=*((HWND*)device);\r
84 \r
85    // May be this device specific part should go to a device specific child class\r
86 \r
87    //init broadcom chipset (Move to video?)\r
88 \r
89 \r
90    //First get connection to egl\r
91    egl_display=eglGetDisplay(EGL_DEFAULT_DISPLAY);\r
92 \r
93    if (egl_display==EGL_NO_DISPLAY) {\r
94            Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());\r
95            vgmutex.Unlock();\r
96            return 0;\r
97    }\r
98 \r
99 \r
100 \r
101    if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {\r
102            Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());\r
103            vgmutex.Unlock();\r
104            return 0;\r
105    }\r
106 \r
107 \r
108    const char *query_str=eglQueryString(egl_display,EGL_CLIENT_APIS);\r
109    if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
110    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());\r
111    query_str=eglQueryString(egl_display,EGL_EXTENSIONS);\r
112    if (query_str)    Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
113    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());\r
114 \r
115    if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {\r
116            Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x",eglGetError());\r
117            vgmutex.Unlock();\r
118            return 0;\r
119    }\r
120 \r
121    const EGLint attributs[]={\r
122                  EGL_RED_SIZE,8,EGL_GREEN_SIZE, 8,EGL_BLUE_SIZE, 8,EGL_ALPHA_SIZE, 8,\r
123          EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT,\r
124          EGL_CONFORMANT, EGL_OPENVG_BIT,\r
125          EGL_NONE\r
126    }; // Here, we might have to select the resolution!\r
127 \r
128 \r
129    EGLint number;\r
130 \r
131    if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {\r
132            Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x",eglGetError());\r
133            vgmutex.Unlock();\r
134            return 0;\r
135    }\r
136 \r
137 \r
138 \r
139    egl_context=eglCreateContext(egl_display,egl_ourconfig,NULL,NULL);\r
140    if (egl_context==EGL_NO_CONTEXT) {\r
141            Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x",eglGetError());\r
142            vgmutex.Unlock();\r
143            return 0;\r
144    }\r
145 \r
146    // warning broadcom specific, get display size!\r
147    display_width=display_height=0;\r
148    if (graphics_get_display_size(0, &display_width, &display_height)<0) {\r
149            Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");\r
150            vgmutex.Unlock();\r
151            return 0;\r
152    }\r
153    Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);\r
154    VC_RECT_T dst_rect ={0,0,display_width,display_height};\r
155    VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16};\r
156   // VC_RECT_T src_rect_bg={0,0,1<<16,1<<16};\r
157  //  VC_RECT_T src_rect_im={0,0,1,1};\r
158 \r
159   /* uint32_t back_image_ptr;\r
160    bcm_backres=vc_dispmanx_resource_create(VC_IMAGE_RGB888,1,1,&back_image_ptr);\r
161    unsigned int color=0x00FF0000;\r
162    vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGB888,4,&color,&src_rect_im);*/\r
163 \r
164    DISPMANX_UPDATE_HANDLE_T  bcm_update;\r
165    bcm_display=vc_dispmanx_display_open(0);\r
166    bcm_update=vc_dispmanx_update_start(0);\r
167    bcm_element=vc_dispmanx_element_add(bcm_update,bcm_display,\r
168          2,&dst_rect, 0,\r
169          &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);\r
170 \r
171 \r
172  /*  bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display,\r
173             0,&dst_rect,bcm_backres ,\r
174             &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);*/\r
175 \r
176    vc_dispmanx_update_submit_sync(bcm_update);\r
177 \r
178 \r
179 \r
180    static EGL_DISPMANX_WINDOW_T nativewindow;\r
181    nativewindow.element=bcm_element;\r
182    nativewindow.height=BACKBUFFER_HEIGHT;\r
183    nativewindow.width=BACKBUFFER_WIDTH;\r
184 \r
185    egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );\r
186    if (egl_surface==EGL_NO_SURFACE) {\r
187            Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");\r
188            vgmutex.Unlock();\r
189            return 0;\r
190    }\r
191    Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d",syscall(SYS_gettid));\r
192    if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {\r
193            Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");\r
194            vgmutex.Unlock();\r
195                    return 0;\r
196    }\r
197    // Test stuff\r
198 \r
199    query_str=(const char*)vgGetString(VG_VERSION) ;\r
200    if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
201    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());\r
202 \r
203    query_str=(const char*)vgGetString(VG_VENDOR) ;\r
204    if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
205    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());\r
206 \r
207    query_str=(const char*)vgGetString(VG_RENDERER) ;\r
208    if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
209    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());\r
210 \r
211    query_str=(const char*)vgGetString(VG_EXTENSIONS) ;\r
212    if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);\r
213    else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());\r
214 \r
215   aspect_correction= ((float)BACKBUFFER_HEIGHT)/576.f/(((float)BACKBUFFER_WIDTH)/720.f);\r
216   initPaths();\r
217   if (!loadFont()) {\r
218           return 0;\r
219   }\r
220   vgttfont=vgCreateFont(0);\r
221   vgttpaint=vgCreatePaint();\r
222   vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);\r
223   vgSetColor(vgttpaint,0xffffffff);\r
224 \r
225   eglSwapInterval(egl_display, 1 );\r
226 \r
227   Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d",syscall(SYS_gettid));\r
228   eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );\r
229   //Now we will create the Screen\r
230   initted = 1; // must set this here or create surface won't work\r
231 \r
232 \r
233   /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init  stuff\r
234           return 0;\r
235   }*/\r
236   InitializeMagick("");\r
237 \r
238   pthread_cond_init(&vgtaskCond, NULL);\r
239   pthread_mutex_init(&vgtaskCondMutex, NULL);\r
240 \r
241   threadStart();\r
242   taskmutex.Unlock();\r
243   vgmutex.Unlock();\r
244 \r
245 \r
246   return 1;\r
247 }\r
248 \r
249 \r
250 void OsdOpenVG::initPaths()\r
251 {\r
252 \r
253 \r
254         VGPath current;\r
255         current=vgCreatePath(VG_PATH_FORMAT_STANDARD,\r
256                         VG_PATH_DATATYPE_F,1.f,0.f,\r
257                         0,0,VG_PATH_CAPABILITY_ALL);\r
258 \r
259         vguLine(current,0.f,0.f,1.f,0.f);\r
260         // HorzLine\r
261         std_paths[HorzLine]=current;\r
262 \r
263         current=vgCreatePath(VG_PATH_FORMAT_STANDARD,\r
264                                 VG_PATH_DATATYPE_F,1.f,0.f,\r
265                                 0,0,VG_PATH_CAPABILITY_ALL);\r
266         vguLine(current,0.f,0.f,0.f,1.f);\r
267         // VertLine\r
268         std_paths[VertLine]=current;\r
269 \r
270         current=vgCreatePath(VG_PATH_FORMAT_STANDARD,\r
271                                 VG_PATH_DATATYPE_F,1.f,0.f,\r
272                                 0,0,VG_PATH_CAPABILITY_ALL);\r
273         //vguRect(current,0.f,0.f,1.f,1.f);\r
274         vguRect(current,0.f,0.f,1.f,1.f);\r
275         // Rectabgle\r
276         std_paths[Rectangle]=current;\r
277 \r
278         current=vgCreatePath(VG_PATH_FORMAT_STANDARD,\r
279                                 VG_PATH_DATATYPE_F,1.f,0.f,\r
280                                 0,0,0);\r
281         vguEllipse(current,0.f,0.f,1.f,1.f);\r
282         // Point\r
283         std_paths[Point]=current;\r
284 \r
285 }\r
286 \r
287 void OsdOpenVG::destroyPaths()\r
288 {\r
289         vgDestroyPath(std_paths[HorzLine]);\r
290         vgDestroyPath(std_paths[VertLine]);\r
291         vgDestroyPath(std_paths[Rectangle]);\r
292         vgDestroyPath(std_paths[Point]);\r
293 \r
294 }\r
295 \r
296 int OsdOpenVG::stopUpdate()\r
297 {\r
298         threadStop();\r
299         processTasks();\r
300         return 1;\r
301 }\r
302 \r
303 \r
304 int OsdOpenVG::shutdown()\r
305 {\r
306   if (!initted) return 0;\r
307 \r
308   initted = 0;\r
309   Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");\r
310   threadStop();\r
311   Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");\r
312   processTasks();\r
313   Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");\r
314 \r
315   taskmutex.Lock();\r
316   vgmutex.Lock();\r
317   //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());\r
318 \r
319   FT_Done_Face(ft_face);\r
320   vgDestroyFont(vgfont);\r
321   vgDestroyFont(vgttfont);\r
322   vgDestroyPaint(vgttpaint);\r
323   destroyPaths();\r
324   vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);\r
325   eglSwapBuffers(egl_display, egl_surface);\r
326   Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");\r
327   eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );\r
328   eglDestroySurface(egl_display,egl_surface);\r
329   eglDestroyContext(egl_display,egl_context);\r
330   eglTerminate(egl_display );\r
331 \r
332   DISPMANX_UPDATE_HANDLE_T  bcm_update;\r
333   bcm_update=vc_dispmanx_update_start(0);\r
334 \r
335   vc_dispmanx_element_remove(bcm_update,bcm_element);\r
336 //  vc_dispmanx_element_remove(bcm_update,bcm_background);\r
337   vc_dispmanx_update_submit_sync(bcm_update);\r
338 //  vc_dispmanx_resource_delete(bcm_backres);\r
339   vc_dispmanx_display_close(bcm_display);\r
340 \r
341 \r
342 \r
343   return 1;\r
344 }\r
345 \r
346 \r
347 \r
348 \r
349 void OsdOpenVG::threadMethod()\r
350 {\r
351         // We have to claim the egl context for this thread\r
352 \r
353         if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {\r
354                 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x",eglGetError());\r
355                 return;\r
356         }\r
357         int ts=0;\r
358         while (true)\r
359         {\r
360                 ts=1;\r
361                 unsigned int waittime=1;\r
362 \r
363                 if (initted) {\r
364 \r
365                         long long time1 = getTimeMS();\r
366                         if ((time1 - lastrendertime) > 200) {//5 fps for OSD updates are enough, avoids tearing\r
367                                 InternalRendering();\r
368                                 lastrendertime = getTimeMS();\r
369 \r
370                         }\r
371                         if (processTasks()) ts=0;\r
372                 }\r
373                 threadCheckExit();\r
374                 if (ts!=0) {\r
375                         struct timespec target_time;\r
376                         clock_gettime(CLOCK_REALTIME,&target_time);\r
377                         target_time.tv_nsec+=1000000LL*ts;\r
378                         if (target_time.tv_nsec>999999999) {\r
379                                 target_time.tv_nsec-=1000000000L;\r
380                                 target_time.tv_sec+=1;\r
381                         }\r
382                         threadLock();\r
383                         threadWaitForSignalTimed(&target_time);\r
384                         threadUnlock();\r
385                 }\r
386                 //Sleep(1);\r
387         }\r
388         //eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );\r
389 }\r
390 \r
391 \r
392 void OsdOpenVG::threadPostStopCleanup()\r
393 {\r
394         //Doing nothing\r
395         //goo;\r
396 }\r
397 \r
398 \r
399 \r
400 \r
401 \r
402 \r
403 void OsdOpenVG::InternalRendering(){\r
404         vgmutex.Lock();\r
405     float colclear[]={1.f,1.0f,1.f,1.f};\r
406     vgSetfv(VG_CLEAR_COLOR,4,colclear);\r
407         vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);\r
408         vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);\r
409 \r
410 \r
411         drawSurfaces(); //iterate through and draws all commands\r
412 \r
413         //Show it to the user!\r
414         eglSwapBuffers(egl_display, egl_surface);\r
415         vgmutex.Unlock();\r
416 \r
417 }\r
418 \r
419 /*font stuff*/\r
420 \r
421 float OsdOpenVG::getFontHeight()\r
422 {\r
423         return font_height; //dummy\r
424 }\r
425 float OsdOpenVG::getCharWidth(wchar_t c)\r
426 {\r
427         unsigned int glyph_index=FT_Get_Char_Index(ft_face,c);\r
428         return font_exp_x[glyph_index];\r
429 }\r
430 \r
431 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)\r
432 {\r
433         unsigned int glyph_index=c.getGlyphIndex();\r
434         if (tt_font_chars.find(glyph_index)!=tt_font_chars.end())\r
435         {\r
436                 return glyph_index;\r
437         }\r
438 \r
439         unsigned int buffer[10];\r
440         const VGfloat glyphOrigin[] = { 0.f, 0.f };\r
441         const VGfloat escapement[] = { 12.f, 0.f };\r
442         unsigned int * charmap = GetFontChar(c, buffer);\r
443         if (!charmap) { //invalid char\r
444                 return 0;\r
445         }\r
446         for (int i=0;i<10;i++) {\r
447                 buffer[i]=charmap[i]>>4;\r
448         }\r
449 \r
450         VGImage handle = vgCreateImage(\r
451                         VG_A_8,\r
452                         12,\r
453                         10,\r
454                         VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER\r
455                                         | VG_IMAGE_QUALITY_BETTER);\r
456         vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);\r
457         vgSetGlyphToImage(\r
458                         vgttfont,\r
459                         glyph_index,\r
460                         handle, glyphOrigin, escapement);\r
461         vgDestroyImage(handle);\r
462         tt_font_chars[glyph_index]=1;\r
463 \r
464         return glyph_index;\r
465 }\r
466 \r
467 int  OsdOpenVG::loadFont()\r
468 {\r
469         int error=FT_Init_FreeType(&ft_library);\r
470         float font_size=16.f;\r
471         if (error)\r
472         {\r
473                 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x",error);\r
474                 return 0;\r
475         }\r
476 \r
477         error=FT_New_Memory_Face(ft_library,font_data,font_data_end-font_data,0,&ft_face );\r
478         if (error) {\r
479                 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x",error);\r
480                 return 0;\r
481         }\r
482         error=FT_Set_Char_Size(ft_face,0,font_size*64,0,0 /*dpi*/);\r
483         if (error) {\r
484                 FT_Done_Face(ft_face);\r
485                 Log::getInstance()->log("OSD", Log::WARN, "Could not set  face size %x",error);\r
486                 return 0;\r
487         }\r
488         vgfont=vgCreateFont(0);\r
489         FT_ULong cur_char;\r
490         FT_UInt glyph;\r
491         font_height=ft_face->size->metrics.height/64.f;\r
492         cur_char = FT_Get_First_Char(ft_face,&glyph);\r
493         vector<VGubyte> segments;\r
494         vector<VGfloat> coord;\r
495         segments.reserve(256);\r
496         coord.reserve(1024);\r
497         //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);\r
498         while (glyph !=0)\r
499         {\r
500                 error=FT_Load_Glyph(ft_face,glyph,FT_LOAD_DEFAULT);\r
501                 if (error){\r
502                         FT_Done_Face(ft_face);\r
503                         Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x",error);\r
504                         return 0;\r
505                 }\r
506                 VGPath path;\r
507                 FT_Outline ot=ft_face->glyph->outline;\r
508                 segments.clear();\r
509                 coord.clear();\r
510 \r
511                 if (ot.n_contours ==0) {\r
512                         path=VG_INVALID_HANDLE;\r
513                 } else {\r
514                         path=vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,\r
515                                         1.0f,0.f,0,0,VG_PATH_CAPABILITY_ALL);\r
516 \r
517                         /* convert glyph */\r
518                         FT_Vector *pt=ot.points;\r
519                         const char *tags=ot.tags;\r
520                         const short* cont=ot.contours;\r
521                         short n_cont=ot.n_contours;\r
522                         short n_point=ot.n_points;\r
523                         short last_cont=0;\r
524                         for (short point=0;n_cont!=0;cont++,n_cont--) {\r
525                                 short next_cont=*cont+1;\r
526                                 bool first=true;\r
527                                 char last_tag=0;\r
528                                 short first_point=point;\r
529                                 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);\r
530                                 for (;point<next_cont;point++) {\r
531                                         char tag=tags[point];\r
532                                         FT_Vector fpoint=pt[point];\r
533                                 //      Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);\r
534                                         if (first) {\r
535                                                 segments.push_back(VG_MOVE_TO);\r
536                                                 first=false;\r
537                                         } else if (tag &0x1) { //on curve\r
538                                                 if (last_tag &0x1) {\r
539                                                         segments.push_back(VG_LINE_TO);\r
540                                                 } else if (last_tag &0x2){\r
541                                                         segments.push_back(VG_CUBIC_TO);\r
542                                                 } else {\r
543                                                         segments.push_back(VG_QUAD_TO);\r
544                                                 }\r
545 \r
546                                         } else {\r
547                                                 if (!(tag &0x2)){\r
548                                                         if (!(last_tag &0x1)) {\r
549                                                                 segments.push_back(VG_QUAD_TO);\r
550                                                                 int coord_size=coord.size();\r
551                                                                 VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/64.f)*0.5f*aspect_correction;\r
552                                                                 VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/64.f))*0.5f;\r
553                                                                 coord.push_back(x);\r
554                                                                 coord.push_back(y);\r
555                                                         }\r
556                                                 }\r
557 \r
558 \r
559                                         }\r
560                                         last_tag=tag;\r
561                                         coord.push_back(((float)fpoint.x)*aspect_correction/64.);\r
562                                         coord.push_back(font_size-((float)fpoint.y)/64.);\r
563                                         //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph coord %d %d %g %g",fpoint.x,fpoint.y,coord[coord.size()-2],coord[coord.size()-1]);\r
564                                 }\r
565                                 if (!(last_tag &0x1)) {\r
566                                         if (last_tag &0x2) {\r
567                                                 segments.push_back(VG_CUBIC_TO);\r
568                                         } else {\r
569                                                 segments.push_back(VG_QUAD_TO);\r
570                                         }\r
571                                         coord.push_back(((float)pt[first_point].x)*aspect_correction/64.);\r
572                                         coord.push_back(font_size-((float)pt[first_point].y)/64.);\r
573                                 }\r
574                                 //segments.push_back(VG_CLOSE_PATH);\r
575 \r
576 \r
577                         }\r
578                         vgAppendPathData(path,segments.size(),&segments[0],&coord[0]);\r
579                         int n=0;\r
580                 /*      for (int m=0;m<segments.size();m++) {\r
581                                 switch (segments[m])\r
582                                 {\r
583                                 case VG_MOVE_TO:\r
584                                         Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;\r
585                                 case VG_LINE_TO:\r
586                                         Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;\r
587                                 case VG_CUBIC_TO:\r
588                                         Log::getInstance()->log("OSD", Log::DEBUG, "Cubic To %g %g %g %g %g %g",coord[n],coord[n+1],coord[n+2],coord[n+3],coord[n+4],coord[n+5]);n+=6; break;\r
589                                 case VG_QUAD_TO:\r
590                                         Log::getInstance()->log("OSD", Log::DEBUG, "Quad To %g %g %g %g",coord[n],coord[n+1],coord[n+2],coord[n+3]);n+=4; break;\r
591                                 case VG_CLOSE_PATH:\r
592                                         Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;\r
593                                 }\r
594 \r
595                         }*/\r
596                         //vguRect(path,0.f,0.f,1.f,1.f);\r
597                         //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());\r
598                 }\r
599                 VGfloat ori[]={0.f,0.f};\r
600                 VGfloat esp[]={ft_face->glyph->advance.x/64.f*aspect_correction,ft_face->glyph->advance.y/64.f};\r
601                 font_exp_x[glyph]=ft_face->glyph->advance.x/64.f*aspect_correction; //recalculate\r
602 \r
603                 vgSetGlyphToPath(vgfont,glyph,path,VG_FALSE,ori,esp);\r
604                 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());\r
605                 if (path!=VG_INVALID_HANDLE) {\r
606                         vgDestroyPath(path);\r
607                 }\r
608                 cur_char = FT_Get_Next_Char(ft_face,cur_char,&glyph);\r
609         }\r
610         return 1;\r
611 }\r
612 \r
613 \r
614 void OsdOpenVG::drawSetTrans(SurfaceCommands & sc)\r
615 {\r
616         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);\r
617         vgLoadIdentity();\r
618         vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);\r
619         vgTranslate(0.f+sc.x,-576.f+sc.y);\r
620 \r
621         vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);\r
622         vgLoadIdentity();\r
623     vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);\r
624         vgTranslate(0.f+sc.x,-576.f+sc.y);\r
625 \r
626         vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);\r
627         vgLoadIdentity();\r
628         vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);\r
629         vgTranslate(0.f+sc.x,-576.f+sc.y);\r
630 \r
631 \r
632 \r
633         //vgTranslate(0.f+sc.x,576.f-sc.y);\r
634         //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);\r
635 \r
636 }\r
637 void OsdOpenVG::executeDrawCommand(SVGCommand & command)\r
638 {\r
639 \r
640         VGfloat  save_matrix[9];\r
641         switch (command.instr) {\r
642         case DrawPath: {\r
643         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);\r
644         //      VGuint rgba;\r
645         //      rgba = vgGetColor((VGPaint) command.reference);\r
646                 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Path %d %x %g %g %g %g",command.reference,command.target.path_index,command.x,command.y,command.w,command.h);\r
647                 //vgSeti(VG_FILL_RULE,);\r
648 \r
649                 vgGetMatrix(save_matrix);\r
650                 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);\r
651                 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);\r
652                 vgTranslate(command.x,command.y);\r
653                 vgScale(command.w,command.h);\r
654                 vgDrawPath(std_paths[command.target.path_index],VG_FILL_PATH);\r
655                 vgLoadMatrix(save_matrix);\r
656         } break;\r
657         case DrawImage: {\r
658             vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);\r
659                 vgGetMatrix(save_matrix);\r
660                 vgTranslate(command.x,command.y);\r
661                 //vgScale(command.w,command.h);\r
662                 if (command.reference) { //special behaviout for bw images they act as a mask on the current paint\r
663                         vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);\r
664                         vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);\r
665                         vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);\r
666                         vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);\r
667                         vgScale(aspect_correction,1.f);\r
668                 } else {\r
669                         VGfloat imagewidth=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);\r
670                         VGfloat imageheight=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);\r
671                         //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));\r
672                         float scalex=command.w/imagewidth;\r
673                         float scaley=command.h/imageheight;\r
674                         //vgScale(command.w/imagewidth,command.h/imageheight);\r
675                         vgScale(scalex,scaley);\r
676                         vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);\r
677                         //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image Scale  %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);\r
678                 }\r
679 \r
680 \r
681                 //vgLoadIdentity();\r
682                 //vgTranslate(200.f,500.f);\r
683                 //vgScale(100.f,100.f);\r
684 \r
685                 vgDrawImage((VGImage) command.target.image);\r
686                 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image %d %x %g %g %g %g %x",command.reference,command.target.image,command.x,command.y,command.w,command.h,\r
687                 //              vgGetError());\r
688                 if (command.reference) {\r
689                         vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);\r
690                         vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);\r
691                 }\r
692                 vgLoadMatrix(save_matrix);\r
693         } break;\r
694         case DrawGlyph: {\r
695                 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);\r
696                 vgGetMatrix(save_matrix);\r
697                 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);\r
698                 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);\r
699                 vgTranslate(command.x,command.y);\r
700                 VGfloat gori[]={0.,0.};\r
701                 vgSetfv(VG_GLYPH_ORIGIN,2,gori);\r
702 \r
703                 unsigned int glyph_index=FT_Get_Char_Index(ft_face,command.target.textchar);\r
704                 vgDrawGlyph(vgfont,glyph_index,VG_FILL_PATH,VG_FALSE);\r
705                 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);\r
706         /*      Log::getInstance()->log("OSD", Log::DEBUG, "Draw Glyph %d %c %d %g %g %x",command.reference,command.target.textchar,glyph_index,command.x,command.y,\r
707                                                 vgGetError());*/\r
708                 vgLoadMatrix(save_matrix);\r
709                 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);\r
710         } break;\r
711         case DrawTTchar:{\r
712                 cTeletextChar tchar;\r
713                 tchar.setInternal(command.target.ttchar);\r
714                 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);\r
715                 vgGetMatrix(save_matrix);\r
716                 enumTeletextColor ttforegcolour=tchar.GetFGColor();\r
717                 enumTeletextColor ttbackgcolour=tchar.GetBGColor();\r
718             if (tchar.GetBoxedOut()) {\r
719                 ttforegcolour=ttcTransparent;\r
720                 ttbackgcolour=ttcTransparent;\r
721             }\r
722             vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);\r
723             vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);\r
724 \r
725 \r
726                 vgTranslate(command.x+command.w*11.85f*1.4f,command.y+command.h*19.75f);\r
727                 VGfloat gori[]={0.,0.};\r
728                 vgSetfv(VG_GLYPH_ORIGIN,2,gori);\r
729 \r
730                 vgScale(-1.4f,2.f);\r
731                 unsigned int color=Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();\r
732                 color=color<<8 | (color &0xff000000)>>24;\r
733                 vgSetColor(vgttpaint,color);\r
734                 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);\r
735                 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);\r
736                 cTeletextChar filled;\r
737                 filled.setInternal(0x187f);\r
738                 unsigned int glyph_index=loadTTchar(filled);\r
739                 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);\r
740 \r
741                 color=Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();\r
742                 color=color<<8 | (color &0xff000000)>>24;\r
743                 vgSetColor(vgttpaint,color);\r
744                 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);\r
745                 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);\r
746                 glyph_index=loadTTchar(tchar);\r
747                 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);\r
748 \r
749                 /*      Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),\r
750                                         vgGetColor(vgttpaint));*/\r
751 \r
752 \r
753                 vgLoadMatrix(save_matrix);\r
754                 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);\r
755                 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);\r
756                 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);\r
757 \r
758         }break;\r
759         }\r
760 }\r
761 \r
762 unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)\r
763 {\r
764         switch (command.task){\r
765         case OVGdestroyImageRef: {\r
766                 vgDestroyImage((VGImage)command.param1);\r
767                 return 0;\r
768         } break;\r
769         case OVGdestroyPaint: {\r
770                 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);\r
771                 vgDestroyPaint((VGPaint)command.param1);\r
772                 return 0;\r
773         } break;\r
774         case OVGcreateImagePalette: {\r
775                 VGImage input=vgCreateImage(VG_A_8,command.param1, command.param2,\r
776                                 VG_IMAGE_QUALITY_NONANTIALIASED|\r
777                                 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);\r
778                 vgImageSubData(input,command.data,command.param1,\r
779                                                         VG_A_8,0,0,command.param1, command.param2); // upload palettized image data\r
780                 VGImage handle=vgCreateImage(VG_sRGBA_8888,command.param1, command.param2,\r
781                                                 VG_IMAGE_QUALITY_NONANTIALIASED|\r
782                                                 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);\r
783                 VGuint *palette=(VGuint*)malloc(256*sizeof(VGuint));\r
784                 VGuint *in_palette=(VGuint*)command.data2;\r
785                 for (int i=0;i<256;i++) {\r
786                         VGuint color=in_palette[i];\r
787                         palette[i]=color<<8 | (color &0xff000000)>>24;\r
788                 }\r
789 \r
790                 vgLookupSingle(handle,input,palette,VG_ALPHA,VG_FALSE,VG_FALSE);\r
791                 free(palette);\r
792                 vgDestroyImage(input);\r
793 \r
794                 return handle;\r
795         } break;\r
796         case OVGcreateMonoBitmap: {\r
797                 VGImage handle=vgCreateImage(VG_A_1,command.param1, command.param2,\r
798                                         VG_IMAGE_QUALITY_NONANTIALIASED|\r
799                                         VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);\r
800                 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono  %d %d %x %d",command.param1,command.param2,vgGetError(),handle);\r
801                 unsigned int buffer_len=(command.param1*command.param2)>>3;\r
802                 unsigned char * buffer=(unsigned char*)malloc(buffer_len);\r
803                 unsigned char * r_buffer1=buffer;\r
804                 const unsigned char * r_buffer2=(const unsigned char *)command.data;\r
805                 unsigned char *buffer_end=buffer+buffer_len;\r
806                 while (r_buffer1!=buffer_end) {\r
807                         unsigned char byte=*r_buffer2;\r
808                         *r_buffer1=((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;\r
809                         r_buffer1++;r_buffer2++;\r
810                 }\r
811 \r
812 \r
813                 vgImageSubData(handle,buffer,command.param1>>3,\r
814                                         VG_A_1,0,0,command.param1, command.param2);\r
815                 free(buffer);\r
816         //      Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2  %d %d %x %d",command.param1,command.param2,vgGetError(),handle);\r
817                 return handle;\r
818         } break;\r
819         case OVGcreateImageFile: {\r
820                 VGImage handle;\r
821                 try{\r
822                         Image *imagefile=(Image*)command.data;\r
823                         Blob imageblob;\r
824                         imagefile->write(&imageblob,"RGBA");\r
825 \r
826 \r
827                         handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),\r
828                                         VG_IMAGE_QUALITY_NONANTIALIASED|\r
829                                         VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);\r
830                 //      Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details  %d %d %x mark1",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());\r
831                         vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,\r
832                                         VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());\r
833                 //      Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details  %d %d %x mark2",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());\r
834                         delete imagefile;\r
835                 }catch( Exception &error_ )\r
836                 {\r
837                         Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());\r
838 \r
839                         return 0;\r
840                 }\r
841 \r
842                 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file  %d %d %x %d",command.param1,command.param2,vgGetError(),handle);\r
843                 return handle;\r
844         } break;\r
845         case OVGcreateColorRef :{\r
846                 VGPaint handle;\r
847                 handle=vgCreatePaint();\r
848                 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);\r
849                 vgSetColor(handle,command.param1);\r
850                 VGuint rgba;\r
851                 rgba = vgGetColor((VGPaint)handle);\r
852                 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);\r
853                 return handle;\r
854         } break;\r
855         case OVGimageUploadLine: {\r
856                 vgImageSubData((VGImage)command.param1,command.data,0,VG_sARGB_8888,0,command.param2,command.param3,1);\r
857                 return 0;\r
858         } break;\r
859 \r
860         }\r
861 }\r
862 \r
863 bool OsdOpenVG::processTasks()\r
864 {\r
865         bool worked=false;\r
866         taskmutex.Lock();\r
867         vgmutex.Lock();\r
868         while (vgcommands.size()>0)\r
869         {\r
870                 OpenVGCommand &comm=vgcommands.front();\r
871                 OpenVGResponse resp;\r
872                 resp.result=handleTask(comm);\r
873                 resp.id=comm.id;\r
874                 if (comm.id) {\r
875                         vgresponses.push_back(resp);\r
876                 }\r
877                 vgcommands.pop_front();\r
878                 taskmutex.Unlock();\r
879                 vgmutex.Unlock();\r
880                 //threadCheckExit();\r
881                 pthread_mutex_lock(&vgtaskCondMutex);\r
882                 pthread_cond_signal(&vgtaskCond);\r
883                 pthread_mutex_unlock(&vgtaskCondMutex);\r
884                 taskmutex.Lock();\r
885                 vgmutex.Lock();\r
886                 worked=true;\r
887         }\r
888         taskmutex.Unlock();\r
889         vgmutex.Unlock();\r
890 \r
891         return worked;\r
892 }\r
893 \r
894 bool OsdOpenVG::haveOpenVGResponse(unsigned int id,unsigned int * resp)\r
895 {\r
896         taskmutex.Lock();\r
897         if (vgresponses.size()>0)\r
898         {\r
899                 deque<OpenVGResponse>::iterator itty=vgresponses.begin();\r
900                 while (itty!=vgresponses.end())\r
901                 {\r
902                         if ((*itty).id==id) {\r
903                                 *resp=(*itty).result;\r
904                                 taskmutex.Unlock();\r
905                                 return true;\r
906                         }\r
907                         itty++;\r
908                 }\r
909         }\r
910         taskmutex.Unlock();\r
911         return false;\r
912 }\r
913 \r
914 \r
915 unsigned int  OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm,bool wait)\r
916 {\r
917         taskmutex.Lock();\r
918         if (wait){\r
919                 comm.id=wait_id;\r
920                 wait_id++;\r
921         } else {\r
922                 comm.id=0; // we are not waiting\r
923         }\r
924         vgcommands.push_back(comm);\r
925         taskmutex.Unlock();\r
926         threadSignal();\r
927         while (wait) {\r
928                 unsigned int resp;\r
929                 if (!haveOpenVGResponse(comm.id,&resp)) {\r
930                         struct timespec target_time;\r
931                         clock_gettime(CLOCK_REALTIME,&target_time);\r
932                         target_time.tv_nsec+=1000000LL*100;\r
933                         if (target_time.tv_nsec>999999999) {\r
934                                         target_time.tv_nsec-=1000000000L;\r
935                                         target_time.tv_sec+=1;\r
936                         }\r
937                         pthread_mutex_lock(&vgtaskCondMutex);\r
938                         pthread_cond_timedwait(&vgtaskCond, &vgtaskCondMutex,&target_time);\r
939                         pthread_mutex_unlock(&vgtaskCondMutex);\r
940                 } else {\r
941                         return resp;\r
942                 }\r
943         }\r
944         return 0;\r
945 }\r
946 \r
947 void OsdOpenVG::imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)\r
948 {\r
949         vgImageSubData((VGImage)index,data,0,VG_sARGB_8888,0,j,width,1);\r
950 \r
951         struct OpenVGCommand comm;\r
952         comm.task=OVGimageUploadLine;\r
953         comm.param1=index;\r
954         comm.param2=j;\r
955         comm.param3=width;\r
956         comm.data=data;\r
957         putOpenVGCommand(comm,true);\r
958 }\r
959 \r
960 void OsdOpenVG::destroyImageRef(ImageIndex index)\r
961 {\r
962         struct OpenVGCommand comm;\r
963         comm.task=OVGdestroyImageRef;\r
964         comm.param1=index;\r
965         putOpenVGCommand(comm,false);\r
966 }\r
967 \r
968 ImageIndex OsdOpenVG::createJpeg(const char* fileName, int *width,int *height)\r
969 {\r
970         Image* magicimage=NULL;\r
971         bool mem=false;\r
972         struct OpenVGCommand comm;\r
973         comm.task=OVGcreateImageFile;\r
974 \r
975         try{\r
976                 // Now figure out, if it is a special case\r
977                 if (strcmp(fileName,"/vdr.jpg")==0) {\r
978                         magicimage=new Image(Blob(vdr_data,vdr_data_end-vdr_data));\r
979                         *height=100; // this is faked so that the system does use the old coordinate system\r
980                         *width=ceil(190.f*aspect_correction);\r
981                         Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm vdr.jpg");\r
982                 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {\r
983                         magicimage=new Image(Blob(wallpaper_data,wallpaper_data_end-wallpaper_data));\r
984                         *width=720; // this is faked so that the system does use the old coordinate system\r
985                         *height=576;\r
986                         Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm wallpaperPAL.jpg");\r
987                 } else {\r
988                         magicimage=new Image();\r
989                         magicimage->read(fileName);\r
990                         Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm file: %s",fileName);\r
991                         *width=ceil(magicimage->baseColumns()*aspect_correction); // this is faked so that the system does use the old coordinate system\r
992                         *height=magicimage->baseRows();\r
993                 }\r
994 \r
995         }catch( Exception &error_ )\r
996         {\r
997                 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick: %s",error_.what());\r
998 \r
999                 return 0;\r
1000         }\r
1001         comm.data=magicimage;\r
1002         return putOpenVGCommand(comm,true);\r
1003 }\r
1004 \r
1005 ImageIndex OsdOpenVG::createMonoBitmap(void *base,int width,int height)\r
1006 {\r
1007         struct OpenVGCommand comm;\r
1008         comm.task=OVGcreateMonoBitmap;\r
1009         comm.param1=width;\r
1010         comm.param2=height;\r
1011         comm.data=base;\r
1012         return putOpenVGCommand(comm,true);\r
1013 }\r
1014 \r
1015 ImageIndex OsdOpenVG::createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)\r
1016 {\r
1017     struct OpenVGCommand comm;\r
1018     comm.task=OVGcreateImagePalette;\r
1019     comm.param1=width;\r
1020     comm.param2=height;\r
1021     comm.data=image_data;\r
1022     comm.data2=palette_data;\r
1023     return putOpenVGCommand(comm,true);\r
1024 }\r
1025 \r
1026 void OsdOpenVG::destroyStyleRef(unsigned int index)\r
1027 {\r
1028         struct OpenVGCommand comm;\r
1029         comm.task=OVGdestroyPaint;\r
1030         comm.param1=index;\r
1031         putOpenVGCommand(comm,false);\r
1032 }\r
1033 \r
1034 unsigned int OsdOpenVG::createStyleRef(const DrawStyle &c)\r
1035 {\r
1036         unsigned int col=c.rgba();\r
1037         struct OpenVGCommand comm;\r
1038         comm.task=OVGcreateColorRef;\r
1039         comm.param1=col<<8 | (col &0xff000000)>>24;\r
1040         comm.data=&c;\r
1041         return putOpenVGCommand(comm,true);\r
1042 }\r
1043 \r
1044 unsigned int OsdOpenVG::createColorRef(const Colour &c)\r
1045 {\r
1046         unsigned int col=c.rgba();\r
1047         struct OpenVGCommand comm;\r
1048         comm.task=OVGcreateColorRef;\r
1049         comm.param1=col<<8 | (col &0xff000000)>>24;\r
1050         comm.data=&c;\r
1051         return putOpenVGCommand(comm,true);\r
1052 }\r
1053 \r
1054 \r