vdr  1.7.31
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.5 2011/03/27 14:50:48 kls Exp $
12  */
13 
14 #ifndef __DVBSPU_H
15 #define __DVBSPU_H
16 
17 #include <inttypes.h>
18 #include "osd.h"
19 #include "spu.h"
20 #include "thread.h"
21 
22 typedef struct sDvbSpuPalDescr {
23  uint8_t index;
24  uint8_t trans;
25 
26  bool operator != (const sDvbSpuPalDescr pd) const {
27  return index != pd.index && trans != pd.trans;
28  };
29 } aDvbSpuPalDescr[4];
30 
31 typedef struct sDvbSpuRect {
32  int x1, y1;
33  int x2, y2;
34 
35  sDvbSpuRect(void) {
36  x1 = y1 = x2 = y2 = 0;
37  };
38  int width() const {
39  return x2 - x1 + 1;
40  };
41  int height() const {
42  return y2 - y1 + 1;
43  };
44 
45  bool operator != (const sDvbSpuRect r) const {
46  return r.x1 != x1 || r.y1 != y1 || r.x2 != x2 || r.y2 != y2;
47  };
48 }
49 
51 
52 // --- cDvbSpuPalette---------------------------------------------------------
53 
55  private:
56  uint32_t palette[16];
57 
58  private:
59  uint32_t yuv2rgb(uint32_t yuv_color);
60 
61  public:
62  void setPalette(const uint32_t * pal);
63  uint32_t getColor(uint8_t idx, uint8_t trans) const;
64 };
65 
66 // --- cDvbSpuBitmap----------------------------------------------------------
67 
69  private:
72  uint8_t *bmp;
73 
74  private:
75  void putPixel(int xp, int yp, int len, uint8_t colorid);
76  void putFieldData(int field, uint8_t * data, uint8_t * endp);
77 
78  public:
80  uint8_t * fodd, uint8_t * eodd,
81  uint8_t * feven, uint8_t * eeven);
83 
84  bool getMinSize(const aDvbSpuPalDescr paldescr,
85  sDvbSpuRect & size) const;
86  int getMinBpp(const aDvbSpuPalDescr paldescr);
87  cBitmap *getBitmap(const aDvbSpuPalDescr paldescr,
88  const cDvbSpuPalette & pal,
89  sDvbSpuRect & size) const;
90 };
91 
92 // --- cDvbSpuDecoder---------------------------------------------------------
93 
95  private:
98 
99  // processing state
100  uint8_t *spu;
101  uint32_t spupts;
102  bool clean;
103  bool ready;
105 
108 
110 
111  //highligh area
112  bool highlight;
115 
116  //palette
118 
119  // spu info's
122 
123  uint16_t DCSQ_offset;
125 
128  private:
129  int cmdOffs(void) {
130  return ((spu[2] << 8) | spu[3]);
131  };
132  int spuSize(void) {
133  return ((spu[0] << 8) | spu[1]);
134  };
135 
136  sDvbSpuRect CalcAreaSize(sDvbSpuRect fgsize, cBitmap *fgbmp, sDvbSpuRect bgsize, cBitmap *bgbmp);
137  int CalcAreaBpp(cBitmap *fgbmp, cBitmap *bgbmp);
138 
139  public:
140  cDvbSpuDecoder();
141  ~cDvbSpuDecoder();
142 
143  int setTime(uint32_t pts);
144 
146  void setScaleMode(cSpuDecoder::eScaleMode ScaleMode);
147  void setPalette(uint32_t * pal);
148  void setHighlight(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey,
149  uint32_t palette);
150  void clearHighlight(void);
151  void Empty(void);
152  void Hide(void);
153  void Draw(void);
154  bool IsVisible(void) { return osd != NULL; }
155  void processSPU(uint32_t pts, uint8_t * buf, bool AllowedShow);
156 };
157 
158 // --- cDvbSpuPalette --------------------------------------------------------
159 
160 inline uint32_t cDvbSpuPalette::yuv2rgb(uint32_t yuv_color)
161 {
162  int Y, Cb, Cr;
163  int Ey, Epb, Epr;
164  int Eg, Eb, Er;
165 
166  Y = (yuv_color >> 16) & 0xff;
167  Cb = (yuv_color) & 0xff;
168  Cr = (yuv_color >> 8) & 0xff;
169 
170  Ey = (Y - 16);
171  Epb = (Cb - 128);
172  Epr = (Cr - 128);
173  /* ITU-R 709
174  Eg = (298*Ey - 55*Epb - 137*Epr)/256;
175  Eb = (298*Ey + 543*Epb)/256;
176  Er = (298*Ey + 460*Epr)/256;
177  */
178  /* FCC ~= mediaLib */
179  Eg = (298 * Ey - 100 * Epb - 208 * Epr) / 256;
180  Eb = (298 * Ey + 516 * Epb) / 256;
181  Er = (298 * Ey + 408 * Epr) / 256;
182 
183  if (Eg > 255)
184  Eg = 255;
185  if (Eg < 0)
186  Eg = 0;
187 
188  if (Eb > 255)
189  Eb = 255;
190  if (Eb < 0)
191  Eb = 0;
192 
193  if (Er > 255)
194  Er = 255;
195  if (Er < 0)
196  Er = 0;
197 
198  return Eb | (Eg << 8) | (Er << 16);
199 }
200 
201 inline uint32_t cDvbSpuPalette::getColor(uint8_t idx, uint8_t trans) const
202 {
203  return palette[idx] | ((trans == 0x0f) ? 0xff000000 : (trans << 28));
204 }
205 
206 #endif // __DVBSPU_H