29 #define PUTBITS2(val)\
31 bitbuf |= (val) << bitcnt;\
41 const uint8_t *bitmap,
int linesize,
51 for(y = 0; y <
h; y++) {
53 if (buf_size * 8LL <
w * 3 + 32)
64 while (x1 <
w && bitmap[x1] ==
color)
71 }
else if (
len >= 3 &&
len <= 10) {
77 }
else if (
len >= 12 &&
len <= 27) {
85 }
else if (
len >= 29) {
116 buf_size -= q - line_begin;
123 #define PUTBITS4(val)\
125 bitbuf |= (val) << bitcnt;\
136 const uint8_t *bitmap,
int linesize,
146 for(y = 0; y <
h; y++) {
148 if (buf_size * 8LL <
w * 6 + 32)
158 color = bitmap[x1++];
159 while (x1 <
w && bitmap[x1] ==
color)
168 }
else if (
len >= 4 &&
len <= 7) {
172 }
else if (
len >= 9 &&
len <= 24) {
177 }
else if (
len >= 25) {
203 buf_size -= q - line_begin;
211 const uint8_t *bitmap,
int linesize,
219 for (y = 0; y <
h; y++) {
221 if (buf_size * 8LL <
w * 12 + 32)
229 color = bitmap[x1++];
230 while (x1 <
w && bitmap[x1] ==
color)
242 }
else if (
len > 2) {
265 buf_size -= q - line_begin;
277 int page_id, region_id, clut_id, object_id,
i, bpp_index, page_state;
284 if (
h->num_rects && !
h->rects)
287 for (
i = 0;
i <
h->num_rects;
i++)
288 if (
h->rects[
i]->w > 0xFFFF ||
h->rects[
i]->h > 0xFFFF)
297 bytestream_put_be16(&q, page_id);
301 bytestream_put_be16(&q, avctx->
width - 1);
302 bytestream_put_be16(&q, avctx->
height - 1);
303 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
309 if (buf_size < 8 + h->num_rects * 6)
313 bytestream_put_be16(&q, page_id);
319 *q++ = (
s->object_version << 4) | (page_state << 2) | 3;
321 for (region_id = 0; region_id <
h->num_rects; region_id++) {
324 bytestream_put_be16(&q,
h->rects[region_id]->x);
325 bytestream_put_be16(&q,
h->rects[region_id]->y);
328 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
329 buf_size -= 8 +
h->num_rects * 6;
332 for (clut_id = 0; clut_id <
h->num_rects; clut_id++) {
335 if (
h->rects[clut_id]->nb_colors <= 4U) {
338 }
else if (
h->rects[clut_id]->nb_colors <= 16U) {
341 }
else if (
h->rects[clut_id]->nb_colors <= 256U) {
348 if (buf_size < 8 + h->rects[clut_id]->nb_colors * 6)
354 bytestream_put_be16(&q, page_id);
358 *q++ = (0 << 4) | 0xf;
360 for(
i = 0;
i <
h->rects[clut_id]->nb_colors;
i++) {
362 *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1;
365 uint32_t x= ((uint32_t*)
h->rects[clut_id]->data[1])[
i];
366 a = (x >> 24) & 0xff;
367 r = (x >> 16) & 0xff;
378 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
379 buf_size -= 8 +
h->rects[clut_id]->nb_colors * 6;
382 if (buf_size < h->num_rects * 22)
384 for (region_id = 0; region_id <
h->num_rects; region_id++) {
388 if (
h->rects[region_id]->nb_colors <= 4) {
391 }
else if (
h->rects[region_id]->nb_colors <= 16) {
394 }
else if (
h->rects[region_id]->nb_colors <= 256) {
403 bytestream_put_be16(&q, page_id);
407 *q++ = (
s->object_version << 4) | (0 << 3) | 0x07;
408 bytestream_put_be16(&q,
h->rects[region_id]->w);
409 bytestream_put_be16(&q,
h->rects[region_id]->h);
410 *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
415 bytestream_put_be16(&q, region_id);
416 *q++ = (0 << 6) | (0 << 4);
421 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
423 buf_size -=
h->num_rects * 22;
425 for (object_id = 0; object_id <
h->num_rects; object_id++) {
426 int (*dvb_encode_rle)(
uint8_t **pq,
int buf_size,
427 const uint8_t *bitmap,
int linesize,
434 if (
h->rects[object_id]->nb_colors <= 4) {
437 }
else if (
h->rects[object_id]->nb_colors <= 16) {
440 }
else if (
h->rects[object_id]->nb_colors <= 256) {
450 bytestream_put_be16(&q, page_id);
454 bytestream_put_be16(&q, object_id);
455 *q++ = (
s->object_version << 4) | (0 << 2) | (0 << 1) | 1;
459 uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
464 pbottom_field_len = q;
469 ret = dvb_encode_rle(&q, buf_size,
470 h->rects[object_id]->data[0],
471 h->rects[object_id]->w * 2,
472 h->rects[object_id]->w,
473 h->rects[object_id]->h >> 1);
478 ret = dvb_encode_rle(&q, buf_size,
479 h->rects[object_id]->data[0] +
h->rects[object_id]->w,
480 h->rects[object_id]->w * 2,
481 h->rects[object_id]->w,
482 h->rects[object_id]->h >> 1);
487 bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
488 bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
491 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
501 bytestream_put_be16(&q, page_id);
505 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
508 s->object_version = (
s->object_version + 1) & 0xf;
Libavcodec external API header.
static int dvbsub_encode(AVCodecContext *avctx, uint8_t *outbuf, int buf_size, const AVSubtitle *h)
static int dvb_encode_rle4(uint8_t **pq, int buf_size, const uint8_t *bitmap, int linesize, int w, int h)
AVCodec ff_dvbsub_encoder
static int dvb_encode_rle2(uint8_t **pq, int buf_size, const uint8_t *bitmap, int linesize, int w, int h)
static int dvb_encode_rle8(uint8_t **pq, int buf_size, const uint8_t *bitmap, int linesize, int w, int h)
@ AV_CODEC_ID_DVB_SUBTITLE
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Various defines for YUV<->RGB conversion.
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
#define RGB_TO_Y_CCIR(r, g, b)
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
main external API structure.
int width
picture width / height.
const char * name
Name of the codec implementation.