summaryrefslogtreecommitdiff
path: root/bitmap.c
blob: c57fa11f136a7934ddb371febf70337eab214528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "bitmap.h"
#include <math.h>

using namespace Magick;

cOSDImageBitmap::cOSDImageBitmap() {
}

cOSDImageBitmap::~cOSDImageBitmap() {
}

bool cOSDImageBitmap::Load(cBitmap &bmp, const char *Filename, int width, int height, int bpp)
{
  try
  {
    #ifdef DEBUG_SKINPEARLHD
    int start = cTimeMs::Now();
	#endif

    int w, h;
    if (bpp > 8)
	  bpp = 8;
	int colors = pow(2,bpp);
	Image osdImage;
	osdImage.read(Filename);

	if (bpp != 0)
	{
	  osdImage.opacity(OpaqueOpacity);
	  osdImage.backgroundColor( Color(0, 0, 0, 0));
	  osdImage.quantizeColorSpace(RGBColorspace);
	  osdImage.quantizeColors(colors);
	  osdImage.quantize();
	}

	if (height != 0 || width != 0)
	  osdImage.sample( Geometry(width, height));
	w = osdImage.columns();
	h = osdImage.rows();
	bmp.SetSize(w, h);
	
	const PixelPacket *pixels = osdImage.getConstPixels(0, 0, w, h);
	
	for (int iy = 0; iy < h; ++iy) {
      for (int ix = 0; ix < w; ++ix) {
        tColor col = (~int(pixels->opacity * 255 / MaxRGB) << 24) 
	      | (int(pixels->green * 255 / MaxRGB) << 8) 
          | (int(pixels->red * 255 / MaxRGB) << 16) 
          | (int(pixels->blue * 255 / MaxRGB) );
        bmp.DrawPixel(ix, iy, col);
        ++pixels;
      }
    }
	#ifdef DEBUG_SKINPEARLHD
    printf ("skinpearlhd: bitmap render took %d ms\n", int(cTimeMs::Now()-start));
	#endif
	return true;
  }
  catch (...)
  {
    return false;
  }
}

#if VDRVERSNUM > 10716
bool cOSDImageBitmap::Load(const char *Filename, int width, int height)
{
  try
  {
    #ifdef DEBUG_SKINPEARLHD
    int start = cTimeMs::Now();
	#endif
	
	osdImage.read(Filename);

	if (height != 0 || width != 0)
	  osdImage.sample( Geometry(width, height));
	
	#ifdef DEBUG_SKINPEARLHD
    printf ("skinpearlhd: bitmap render took %d ms\n", int(cTimeMs::Now()-start));
	#endif
	return true;
  }
  catch (...)
  {
    return false;
  }
}

cImage cOSDImageBitmap::GetImage()
{
  int w, h;
  w = osdImage.columns();
  h = osdImage.rows();
  cImage image (cSize(w, h));
  const PixelPacket *pixels = osdImage.getConstPixels(0, 0, w, h);
  for (int iy = 0; iy < h; ++iy) {
    for (int ix = 0; ix < w; ++ix) {
      tColor col = (~int(pixels->opacity * 255 / MaxRGB) << 24) 
	    | (int(pixels->green * 255 / MaxRGB) << 8) 
        | (int(pixels->red * 255 / MaxRGB) << 16) 
        | (int(pixels->blue * 255 / MaxRGB) );
      image.SetPixel(cPoint(ix, iy), col);
      ++pixels;
    }
  }
  return image;
}
#endif