vdr 2.7.5
hdffosd.c
Go to the documentation of this file.
1/*
2 * hdffosd.c: Implementation of the DVB HD Full Featured On Screen Display
3 *
4 * See the README file for copyright information and how to reach the author.
5 */
6
7#include "hdffosd.h"
8#include <linux/dvb/osd.h>
9#include <sys/ioctl.h>
10#include <sys/time.h>
11#include "hdffcmd.h"
12#include "setup.h"
13
14#define MAX_NUM_FONTFACES 8
15#define MAX_NUM_FONTS 8
16#define MAX_BITMAP_SIZE (1024*1024)
17
18typedef struct _tFontFace
19{
21 uint32_t Handle;
23
24typedef struct _tFont
25{
26 uint32_t hFontFace;
27 int Size;
28 uint32_t Handle;
30
31class cHdffOsd : public cOsd
32{
33private:
35 int mLeft;
36 int mTop;
40 uint32_t mDisplay;
44 uint32_t mBitmapColors[256];
45
47
48protected:
49 virtual void SetActive(bool On);
50public:
51 cHdffOsd(int Left, int Top, HDFF::cHdffCmdIf * pHdffCmdIf, uint Level);
52 virtual ~cHdffOsd();
53 virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas);
54 virtual eOsdError SetAreas(const tArea *Areas, int NumAreas);
55 virtual void SaveRegion(int x1, int y1, int x2, int y2);
56 virtual void RestoreRegion(void);
57 virtual void DrawPixel(int x, int y, tColor Color);
58 virtual void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool ReplacePalette = false, bool Overlay = false);
59 virtual void DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width = 0, int Height = 0, int Alignment = taDefault);
60 virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color);
61 virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0);
62 virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type);
63 virtual void Flush(void);
64};
65
66cHdffOsd::cHdffOsd(int Left, int Top, HDFF::cHdffCmdIf * pHdffCmdIf, uint Level)
67: cOsd(Left, Top, Level)
68{
69 double pixelAspect;
70 HdffOsdConfig_t config;
71
72 //printf("cHdffOsd %d, %d, %d\n", Left, Top, Level);
73 mHdffCmdIf = pHdffCmdIf;
74 mLeft = Left;
75 mTop = Top;
76 mChanged = false;
78
79 mSupportsUtf8Text = false;
80 if (mHdffCmdIf->CmdGetFirmwareVersion(NULL, 0) >= 0x309)
81 mSupportsUtf8Text = true;
82
83 memset(&config, 0, sizeof(config));
84 config.FontKerning = true;
85 config.FontAntialiasing = Setup.AntiAlias ? true : false;
86 mHdffCmdIf->CmdOsdConfigure(&config);
87
88 gHdffSetup.GetOsdSize(mDispWidth, mDispHeight, pixelAspect);
90 mHdffCmdIf->CmdOsdSetDisplayOutputRectangle(mDisplay, 0, 0, HDFF_SIZE_FULL_SCREEN, HDFF_SIZE_FULL_SCREEN);
91 for (int i = 0; i < MAX_NUM_FONTFACES; i++)
92 {
93 mFontFaces[i].Name = "";
95 }
96 for (int i = 0; i < MAX_NUM_FONTS; i++)
97 {
98 mFonts[i].hFontFace = HDFF_INVALID_HANDLE;
99 mFonts[i].Size = 0;
100 mFonts[i].Handle = HDFF_INVALID_HANDLE;
101 }
102}
103
105{
106 //printf("~cHdffOsd %d %d\n", mLeft, mTop);
107 if (Active()) {
108 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
109 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
110 }
111 SetActive(false);
112
113 for (int i = 0; i < MAX_NUM_FONTS; i++)
114 {
115 if (mFonts[i].Handle == HDFF_INVALID_HANDLE)
116 break;
117 mHdffCmdIf->CmdOsdDeleteFont(mFonts[i].Handle);
118 }
119 for (int i = 0; i < MAX_NUM_FONTFACES; i++)
120 {
121 if (mFontFaces[i].Handle == HDFF_INVALID_HANDLE)
122 break;
123 mHdffCmdIf->CmdOsdDeleteFontFace(mFontFaces[i].Handle);
124 }
125
127 mHdffCmdIf->CmdOsdDeletePalette(mBitmapPalette);
128 mHdffCmdIf->CmdOsdDeleteDisplay(mDisplay);
129}
130
131eOsdError cHdffOsd::CanHandleAreas(const tArea *Areas, int NumAreas)
132{
133 eOsdError Result = cOsd::CanHandleAreas(Areas, NumAreas);
134 if (Result == oeOk)
135 {
136 for (int i = 0; i < NumAreas; i++)
137 {
138 if (Areas[i].bpp != 1 && Areas[i].bpp != 2 && Areas[i].bpp != 4 && Areas[i].bpp != 8)
139 return oeBppNotSupported;
140 }
141 }
142 return Result;
143}
144
145eOsdError cHdffOsd::SetAreas(const tArea *Areas, int NumAreas)
146{
147 eOsdError error;
148 cBitmap * bitmap;
149
150 for (int i = 0; i < NumAreas; i++)
151 {
152 //printf("SetAreas %d: %d %d %d %d %d\n", i, Areas[i].x1, Areas[i].y1, Areas[i].x2, Areas[i].y2, Areas[i].bpp);
153 }
155 {
156 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
157 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
158 }
159 error = cOsd::SetAreas(Areas, NumAreas);
160
161 for (int i = 0; (bitmap = GetBitmap(i)) != NULL; i++)
162 {
163 bitmap->Clean();
164 }
165
166 return error;
167}
168
170{
171 if (On != Active())
172 {
173 cOsd::SetActive(On);
174 if (On)
175 {
176 if (GetBitmap(0)) // only flush here if there are already bitmaps
177 Flush();
178 }
179 else if (mDisplay != HDFF_INVALID_HANDLE)
180 {
181 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
182 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
183 }
184 }
185}
186
187void cHdffOsd::SaveRegion(int x1, int y1, int x2, int y2)
188{
189 mHdffCmdIf->CmdOsdSaveRegion(mDisplay, mLeft + x1, mTop + y1, x2 - x1 + 1, y2 - y1 + 1);
190 mChanged = true;
191}
192
194{
195 mHdffCmdIf->CmdOsdRestoreRegion(mDisplay);
196 mChanged = true;
197}
198
199void cHdffOsd::DrawPixel(int x, int y, tColor Color)
200{
201 //printf("DrawPixel\n");
202}
203
204void cHdffOsd::DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg, tColor ColorBg, bool ReplacePalette, bool Overlay)
205{
206 //printf("DrawBitmap %d %d %d x %d\n", x, y, Bitmap.Width(), Bitmap.Height());
207 int i;
208 int numColors;
209 const tColor * colors = Bitmap.Colors(numColors);
210
211 for (i = 0; i < numColors; i++)
212 {
213 mBitmapColors[i] = colors[i];
214 if (ColorFg || ColorBg)
215 {
216 if (i == 0)
217 mBitmapColors[i] = ColorBg;
218 else if (i == 1)
219 mBitmapColors[i] = ColorFg;
220 }
221 }
223 {
224 mBitmapPalette = mHdffCmdIf->CmdOsdCreatePalette(HDFF_COLOR_TYPE_CLUT8,
226 }
227 else
228 {
229 mHdffCmdIf->CmdOsdSetPaletteColors(mBitmapPalette,
231 }
232 int width = Bitmap.Width();
233 int height = Bitmap.Height();
234 int chunk = MAX_BITMAP_SIZE / width;
235 if (chunk > height)
236 chunk = height;
237 for (int yc = 0; yc < height; yc += chunk)
238 {
239 int hc = chunk;
240 if (yc + hc > height)
241 hc = height - yc;
242 mHdffCmdIf->CmdOsdDrawBitmap(mDisplay, mLeft + x, mTop + y + yc,
243 (uint8_t *) Bitmap.Data(0, yc), width, hc,
245 }
246 mChanged = true;
247}
248
249void cHdffOsd::DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width, int Height, int Alignment)
250{
251 int w = Font->Width(s);
252 int h = Font->Height();
253 int cw = Width ? Width : w;
254 int ch = Height ? Height : h;
255 int i;
256 int size = Font->Size();
257 tFontFace * pFontFace;
258 tFont * pFont;
259
260 if (ColorBg != clrTransparent)
261 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, mLeft + x, mTop + y, cw, ch, ColorBg);
262
263 if (s == NULL)
264 return;
265
266 pFontFace = NULL;
267 for (i = 0; i < MAX_NUM_FONTFACES; i++)
268 {
269 if (mFontFaces[i].Handle == HDFF_INVALID_HANDLE)
270 break;
271
272 if (strcmp(mFontFaces[i].Name, Font->FontName()) == 0)
273 {
274 pFontFace = &mFontFaces[i];
275 break;
276 }
277 }
278 if (pFontFace == NULL)
279 {
280 if (i < MAX_NUM_FONTFACES)
281 {
282 cString fontFileName = Font->FontName();
283 FILE * fp = fopen(fontFileName, "rb");
284 if (fp)
285 {
286 fseek(fp, 0, SEEK_END);
287 long fileSize = ftell(fp);
288 fseek(fp, 0, SEEK_SET);
289 if (fileSize > 0)
290 {
291 uint8_t * buffer = new uint8_t[fileSize];
292 if (buffer)
293 {
294 if (fread(buffer, fileSize, 1, fp) == 1)
295 {
296 mFontFaces[i].Handle = mHdffCmdIf->CmdOsdCreateFontFace(buffer, fileSize);
297 if (mFontFaces[i].Handle != HDFF_INVALID_HANDLE)
298 {
299 mFontFaces[i].Name = Font->FontName();
300 pFontFace = &mFontFaces[i];
301 }
302 }
303 delete[] buffer;
304 }
305 }
306 fclose(fp);
307 }
308 }
309 }
310 if (pFontFace == NULL)
311 return;
312
313 pFont = NULL;
314 for (i = 0; i < MAX_NUM_FONTS; i++)
315 {
316 if (mFonts[i].Handle == HDFF_INVALID_HANDLE)
317 break;
318
319 if (mFonts[i].hFontFace == pFontFace->Handle
320 && mFonts[i].Size == size)
321 {
322 pFont = &mFonts[i];
323 break;
324 }
325 }
326 if (pFont == NULL)
327 {
328 if (i < MAX_NUM_FONTS)
329 {
330 mFonts[i].Handle = mHdffCmdIf->CmdOsdCreateFont(pFontFace->Handle, size);
331 if (mFonts[i].Handle != HDFF_INVALID_HANDLE)
332 {
333 mFonts[i].hFontFace = pFontFace->Handle;
334 mFonts[i].Size = size;
335 pFont = &mFonts[i];
336 }
337 }
338 }
339 if (pFont == NULL)
340 return;
341
342 mHdffCmdIf->CmdOsdSetDisplayClippingArea(mDisplay, true, mLeft + x, mTop + y, cw, ch);
343
344 if (Width || Height)
345 {
346 if (Width)
347 {
348 if ((Alignment & taLeft) != 0)
349 {
350#if (APIVERSNUM >= 10728)
351 if ((Alignment & taBorder) != 0)
352 x += max(h / TEXT_ALIGN_BORDER, 1);
353#endif
354 }
355 else if ((Alignment & taRight) != 0)
356 {
357 if (w < Width)
358 x += Width - w;
359#if (APIVERSNUM >= 10728)
360 if ((Alignment & taBorder) != 0)
361 x -= max(h / TEXT_ALIGN_BORDER, 1);
362#endif
363 }
364 else
365 { // taCentered
366 if (w < Width)
367 x += (Width - w) / 2;
368 }
369 }
370 if (Height)
371 {
372 if ((Alignment & taTop) != 0)
373 ;
374 else if ((Alignment & taBottom) != 0)
375 {
376 if (h < Height)
377 y += Height - h;
378 }
379 else
380 { // taCentered
381 if (h < Height)
382 y += (Height - h) / 2;
383 }
384 }
385 }
386#if 0
388 {
389 mHdffCmdIf->CmdOsdDrawUtf8Text(mDisplay, pFont->Handle, x + mLeft, y + mTop + h, s, ColorFg);
390 }
391 else
392#endif
393 {
394 uint16_t tmp[1000];
395 uint16_t len = 0;
396 while (*s && (len < (sizeof(tmp) - 1)))
397 {
398 int sl = Utf8CharLen(s);
399 uint sym = Utf8CharGet(s, sl);
400 s += sl;
401 tmp[len] = sym;
402 len++;
403 }
404 tmp[len] = 0;
405 mHdffCmdIf->CmdOsdDrawTextW(mDisplay, pFont->Handle, x + mLeft, y + mTop + h, tmp, ColorFg);
406 }
407 mHdffCmdIf->CmdOsdSetDisplayClippingArea(mDisplay, false, 0, 0, 0, 0);
408 mChanged = true;
409}
410
411void cHdffOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
412{
413 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, mLeft + x1, mTop + y1, x2 - x1 + 1, y2 - y1 + 1, Color);
414 mChanged = true;
415}
416
417void cHdffOsd::DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants)
418{
419 uint32_t flags;
420 int cx;
421 int cy;
422 int rx;
423 int ry;
424
425 switch (abs(Quadrants))
426 {
427 case 1:
428 if (Quadrants > 0)
430 else
432 cx = x1;
433 cy = y2;
434 rx = x2 - x1;
435 ry = y2 - y1;
436 break;
437 case 2:
438 if (Quadrants > 0)
440 else
442 cx = x2;
443 cy = y2;
444 rx = x2 - x1;
445 ry = y2 - y1;
446 break;
447 case 3:
448 if (Quadrants > 0)
450 else
452 cx = x2;
453 cy = y1;
454 rx = x2 - x1;
455 ry = y2 - y1;
456 break;
457 case 4:
458 if (Quadrants > 0)
460 else
462 cx = x1;
463 cy = y1;
464 rx = x2 - x1;
465 ry = y2 - y1;
466 break;
467 case 5:
468 flags = HDFF_DRAW_HALF_RIGHT;
469 cx = x1;
470 cy = (y1 + y2) / 2;
471 rx = x2 - x1;
472 ry = (y2 - y1) / 2;
473 break;
474 case 6:
475 flags = HDFF_DRAW_HALF_TOP;
476 cx = (x1 + x2) / 2;
477 cy = y2;
478 rx = (x2 - x1) / 2;
479 ry = y2 - y1;
480 break;
481 case 7:
482 flags = HDFF_DRAW_HALF_LEFT;
483 cx = x2;
484 cy = (y1 + y2) / 2;
485 rx = x2 - x1;
486 ry = (y2 - y1) / 2;
487 break;
488 case 8:
489 flags = HDFF_DRAW_HALF_BOTTOM;
490 cx = (x1 + x2) / 2;
491 cy = y1;
492 rx = (x2 - x1) / 2;
493 ry = y2 - y1;
494 break;
495 default:
496 flags = HDFF_DRAW_FULL;
497 cx = (x1 + x2) / 2;
498 cy = (y1 + y2) / 2;
499 rx = (x2 - x1) / 2;
500 ry = (y2 - y1) / 2;
501 break;
502 }
503 mHdffCmdIf->CmdOsdDrawEllipse(mDisplay, mLeft + cx, mTop + cy, rx, ry, Color, flags);
504 mChanged = true;
505}
506
507void cHdffOsd::DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type)
508{
509 //printf("DrawSlope\n");
510 mHdffCmdIf->CmdOsdDrawSlope(mDisplay, mLeft + x1, mTop + y1,
511 x2 - x1 + 1, y2 - y1 + 1, Color, Type);
512 mChanged = true;
513}
514
516{
517 if (!Active())
518 return;
519
520 //printf("Flush\n");
521 cBitmap * Bitmap;
522
523 for (int i = 0; (Bitmap = GetBitmap(i)) != NULL; i++)
524 {
525 int x1;
526 int y1;
527 int x2;
528 int y2;
529
530 if (Bitmap->Dirty(x1, y1, x2, y2))
531 {
532 //printf("dirty %d %d, %d %d\n", x1, y1, x2, y2);
533 DrawBitmap(0, 0, *Bitmap);
534 Bitmap->Clean();
535 }
536 }
537
538 if (!mChanged)
539 return;
540
541 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
542
543 mChanged = false;
544}
545
546
547class cHdffOsdRaw : public cOsd
548{
549private:
554 uint32_t mDisplay;
556 uint32_t mBitmapColors[256];
557
558protected:
559 virtual void SetActive(bool On);
560public:
561 cHdffOsdRaw(int Left, int Top, HDFF::cHdffCmdIf * pHdffCmdIf, uint Level);
562 virtual ~cHdffOsdRaw();
563 virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas);
564 virtual eOsdError SetAreas(const tArea *Areas, int NumAreas);
565 virtual void Flush(void);
566};
567
568cHdffOsdRaw::cHdffOsdRaw(int Left, int Top, HDFF::cHdffCmdIf * pHdffCmdIf, uint Level)
569: cOsd(Left, Top, Level)
570{
571 double pixelAspect;
572
573 //printf("cHdffOsdRaw %d, %d, %d\n", Left, Top, Level);
574 mHdffCmdIf = pHdffCmdIf;
575 refresh = true;
578
579 gHdffSetup.GetOsdSize(mDispWidth, mDispHeight, pixelAspect);
580}
581
583{
584 //printf("~cHdffOsdRaw %d %d\n", Left(), Top());
586 {
587 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
588 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
589 }
591 mHdffCmdIf->CmdOsdDeletePalette(mBitmapPalette);
594 mHdffCmdIf->CmdOsdDeleteDisplay(mDisplay);
596}
597
599{
600 if (On != Active())
601 {
602 cOsd::SetActive(On);
603 if (On)
604 {
606 {
609 mHdffCmdIf->CmdOsdSetDisplayOutputRectangle(mDisplay, 0, 0, HDFF_SIZE_FULL_SCREEN, HDFF_SIZE_FULL_SCREEN);
610 }
611 refresh = true;
612 if (GetBitmap(0)) // only flush here if there are already bitmaps
613 Flush();
614 }
615 else
616 {
618 {
619 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
620 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
621 }
623 mHdffCmdIf->CmdOsdDeletePalette(mBitmapPalette);
626 mHdffCmdIf->CmdOsdDeleteDisplay(mDisplay);
628 }
629 }
630}
631
632eOsdError cHdffOsdRaw::CanHandleAreas(const tArea *Areas, int NumAreas)
633{
634 eOsdError Result = cOsd::CanHandleAreas(Areas, NumAreas);
635 if (Result == oeOk)
636 {
637 for (int i = 0; i < NumAreas; i++)
638 {
639 if (Areas[i].bpp != 1 && Areas[i].bpp != 2 && Areas[i].bpp != 4 && Areas[i].bpp != 8
640 && (Areas[i].bpp != 32 || !gHdffSetup.TrueColorOsd))
641 return oeBppNotSupported;
642 }
643 }
644 return Result;
645}
646
647eOsdError cHdffOsdRaw::SetAreas(const tArea *Areas, int NumAreas)
648{
649 for (int i = 0; i < NumAreas; i++)
650 {
651 //printf("SetAreas %d: %d %d %d %d %d\n", i, Areas[i].x1, Areas[i].y1, Areas[i].x2, Areas[i].y2, Areas[i].bpp);
652 }
654 {
655 mHdffCmdIf->CmdOsdDrawRectangle(mDisplay, 0, 0, mDispWidth, mDispHeight, 0);
656 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
657 refresh = true;
658 }
659 return cOsd::SetAreas(Areas, NumAreas);
660}
661
663{
664 if (!Active() || (mDisplay == HDFF_INVALID_HANDLE))
665 return;
666#ifdef MEASURE_OSD_TIME
667 struct timeval start;
668 struct timeval end;
669 struct timezone timeZone;
670 gettimeofday(&start, &timeZone);
671#endif
672
673 bool render = false;
674 if (IsTrueColor())
675 {
676 uint8_t * buffer = 0;
677 if (gHdffSetup.TrueColorFormat != 0)
678 {
679 buffer = new uint8_t[MAX_BITMAP_SIZE];
680 if (!buffer)
681 return;
682 }
684#if (APIVERSNUM >= 20110)
685 while (cPixmapMemory *pm = dynamic_cast<cPixmapMemory *>(RenderPixmaps()))
686#else
687 while (cPixmapMemory *pm = RenderPixmaps())
688#endif
689 {
690 int w = pm->ViewPort().Width();
691 int h = pm->ViewPort().Height();
692 int d = w * sizeof(tColor);
693 int Chunk = MAX_BITMAP_SIZE / w / sizeof(tColor);
694 if (Chunk > h)
695 Chunk = h;
696 for (int y = 0; y < h; y += Chunk)
697 {
698 int hc = Chunk;
699 if (y + hc > h)
700 hc = h - y;
701 if (gHdffSetup.TrueColorFormat == 0) // ARGB8888 (32 bit)
702 {
703 mHdffCmdIf->CmdOsdDrawBitmap(mDisplay,
704 Left() + pm->ViewPort().X(), Top() + pm->ViewPort().Y() + y,
705 pm->Data() + y * d, w, hc, hc * d,
707 }
708 else if (gHdffSetup.TrueColorFormat == 1) // ARGB8565 (24 bit)
709 {
710 const tColor * pixmapData = (const tColor *) (pm->Data() + y * d);
711 uint8_t * bitmapData = buffer;
712 for (int i = 0; i < hc * w; i++)
713 {
714 bitmapData[2] = (pixmapData[i] & 0xFF000000) >> 24;
715 bitmapData[1] = ((pixmapData[i] & 0x00F80000) >> 16)
716 | ((pixmapData[i] & 0x0000E000) >> 13);
717 bitmapData[0] = ((pixmapData[i] & 0x00001C00) >> 5)
718 | ((pixmapData[i] & 0x000000F8) >> 3);
719 bitmapData += 3;
720 }
721 mHdffCmdIf->CmdOsdDrawBitmap(mDisplay,
722 Left() + pm->ViewPort().X(), Top() + pm->ViewPort().Y() + y,
723 buffer, w, hc, hc * w * 3,
725 }
726 else if (gHdffSetup.TrueColorFormat == 2) // ARGB4444 (16 bit)
727 {
728 const tColor * pixmapData = (const tColor *) (pm->Data() + y * d);
729 uint16_t * bitmapData = (uint16_t *) buffer;
730 for (int i = 0; i < hc * w; i++)
731 {
732 bitmapData[i] = ((pixmapData[i] & 0xF0000000) >> 16)
733 | ((pixmapData[i] & 0x00F00000) >> 12)
734 | ((pixmapData[i] & 0x0000F000) >> 8)
735 | ((pixmapData[i] & 0x000000F0) >> 4);
736 }
737 mHdffCmdIf->CmdOsdDrawBitmap(mDisplay,
738 Left() + pm->ViewPort().X(), Top() + pm->ViewPort().Y() + y,
739 buffer, w, hc, hc * w * 2,
741 }
742 }
743#if (APIVERSNUM >= 20110)
744 DestroyPixmap(pm);
745#else
746 delete pm;
747#endif
748 render = true;
749 }
750 if (buffer)
751 delete[] buffer;
752 }
753 else
754 {
755 uint8_t * buffer = new uint8_t[MAX_BITMAP_SIZE];
756 if (!buffer)
757 return;
758 cBitmap * bitmap;
759 for (int i = 0; (bitmap = GetBitmap(i)) != NULL; i++)
760 {
761 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
762 if (refresh || bitmap->Dirty(x1, y1, x2, y2))
763 {
764 if (refresh)
765 {
766 x2 = bitmap->Width() - 1;
767 y2 = bitmap->Height() - 1;
768 }
769 // commit colors:
770 int numColors;
771 const tColor * colors = bitmap->Colors(numColors);
772 if (colors)
773 {
774 for (int c = 0; c < numColors; c++)
775 mBitmapColors[c] = colors[c];
777 {
778 mBitmapPalette = mHdffCmdIf->CmdOsdCreatePalette(HDFF_COLOR_TYPE_CLUT8,
780 }
781 else
782 {
783 mHdffCmdIf->CmdOsdSetPaletteColors(mBitmapPalette,
785 }
786 }
787 // commit modified data:
788 int width = x2 - x1 + 1;
789 int height = y2 - y1 + 1;
790 int chunk = MAX_BITMAP_SIZE / width;
791 if (chunk > height)
792 chunk = height;
793 for (int y = 0; y < height; y += chunk)
794 {
795 int hc = chunk;
796 if (y + hc > height)
797 hc = height - y;
798 for (int r = 0; r < hc; r++)
799 memcpy(buffer + r * width, bitmap->Data(x1, y1 + y + r), width);
800 mHdffCmdIf->CmdOsdDrawBitmap(mDisplay,
801 Left() + bitmap->X0() + x1, Top() + bitmap->Y0() + y1 + y,
802 buffer, width, hc, hc * width,
804 }
805 render = true;
806 }
807 bitmap->Clean();
808 }
809 delete[] buffer;
810 }
811 if (render)
812 {
813 mHdffCmdIf->CmdOsdRenderDisplay(mDisplay);
814#ifdef MEASURE_OSD_TIME
815 gettimeofday(&end, &timeZone);
816 int timeNeeded = end.tv_usec - start.tv_usec;
817 timeNeeded += (end.tv_sec - start.tv_sec) * 1000000;
818 printf("time = %d\n", timeNeeded);
819#endif
820 }
821 refresh = false;
822}
823
824
825
826
828{
829 mHdffCmdIf = HdffCmdIf;
830}
831
832cOsd *cHdffOsdProvider::CreateOsd(int Left, int Top, uint Level)
833{
834 //printf("CreateOsd %d %d %d\n", Left, Top, Level);
835 if (gHdffSetup.HighLevelOsd)
836 return new cHdffOsd(Left, Top, mHdffCmdIf, Level);
837 else
838 return new cHdffOsdRaw(Left, Top, mHdffCmdIf, Level);
839}
840
842{
843 return gHdffSetup.TrueColorOsd && !gHdffSetup.HighLevelOsd;
844}
Definition osd.h:169
int Height(void) const
Definition osd.h:189
bool Dirty(int &x1, int &y1, int &x2, int &y2)
Tells whether there is a dirty area and returns the bounding rectangle of that area (relative to the ...
Definition osd.c:342
int X0(void) const
Definition osd.h:186
void Clean(void)
Marks the dirty area as clean.
Definition osd.c:354
int Y0(void) const
Definition osd.h:187
int Width(void) const
Definition osd.h:188
const tIndex * Data(int x, int y) const
Returns the address of the index byte at the given coordinates.
Definition osd.c:760
Definition font.h:37
cHdffOsdProvider(HDFF::cHdffCmdIf *pHdffCmdIf)
Definition hdffosd.c:827
HDFF::cHdffCmdIf * mHdffCmdIf
Definition hdffosd.h:17
virtual bool ProvidesTrueColor(void)
Returns true if this OSD provider is able to handle a true color OSD.
Definition hdffosd.c:841
virtual cOsd * CreateOsd(int Left, int Top, uint Level)
Returns a pointer to a newly created cOsd object, which will be located at the given coordinates.
Definition hdffosd.c:832
virtual ~cHdffOsdRaw()
Definition hdffosd.c:582
int mDispHeight
Definition hdffosd.c:552
uint32_t mBitmapColors[256]
Definition hdffosd.c:556
HDFF::cHdffCmdIf * mHdffCmdIf
Definition hdffosd.c:550
cHdffOsdRaw(int Left, int Top, HDFF::cHdffCmdIf *pHdffCmdIf, uint Level)
Definition hdffosd.c:568
int mDispWidth
Definition hdffosd.c:551
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas)
Checks whether the OSD can display the given set of sub-areas.
Definition hdffosd.c:632
bool refresh
Definition hdffosd.c:553
uint32_t mBitmapPalette
Definition hdffosd.c:555
virtual void SetActive(bool On)
Sets this OSD to be the active one.
Definition hdffosd.c:598
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas)
Sets the sub-areas to the given areas.
Definition hdffosd.c:647
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition hdffosd.c:662
uint32_t mDisplay
Definition hdffosd.c:554
virtual void SetActive(bool On)
Sets this OSD to be the active one.
Definition hdffosd.c:169
virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants=0)
Draws a filled ellipse defined by the upper left (x1, y1) and lower right (x2, y2) corners with the g...
Definition hdffosd.c:417
uint32_t mBitmapColors[256]
Definition hdffosd.c:44
virtual void SaveRegion(int x1, int y1, int x2, int y2)
Saves the region defined by the given coordinates for later restoration through RestoreRegion().
Definition hdffosd.c:187
virtual void DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width=0, int Height=0, int Alignment=taDefault)
Draws the given string at coordinates (x, y) with the given foreground and background color and font.
Definition hdffosd.c:249
int mLeft
Definition hdffosd.c:35
bool mSupportsUtf8Text
Definition hdffosd.c:46
tFontFace mFontFaces[MAX_NUM_FONTFACES]
Definition hdffosd.c:41
int mDispWidth
Definition hdffosd.c:37
virtual void DrawPixel(int x, int y, tColor Color)
Sets the pixel at the given coordinates to the given Color, which is a full 32 bit ARGB value.
Definition hdffosd.c:199
uint32_t mDisplay
Definition hdffosd.c:40
int mTop
Definition hdffosd.c:36
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition hdffosd.c:515
int mDispHeight
Definition hdffosd.c:38
virtual void RestoreRegion(void)
Restores the region previously saved by a call to SaveRegion().
Definition hdffosd.c:193
virtual ~cHdffOsd()
Definition hdffosd.c:104
cHdffOsd(int Left, int Top, HDFF::cHdffCmdIf *pHdffCmdIf, uint Level)
Definition hdffosd.c:66
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas)
Sets the sub-areas to the given areas.
Definition hdffosd.c:145
HDFF::cHdffCmdIf * mHdffCmdIf
Definition hdffosd.c:34
bool mChanged
Definition hdffosd.c:39
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas)
Checks whether the OSD can display the given set of sub-areas.
Definition hdffosd.c:131
tFont mFonts[MAX_NUM_FONTS]
Definition hdffosd.c:42
virtual void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg=0, tColor ColorBg=0, bool ReplacePalette=false, bool Overlay=false)
Sets the pixels in the OSD with the data from the given Bitmap, putting the upper left corner of the ...
Definition hdffosd.c:204
virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
Draws a filled rectangle defined by the upper left (x1, y1) and lower right (x2, y2) corners with the...
Definition hdffosd.c:411
uint32_t mBitmapPalette
Definition hdffosd.c:43
virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type)
Draws a "slope" into the rectangle defined by the upper left (x1, y1) and lower right (x2,...
Definition hdffosd.c:507
The cOsd class is the interface to the "On Screen Display".
Definition osd.h:753
cOsd(int Left, int Top, uint Level)
Initializes the OSD with the given coordinates.
Definition osd.c:1911
bool IsTrueColor(void) const
Returns 'true' if this is a true color OSD (providing full 32 bit color depth).
Definition osd.h:839
virtual void SetActive(bool On)
Sets this OSD to be the active one.
Definition osd.h:791
int Width(void)
Definition osd.h:844
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas)
Sets the sub-areas to the given areas.
Definition osd.c:2092
cBitmap * GetBitmap(int Area)
Returns a pointer to the bitmap for the given Area, or NULL if no such bitmap exists.
Definition osd.c:1967
virtual void DestroyPixmap(cPixmap *Pixmap)
Destroys the given Pixmap, which has previously been created by a call to CreatePixmap().
Definition osd.c:1989
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas)
Checks whether the OSD can display the given set of sub-areas.
Definition osd.c:2070
cPixmap * RenderPixmaps(void)
Renders the dirty part of all pixmaps into a resulting pixmap that shall be displayed on the OSD.
Definition osd.c:2019
int Left(void)
Definition osd.h:842
int height
Definition osd.h:766
int Top(void)
Definition osd.h:843
bool Active(void)
Definition osd.h:790
int width
Definition osd.h:766
int Height(void)
Definition osd.h:845
const tColor * Colors(int &NumColors) const
Returns a pointer to the complete color table and stores the number of valid entries in NumColors.
Definition osd.c:185
cSetup Setup
Definition config.c:372
uint32_t tColor
Definition font.h:30
@ HDFF_COLOR_TYPE_ARGB8565
Definition hdffcmd_osd.h:53
@ HDFF_COLOR_TYPE_ARGB4444
Definition hdffcmd_osd.h:54
@ HDFF_COLOR_TYPE_ARGB8888
Definition hdffcmd_osd.h:52
@ HDFF_COLOR_TYPE_CLUT8
Definition hdffcmd_osd.h:51
#define HDFF_INVALID_HANDLE
Definition hdffcmd_osd.h:28
#define HDFF_SIZE_FULL_SCREEN
Definition hdffcmd_osd.h:33
@ HDFF_COLOR_FORMAT_ARGB
Definition hdffcmd_osd.h:62
@ HDFF_DRAW_QUARTER_TOP_LEFT_INVERTED
Definition hdffcmd_osd.h:77
@ HDFF_DRAW_QUARTER_BOTTOM_LEFT_INVERTED
Definition hdffcmd_osd.h:79
@ HDFF_DRAW_FULL
Definition hdffcmd_osd.h:68
@ HDFF_DRAW_HALF_BOTTOM
Definition hdffcmd_osd.h:71
@ HDFF_DRAW_HALF_TOP
Definition hdffcmd_osd.h:69
@ HDFF_DRAW_QUARTER_BOTTOM_RIGHT
Definition hdffcmd_osd.h:76
@ HDFF_DRAW_QUARTER_BOTTOM_LEFT
Definition hdffcmd_osd.h:75
@ HDFF_DRAW_QUARTER_TOP_RIGHT_INVERTED
Definition hdffcmd_osd.h:78
@ HDFF_DRAW_QUARTER_TOP_LEFT
Definition hdffcmd_osd.h:73
@ HDFF_DRAW_QUARTER_TOP_RIGHT
Definition hdffcmd_osd.h:74
@ HDFF_DRAW_QUARTER_BOTTOM_RIGHT_INVERTED
Definition hdffcmd_osd.h:80
@ HDFF_DRAW_HALF_LEFT
Definition hdffcmd_osd.h:70
@ HDFF_DRAW_HALF_RIGHT
Definition hdffcmd_osd.h:72
struct _tFontFace tFontFace
#define MAX_NUM_FONTS
Definition hdffosd.c:15
struct _tFont tFont
#define MAX_NUM_FONTFACES
Definition hdffosd.c:14
#define MAX_BITMAP_SIZE
Definition hdffosd.c:16
@ taBorder
Definition osd.h:163
@ taTop
Definition osd.h:161
@ taBottom
Definition osd.h:162
@ taRight
Definition osd.h:160
@ taDefault
Definition osd.h:164
@ taLeft
Definition osd.h:159
eOsdError
Definition osd.h:44
@ oeOk
Definition osd.h:44
@ oeBppNotSupported
Definition osd.h:47
#define LOCK_PIXMAPS
Definition osd.h:707
#define TEXT_ALIGN_BORDER
Definition osd.h:28
cHdffSetup gHdffSetup
Definition setup.c:16
#define clrTransparent
Definition skincurses.c:36
static const cCursesFont Font
Definition skincurses.c:31
uint32_t Handle
Definition hdffosd.c:21
cString Name
Definition hdffosd.c:20
int Size
Definition hdffosd.c:27
uint32_t Handle
Definition hdffosd.c:28
uint32_t hFontFace
Definition hdffosd.c:26
Definition osd.h:298
uint Utf8CharGet(const char *s, int Length)
Returns the UTF-8 symbol at the beginning of the given string.
Definition tools.c:841
int Utf8CharLen(const char *s)
Returns the number of character bytes at the beginning of the given string that form a UTF-8 symbol.
Definition tools.c:827
T max(T a, T b)
Definition tools.h:64