50 int r_add, g_add, b_add;
52 for (i = num_values; i > 0; i--) {
58 *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
67 for (t = 1; v < t && t <= 0x40; t <<= 2)
106 bit_len = (buf_size -
start) * 8;
119 len =
FFMIN(len, w - x);
120 memset(d + x, color, len);
136 uint32_t *rgba_palette,
137 uint32_t subtitle_color)
139 static const uint8_t level_map[4][4] = {
145 {0x00, 0x55, 0xaa, 0xff},
147 uint8_t color_used[16] = { 0 };
148 int nb_opaque_colors, i,
level, j,
r,
g,
b;
152 for(i = 0; i < 4; i++)
153 rgba_palette[i] = (ctx->
palette[colormap[i]] & 0x00ffffff)
154 | ((
alpha[i] * 17
U) << 24);
158 for(i = 0; i < 4; i++)
161 nb_opaque_colors = 0;
162 for(i = 0; i < 4; i++) {
163 if (
alpha[i] != 0 && !color_used[colormap[i]]) {
164 color_used[colormap[i]] = 1;
169 if (nb_opaque_colors == 0)
173 memset(color_used, 0, 16);
174 for(i = 0; i < 4; i++) {
176 if (!color_used[colormap[i]]) {
177 level = level_map[nb_opaque_colors][j];
178 r = (((subtitle_color >> 16) & 0xff) *
level) >> 8;
179 g = (((subtitle_color >> 8) & 0xff) *
level) >> 8;
180 b = (((subtitle_color >> 0) & 0xff) *
level) >> 8;
181 rgba_palette[i] = b | (g << 8) | (r << 16) | ((
alpha[i] * 17) << 24);
182 color_used[colormap[i]] = (i + 1);
185 rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
186 ((
alpha[i] * 17) << 24);
196 if (sub_header->
rects != NULL) {
197 for (i = 0; i < sub_header->
num_rects; i++) {
207 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
212 int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
213 int big_offsets, offset_size, is_8bit = 0;
214 const uint8_t *yuv_palette = 0;
235 if (cmd_pos < 0 || cmd_pos > buf_size - 2 - offset_size)
238 while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
241 av_dlog(NULL,
"cmd_pos=0x%04x next=0x%04x date=%d\n",
242 cmd_pos, next_cmd_pos, date);
243 pos = cmd_pos + 2 + offset_size;
246 x1 = y1 = x2 = y2 = 0;
247 while (pos < buf_size) {
249 av_dlog(NULL,
"cmd=%02x\n", cmd);
265 if ((buf_size - pos) < 2)
267 colormap[3] = buf[pos] >> 4;
268 colormap[2] = buf[pos] & 0x0f;
269 colormap[1] = buf[pos + 1] >> 4;
270 colormap[0] = buf[pos + 1] & 0x0f;
275 if ((buf_size - pos) < 2)
277 alpha[3] = buf[pos] >> 4;
278 alpha[2] = buf[pos] & 0x0f;
279 alpha[1] = buf[pos + 1] >> 4;
280 alpha[0] = buf[pos + 1] & 0x0f;
286 if ((buf_size - pos) < 6)
288 x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
289 x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
290 y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
291 y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
294 av_dlog(NULL,
"x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
298 if ((buf_size - pos) < 4)
301 offset2 =
AV_RB16(buf + pos + 2);
302 av_dlog(NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
306 if ((buf_size - pos) < 8)
309 offset2 =
AV_RB32(buf + pos + 4);
310 av_dlog(NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
316 if ((buf_size - pos) < 768)
318 yuv_palette = buf + pos;
323 if ((buf_size - pos) < 256)
325 for (i = 0; i < 256; i++)
326 alpha[i] = 0xFF - buf[pos+i];
333 av_dlog(NULL,
"unrecognised subpicture command 0x%x\n", cmd);
349 if (w > 0 && h > 0) {
358 buf, offset1, buf_size, is_8bit);
360 buf, offset2, buf_size, is_8bit);
363 if (yuv_palette == 0)
372 sub_header->
rects[0]->
x = x1;
373 sub_header->
rects[0]->
y = y1;
374 sub_header->
rects[0]->
w = w;
375 sub_header->
rects[0]->
h = h;
381 if (next_cmd_pos < cmd_pos) {
385 if (next_cmd_pos == cmd_pos)
387 cmd_pos = next_cmd_pos;
400 for(i = 0; i <
n; i++) {
401 if (!transp_color[*buf])
411 uint8_t transp_color[256] = { 0 };
412 int y1, y2, x1, x2,
y, w, h, i;
424 1, s->
rects[0]->
w, transp_color))
426 if (y1 == s->
rects[0]->
h) {
434 s->
rects[0]->
w, transp_color))
438 s->
rects[0]->
h, transp_color))
449 for(y = 0; y < h; y++) {
466 static void ppm_save(
const char *filename,
uint8_t *bitmap,
int w,
int h,
467 uint32_t *rgba_palette)
472 f = fopen(filename,
"w");
481 for(y = 0; y < h; y++) {
482 for(x = 0; x < w; x++) {
483 v = rgba_palette[bitmap[y * w + x]];
484 putc((v >> 16) & 0xff, f);
485 putc((v >> 8) & 0xff, f);
486 putc((v >> 0) & 0xff, f);
498 if (ctx->
buf_size > 0xffff - buf_size) {
500 "too large SPU packets aborted.\n");
513 void *
data,
int *data_size,
518 int buf_size = avpkt->
size;
533 if (is_menu ==
AVERROR(EAGAIN)) {
551 snprintf(ppm_name,
sizeof(ppm_name),
"/tmp/%05d.ppm", ctx->sub_id++);
552 av_dlog(NULL,
"start=%d ms end =%d ms\n",
572 ctx->
palette[i] = strtoul(p, &p, 16);
581 char *dataorig, *
data;
593 int pos = strcspn(
data,
"\n\r");
594 if (pos==0 && *
data==0)
597 if (strncmp(
"palette:",
data, 8) == 0) {
599 }
else if (strncmp(
"size:",
data, 5) == 0) {
601 if (sscanf(
data + 5,
"%dx%d", &w, &h) == 2 &&
643 #define OFFSET(field) offsetof(DVDSubContext, field)
644 #define VD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
665 .priv_class = &dvdsub_class,