vdr  2.2.0
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 3.1 2014/02/08 12:27:34 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:
72  sDvbSpuRect minsize[4];
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);
83  ~cDvbSpuBitmap();
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;
105 
106  enum spFlag { spNONE, spHIDE, spSHOW, spMENU };
108 
110  double xscaling, yscaling;
111 
112  //highligh area
113  bool highlight;
116 
117  //palette
119 
120  // spu info's
123 
124  uint16_t DCSQ_offset;
126 
129  private:
130  int cmdOffs(void) {
131  return ((spu[2] << 8) | spu[3]);
132  };
133  int spuSize(void) {
134  return ((spu[0] << 8) | spu[1]);
135  };
136 
137  void SetSpuScaling(void);
138  sDvbSpuRect CalcAreaSize(sDvbSpuRect fgsize, cBitmap *fgbmp, sDvbSpuRect bgsize, cBitmap *bgbmp);
139  int CalcAreaBpp(cBitmap *fgbmp, cBitmap *bgbmp);
140 
141  public:
142  cDvbSpuDecoder();
143  ~cDvbSpuDecoder();
144 
145  int setTime(uint32_t pts);
146 
147  cSpuDecoder::eScaleMode getScaleMode(void) { return scaleMode; }
148  void setScaleMode(cSpuDecoder::eScaleMode ScaleMode);
149  void setPalette(uint32_t * pal);
150  void setHighlight(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey,
151  uint32_t palette);
152  void clearHighlight(void);
153  void Empty(void);
154  void Hide(void);
155  void Draw(void);
156  bool IsVisible(void) { return osd != NULL; }
157  void processSPU(uint32_t pts, uint8_t * buf, bool AllowedShow);
158 };
159 
160 // --- cDvbSpuPalette --------------------------------------------------------
161 
162 inline uint32_t cDvbSpuPalette::yuv2rgb(uint32_t yuv_color)
163 {
164  int Y, Cb, Cr;
165  int Ey, Epb, Epr;
166  int Eg, Eb, Er;
167 
168  Y = (yuv_color >> 16) & 0xff;
169  Cb = (yuv_color) & 0xff;
170  Cr = (yuv_color >> 8) & 0xff;
171 
172  Ey = (Y - 16);
173  Epb = (Cb - 128);
174  Epr = (Cr - 128);
175  /* ITU-R 709
176  Eg = (298*Ey - 55*Epb - 137*Epr)/256;
177  Eb = (298*Ey + 543*Epb)/256;
178  Er = (298*Ey + 460*Epr)/256;
179  */
180  /* FCC ~= mediaLib */
181  Eg = (298 * Ey - 100 * Epb - 208 * Epr) / 256;
182  Eb = (298 * Ey + 516 * Epb) / 256;
183  Er = (298 * Ey + 408 * Epr) / 256;
184 
185  if (Eg > 255)
186  Eg = 255;
187  if (Eg < 0)
188  Eg = 0;
189 
190  if (Eb > 255)
191  Eb = 255;
192  if (Eb < 0)
193  Eb = 0;
194 
195  if (Er > 255)
196  Er = 255;
197  if (Er < 0)
198  Er = 0;
199 
200  return Eb | (Eg << 8) | (Er << 16);
201 }
202 
203 inline uint32_t cDvbSpuPalette::getColor(uint8_t idx, uint8_t trans) const
204 {
205  return palette[idx] | ((trans == 0x0f) ? 0xff000000 : (trans << 28));
206 }
207 
208 #endif // __DVBSPU_H
uint8_t * spu
Definition: dvbspu.h:101
uint32_t yuv2rgb(uint32_t yuv_color)
Definition: dvbspu.h:162
struct sDvbSpuRect sDvbSpuRect
aDvbSpuPalDescr hlpDescr
Definition: dvbspu.h:115
int cmdOffs(void)
Definition: dvbspu.h:130
sDvbSpuRect bmpsize
Definition: dvbspu.h:71
uint8_t index
Definition: dvbspu.h:24
bool allowedShow
Definition: dvbspu.h:128
sDvbSpuRect(void)
Definition: dvbspu.h:36
aDvbSpuPalDescr palDescr
Definition: dvbspu.h:122
bool IsVisible(void)
Definition: dvbspu.h:156
uint32_t spupts
Definition: dvbspu.h:102
bool clean
Definition: dvbspu.h:103
cSpuDecoder::eScaleMode scaleMode
Definition: dvbspu.h:109
bool operator!=(const sDvbSpuPalDescr pd) const
Definition: dvbspu.h:27
spFlag state
Definition: dvbspu.h:107
cDvbSpuPalette palette
Definition: dvbspu.h:118
Definition: osd.h:169
int x1
Definition: dvbspu.h:33
sDvbSpuRect size
Definition: dvbspu.h:121
cOsd * osd
Definition: dvbspu.h:97
int y1
Definition: dvbspu.h:33
double yscaling
Definition: dvbspu.h:110
struct sDvbSpuPalDescr aDvbSpuPalDescr[4]
The cOsd class is the interface to the "On Screen Display".
Definition: osd.h:720
int y2
Definition: dvbspu.h:34
uint16_t DCSQ_offset
Definition: dvbspu.h:124
Definition: thread.h:63
uint8_t * bmp
Definition: dvbspu.h:73
int width() const
Definition: dvbspu.h:39
bool restricted_osd
Definition: dvbspu.h:104
uint8_t trans
Definition: dvbspu.h:25
cMutex mutex
Definition: dvbspu.h:98
bool highlight
Definition: dvbspu.h:113
int height() const
Definition: dvbspu.h:42
uint32_t getColor(uint8_t idx, uint8_t trans) const
Definition: dvbspu.h:203
sDvbSpuRect hlpsize
Definition: dvbspu.h:114
cSpuDecoder::eScaleMode getScaleMode(void)
Definition: dvbspu.h:147
int spuSize(void)
Definition: dvbspu.h:133
uint16_t prev_DCSQ_offset
Definition: dvbspu.h:125
int x2
Definition: dvbspu.h:34
eScaleMode
Definition: spu.h:21
cDvbSpuBitmap * spubmp
Definition: dvbspu.h:127