55     int r_add, g_add, b_add;
 
   57     for (i = num_values; i > 0; i--) {
 
   63         *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
 
   72     for (t = 1; v < t && t <= 0x40; t <<= 2)
 
  111     if (start >= buf_size)
 
  114     if (w <= 0 || h <= 0)
 
  117     bit_len = (buf_size - 
start) * 8;
 
  130         len = 
FFMIN(len, w - x);
 
  131         memset(d + x, color, len);
 
  147                           uint32_t *rgba_palette,
 
  148                           uint32_t subtitle_color)
 
  150     static const uint8_t level_map[4][4] = {
 
  156         {0x00, 0x55, 0xaa, 0xff},
 
  158     uint8_t color_used[16] = { 0 };
 
  159     int nb_opaque_colors, i, 
level, j, 
r, 
g, 
b;
 
  163         for(i = 0; i < 4; i++)
 
  164             rgba_palette[i] = (ctx->
palette[colormap[i]] & 0x00ffffff)
 
  165                               | ((
alpha[i] * 17
U) << 24);
 
  169     for(i = 0; i < 4; i++)
 
  172     nb_opaque_colors = 0;
 
  173     for(i = 0; i < 4; i++) {
 
  174         if (
alpha[i] != 0 && !color_used[colormap[i]]) {
 
  175             color_used[colormap[i]] = 1;
 
  180     if (nb_opaque_colors == 0)
 
  184     memset(color_used, 0, 16);
 
  185     for(i = 0; i < 4; i++) {
 
  187             if (!color_used[colormap[i]])  {
 
  188                 level = level_map[nb_opaque_colors][j];
 
  189                 r = (((subtitle_color >> 16) & 0xff) * 
level) >> 8;
 
  190                 g = (((subtitle_color >> 8) & 0xff) * 
level) >> 8;
 
  191                 b = (((subtitle_color >> 0) & 0xff) * 
level) >> 8;
 
  192                 rgba_palette[i] = b | (g << 8) | (r << 16) | ((
alpha[i] * 17) << 24);
 
  193                 color_used[colormap[i]] = (i + 1);
 
  196                 rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
 
  197                                     ((
alpha[i] * 17) << 24);
 
  207     if (sub_header->
rects) {
 
  208         for (i = 0; i < sub_header->
num_rects; i++) {
 
  218 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a)) 
  223     int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
 
  224     int big_offsets, offset_size, is_8bit = 0;
 
  246     if (cmd_pos < 0 || cmd_pos > buf_size - 2 - offset_size)
 
  249     while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
 
  252         av_dlog(
NULL, 
"cmd_pos=0x%04x next=0x%04x date=%d\n",
 
  253                 cmd_pos, next_cmd_pos, date);
 
  254         pos = cmd_pos + 2 + offset_size;
 
  257         x1 = y1 = x2 = y2 = 0;
 
  258         while (pos < buf_size) {
 
  276                 if ((buf_size - pos) < 2)
 
  278                 colormap[3] = buf[pos] >> 4;
 
  279                 colormap[2] = buf[pos] & 0x0f;
 
  280                 colormap[1] = buf[pos + 1] >> 4;
 
  281                 colormap[0] = buf[pos + 1] & 0x0f;
 
  286                 if ((buf_size - pos) < 2)
 
  288                 alpha[3] = buf[pos] >> 4;
 
  289                 alpha[2] = buf[pos] & 0x0f;
 
  290                 alpha[1] = buf[pos + 1] >> 4;
 
  291                 alpha[0] = buf[pos + 1] & 0x0f;
 
  297                 if ((buf_size - pos) < 6)
 
  299                 x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
 
  300                 x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
 
  301                 y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
 
  302                 y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
 
  305                 av_dlog(
NULL, 
"x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
 
  309                 if ((buf_size - pos) < 4)
 
  312                 offset2 = 
AV_RB16(buf + pos + 2);
 
  313                 av_dlog(
NULL, 
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
 
  317                 if ((buf_size - pos) < 8)
 
  320                 offset2 = 
AV_RB32(buf + pos + 4);
 
  321                 av_dlog(
NULL, 
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
 
  327                 if ((buf_size - pos) < 768)
 
  329                 yuv_palette = buf + pos;
 
  334                 if ((buf_size - pos) < 256)
 
  336                 for (i = 0; i < 256; i++)
 
  337                     alpha[i] = 0xFF - buf[pos+i];
 
  344                 av_dlog(
NULL, 
"unrecognised subpicture command 0x%x\n", cmd);
 
  360             if (w > 0 && h > 0) {
 
  364                 if (!sub_header->
rects)
 
  367                 if (!sub_header->
rects[0])
 
  374                                buf, offset1, buf_size, is_8bit) < 0)
 
  377                                buf, offset2, buf_size, is_8bit) < 0)
 
  392                 sub_header->
rects[0]->
x = x1;
 
  393                 sub_header->
rects[0]->
y = y1;
 
  394                 sub_header->
rects[0]->
w = w;
 
  395                 sub_header->
rects[0]->
h = h;
 
  401         if (next_cmd_pos < cmd_pos) {
 
  405         if (next_cmd_pos == cmd_pos)
 
  407         cmd_pos = next_cmd_pos;
 
  420     for(i = 0; i < 
n; i++) {
 
  421         if (!transp_color[*buf])
 
  431     uint8_t transp_color[256] = { 0 };
 
  432     int y1, y2, x1, x2, 
y, w, h, i;
 
  444                                   1, s->
rects[0]->
w, transp_color))
 
  446     if (y1 == s->
rects[0]->
h) {
 
  454                                s->
rects[0]->
w, transp_color))
 
  458                                         s->
rects[0]->
h, transp_color))
 
  469     for(y = 0; y < h; y++) {
 
  483 #define ALPHA_MIX(A,BACK,FORE) (((255-(A)) * (BACK) + (A) * (FORE)) / 255) 
  484 static void ppm_save(
const char *filename, 
uint8_t *bitmap, 
int w, 
int h,
 
  485                      uint32_t *rgba_palette)
 
  489     int back[3] = {0, 255, 0};  
 
  492     f = fopen(filename, 
"w");
 
  501     for(y = 0; y < h; y++) {
 
  502         for(x = 0; x < w; x++) {
 
  503             v = rgba_palette[bitmap[y * w + x]];
 
  505             putc(ALPHA_MIX(alpha, back[0], (v >> 16) & 0xff), f);
 
  506             putc(ALPHA_MIX(alpha, back[1], (v >> 8) & 0xff), f);
 
  507             putc(ALPHA_MIX(alpha, back[2], (v >> 0) & 0xff), f);
 
  519     if (ctx->
buf_size >= 
sizeof(ctx->
buf) - buf_size) {
 
  521                "too large SPU packets aborted.\n");
 
  530                          void *
data, 
int *data_size,
 
  535     int buf_size = avpkt->
size;
 
  550     if (is_menu == 
AVERROR(EAGAIN)) {
 
  572     snprintf(ppm_name, 
sizeof(ppm_name), 
"/tmp/%05d.ppm", ctx->sub_id++);
 
  592         ctx->
palette[i] = strtoul(p, &p, 16);
 
  602     uint32_t sp_pgci, pgci, off_pgc, pgc;
 
  604     int i, 
y, 
cb, 
cr, r_add, g_add, b_add;
 
  609     if ((ifo = fopen(p, 
"r")) == 
NULL) {
 
  613     if (fread(ifostr, 12, 1, ifo) != 1 || memcmp(ifostr, 
"DVDVIDEO-VTS", 12)) {
 
  618     if (fseek(ifo, 0xCC, SEEK_SET) == -1) {
 
  622     if (fread(&sp_pgci, 4, 1, ifo) == 1) {
 
  624         if (fseek(ifo, pgci + 0x0C, SEEK_SET) == -1) {
 
  628         if (fread(&off_pgc, 4, 1, ifo) == 1) {
 
  630             if (fseek(ifo, pgc + 0xA4, SEEK_SET) == -1) {
 
  634             if (fread(yuv, 64, 1, ifo) == 1) {
 
  636                 for(i=0; i<16; i++) {
 
  642                     ctx->
palette[i] = (r << 16) + (g << 8) + 
b;
 
  661     char *dataorig, *
data;
 
  674         int pos = strcspn(
data, 
"\n\r");
 
  675         if (pos==0 && *
data==0)
 
  678         if (strncmp(
"palette:", 
data, 8) == 0) {
 
  680         } 
else if (strncmp(
"size:", 
data, 5) == 0) {
 
  682             if (sscanf(
data + 5, 
"%dx%d", &w, &h) == 2) {
 
  728 #define OFFSET(field) offsetof(DVDSubContext, field) 
  729 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM 
  733     { 
"forced_subs_only", 
"Only show forced subtitles", 
OFFSET(forced_subs_only), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, 
SD},
 
  752     .priv_class     = &dvdsub_class,