vdr  2.0.2
dvbspu.h
Go to the documentation of this file.
1 /*
2  * SPU decoder for DVB devices
3  *
4  * Copyright (C) 2001.2002 Andreas Schultz <aschultz@warp10.net>
5  *
6  * This code is distributed under the terms and conditions of the
7  * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
8  *
9  * parts of this file are derived from the OMS program.
10  *
11  * $Id: dvbspu.h 2.6 2013/01/20 10:15:47 kls Exp $
12  */
13 
14 #ifndef __DVBSPU_H
15 #define __DVBSPU_H
16 
17 #include <inttypes.h>
18 #include "device.h"
19 #include "osd.h"
20 #include "spu.h"
21 #include "thread.h"
22 
23 typedef struct sDvbSpuPalDescr {
24  uint8_t index;
25  uint8_t trans;
26 
27  bool operator != (const sDvbSpuPalDescr pd) const {
28  return index != pd.index && trans != pd.trans;
29  };
30 } aDvbSpuPalDescr[4];
31 
32 typedef struct sDvbSpuRect {
33  int x1, y1;
34  int x2, y2;
35 
36  sDvbSpuRect(void) {
37  x1 = y1 = x2 = y2 = 0;
38  };
39  int width() const {
40  return x2 - x1 + 1;
41  };
42  int height() const {
43  return y2 - y1 + 1;
44  };
45 
46  bool operator != (const sDvbSpuRect r) const {
47  return r.x1 != x1 || r.y1 != y1 || r.x2 != x2 || r.y2 != y2;
48  };
49 }
50 
52 
53 // --- cDvbSpuPalette---------------------------------------------------------
54 
56  private:
57  uint32_t palette[16];
58 
59  private:
60  uint32_t yuv2rgb(uint32_t yuv_color);
61 
62  public:
63  void setPalette(const uint32_t * pal);
64  uint32_t getColor(uint8_t idx, uint8_t trans) const;
65 };
66 
67 // --- cDvbSpuBitmap----------------------------------------------------------
68 
70  private:
73  uint8_t *bmp;
74 
75  private:
76  void putPixel(int xp, int yp, int len, uint8_t colorid);
77  void putFieldData(int field, uint8_t * data, uint8_t * endp);
78 
79  public:
81  uint8_t * fodd, uint8_t * eodd,
82  uint8_t * feven, uint8_t * eeven);
84 
85  bool getMinSize(const aDvbSpuPalDescr paldescr,
86  sDvbSpuRect & size) const;
87  int getMinBpp(const aDvbSpuPalDescr paldescr);
88  cBitmap *getBitmap(const aDvbSpuPalDescr paldescr,
89  const cDvbSpuPalette & pal,
90  sDvbSpuRect & size) const;
91 };
92 
93 // --- cDvbSpuDecoder---------------------------------------------------------
94 
96  private:
99 
100  // processing state
101  uint8_t *spu;
102  uint32_t spupts;
103  bool clean;
104  bool ready;
106 
109 
112 
113  //highligh area
114  bool highlight;
117 
118  //palette
120 
121  // spu info's
124 
125  uint16_t DCSQ_offset;
127 
130  private:
131  int cmdOffs(void) {
132  return ((spu[2] << 8) | spu[3]);
133  };
134  int spuSize(void) {
135  return ((spu[0] << 8) | spu[1]);
136  };
137 
138  void SetSpuScaling(void);
139  sDvbSpuRect CalcAreaSize(sDvbSpuRect fgsize, cBitmap *fgbmp, sDvbSpuRect bgsize, cBitmap *bgbmp);
140  int CalcAreaBpp(cBitmap *fgbmp, cBitmap *bgbmp);
141 
142  public:
143  cDvbSpuDecoder();
144  ~cDvbSpuDecoder();
145 
146  int setTime(uint32_t pts);
147 
149  void setScaleMode(cSpuDecoder::eScaleMode ScaleMode);
150  void setPalette(uint32_t * pal);
151  void setHighlight(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey,
152  uint32_t palette);
153  void clearHighlight(void);
154  void Empty(void);
155  void Hide(void);
156  void Draw(void);
157  bool IsVisible(void) { return osd != NULL; }
158  void processSPU(uint32_t pts, uint8_t * buf, bool AllowedShow);
159 };
160 
161 // --- cDvbSpuPalette --------------------------------------------------------
162 
163 inline uint32_t cDvbSpuPalette::yuv2rgb(uint32_t yuv_color)
164 {
165  int Y, Cb, Cr;
166  int Ey, Epb, Epr;
167  int Eg, Eb, Er;
168 
169  Y = (yuv_color >> 16) & 0xff;
170  Cb = (yuv_color) & 0xff;
171  Cr = (yuv_color >> 8) & 0xff;
172 
173  Ey = (Y - 16);
174  Epb = (Cb - 128);
175  Epr = (Cr - 128);
176  /* ITU-R 709
177  Eg = (298*Ey - 55*Epb - 137*Epr)/256;
178  Eb = (298*Ey + 543*Epb)/256;
179  Er = (298*Ey + 460*Epr)/256;
180  */
181  /* FCC ~= mediaLib */
182  Eg = (298 * Ey - 100 * Epb - 208 * Epr) / 256;
183  Eb = (298 * Ey + 516 * Epb) / 256;
184  Er = (298 * Ey + 408 * Epr) / 256;
185 
186  if (Eg > 255)
187  Eg = 255;
188  if (Eg < 0)
189  Eg = 0;
190 
191  if (Eb > 255)
192  Eb = 255;
193  if (Eb < 0)
194  Eb = 0;
195 
196  if (Er > 255)
197  Er = 255;
198  if (Er < 0)
199  Er = 0;
200 
201  return Eb | (Eg << 8) | (Er << 16);
202 }
203 
204 inline uint32_t cDvbSpuPalette::getColor(uint8_t idx, uint8_t trans) const
205 {
206  return palette[idx] | ((trans == 0x0f) ? 0xff000000 : (trans << 28));
207 }
208 
209 #endif // __DVBSPU_H
210