|
SASC-NG
DVBSoftCAM
|
00001 /* 00002 * SPU decoder for DVB devices 00003 * 00004 * Copyright (C) 2001.2002 Andreas Schultz <aschultz@warp10.net> 00005 * 00006 * This code is distributed under the terms and conditions of the 00007 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details. 00008 * 00009 * parts of this file are derived from the OMS program. 00010 * 00011 * $Id: dvbspu.h 1.12 2006/04/17 12:47:29 kls Exp $ 00012 */ 00013 00014 #ifndef __DVBSPU_H 00015 #define __DVBSPU_H 00016 00017 #include <inttypes.h> 00018 #include "osd.h" 00019 #include "spu.h" 00020 #include "thread.h" 00021 00022 typedef struct sDvbSpuPalDescr { 00023 uint8_t index; 00024 uint8_t trans; 00025 00026 bool operator != (const sDvbSpuPalDescr pd) const { 00027 return index != pd.index && trans != pd.trans; 00028 }; 00029 } aDvbSpuPalDescr[4]; 00030 00031 typedef struct sDvbSpuRect { 00032 int x1, y1; 00033 int x2, y2; 00034 00035 int width() { 00036 return x2 - x1 + 1; 00037 }; 00038 int height() { 00039 return y2 - y1 + 1; 00040 }; 00041 00042 bool operator != (const sDvbSpuRect r) const { 00043 return r.x1 != x1 || r.y1 != y1 || r.x2 != x2 || r.y2 != y2; 00044 }; 00045 } 00046 00047 sDvbSpuRect; 00048 00049 // --- cDvbSpuPalette--------------------------------------------------------- 00050 00051 class cDvbSpuPalette { 00052 private: 00053 uint32_t palette[16]; 00054 00055 private: 00056 uint32_t yuv2rgb(uint32_t yuv_color); 00057 00058 public: 00059 void setPalette(const uint32_t * pal); 00060 uint32_t getColor(uint8_t idx, uint8_t trans) const; 00061 }; 00062 00063 // --- cDvbSpuBitmap---------------------------------------------------------- 00064 00065 class cDvbSpuBitmap { 00066 00067 public: 00068 private: 00069 sDvbSpuRect bmpsize; 00070 sDvbSpuRect minsize[4]; 00071 uint8_t *bmp; 00072 00073 private: 00074 void putPixel(int xp, int yp, int len, uint8_t colorid); 00075 void putFieldData(int field, uint8_t * data, uint8_t * endp); 00076 00077 public: 00078 cDvbSpuBitmap(sDvbSpuRect size, 00079 uint8_t * fodd, uint8_t * eodd, 00080 uint8_t * feven, uint8_t * eeven); 00081 ~cDvbSpuBitmap(); 00082 00083 bool getMinSize(const aDvbSpuPalDescr paldescr, 00084 sDvbSpuRect & size) const; 00085 cBitmap *getBitmap(const aDvbSpuPalDescr paldescr, 00086 const cDvbSpuPalette & pal, 00087 sDvbSpuRect & size) const; 00088 }; 00089 00090 // --- cDvbSpuDecoder--------------------------------------------------------- 00091 00092 class cDvbSpuDecoder:public cSpuDecoder { 00093 private: 00094 cOsd *osd; 00095 cMutex mutex; 00096 00097 // processing state 00098 uint8_t *spu; 00099 uint32_t spupts; 00100 bool clean; 00101 bool ready; 00102 00103 enum spFlag { spNONE, spHIDE, spSHOW, spMENU }; 00104 spFlag state; 00105 00106 cSpuDecoder::eScaleMode scaleMode; 00107 00108 //highligh area 00109 bool highlight; 00110 sDvbSpuRect hlpsize; 00111 aDvbSpuPalDescr hlpDescr; 00112 00113 //palette 00114 cDvbSpuPalette palette; 00115 00116 // spu info's 00117 sDvbSpuRect size; 00118 aDvbSpuPalDescr palDescr; 00119 00120 uint16_t DCSQ_offset; 00121 uint16_t prev_DCSQ_offset; 00122 00123 cDvbSpuBitmap *spubmp; 00124 bool allowedShow; 00125 private: 00126 int cmdOffs(void) { 00127 return ((spu[2] << 8) | spu[3]); 00128 }; 00129 int spuSize(void) { 00130 return ((spu[0] << 8) | spu[1]); 00131 }; 00132 00133 sDvbSpuRect CalcAreaSize(sDvbSpuRect fgsize, cBitmap *fgbmp, sDvbSpuRect bgsize, cBitmap *bgbmp); 00134 00135 public: 00136 cDvbSpuDecoder(); 00137 ~cDvbSpuDecoder(); 00138 00139 int setTime(uint32_t pts); 00140 00141 cSpuDecoder::eScaleMode getScaleMode(void) { return scaleMode; } 00142 void setScaleMode(cSpuDecoder::eScaleMode ScaleMode); 00143 void setPalette(uint32_t * pal); 00144 void setHighlight(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, 00145 uint32_t palette); 00146 void clearHighlight(void); 00147 void Empty(void); 00148 void Hide(void); 00149 void Draw(void); 00150 bool IsVisible(void) { return osd != NULL; } 00151 void processSPU(uint32_t pts, uint8_t * buf, bool AllowedShow); 00152 }; 00153 00154 // --- cDvbSpuPalette -------------------------------------------------------- 00155 00156 inline uint32_t cDvbSpuPalette::yuv2rgb(uint32_t yuv_color) 00157 { 00158 int Y, Cb, Cr; 00159 int Ey, Epb, Epr; 00160 int Eg, Eb, Er; 00161 00162 Y = (yuv_color >> 16) & 0xff; 00163 Cb = (yuv_color) & 0xff; 00164 Cr = (yuv_color >> 8) & 0xff; 00165 00166 Ey = (Y - 16); 00167 Epb = (Cb - 128); 00168 Epr = (Cr - 128); 00169 /* ITU-R 709 00170 Eg = (298*Ey - 55*Epb - 137*Epr)/256; 00171 Eb = (298*Ey + 543*Epb)/256; 00172 Er = (298*Ey + 460*Epr)/256; 00173 */ 00174 /* FCC ~= mediaLib */ 00175 Eg = (298 * Ey - 100 * Epb - 208 * Epr) / 256; 00176 Eb = (298 * Ey + 516 * Epb) / 256; 00177 Er = (298 * Ey + 408 * Epr) / 256; 00178 00179 if (Eg > 255) 00180 Eg = 255; 00181 if (Eg < 0) 00182 Eg = 0; 00183 00184 if (Eb > 255) 00185 Eb = 255; 00186 if (Eb < 0) 00187 Eb = 0; 00188 00189 if (Er > 255) 00190 Er = 255; 00191 if (Er < 0) 00192 Er = 0; 00193 00194 return Eb | (Eg << 8) | (Er << 16); 00195 } 00196 00197 inline uint32_t cDvbSpuPalette::getColor(uint8_t idx, uint8_t trans) const 00198 { 00199 uint8_t t = trans == 0x0f ? 0xff : trans << 4; 00200 return palette[idx] | (t << 24); 00201 } 00202 00203 #endif // __DVBSPU_H