28 #define DVBSUB_PAGE_SEGMENT 0x10 29 #define DVBSUB_REGION_SEGMENT 0x11 30 #define DVBSUB_CLUT_SEGMENT 0x12 31 #define DVBSUB_OBJECT_SEGMENT 0x13 32 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14 33 #define DVBSUB_DISPLAY_SEGMENT 0x80 35 #define cm (ff_crop_tab + MAX_NEG_CROP) 38 static void png_save(
const char *filename, uint32_t *bitmap,
int w,
int h)
42 char fname[40], fname2[40];
45 snprintf(fname,
sizeof(fname),
"%s.ppm", filename);
47 f = fopen(fname,
"w");
56 for(y = 0; y < h; y++) {
57 for(x = 0; x < w; x++) {
58 v = bitmap[y * w + x];
59 putc((v >> 16) & 0xff, f);
60 putc((v >> 8) & 0xff, f);
61 putc((v >> 0) & 0xff, f);
67 snprintf(fname2,
sizeof(fname2),
"%s-a.pgm", filename);
69 f = fopen(fname2,
"w");
78 for(y = 0; y < h; y++) {
79 for(x = 0; x < w; x++) {
80 v = bitmap[y * w + x];
81 putc((v >> 24) & 0xff, f);
86 snprintf(command,
sizeof(command),
"pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
89 snprintf(command,
sizeof(command),
"rm %s %s", fname, fname2);
94 #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) 187 while (ptr && ptr->
id != object_id) {
198 while (ptr && ptr->
id != clut_id) {
209 while (ptr && ptr->
id != region_id) {
227 obj_disp_ptr = &
object->display_list;
228 obj_disp = *obj_disp_ptr;
230 while (obj_disp && obj_disp != display) {
232 obj_disp = *obj_disp_ptr;
242 while (obj2 !=
object) {
244 obj2_ptr = &obj2->
next;
248 *obj2_ptr = obj2->
next;
294 int i,
r,
g,
b,
a = 0;
306 default_clut.
id = -1;
309 default_clut.
clut4[0] =
RGBA( 0, 0, 0, 0);
310 default_clut.
clut4[1] =
RGBA(255, 255, 255, 255);
311 default_clut.
clut4[2] =
RGBA( 0, 0, 0, 255);
312 default_clut.
clut4[3] =
RGBA(127, 127, 127, 255);
315 for (i = 1; i < 16; i++) {
317 r = (i & 1) ? 255 : 0;
318 g = (i & 2) ? 255 : 0;
319 b = (i & 4) ? 255 : 0;
321 r = (i & 1) ? 127 : 0;
322 g = (i & 2) ? 127 : 0;
323 b = (i & 4) ? 127 : 0;
329 for (i = 1; i < 256; i++) {
331 r = (i & 1) ? 255 : 0;
332 g = (i & 2) ? 255 : 0;
333 b = (i & 4) ? 255 : 0;
338 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
339 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
340 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
344 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
345 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
346 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
350 r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
351 g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
352 b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
356 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
357 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
358 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
387 const uint8_t **srcbuf,
int buf_size,
388 int non_mod,
uint8_t *map_table)
398 while (
get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
402 if (non_mod != 1 || bits != 1) {
404 *destbuf++ = map_table[
bits];
415 if (non_mod == 1 && bits == 1)
416 pixels_read += run_length;
419 bits = map_table[
bits];
420 while (run_length-- > 0 && pixels_read < dbuf_len) {
433 if (non_mod == 1 && bits == 1)
434 pixels_read += run_length;
437 bits = map_table[
bits];
438 while (run_length-- > 0 && pixels_read < dbuf_len) {
443 }
else if (bits == 3) {
447 if (non_mod == 1 && bits == 1)
448 pixels_read += run_length;
451 bits = map_table[
bits];
452 while (run_length-- > 0 && pixels_read < dbuf_len) {
457 }
else if (bits == 1) {
463 if (pixels_read <= dbuf_len) {
492 const uint8_t **srcbuf,
int buf_size,
493 int non_mod,
uint8_t *map_table)
503 while (
get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
507 if (non_mod != 1 || bits != 1) {
509 *destbuf++ = map_table[
bits];
519 if (run_length == 0) {
531 while (run_length-- > 0 && pixels_read < dbuf_len) {
541 if (non_mod == 1 && bits == 1)
542 pixels_read += run_length;
545 bits = map_table[
bits];
546 while (run_length-- > 0 && pixels_read < dbuf_len) {
557 if (non_mod == 1 && bits == 1)
558 pixels_read += run_length;
561 bits = map_table[
bits];
562 while (run_length-- > 0 && pixels_read < dbuf_len) {
567 }
else if (bits == 3) {
571 if (non_mod == 1 && bits == 1)
572 pixels_read += run_length;
575 bits = map_table[
bits];
576 while (run_length-- > 0 && pixels_read < dbuf_len) {
581 }
else if (bits == 1) {
587 if (pixels_read <= dbuf_len) {
613 const uint8_t **srcbuf,
int buf_size,
614 int non_mod,
uint8_t *map_table)
616 const uint8_t *sbuf_end = (*srcbuf) + buf_size;
621 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
625 if (non_mod != 1 || bits != 1) {
627 *destbuf++ = map_table[
bits];
634 run_length = bits & 0x7f;
635 if ((bits & 0x80) == 0) {
636 if (run_length == 0) {
642 if (non_mod == 1 && bits == 1)
643 pixels_read += run_length;
649 while (run_length-- > 0 && pixels_read < dbuf_len) {
665 const uint8_t *buf,
int buf_size,
int top_bottom,
int non_mod)
670 const uint8_t *buf_end = buf + buf_size;
675 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
676 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
677 uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
678 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
681 ff_dlog(avctx,
"DVB pixel block size %d, %s field:\n", buf_size,
682 top_bottom ?
"bottom" :
"top");
684 for (i = 0; i < buf_size; i++) {
686 ff_dlog(avctx,
"0x%8p: ", buf+i);
688 ff_dlog(avctx,
"%02x ", buf[i]);
701 x_pos = display->
x_pos;
702 y_pos = display->
y_pos;
704 if ((y_pos & 1) != top_bottom)
707 while (buf < buf_end) {
708 if (x_pos > region->
width || y_pos > region->
height) {
715 if (region->
depth == 8)
717 else if (region->
depth == 4)
723 region->
width - x_pos, &buf, buf_end - buf,
727 if (region->
depth < 4) {
732 if (region->
depth == 8)
738 region->
width - x_pos, &buf, buf_end - buf,
742 if (region->
depth < 8) {
748 region->
width - x_pos, &buf, buf_end - buf,
753 map2to4[0] = (*buf) >> 4;
754 map2to4[1] = (*buf++) & 0xf;
755 map2to4[2] = (*buf) >> 4;
756 map2to4[3] = (*buf++) & 0xf;
759 for (i = 0; i < 4; i++)
763 for (i = 0; i < 16; i++)
768 x_pos = display->
x_pos;
779 const uint8_t *buf,
int buf_size)
783 const uint8_t *buf_end = buf + buf_size;
788 int top_field_len, bottom_field_len;
790 int coding_method, non_modifying_color;
800 coding_method = ((*buf) >> 2) & 3;
801 non_modifying_color = ((*buf++) >> 1) & 1;
803 if (coding_method == 0) {
806 bottom_field_len =
AV_RB16(buf);
809 if (buf + top_field_len + bottom_field_len > buf_end) {
818 non_modifying_color);
820 if (bottom_field_len > 0)
821 block = buf + top_field_len;
823 bottom_field_len = top_field_len;
826 non_modifying_color);
839 const uint8_t *buf,
int buf_size)
843 const uint8_t *buf_end = buf + buf_size;
846 int entry_id, depth , full_range;
847 int y, cr, cb, alpha;
848 int r,
g,
b, r_add, g_add, b_add;
850 ff_dlog(avctx,
"DVB clut packet:\n");
852 for (i=0; i < buf_size; i++) {
853 ff_dlog(avctx,
"%02x ", buf[i]);
871 memcpy(clut, &default_clut,
sizeof(
DVBSubCLUT));
879 while (buf + 4 < buf_end) {
882 depth = (*buf) & 0xe0;
889 full_range = (*buf++) & 1;
898 cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
899 cb = (buf[1] << 2) & 0xf0;
900 alpha = (buf[1] << 6) & 0xc0;
911 ff_dlog(avctx,
"clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
914 clut->
clut4[entry_id] =
RGBA(r,g,b,255 - alpha);
916 clut->
clut16[entry_id] =
RGBA(r,g,b,255 - alpha);
926 const uint8_t *buf,
int buf_size)
930 const uint8_t *buf_end = buf + buf_size;
931 int region_id, object_id;
949 region->
id = region_id;
955 fill = ((*buf++) >> 3) & 1;
974 region->
depth = 1 << (((*buf++) >> 2) & 7);
979 region->
clut = *buf++;
981 if (region->
depth == 8)
986 if (region->
depth == 4)
987 region->
bgcolor = (((*buf++) >> 4) & 15);
989 region->
bgcolor = (((*buf++) >> 2) & 3);
1001 while (buf + 5 < buf_end) {
1012 object->id = object_id;
1017 object->
type = (*buf) >> 6;
1031 if ((object->
type == 1 || object->
type == 2) && buf+1 < buf_end) {
1040 object->display_list = display;
1047 const uint8_t *buf,
int buf_size)
1053 const uint8_t *buf_end = buf + buf_size;
1061 page_state = ((*buf++) >> 2) & 3;
1063 ff_dlog(avctx,
"Page time out %ds, state %d\n", ctx->
time_out, page_state);
1065 if (page_state == 2) {
1073 while (buf + 5 < buf_end) {
1077 display = tmp_display_list;
1078 tmp_ptr = &tmp_display_list;
1080 while (display && display->
region_id != region_id) {
1081 tmp_ptr = &display->
next;
1082 display = display->
next;
1098 *tmp_ptr = display->
next;
1104 ff_dlog(avctx,
"Region %d, (%d,%d)\n", region_id, display->
x_pos, display->
y_pos);
1107 while (tmp_display_list) {
1108 display = tmp_display_list;
1110 tmp_display_list = display->
next;
1125 uint32_t *clut_table;
1127 int x, y, y_off, x_off;
1130 static int fileno_index = 0;
1141 x_pos = display->
x_pos;
1142 y_pos = display->
y_pos;
1143 width = region->
width;
1146 if (display->
x_pos < x_pos) {
1147 width += (x_pos - display->
x_pos);
1148 x_pos = display->
x_pos;
1151 if (display->
y_pos < y_pos) {
1152 height += (y_pos - display->
y_pos);
1153 y_pos = display->
y_pos;
1156 if (display->
x_pos + region->
width > x_pos + width) {
1157 width = display->
x_pos + region->
width - x_pos;
1160 if (display->
y_pos + region->
height > y_pos + height) {
1175 x_off = display->
x_pos - x_pos;
1176 y_off = display->
y_pos - y_pos;
1183 switch (region->
depth) {
1185 clut_table = clut->
clut4;
1192 clut_table = clut->
clut16;
1196 for (y = 0; y < region->
height; y++) {
1197 for (x = 0; x < region->
width; x++) {
1198 pbuf[((y + y_off) * width) + x_off + x] =
1199 clut_table[region->
pbuf[y * region->
width + x]];
1205 snprintf(filename,
sizeof(filename),
"dvbs.%d", fileno_index);
1207 png_save(filename, pbuf, width, height);
1223 int dds_version, info_byte;
1228 info_byte = bytestream_get_byte(&buf);
1229 dds_version = info_byte >> 4;
1230 if (display_def && display_def->
version == dds_version)
1234 display_def =
av_mallocz(
sizeof(*display_def));
1240 display_def->
version = dds_version;
1243 display_def->
width = bytestream_get_be16(&buf) + 1;
1244 display_def->
height = bytestream_get_be16(&buf) + 1;
1249 if (info_byte & 1<<3) {
1250 display_def->
x = bytestream_get_be16(&buf);
1251 display_def->
y = bytestream_get_be16(&buf);
1252 display_def->
width = bytestream_get_be16(&buf) - display_def->
x + 1;
1253 display_def->
height = bytestream_get_be16(&buf) - display_def->
y + 1;
1269 uint32_t *clut_table;
1271 int offset_x=0, offset_y=0;
1279 offset_x = display_def->
x;
1280 offset_y = display_def->
y;
1291 if (!sub->
rects[i]) {
1301 rect = sub->
rects[i];
1306 rect->
x = display->
x_pos + offset_x;
1307 rect->
y = display->
y_pos + offset_y;
1319 switch (region->
depth) {
1321 clut_table = clut->
clut4;
1328 clut_table = clut->
clut16;
1333 if (!rect->
data[1]) {
1337 memcpy(rect->
data[1], clut_table, (1 << region->
depth) *
sizeof(uint32_t));
1340 if (!rect->
data[0]) {
1347 #if FF_API_AVPICTURE 1351 for (j = 0; j < 4; j++) {
1365 save_display_set(ctx);
1372 void *
data,
int *data_size,
1376 int buf_size = avpkt->
size;
1385 ff_dlog(avctx,
"DVB sub packet:\n");
1387 for (i=0; i < buf_size; i++) {
1388 ff_dlog(avctx,
"%02x ", buf[i]);
1396 if (buf_size <= 6 || *buf != 0x0f) {
1397 ff_dlog(avctx,
"incomplete or broken packet");
1402 p_end = buf + buf_size;
1404 while (p_end - p >= 6 && *p == 0x0f) {
1406 segment_type = *p++;
1412 if (p_end - p < segment_length) {
1413 ff_dlog(avctx,
"incomplete or broken packet");
1420 switch (segment_type) {
1442 ff_dlog(avctx,
"Subtitling segment type 0x%x, page id %d, length %d\n",
1443 segment_type, page_id, segment_length);
1450 p += segment_length;
static DVBSubCLUT * get_clut(DVBSubContext *ctx, int clut_id)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
int x
top left corner of pict, undefined when pict is not set
static DVBSubRegion * get_region(DVBSubContext *ctx, int region_id)
static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, AVSubtitle *sub)
DVBSubRegionDisplay * display_list
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define YUV_TO_RGB1_CCIR(cb1, cr1)
int nb_colors
number of colors in pict, undefined when pict is not set
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
Various defines for YUV<->RGB conversion.
attribute_deprecated AVPicture pict
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int w
width of pict, undefined when pict is not set
attribute_deprecated int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int get_bits_count(const GetBitContext *s)
static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table)
bitstream reader API header.
static void delete_state(DVBSubContext *ctx)
int h
height of pict, undefined when pict is not set
DVBSubRegion * region_list
#define DVBSUB_DISPLAYDEFINITION_SEGMENT
struct DVBSubRegion * next
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int y
top left corner of pict, undefined when pict is not set
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static DVBSubCLUT default_clut
static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
const char * name
Name of the codec implementation.
uint32_t end_display_time
struct DVBSubObject * next
AVCodec ff_dvbsub_decoder
A bitmap, pict will be set.
DVBSubObjectDisplay * display_list
struct DVBSubObjectDisplay * region_list_next
static int dvbsub_parse_clut_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
attribute_deprecated uint8_t * data[AV_NUM_DATA_POINTERS]
DVBSubObjectDisplay * display_list
DVBSubDisplayDefinition * display_definition
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
static int dvbsub_parse_page_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define AV_LOG_INFO
Standard information.
#define DVBSUB_CLUT_SEGMENT
Libavcodec external API header.
main external API structure.
static DVBSubObject * get_object(DVBSubContext *ctx, int object_id)
static unsigned int get_bits1(GetBitContext *s)
static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
#define DVBSUB_DISPLAY_SEGMENT
struct DVBSubRegionDisplay * next
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
struct DVBSubObjectDisplay * object_list_next
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define DVBSUB_PAGE_SEGMENT
static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
#define DVBSUB_REGION_SEGMENT
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
uint32_t start_display_time
static int dvbsub_decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
static av_cold int init(AVCodecParserContext *s)
#define FF_ENABLE_DEPRECATION_WARNINGS
static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table)
static int dvbsub_parse_object_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
DVBSubObject * object_list
static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table)
static int dvbsub_parse_region_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define DVBSUB_OBJECT_SEGMENT
static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...