00001
00002
00003 #include "teletextextractorreader.h"
00004
00005 void TeletextExtractorReader::PageUpdated(int page, int subpage)
00006 {
00007 m_updated_pages.insert(qMakePair(page, subpage));
00008 TeletextReader::PageUpdated(page, subpage);
00009 }
00010
00011 void TeletextExtractorReader::HeaderUpdated(
00012 int page, int subpage, uint8_t *page_ptr, int lang)
00013 {
00014 m_updated_pages.insert(qMakePair(page, subpage));
00015 TeletextReader::HeaderUpdated(page, subpage, page_ptr, lang);
00016 }
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 static const uint16_t ppi_national_subsets[][20] =
00057 {
00058 { 0x00a3, 0x0024, 0x0040, 0x00ab, 0x00bd, 0x00bb, 0x005e, 0x0023,
00059 0x002d, 0x00bc, 0x00a6, 0x00be, 0x00f7 },
00060
00061 { 0x00e9, 0x00ef, 0x00e0, 0x00eb, 0x00ea, 0x00f9, 0x00ee, 0x0023,
00062 0x00e8, 0x00e2, 0x00f4, 0x00fb, 0x00e7, 0, 0x00eb, 0, 0x00ef
00063 },
00064
00065 { 0x0023, 0x00a4, 0x00c9, 0x00c4, 0x00d6, 0x00c5, 0x00dc, 0x005f,
00066 0x00e9, 0x00e4, 0x00f6, 0x00e5, 0x00fc
00067 },
00068
00069 { 0x0023, 0x016f, 0x010d, 0x0165, 0x017e, 0x00fd, 0x00ed, 0x0159,
00070 0x00e9, 0x00e1, 0x011b, 0x00fa, 0x0161 },
00071
00072 { 0x0023, 0x0024, 0x00a7, 0x00c4, 0x00d6, 0x00dc, 0x005e, 0x005f,
00073 0x00b0, 0x00e4, 0x00f6, 0x00fc, 0x00df },
00074
00075 { 0x00e7, 0x0024, 0x00a1, 0x00e1, 0x00e9, 0x00ed, 0x00f3, 0x00fa,
00076 0x00bf, 0x00fc, 0x00f1, 0x00e8, 0x00e0 },
00077
00078 { 0x00a3, 0x0024, 0x00e9, 0x00b0, 0x00e7, 0x00bb, 0x005e, 0x0023,
00079 0x00f9, 0x00e0, 0x00f2, 0x00e8, 0x00ec },
00080
00081 { 0x0023, 0x00a4, 0x0162, 0x00c2, 0x015e, 0x0102, 0x00ce, 0x0131,
00082 0x0163, 0x00e2, 0x015f, 0x0103, 0x00ee },
00083
00084
00085 { 0x0023, 0x0024, 0x0160, 0x0117, 0x0119, 0x017d, 0x010d, 0x016b,
00086 0x0161, 0x0105, 0x0173, 0x017e, 0x012f },
00087
00088 { 0x0023, 0x0144, 0x0105, 0x005a, 0x015a, 0x0141, 0x0107, 0x00f3,
00089 0x0119, 0x017c, 0x015b, 0x0142, 0x017a },
00090
00091 { 0x0023, 0x00cb, 0x010c, 0x0106, 0x017d, 0x0110, 0x0160, 0x00eb,
00092 0x010d, 0x0107, 0x017e, 0x0111, 0x0161
00093 },
00094
00095 { 0x0023, 0x00f5, 0x0160, 0x00c4, 0x00d6, 0x017e, 0x00dc, 0x00d5,
00096 0x0161, 0x00e4, 0x00f6, 0x017e, 0x00fc },
00097
00098 { 0x0054, 0x011f, 0x0130, 0x015e, 0x00d6, 0x00c7, 0x00dc, 0x011e,
00099 0x0131, 0x015f, 0x00f6, 0x00e7, 0x00fc },
00100 };
00101
00102
00103
00104
00105 static void to_utf8(char *res, uint16_t ch)
00106 {
00107 if(ch >= 0x80)
00108 {
00109 if(ch >= 0x800)
00110 {
00111 res[0] = (ch >> 12) | 0xE0;
00112 res[1] = ((ch >> 6) & 0x3F) | 0x80;
00113 res[2] = (ch & 0x3F) | 0x80;
00114 res[3] = 0;
00115 }
00116 else
00117 {
00118 res[0] = (ch >> 6) | 0xC0;
00119 res[1] = (ch & 0x3F) | 0x80;
00120 res[2] = 0;
00121 }
00122 }
00123 else
00124 {
00125 res[0] = ch;
00126 res[1] = 0;
00127 }
00128 }
00129
00134 QString decode_teletext(int codePage, const uint8_t data[40])
00135 {
00136 QString res;
00137 char utf8[7];
00138
00139 const uint16_t *pi_active_national_set = ppi_national_subsets[codePage];
00140
00141 for (int i = 0; i < 40; ++i)
00142 {
00143
00144 int in = data[i] & 0x7f;
00145 uint16_t out = 32;
00146
00147 switch (in)
00148 {
00149
00150 case 0x23:
00151 out = pi_active_national_set[0];
00152 break;
00153 case 0x24:
00154 out = pi_active_national_set[1];
00155 break;
00156 case 0x40:
00157 out = pi_active_national_set[2];
00158 break;
00159 case 0x5b:
00160 out = pi_active_national_set[3];
00161 break;
00162 case 0x5c:
00163 out = pi_active_national_set[4];
00164 break;
00165 case 0x5d:
00166 out = pi_active_national_set[5];
00167 break;
00168 case 0x5e:
00169 out = pi_active_national_set[6];
00170 break;
00171 case 0x5f:
00172 out = pi_active_national_set[7];
00173 break;
00174 case 0x60:
00175 out = pi_active_national_set[8];
00176 break;
00177 case 0x7b:
00178 out = pi_active_national_set[9];
00179 break;
00180 case 0x7c:
00181 out = pi_active_national_set[10];
00182 break;
00183 case 0x7d:
00184 out = pi_active_national_set[11];
00185 break;
00186 case 0x7e:
00187 out = pi_active_national_set[12];
00188 break;
00189
00190 case 0x0a:
00191 case 0x0b:
00192 case 0x0d:
00193
00194 out = 32;
00195 break;
00196
00197 default:
00198
00199 if (in >= 0x08 && in <= 0x0f)
00200 {
00201 out = pi_active_national_set[13 + in - 8];
00202 break;
00203 }
00204
00205
00206 if (in > 32 && in < 0x7f)
00207 out = in;
00208 }
00209
00210
00211 if (out == 0)
00212 out = '?';
00213
00214
00215 to_utf8(utf8, out);
00216 res += QString::fromUtf8(utf8, strlen(utf8));
00217 }
00218
00219 return res;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245