8 #include <lib/dvb/idemux.h>
9 #include <lib/dvb/subtitle.h>
10 #include <lib/base/smartptr.h>
11 #include <lib/base/eerror.h>
12 #include <lib/gdi/gpixmap.h>
14 void bitstream_init(bitstream *bit, const void *buffer, int size)
16 bit->data = (__u8*) buffer;
22 int bitstream_get(bitstream *bit)
25 bit->avail -= bit->size;
26 val = ((*bit->data) >> bit->avail) & ((1<<bit->size) - 1);
36 static int extract_pts(pts_t &pts, __u8 *pkt)
41 pkt++; // header length
43 if (flags & 0x80) /* PTS present? */
46 pts = ((unsigned long long)(((pkt[0] >> 1) & 7))) << 30;
48 pts |= (pkt[2]>>1) << 15;
57 void eDVBSubtitleParser::subtitle_process_line(subtitle_page *page, int object_id, int line, __u8 *data, int len)
59 subtitle_region *region = page->regions;
60 // eDebug("line for %d:%d", page->page_id, object_id);
63 subtitle_region_object *object = region->region_objects;
66 if (object->object_id == object_id)
68 int x = object->object_horizontal_position;
69 int y = object->object_vertical_position + line;
70 if (x + len > region->region_width)
72 //eDebug("[SUB] !!!! XCLIP %d + %d > %d", x, len, region->region_width);
73 len = region->region_width - x;
77 if (y >= region->region_height)
79 //eDebug("[SUB] !!!! YCLIP %d >= %d", y, region->region_height);
82 // //eDebug("inserting %d bytes (into region %d)", len, region->region_id);
83 // eDebug("put data to region_buffer %p", &(*region->region_buffer));
84 memcpy((__u8*)region->region_buffer->surface->data + region->region_width * y + x, data, len);
86 object = object->next;
88 region = region->next;
92 int eDVBSubtitleParser::subtitle_process_pixel_data(subtitle_page *page, int object_id, int *linenr, int *linep, __u8 *data)
94 int data_type = *data++;
95 static __u8 line[720];
101 case 0x10: // 2bit pixel data
102 bitstream_init(&bit, data, 2);
106 int code = bitstream_get(&bit);
113 code = bitstream_get(&bit);
116 code = bitstream_get(&bit);
121 } else if (code == 2)
123 len = bitstream_get(&bit) << 2;
124 len |= bitstream_get(&bit);
126 col = bitstream_get(&bit);
127 } else if (code == 3)
129 len = bitstream_get(&bit) << 6;
130 len |= bitstream_get(&bit) << 4;
131 len |= bitstream_get(&bit) << 2;
132 len |= bitstream_get(&bit);
134 col = bitstream_get(&bit);
144 len = 3 + 4 + bitstream_get(&bit);
146 len = 3 + bitstream_get(&bit);
147 col = bitstream_get(&bit);
150 while (len && ((*linep) < 720))
152 line[(*linep)++] = col;
156 while (bit.avail != 8)
158 return bit.consumed + 1;
159 case 0x11: // 4bit pixel data
160 bitstream_init(&bit, data, 4);
164 int code = bitstream_get(&bit);
171 code = bitstream_get(&bit);
174 else if (code == 0xC)
178 } else if (code == 0xD)
185 len = (code & 7) + 2;
186 } else if ((code & 0xC) == 0x8)
188 col = bitstream_get(&bit);
189 len = (code & 3) + 4;
190 } else if (code == 0xE)
192 len = bitstream_get(&bit) + 9;
193 col = bitstream_get(&bit);
194 } else if (code == 0xF)
196 len = bitstream_get(&bit) << 4;
197 len |= bitstream_get(&bit);
199 col = bitstream_get(&bit);
202 while (len && ((*linep) < 720))
204 line[(*linep)++] = col;
208 while (bit.avail != 8)
210 return bit.consumed + 1;
211 case 0x12: // 8bit pixel data
212 bitstream_init(&bit, data, 8);
216 int code = bitstream_get(&bit);
223 code = bitstream_get(&bit);
224 if ((code & 0x80) == 0x80)
227 col = bitstream_get(&bit);
228 } else if (code&0x7F)
235 while (len && ((*linep) < 720))
237 line[(*linep)++] = col;
241 return bit.consumed + 1;
242 case 0x20: // ignore 2 -> 4bit map table
243 bitstream_init(&bit, data, 4);
244 for ( int i=0; i < 4; ++i )
247 case 0x21: // ignore 2 -> 8bit map table
248 bitstream_init(&bit, data, 8);
249 for ( int i=0; i < 4; ++i )
252 case 0x22: // ignore 4 -> 8bit map table
253 bitstream_init(&bit, data, 8);
254 for ( int i=0; i < 16; ++i )
258 subtitle_process_line(page, object_id, *linenr, line, *linep);
261 for (i=0; i<720; ++i)
262 //eDebugNoNewLine("%d ", line[i]);
265 (*linenr)+=2; // interlaced
267 // //eDebug("[SUB] EOL");
270 eDebug("subtitle_process_pixel_data: invalid data_type %02x", data_type);
276 int eDVBSubtitleParser::subtitle_process_segment(__u8 *segment)
278 int segment_type, page_id, segment_length, processed_length;
279 if (*segment++ != 0x0F)
281 eDebug("out of sync.");
284 segment_type = *segment++;
285 page_id = *segment++ << 8;
286 page_id |= *segment++;
287 segment_length = *segment++ << 8;
288 segment_length |= *segment++;
289 if (segment_type == 0xFF)
290 return segment_length + 6;
291 if (page_id != m_composition_page_id && page_id != m_ancillary_page_id)
292 return segment_length + 6;
293 //eDebug("have %d bytes of segment data", segment_length);
295 //eDebug("page_id %d, segtype %02x", page_id, segment_type);
297 subtitle_page *page, **ppage;
299 page = m_pages; ppage = &m_pages;
303 if (page->page_id == page_id)
309 processed_length = 0;
311 switch (segment_type)
313 case 0x10: // page composition segment
315 int page_time_out = *segment++; processed_length++;
316 int page_version_number = *segment >> 4;
317 int page_state = (*segment >> 2) & 0x3;
318 //eDebug("pcs with %d bytes data (%d:%d:%d)", segment_length, page_id, page_version_number, page_state);
322 //eDebug("page time out: %d", page_time_out);
323 //eDebug("page_version_number: %d" ,page_version_number);
324 //eDebug("page_state: %d", page_state);
328 //eDebug("page not found");
329 page = new subtitle_page;
330 page->page_regions = 0;
332 page->page_id = page_id;
338 if (page->pcs_size != segment_length)
339 page->page_version_number = -1;
340 // if no update, just skip this data.
341 if (page->page_version_number == page_version_number)
343 // eDebug("skip data... ");
348 page->state = page_state;
350 //eDebug("page updated: old: %d, new: %d", page->page_version_number, page_version_number);
351 // when acquisition point or mode change: remove all displayed pages.
352 if ((page_state == 1) || (page_state == 2))
354 while (page->page_regions)
356 subtitle_page_region *p = page->page_regions->next;
357 //eDebug("delete page_region %d", page->page_regions->region_id);
358 delete page->page_regions;
359 page->page_regions = p;
361 while (page->regions)
363 subtitle_region *p = page->regions->next;
364 //eDebug("delete region %d", page->regions->region_id);
365 while(page->regions->region_objects)
367 //eDebug("delete region object");
368 subtitle_region_object *ob = page->regions->region_objects->next;
369 delete page->regions->region_objects;
370 page->regions->region_objects = ob;
372 delete page->regions;
378 //eDebug("new page.. (%d)", page_state);
380 page->page_time_out = page_time_out;
382 page->page_version_number = page_version_number;
384 subtitle_page_region **r = &page->page_regions;
386 //eDebug("%d / %d data left", processed_length, segment_length);
392 if (processed_length == segment_length && !page->page_regions)
394 //eDebug("no regions in page.. clear screen!!");
395 subtitle_redraw(page->page_id);
398 while (processed_length < segment_length)
400 subtitle_page_region *pr;
402 // append new entry to list
403 pr = new subtitle_page_region;
408 pr->region_id = *segment++; processed_length++;
409 segment++; processed_length++;
411 pr->region_horizontal_address = *segment++ << 8;
412 pr->region_horizontal_address |= *segment++;
413 processed_length += 2;
415 pr->region_vertical_address = *segment++ << 8;
416 pr->region_vertical_address |= *segment++;
417 processed_length += 2;
419 //eDebug("appended active region");
422 if (processed_length != segment_length)
423 eDebug("%d != %d", processed_length, segment_length);
426 case 0x11: // region composition segment
428 int region_id = *segment++; processed_length++;
429 int region_version_number = *segment >> 4;
430 int region_fill_flag = (*segment >> 3) & 1;
431 segment++; processed_length++;
433 // if we didn't yet received the pcs for this page, drop the region
436 eDebug("ignoring region %x, since page %02x doesn't yet exist.", region_id, page_id);
440 subtitle_region *region, **pregion;
442 region = page->regions; pregion = &page->regions;
447 if (region->region_id == region_id)
449 pregion = ®ion->next;
450 region = region->next;
455 //eDebug("create region !!!!!!!!!!");
456 *pregion = region = new subtitle_region;
458 region->committed = false;
460 else if (region->region_version_number != region_version_number)
462 subtitle_region_object *objects = region->region_objects;
463 //eDebug("unequal version %p %p", objects, objects?objects->next:objects);
466 subtitle_region_object *n = objects->next;
470 if (region->region_buffer)
472 //eDebug("no more need of region_buffer %p", &(*region->region_buffer));
473 region->region_buffer=0;
475 region->committed = false;
480 //eDebug("region %d:%d update", page_id, region_id);
482 region->region_id = region_id;
483 region->region_version_number = region_version_number;
485 region->region_width = *segment++ << 8;
486 region->region_width |= *segment++;
487 processed_length += 2;
489 region->region_height = *segment++ << 8;
490 region->region_height |= *segment++;
491 processed_length += 2;
493 region->region_buffer = new gPixmap(eSize(region->region_width, region->region_height), 8);
494 //eDebug("new region_buffer %p", &(*region->region_buffer));
496 int region_level_of_compatibility, region_depth;
498 region_level_of_compatibility = (*segment >> 5) & 7;
499 region_depth = (*segment++ >> 2) & 7;
500 region->region_depth = (subtitle_region::depth) region_depth;
503 int CLUT_id = *segment++; processed_length++;
505 region->clut_id = CLUT_id;
507 int region_8bit_pixel_code, region_4bit_pixel_code, region_2bit_pixel_code;
508 region_8bit_pixel_code = *segment++; processed_length++;
509 region_4bit_pixel_code = *segment >> 4;
510 region_2bit_pixel_code = (*segment++ >> 2) & 3;
513 if (!region_fill_flag)
515 region_2bit_pixel_code = region_4bit_pixel_code = region_8bit_pixel_code = 0;
516 region_fill_flag = 1;
519 if (region_fill_flag)
521 //eDebug("region fill region_buffer %p", &(*region->region_buffer));
522 if (region_depth == 1)
523 memset(region->region_buffer->surface->data, region_2bit_pixel_code, region->region_height * region->region_width);
524 else if (region_depth == 2)
525 memset(region->region_buffer->surface->data, region_4bit_pixel_code, region->region_height * region->region_width);
526 else if (region_depth == 3)
527 memset(region->region_buffer->surface->data, region_8bit_pixel_code, region->region_height * region->region_width);
529 eDebug("!!!! invalid depth");
532 //eDebug("region %02x, version %d, %dx%d", region->region_id, region->region_version_number, region->region_width, region->region_height);
534 region->region_objects = 0;
535 subtitle_region_object **pobject = ®ion->region_objects;
537 while (processed_length < segment_length)
539 subtitle_region_object *object;
541 object = new subtitle_region_object;
545 pobject = &object->next;
547 object->object_id = *segment++ << 8;
548 object->object_id |= *segment++; processed_length += 2;
550 object->object_type = *segment >> 6;
551 object->object_provider_flag = (*segment >> 4) & 3;
552 object->object_horizontal_position = (*segment++ & 0xF) << 8;
553 object->object_horizontal_position |= *segment++;
554 processed_length += 2;
556 object->object_vertical_position = *segment++ << 8;
557 object->object_vertical_position |= *segment++ ;
558 processed_length += 2;
560 if ((object->object_type == 1) || (object->object_type == 2))
562 object->foreground_pixel_value = *segment++;
563 object->background_pixel_value = *segment++;
564 processed_length += 2;
568 if (processed_length != segment_length)
569 eDebug("too less data! (%d < %d)", segment_length, processed_length);
573 case 0x12: // CLUT definition segment
575 int CLUT_id, CLUT_version_number;
576 subtitle_clut *clut, **pclut;
581 //eDebug("CLUT: %02x", *segment);
582 CLUT_id = *segment++;
584 CLUT_version_number = *segment++ >> 4;
585 processed_length += 2;
587 //eDebug("page %d, CLUT %02x, version %d", page->page_id, CLUT_id, CLUT_version_number);
589 clut = page->cluts; pclut = &page->cluts;
593 if (clut->clut_id == CLUT_id)
601 *pclut = clut = new subtitle_clut;
603 clut->clut_id = CLUT_id;
605 else if (clut->CLUT_version_number == CLUT_version_number)
608 clut->CLUT_version_number=CLUT_version_number;
610 memset(clut->entries_2bit, 0, sizeof(clut->entries_2bit));
611 memset(clut->entries_4bit, 0, sizeof(clut->entries_4bit));
612 memset(clut->entries_8bit, 0, sizeof(clut->entries_8bit));
614 //eDebug("new clut");
615 while (processed_length < segment_length)
617 int CLUT_entry_id, entry_CLUT_flag, full_range;
618 int v_Y, v_Cr, v_Cb, v_T;
620 CLUT_entry_id = *segment++;
621 full_range = *segment & 1;
622 entry_CLUT_flag = (*segment++ & 0xE0) >> 5;
623 processed_length += 2;
631 processed_length += 4;
634 v_Y = *segment & 0xFC;
635 v_Cr = (*segment++ & 3) << 6;
636 v_Cr |= (*segment & 0xC0) >> 2;
637 v_Cb = (*segment & 0x3C) << 2;
638 v_T = (*segment++ & 3) << 6;
639 processed_length += 2;
642 if (entry_CLUT_flag & 1) // 8bit
644 ASSERT(CLUT_entry_id < 256);
645 clut->entries_8bit[CLUT_entry_id].Y = v_Y;
646 clut->entries_8bit[CLUT_entry_id].Cr = v_Cr;
647 clut->entries_8bit[CLUT_entry_id].Cb = v_Cb;
648 clut->entries_8bit[CLUT_entry_id].T = v_T;
649 clut->entries_8bit[CLUT_entry_id].valid = 1;
651 if (entry_CLUT_flag & 2) // 4bit
653 ASSERT(CLUT_entry_id < 16);
654 clut->entries_4bit[CLUT_entry_id].Y = v_Y;
655 clut->entries_4bit[CLUT_entry_id].Cr = v_Cr;
656 clut->entries_4bit[CLUT_entry_id].Cb = v_Cb;
657 clut->entries_4bit[CLUT_entry_id].T = v_T;
658 clut->entries_4bit[CLUT_entry_id].valid = 1;
660 if (entry_CLUT_flag & 4) // 2bit
662 ASSERT(CLUT_entry_id < 4);
663 clut->entries_2bit[CLUT_entry_id].Y = v_Y;
664 clut->entries_2bit[CLUT_entry_id].Cr = v_Cr;
665 clut->entries_2bit[CLUT_entry_id].Cb = v_Cb;
666 clut->entries_2bit[CLUT_entry_id].T = v_T;
667 clut->entries_2bit[CLUT_entry_id].valid = 1;
669 //eDebug(" %04x %02x %02x %02x %02x", CLUT_entry_id, v_Y, v_Cb, v_Cr, v_T);
673 case 0x13: // object data segment
675 int object_id, object_version_number, object_coding_method, non_modifying_color_flag;
677 object_id = *segment++ << 8;
678 object_id |= *segment++;
679 processed_length += 2;
681 object_version_number = *segment >> 4;
682 object_coding_method = (*segment >> 2) & 3;
683 non_modifying_color_flag = (*segment++ >> 1) & 1;
686 //eDebug("object id %04x, version %d, object_coding_method %d (page_id %d)", object_id, object_version_number, object_coding_method, page_id);
688 if (object_coding_method == 0)
690 int top_field_data_blocklength, bottom_field_data_blocklength;
693 top_field_data_blocklength = *segment++ << 8;
694 top_field_data_blocklength |= *segment++;
696 bottom_field_data_blocklength = *segment++ << 8;
697 bottom_field_data_blocklength |= *segment++;
698 eDebug("%d / %d bytes", top_field_data_blocklength, bottom_field_data_blocklength);
699 processed_length += 4;
704 while (i < top_field_data_blocklength)
707 len = subtitle_process_pixel_data(page, object_id, &line, &linep, segment);
711 processed_length += len;
718 if (bottom_field_data_blocklength)
721 while (i < bottom_field_data_blocklength)
724 len = subtitle_process_pixel_data(page, object_id, &line, &linep, segment);
728 processed_length += len;
732 else if (top_field_data_blocklength)
733 eDebug("!!!! unimplemented: no bottom field! (%d : %d)", top_field_data_blocklength, bottom_field_data_blocklength);
735 if ((top_field_data_blocklength + bottom_field_data_blocklength) & 1)
737 segment++; processed_length++;
740 else if (object_coding_method == 1)
741 eDebug("---- object_coding_method 1 unsupported!");
745 case 0x80: // end of display set segment
747 //eDebug("end of display set segment");
748 subtitle_redraw_all();
750 case 0xFF: // stuffing
753 eDebug("unhandled segment type %02x", segment_type);
756 return segment_length + 6;
759 void eDVBSubtitleParser::subtitle_process_pes(__u8 *pkt, int len)
761 eDebugNoNewLine("subtitle_process_pes");
762 if (!extract_pts(m_show_time, pkt))
764 eDebug(" %lld", m_show_time);
770 int hdr_len = *pkt++; len--;
772 pkt+=hdr_len; len-=hdr_len;
776 //eDebug("data identifier is 0x%02x, but not 0x20", *pkt);
779 pkt++; len--; // data identifier
780 *pkt++; len--; // stream id;
784 //eDebug("no data left (%d)", len);
788 while (len && *pkt == 0x0F)
790 int l = subtitle_process_segment(pkt);
796 if (len && *pkt != 0xFF)
797 eDebug("strange data at the end");
800 eDebug("\ndvb subtitle packet without PTS.. ignore!!");
803 void eDVBSubtitleParser::subtitle_redraw_all()
806 subtitle_page *page = m_pages;
809 if (page->state != 0)
810 subtitle_redraw(page->page_id);
814 subtitle_page *page = m_pages;
815 eDebug("----------- end of display set");
816 eDebug("active pages:");
819 eDebug(" page_id %02x", page->page_id);
820 eDebug(" page_version_number: %d", page->page_version_number);
821 eDebug(" active regions:");
823 subtitle_page_region *region = page->page_regions;
826 eDebug(" region_id: %04x", region->region_id);
827 eDebug(" region_horizontal_address: %d", region->region_horizontal_address);
828 eDebug(" region_vertical_address: %d", region->region_vertical_address);
830 region = region->next;
834 subtitle_redraw(page->page_id);
835 eDebug("defined regions:");
836 subtitle_region *region = page->regions;
839 eDebug(" region_id %04x, version %d, %dx%d", region->region_id, region->region_version_number, region->region_width, region->region_height);
841 subtitle_region_object *object = region->region_objects;
844 eDebug(" object %02x, type %d, %d:%d", object->object_id, object->object_type, object->object_horizontal_position, object->object_vertical_position);
845 object = object->next;
847 region = region->next;
854 void eDVBSubtitleParser::subtitle_reset()
856 while (subtitle_page *page = m_pages)
858 /* free page regions */
859 while (page->page_regions)
861 subtitle_page_region *p = page->page_regions->next;
862 delete page->page_regions;
863 page->page_regions = p;
866 while (page->regions)
868 subtitle_region *region = page->regions;
870 while (region->region_objects)
872 subtitle_region_object *obj = region->region_objects;
873 region->region_objects = obj->next;
877 if (region->region_buffer)
879 // eDebug("no more need of region_buffer 2 %p", &(*region->region_buffer));
880 region->region_buffer=0;
883 page->regions = region->next;
890 subtitle_clut *clut = page->cluts;
891 page->cluts = clut->next;
895 m_pages = page->next;
900 void eDVBSubtitleParser::subtitle_redraw(int page_id)
902 subtitle_page *page = m_pages;
904 // eDebug("displaying page id %d", page_id);
908 if (page->page_id == page_id)
914 //eDebug("page not found");
918 //eDebug("iterating regions..");
919 /* iterate all regions in this pcs */
920 subtitle_page_region *region = page->page_regions;
922 eDVBSubtitlePage Page;
923 Page.m_show_time = m_show_time;
924 for (; region; region=region->next)
926 // eDebug("region %d", region->region_id);
927 /* find corresponding region */
928 subtitle_region *reg = page->regions;
931 if (reg->region_id == region->region_id)
939 // eDebug("copy region %d to %d, %d", region->region_id, region->region_horizontal_address, region->region_vertical_address);
941 int x0 = region->region_horizontal_address;
942 int y0 = region->region_vertical_address;
944 if ((x0 < 0) || (y0 < 0))
946 // eDebug("x0 %d, y0 %d",
951 /* find corresponding clut */
952 subtitle_clut *clut = page->cluts;
955 //eDebug("have %d, want %d", clut->clut_id, main_clut_id);
956 if (clut->clut_id == reg->clut_id)
961 int clut_size = reg->region_buffer->surface->clut.colors = reg->region_depth == subtitle_region::bpp2 ?
962 4 : reg->region_depth == subtitle_region::bpp4 ? 16 : 256;
964 reg->region_buffer->surface->clut.data = new gRGB[clut_size];
965 // eDebug("create clut data for region_buffer %p", &(*reg->region_buffer));
967 gRGB *palette = reg->region_buffer->surface->clut.data;
969 subtitle_clut_entry *entries=0;
970 switch(reg->region_depth)
972 case subtitle_region::bpp2:
974 entries = clut->entries_2bit;
975 memset(palette, 0, 4*sizeof(gRGB));
977 palette[2].r = palette[2].g = palette[2].b = 0xFF;
978 palette[3].r = palette[3].g = palette[3].b = 0x80;
980 case subtitle_region::bpp4:
982 entries = clut->entries_4bit;
983 memset(palette, 0, 16*sizeof(gRGB));
984 for (int i=0; i < 16; ++i)
1000 palette[i].r = 0xFF;
1002 palette[i].g = 0xFF;
1004 palette[i].b = 0xFF;
1008 case subtitle_region::bpp8:
1010 entries = clut->entries_8bit;
1011 memset(palette, 0, 16*sizeof(gRGB));
1012 for (int i=0; i < 256; ++i)
1016 case 0: // b1 == 0 && b5 == 0
1017 if (!(i & 14)) // b2 == 0 && b3 == 0 && b4 == 0
1019 if (!(i & 224)) // b6 == 0 && b7 == 0 && b8 == 0
1020 palette[i].a = 0xFF;
1023 if (i & 128) // R = 100% x b8
1024 palette[i].r = 0xFF;
1025 if (i & 64) // G = 100% x b7
1026 palette[i].g = 0xFF;
1027 if (i & 32) // B = 100% x b6
1028 palette[i].b = 0xFF;
1029 palette[i].a = 0xBF; // T = 75%
1034 case 16: // b1 == 0 && b5 == 1
1035 if (i & 128) // R = 33% x b8
1036 palette[i].r = 0x55;
1037 if (i & 64) // G = 33% x b7
1038 palette[i].g = 0x55;
1039 if (i & 32) // B = 33% x b6
1040 palette[i].b = 0x55;
1041 if (i & 8) // R + 66,7% x b4
1042 palette[i].r += 0xAA;
1043 if (i & 4) // G + 66,7% x b3
1044 palette[i].g += 0xAA;
1045 if (i & 2) // B + 66,7% x b2
1046 palette[i].b += 0xAA;
1047 if (i & 16) // needed for fall through from case 0!!
1048 palette[i].a = 0x80; // T = 50%
1050 case 1: // b1 == 1 && b5 == 0
1053 palette[i].b = 0x80; // 50%
1055 case 17: // b1 == 1 && b5 == 1
1056 if (i & 128) // R += 16.7% x b8
1057 palette[i].r += 0x2A;
1058 if (i & 64) // G += 16.7% x b7
1059 palette[i].g += 0x2A;
1060 if (i & 32) // B += 16.7% x b6
1061 palette[i].b += 0x2A;
1062 if (i & 8) // R += 33% x b4
1063 palette[i].r += 0x55;
1064 if (i & 4) // G += 33% x b3
1065 palette[i].g += 0x55;
1066 if (i & 2) // B += 33% x b2
1067 palette[i].b += 0x55;
1076 for (int i=0; i<clut_size; ++i)
1078 if (entries[i].valid)
1080 int y = entries[i].Y,
1088 palette[i].r = MAX(MIN(((298 * y + 460 * cr) / 256), 255), 0);
1089 palette[i].g = MAX(MIN(((298 * y - 55 * cb - 137 * cr) / 256), 255), 0);
1090 palette[i].b = MAX(MIN(((298 * y + 543 * cb ) / 256), 255), 0);
1091 palette[i].a = (entries[i].T) & 0xFF;
1092 // eDebug("override clut entry %d RGBA %02x%02x%02x%02x", i,
1093 // palette[i].r, palette[i].g, palette[i].b, palette[i].a);
1097 // eDebug("mist %d", i);
1101 palette[i].a = 0xFF;
1107 // eDebug("commit region_buffer %p", &(*reg->region_buffer));
1108 eDVBSubtitleRegion Region;
1109 Region.m_pixmap = reg->region_buffer;
1110 Region.m_position.setX(x0);
1111 Region.m_position.setY(y0);
1112 Page.m_regions.push_back(Region);
1113 reg->committed = true;
1116 eDebug("region not found");
1118 m_new_subtitle_page(Page);
1119 Page.m_regions.clear();
1120 // eDebug("page timeout is %d", page->page_time_out);
1121 // Page.m_show_time += (page->page_time_out * 90000);
1122 // m_new_subtitle_page(Page);
1123 //eDebug("schon gut.");
1126 DEFINE_REF(eDVBSubtitleParser);
1128 eDVBSubtitleParser::eDVBSubtitleParser(iDVBDemux *demux)
1133 if (demux->createPESReader(eApp, m_pes_reader))
1134 eDebug("failed to create dvb subtitle PES reader!");
1136 m_pes_reader->connectRead(slot(*this, &eDVBSubtitleParser::processData), m_read_connection);
1139 eDVBSubtitleParser::~eDVBSubtitleParser()
1144 int eDVBSubtitleParser::stop()
1148 eDebug("disable dvb subtitles");
1149 return m_pes_reader->stop();
1154 int eDVBSubtitleParser::start(int pid, int composition_page_id, int ancillary_page_id)
1158 eDebug("start dvb subtitles on pid 0x%04x with composition_page_id %d and ancillary_page_id %d",
1159 pid, composition_page_id, ancillary_page_id);
1160 m_composition_page_id = composition_page_id;
1161 m_ancillary_page_id = ancillary_page_id;
1162 return m_pes_reader->start(pid);
1167 void eDVBSubtitleParser::connectNewPage(const Slot1<void, const eDVBSubtitlePage&> &slot, ePtr<eConnection> &connection)
1169 connection = new eConnection(this, m_new_subtitle_page.connect(slot));