11 int parseCDThead(unsigned char *data, CDThead *h) {
14 memset(h, 0, sizeof(CDThead));
16 h->table_id = getBit(data, &boff, 8);
17 h->section_syntax_indicator = getBit(data, &boff, 1);
18 h->reserved_future_use1 = getBit(data, &boff, 1);
19 h->reserved1 = getBit(data, &boff, 2);
20 h->section_length = getBit(data, &boff, 12);
21 h->download_data_id = getBit(data, &boff, 16);
22 h->reserved2 = getBit(data, &boff, 2);
23 h->version_number = getBit(data, &boff, 5);
24 h->current_next_indicator = getBit(data, &boff, 1);
25 h->section_number = getBit(data, &boff, 8);
26 h->last_section_number = getBit(data, &boff, 8);
27 h->original_network_id = getBit(data, &boff, 16);
28 h->data_type = getBit(data, &boff, 8);
29 h->reserved_future_use2 = getBit(data, &boff, 4);
30 h->descriptors_loop_length = getBit(data, &boff, 12);
35 int parseCDTdesc(unsigned char *data, CDTdesc *desc) {
39 memset(desc, 0, sizeof(CDTdesc));
41 desc->descriptor_tag = getBit(data, &boff, 8);
42 desc->descriptor_length = getBit(data, &boff, 8);
44 return desc->descriptor_length + 2;
47 int parseCDTdata(unsigned char *data, CDTdata *cdtd) {
50 memset(cdtd, 0, sizeof(CDTdata));
52 cdtd->logo_type = getBit(data, &boff, 8);
53 cdtd->reserved_future_use1 = getBit(data, &boff, 7);
54 cdtd->logo_id = getBit(data, &boff, 9);
55 cdtd->reserved_future_use2 = getBit(data, &boff, 4);
56 cdtd->logo_version = getBit(data, &boff, 12);
57 cdtd->data_size = getBit(data, &boff, 16);
58 cdtd->data = calloc(1, cdtd->data_size);
59 memcpy(cdtd->data, data + boff / 8, cdtd->data_size);
60 //boff += cdtd->data_size * 8;
62 return cdtd->data_size + 7;
65 void dumpCDT(unsigned char *ptr, STATION *station, int station_count)
78 len = parseCDThead(ptr, &cdth);
80 loop_len = cdth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
82 desc_len = cdth.descriptors_loop_length;
84 len = parseCDTdesc(ptr, &desc);
92 0x00 24x48 864 SD4:3 スモール
93 0x01 24x36 648 SD16:9 スモール
94 0x02 27x48 972 HD スモール
95 0x03 36x72 1296 SD4:3 ラージ
96 0x04 36x54 972 SD16:9 ラージ
97 0x05 36x64 1152 HD ラージ
99 len = parseCDTdata(ptr, &cdtd);
104 sprintf(fname,"%d_%d.png",cdth.download_data_id,cdtd.logo_type);
105 FILE* png = fopen(fname,"wb");
106 void* mem_png = NULL;
108 clt2png(cdtd.data,&mem_png, &size_png);
109 fwrite(mem_png, 1, size_png, png);
113 printf("CDT=(%d:%d:%d:%d:%d:%dbyte:desc%dbyte)%d,%d,%d,%d\n",
114 cdth.table_id, cdth.download_data_id, cdth.version_number,
115 cdth.original_network_id, cdth.data_type,
116 cdth.section_length, cdth.descriptors_loop_length,
118 cdtd.logo_type, cdtd.logo_id, cdtd.logo_version,
121 for ( i = 0; i < station_count; i++ ) {
122 pLogo = &station[i].logo_array[cdtd.logo_type];
123 if ( station[i].logo_download_data_id == cdth.download_data_id ) {
125 clt2png(cdtd.data, &pLogo->logo, &pLogo->logo_size);