33 #define PUTBITS2(val)\
35 bitbuf |= (val) << bitcnt;\
45 const uint8_t *bitmap,
int linesize,
48 uint8_t *q, *line_begin;
55 for(y = 0; y <
h; y++) {
57 if (buf_size * 8 <
w * 3 + 32)
68 while (x1 <
w && bitmap[x1] ==
color)
75 }
else if (
len >= 3 &&
len <= 10) {
81 }
else if (
len >= 12 &&
len <= 27) {
89 }
else if (
len >= 29) {
120 buf_size -= q - line_begin;
127 #define PUTBITS4(val)\
129 bitbuf |= (val) << bitcnt;\
140 const uint8_t *bitmap,
int linesize,
143 uint8_t *q, *line_begin;
150 for(y = 0; y <
h; y++) {
152 if (buf_size * 8 <
w * 6 + 32)
162 color = bitmap[x1++];
163 while (x1 <
w && bitmap[x1] ==
color)
172 }
else if (
len >= 4 &&
len <= 7) {
176 }
else if (
len >= 9 &&
len <= 24) {
181 }
else if (
len >= 25) {
207 buf_size -= q - line_begin;
215 const uint8_t *bitmap,
int linesize,
218 uint8_t *q, *line_begin;
223 for (y = 0; y <
h; y++) {
225 if (buf_size * 8 <
w * 12 + 24)
233 color = bitmap[x1++];
234 while (x1 <
w && bitmap[x1] ==
color)
246 }
else if (
len > 2) {
269 buf_size -= q - line_begin;
280 uint8_t *q, *pseg_len;
281 int page_id, region_id, clut_id, object_id,
i, bpp_index, page_state, min_colors;
292 min_colors = 1 <<
s->min_bpp;
299 if (
h->num_rects && !
h->rects)
302 if (
h->num_rects >= 256)
311 bytestream_put_be16(&q, page_id);
315 bytestream_put_be16(&q, avctx->
width - 1);
316 bytestream_put_be16(&q, avctx->
height - 1);
317 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
323 if (buf_size < 8 + h->num_rects * 6)
327 bytestream_put_be16(&q, page_id);
333 *q++ = (
s->object_version << 4) | (page_state << 2) | 3;
335 for (region_id = 0; region_id <
h->num_rects; region_id++) {
338 bytestream_put_be16(&q,
h->rects[region_id]->x);
339 bytestream_put_be16(&q,
h->rects[region_id]->y);
342 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
343 buf_size -= 8 +
h->num_rects * 6;
346 for (clut_id = 0; clut_id <
h->num_rects; clut_id++) {
348 int nb_colors =
FFMAX(min_colors,
h->rects[clut_id]->nb_colors);
350 if (nb_colors <= 4
U) {
353 }
else if (nb_colors <= 16
U) {
356 }
else if (nb_colors <= 256
U) {
363 if (buf_size < 6 + h->rects[clut_id]->nb_colors * 6)
369 bytestream_put_be16(&q, page_id);
373 *q++ = (0 << 4) | 0
xf;
375 for(
i = 0;
i <
h->rects[clut_id]->nb_colors;
i++) {
377 *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1;
380 uint32_t x= ((uint32_t*)
h->rects[clut_id]->data[1])[
i];
381 a = (x >> 24) & 0xff;
382 r = (x >> 16) & 0xff;
393 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
394 buf_size -= 6 +
h->rects[clut_id]->nb_colors * 6;
397 if (buf_size < h->num_rects * 22)
399 for (region_id = 0; region_id <
h->num_rects; region_id++) {
402 int nb_colors =
FFMAX(min_colors,
h->rects[region_id]->nb_colors);
404 if (nb_colors <= 4) {
407 }
else if (nb_colors <= 16) {
410 }
else if (nb_colors <= 256) {
419 bytestream_put_be16(&q, page_id);
423 *q++ = (
s->object_version << 4) | (0 << 3) | 0x07;
424 bytestream_put_be16(&q,
h->rects[region_id]->w);
425 bytestream_put_be16(&q,
h->rects[region_id]->h);
426 *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
431 bytestream_put_be16(&q, region_id);
432 *q++ = (0 << 6) | (0 << 4);
437 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
439 buf_size -=
h->num_rects * 22;
441 for (object_id = 0; object_id <
h->num_rects; object_id++) {
442 int (*dvb_encode_rle)(uint8_t **pq,
int buf_size,
443 const uint8_t *bitmap,
int linesize,
446 int nb_colors =
FFMAX(min_colors,
h->rects[object_id]->nb_colors);
452 if (nb_colors <= 4) {
455 }
else if (nb_colors <= 16) {
458 }
else if (nb_colors <= 256) {
468 bytestream_put_be16(&q, page_id);
472 bytestream_put_be16(&q, object_id);
473 *q++ = (
s->object_version << 4) | (0 << 2) | (0 << 1) | 1;
477 uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
482 pbottom_field_len = q;
487 ret = dvb_encode_rle(&q, buf_size,
488 h->rects[object_id]->data[0],
489 h->rects[object_id]->w * 2,
490 h->rects[object_id]->w,
491 h->rects[object_id]->h >> 1);
496 ret = dvb_encode_rle(&q, buf_size,
497 h->rects[object_id]->data[0] +
h->rects[object_id]->w,
498 h->rects[object_id]->w * 2,
499 h->rects[object_id]->w,
500 h->rects[object_id]->h >> 1);
505 bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
506 bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
509 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
519 bytestream_put_be16(&q, page_id);
523 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
526 s->object_version = (
s->object_version + 1) & 0
xf;
530 #define OFFSET(x) offsetof(DVBSubtitleContext, x)
531 #define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
533 {
"min_bpp",
"minimum bits-per-pixel for subtitle colors (2, 4 or 8)",
OFFSET(min_bpp),
AV_OPT_TYPE_INT, {.i64 = 4}, 2, 8,
SE},