Libav
dvdsubdec.c
Go to the documentation of this file.
1 /*
2  * DVD subtitle decoding
3  * Copyright (c) 2005 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avcodec.h"
23 #include "get_bits.h"
24 #include "internal.h"
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/colorspace.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/avstring.h"
30 
31 typedef struct DVDSubContext {
32  uint32_t palette[16];
35 
36 static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values)
37 {
39  uint8_t r, g, b;
40  int i, y, cb, cr;
41  int r_add, g_add, b_add;
42 
43  for (i = num_values; i > 0; i--) {
44  y = *ycbcr++;
45  cr = *ycbcr++;
46  cb = *ycbcr++;
47  YUV_TO_RGB1_CCIR(cb, cr);
48  YUV_TO_RGB2_CCIR(r, g, b, y);
49  *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
50  }
51 }
52 
53 static int decode_run_2bit(GetBitContext *gb, int *color)
54 {
55  unsigned int v, t;
56 
57  v = 0;
58  for (t = 1; v < t && t <= 0x40; t <<= 2)
59  v = (v << 4) | get_bits(gb, 4);
60  *color = v & 3;
61  if (v < 4) { /* Code for fill rest of line */
62  return INT_MAX;
63  }
64  return v >> 2;
65 }
66 
67 static int decode_run_8bit(GetBitContext *gb, int *color)
68 {
69  int len;
70  int has_run = get_bits1(gb);
71  if (get_bits1(gb))
72  *color = get_bits(gb, 8);
73  else
74  *color = get_bits(gb, 2);
75  if (has_run) {
76  if (get_bits1(gb)) {
77  len = get_bits(gb, 7);
78  if (len == 0)
79  len = INT_MAX;
80  else
81  len += 9;
82  } else
83  len = get_bits(gb, 3) + 2;
84  } else
85  len = 1;
86  return len;
87 }
88 
89 static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
90  const uint8_t *buf, int start, int buf_size, int is_8bit)
91 {
92  GetBitContext gb;
93  int bit_len;
94  int x, y, len, color;
95  uint8_t *d;
96 
97  bit_len = (buf_size - start) * 8;
98  init_get_bits(&gb, buf + start, bit_len);
99 
100  x = 0;
101  y = 0;
102  d = bitmap;
103  for(;;) {
104  if (get_bits_count(&gb) > bit_len)
105  return -1;
106  if (is_8bit)
107  len = decode_run_8bit(&gb, &color);
108  else
109  len = decode_run_2bit(&gb, &color);
110  len = FFMIN(len, w - x);
111  memset(d + x, color, len);
112  x += len;
113  if (x >= w) {
114  y++;
115  if (y >= h)
116  break;
117  d += linesize;
118  x = 0;
119  /* byte align */
120  align_get_bits(&gb);
121  }
122  }
123  return 0;
124 }
125 
126 static void guess_palette(DVDSubContext* ctx,
127  uint32_t *rgba_palette,
128  uint8_t *colormap,
129  uint8_t *alpha,
130  uint32_t subtitle_color)
131 {
132  uint8_t color_used[16] = { 0 };
133  int nb_opaque_colors, i, level, j, r, g, b;
134 
135  if (ctx->has_palette) {
136  for (i = 0; i < 4; i++)
137  rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff)
138  | ((alpha[i] * 17) << 24);
139  return;
140  }
141 
142  for(i = 0; i < 4; i++)
143  rgba_palette[i] = 0;
144 
145  nb_opaque_colors = 0;
146  for(i = 0; i < 4; i++) {
147  if (alpha[i] != 0 && !color_used[colormap[i]]) {
148  color_used[colormap[i]] = 1;
149  nb_opaque_colors++;
150  }
151  }
152 
153  if (nb_opaque_colors == 0)
154  return;
155 
156  j = nb_opaque_colors;
157  memset(color_used, 0, 16);
158  for(i = 0; i < 4; i++) {
159  if (alpha[i] != 0) {
160  if (!color_used[colormap[i]]) {
161  level = (0xff * j) / nb_opaque_colors;
162  r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
163  g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
164  b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
165  rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
166  color_used[colormap[i]] = (i + 1);
167  j--;
168  } else {
169  rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
170  ((alpha[i] * 17) << 24);
171  }
172  }
173  }
174 }
175 
176 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
177 
178 static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
179  const uint8_t *buf, int buf_size)
180 {
181  int cmd_pos, pos, cmd, x1, y1, x2, y2, next_cmd_pos;
182  int big_offsets, offset_size, is_8bit = 0;
183  const uint8_t *yuv_palette = 0;
184  uint8_t colormap[4] = { 0 }, alpha[256] = { 0 };
185  int date;
186  int i;
187  int is_menu = 0;
188  int64_t offset1, offset2;
189 
190  if (buf_size < 10)
191  return -1;
192  memset(sub_header, 0, sizeof(*sub_header));
193 
194  if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */
195  big_offsets = 1;
196  offset_size = 4;
197  cmd_pos = 6;
198  } else {
199  big_offsets = 0;
200  offset_size = 2;
201  cmd_pos = 2;
202  }
203 
204  cmd_pos = READ_OFFSET(buf + cmd_pos);
205 
206  while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
207  date = AV_RB16(buf + cmd_pos);
208  next_cmd_pos = READ_OFFSET(buf + cmd_pos + 2);
209  av_dlog(NULL, "cmd_pos=0x%04x next=0x%04x date=%d\n",
210  cmd_pos, next_cmd_pos, date);
211  pos = cmd_pos + 2 + offset_size;
212  offset1 = -1;
213  offset2 = -1;
214  x1 = y1 = x2 = y2 = 0;
215  while (pos < buf_size) {
216  cmd = buf[pos++];
217  av_dlog(NULL, "cmd=%02x\n", cmd);
218  switch(cmd) {
219  case 0x00:
220  /* menu subpicture */
221  is_menu = 1;
222  break;
223  case 0x01:
224  /* set start date */
225  sub_header->start_display_time = (date << 10) / 90;
226  break;
227  case 0x02:
228  /* set end date */
229  sub_header->end_display_time = (date << 10) / 90;
230  break;
231  case 0x03:
232  /* set colormap */
233  if ((buf_size - pos) < 2)
234  goto fail;
235  colormap[3] = buf[pos] >> 4;
236  colormap[2] = buf[pos] & 0x0f;
237  colormap[1] = buf[pos + 1] >> 4;
238  colormap[0] = buf[pos + 1] & 0x0f;
239  pos += 2;
240  break;
241  case 0x04:
242  /* set alpha */
243  if ((buf_size - pos) < 2)
244  goto fail;
245  alpha[3] = buf[pos] >> 4;
246  alpha[2] = buf[pos] & 0x0f;
247  alpha[1] = buf[pos + 1] >> 4;
248  alpha[0] = buf[pos + 1] & 0x0f;
249  pos += 2;
250  av_dlog(NULL, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
251  break;
252  case 0x05:
253  case 0x85:
254  if ((buf_size - pos) < 6)
255  goto fail;
256  x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
257  x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
258  y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
259  y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
260  if (cmd & 0x80)
261  is_8bit = 1;
262  av_dlog(NULL, "x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
263  pos += 6;
264  break;
265  case 0x06:
266  if ((buf_size - pos) < 4)
267  goto fail;
268  offset1 = AV_RB16(buf + pos);
269  offset2 = AV_RB16(buf + pos + 2);
270  av_dlog(NULL, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
271  pos += 4;
272  break;
273  case 0x86:
274  if ((buf_size - pos) < 8)
275  goto fail;
276  offset1 = AV_RB32(buf + pos);
277  offset2 = AV_RB32(buf + pos + 4);
278  av_dlog(NULL, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
279  pos += 8;
280  break;
281 
282  case 0x83:
283  /* HD set palette */
284  if ((buf_size - pos) < 768)
285  goto fail;
286  yuv_palette = buf + pos;
287  pos += 768;
288  break;
289  case 0x84:
290  /* HD set contrast (alpha) */
291  if ((buf_size - pos) < 256)
292  goto fail;
293  for (i = 0; i < 256; i++)
294  alpha[i] = 0xFF - buf[pos+i];
295  pos += 256;
296  break;
297 
298  case 0xff:
299  goto the_end;
300  default:
301  av_dlog(NULL, "unrecognised subpicture command 0x%x\n", cmd);
302  goto the_end;
303  }
304  }
305  the_end:
306  if (offset1 >= buf_size || offset2 >= buf_size)
307  goto fail;
308 
309  if (offset1 >= 0) {
310  int w, h;
311  uint8_t *bitmap;
312 
313  /* decode the bitmap */
314  w = x2 - x1 + 1;
315  if (w < 0)
316  w = 0;
317  h = y2 - y1;
318  if (h < 0)
319  h = 0;
320  if (w > 0 && h > 0) {
321  if (sub_header->rects) {
322  for (i = 0; i < sub_header->num_rects; i++) {
323  av_freep(&sub_header->rects[i]->pict.data[0]);
324  av_freep(&sub_header->rects[i]->pict.data[1]);
325  av_freep(&sub_header->rects[i]);
326  }
327  av_freep(&sub_header->rects);
328  sub_header->num_rects = 0;
329  }
330 
331  bitmap = av_malloc(w * h);
332  sub_header->rects = av_mallocz(sizeof(*sub_header->rects));
333  sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect));
334  sub_header->num_rects = 1;
335  sub_header->rects[0]->pict.data[0] = bitmap;
336  decode_rle(bitmap, w * 2, w, (h + 1) / 2,
337  buf, offset1, buf_size, is_8bit);
338  decode_rle(bitmap + w, w * 2, w, h / 2,
339  buf, offset2, buf_size, is_8bit);
340  sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
341  if (is_8bit) {
342  if (yuv_palette == 0)
343  goto fail;
344  sub_header->rects[0]->nb_colors = 256;
345  yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
346  } else {
347  sub_header->rects[0]->nb_colors = 4;
348  guess_palette(ctx,
349  (uint32_t*)sub_header->rects[0]->pict.data[1],
350  colormap, alpha, 0xffff00);
351  }
352  sub_header->rects[0]->x = x1;
353  sub_header->rects[0]->y = y1;
354  sub_header->rects[0]->w = w;
355  sub_header->rects[0]->h = h;
356  sub_header->rects[0]->type = SUBTITLE_BITMAP;
357  sub_header->rects[0]->pict.linesize[0] = w;
358  }
359  }
360  if (next_cmd_pos == cmd_pos)
361  break;
362  cmd_pos = next_cmd_pos;
363  }
364  if (sub_header->num_rects > 0)
365  return is_menu;
366  fail:
367  if (!sub_header->rects) {
368  for (i = 0; i < sub_header->num_rects; i++) {
369  av_freep(&sub_header->rects[i]->pict.data[0]);
370  av_freep(&sub_header->rects[i]->pict.data[1]);
371  av_freep(&sub_header->rects[i]);
372  }
373  av_freep(&sub_header->rects);
374  sub_header->num_rects = 0;
375  }
376  return -1;
377 }
378 
379 static int is_transp(const uint8_t *buf, int pitch, int n,
380  const uint8_t *transp_color)
381 {
382  int i;
383  for(i = 0; i < n; i++) {
384  if (!transp_color[*buf])
385  return 0;
386  buf += pitch;
387  }
388  return 1;
389 }
390 
391 /* return 0 if empty rectangle, 1 if non empty */
393 {
394  uint8_t transp_color[256] = { 0 };
395  int y1, y2, x1, x2, y, w, h, i;
396  uint8_t *bitmap;
397 
398  if (s->num_rects == 0 || !s->rects || s->rects[0]->w <= 0 || s->rects[0]->h <= 0)
399  return 0;
400 
401  for(i = 0; i < s->rects[0]->nb_colors; i++) {
402  if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)
403  transp_color[i] = 1;
404  }
405  y1 = 0;
406  while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],
407  1, s->rects[0]->w, transp_color))
408  y1++;
409  if (y1 == s->rects[0]->h) {
410  av_freep(&s->rects[0]->pict.data[0]);
411  s->rects[0]->w = s->rects[0]->h = 0;
412  return 0;
413  }
414 
415  y2 = s->rects[0]->h - 1;
416  while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,
417  s->rects[0]->w, transp_color))
418  y2--;
419  x1 = 0;
420  while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],
421  s->rects[0]->h, transp_color))
422  x1++;
423  x2 = s->rects[0]->w - 1;
424  while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,
425  transp_color))
426  x2--;
427  w = x2 - x1 + 1;
428  h = y2 - y1 + 1;
429  bitmap = av_malloc(w * h);
430  if (!bitmap)
431  return 1;
432  for(y = 0; y < h; y++) {
433  memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);
434  }
435  av_freep(&s->rects[0]->pict.data[0]);
436  s->rects[0]->pict.data[0] = bitmap;
437  s->rects[0]->pict.linesize[0] = w;
438  s->rects[0]->w = w;
439  s->rects[0]->h = h;
440  s->rects[0]->x += x1;
441  s->rects[0]->y += y1;
442  return 1;
443 }
444 
445 #ifdef DEBUG
446 static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h,
447  uint32_t *rgba_palette)
448 {
449  int x, y, v;
450  FILE *f;
451 
452  f = fopen(filename, "w");
453  if (!f) {
454  perror(filename);
455  exit(1);
456  }
457  fprintf(f, "P6\n"
458  "%d %d\n"
459  "%d\n",
460  w, h, 255);
461  for(y = 0; y < h; y++) {
462  for(x = 0; x < w; x++) {
463  v = rgba_palette[bitmap[y * w + x]];
464  putc((v >> 16) & 0xff, f);
465  putc((v >> 8) & 0xff, f);
466  putc((v >> 0) & 0xff, f);
467  }
468  }
469  fclose(f);
470 }
471 #endif
472 
473 static int dvdsub_decode(AVCodecContext *avctx,
474  void *data, int *data_size,
475  AVPacket *avpkt)
476 {
477  DVDSubContext *ctx = avctx->priv_data;
478  const uint8_t *buf = avpkt->data;
479  int buf_size = avpkt->size;
480  AVSubtitle *sub = data;
481  int is_menu;
482 
483  is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);
484 
485  if (is_menu < 0) {
486  no_subtitle:
487  *data_size = 0;
488 
489  return buf_size;
490  }
491  if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)
492  goto no_subtitle;
493 
494 #if defined(DEBUG)
495  av_dlog(NULL, "start=%d ms end =%d ms\n",
496  sub->start_display_time,
497  sub->end_display_time);
498  ppm_save("/tmp/a.ppm", sub->rects[0]->pict.data[0],
499  sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->pict.data[1]);
500 #endif
501 
502  *data_size = 1;
503  return buf_size;
504 }
505 
507 {
508  DVDSubContext *ctx = avctx->priv_data;
509  char *data, *cur;
510  int ret = 0;
511 
512  if (!avctx->extradata || !avctx->extradata_size)
513  return 0;
514 
515  data = av_malloc(avctx->extradata_size + 1);
516  if (!data)
517  return AVERROR(ENOMEM);
518  memcpy(data, avctx->extradata, avctx->extradata_size);
519  data[avctx->extradata_size] = '\0';
520  cur = data;
521 
522  while (*cur) {
523  if (strncmp("palette:", cur, 8) == 0) {
524  int i;
525  char *p = cur + 8;
526  ctx->has_palette = 1;
527  for (i = 0; i < 16; i++) {
528  ctx->palette[i] = strtoul(p, &p, 16);
529  while (*p == ',' || av_isspace(*p))
530  p++;
531  }
532  } else if (!strncmp("size:", cur, 5)) {
533  int w, h;
534  if (sscanf(cur + 5, "%dx%d", &w, &h) == 2) {
535  ret = ff_set_dimensions(avctx, w, h);
536  if (ret < 0)
537  goto fail;
538  }
539  }
540  cur += strcspn(cur, "\n\r");
541  cur += strspn(cur, "\n\r");
542  }
543 
544 fail:
545  av_free(data);
546  return ret;
547 }
548 
550  .name = "dvdsub",
551  .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
552  .type = AVMEDIA_TYPE_SUBTITLE,
554  .priv_data_size = sizeof(DVDSubContext),
555  .init = dvdsub_init,
557 };
#define AVPALETTE_SIZE
Definition: avcodec.h:3051
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3044
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3075
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition: colorspace.h:34
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:133
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:3079
int size
Definition: avcodec.h:974
#define MAX_NEG_CROP
Definition: mathops.h:30
Various defines for YUV<->RGB conversion.
unsigned num_rects
Definition: avcodec.h:3103
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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)
uint32_t palette[16]
Definition: dvdsubdec.c:32
AVCodec.
Definition: avcodec.h:2812
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVSubtitleRect ** rects
Definition: avcodec.h:3104
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:3077
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
uint8_t
#define av_cold
Definition: attributes.h:66
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:3043
#define AV_RB32
Definition: intreadwrite.h:130
#define b
Definition: input.c:52
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
static void guess_palette(DVDSubContext *ctx, uint32_t *rgba_palette, uint8_t *colormap, uint8_t *alpha, uint32_t subtitle_color)
Definition: dvdsubdec.c:126
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:194
#define READ_OFFSET(a)
Definition: dvdsubdec.c:176
bitstream reader API header.
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:3078
static av_cold int dvdsub_init(AVCodecContext *avctx)
Definition: dvdsubdec.c:506
#define cm
Definition: dvbsubdec.c:34
#define r
Definition: input.c:51
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3076
#define AV_RB16
Definition: intreadwrite.h:53
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
g
Definition: yuv2rgb.c:535
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.c:225
uint32_t end_display_time
Definition: avcodec.h:3102
static int decode_run_8bit(GetBitContext *gb, int *color)
Definition: dvdsubdec.c:67
A bitmap, pict will be set.
Definition: avcodec.h:3057
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3085
#define FFMIN(a, b)
Definition: common.h:57
static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values)
Definition: dvdsubdec.c:36
static int is_transp(const uint8_t *buf, int pitch, int n, const uint8_t *transp_color)
Definition: dvdsubdec.c:379
int has_palette
Definition: dvdsubdec.c:33
AVCodec ff_dvdsub_decoder
Definition: dvdsubdec.c:549
NULL
Definition: eval.c:55
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1050
static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, const uint8_t *buf, int buf_size)
Definition: dvdsubdec.c:178
int extradata_size
Definition: avcodec.h:1165
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
Definition: colorspace.h:55
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
static int decode_run_2bit(GetBitContext *gb, int *color)
Definition: dvdsubdec.c:53
uint8_t level
Definition: svq3.c:147
static int find_smallest_bounding_rectangle(AVSubtitle *s)
Definition: dvdsubdec.c:392
common internal api header.
uint32_t start_display_time
Definition: avcodec.h:3101
#define ff_crop_tab
static const uint8_t color[]
Definition: log.c:55
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
int len
static int dvdsub_decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: dvdsubdec.c:473
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:416
enum AVSubtitleType type
Definition: avcodec.h:3086
This structure stores compressed data.
Definition: avcodec.h:950
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
static int decode_rle(uint8_t *bitmap, int linesize, int w, int h, const uint8_t *buf, int start, int buf_size, int is_8bit)
Definition: dvdsubdec.c:89