45 int r_add, g_add, b_add;
47 for (i = num_values; i > 0; i--) {
53 *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
62 for (t = 1; v < t && t <= 0x40; t <<= 2)
101 bit_len = (buf_size -
start) * 8;
114 len =
FFMIN(len, w - x);
115 memset(d + x, color, len);
131 uint32_t *rgba_palette,
132 uint32_t subtitle_color)
134 static const uint8_t level_map[4][4] = {
140 {0x00, 0x55, 0xaa, 0xff},
142 uint8_t color_used[16] = { 0 };
143 int nb_opaque_colors, i,
level, j,
r,
g,
b;
147 for(i = 0; i < 4; i++)
148 rgba_palette[i] = (ctx->
palette[colormap[i]] & 0x00ffffff)
149 | ((
alpha[i] * 17
U) << 24);
153 for(i = 0; i < 4; i++)
156 nb_opaque_colors = 0;
157 for(i = 0; i < 4; i++) {
158 if (
alpha[i] != 0 && !color_used[colormap[i]]) {
159 color_used[colormap[i]] = 1;
164 if (nb_opaque_colors == 0)
168 memset(color_used, 0, 16);
169 for(i = 0; i < 4; i++) {
171 if (!color_used[colormap[i]]) {
172 level = level_map[nb_opaque_colors][j];
173 r = (((subtitle_color >> 16) & 0xff) *
level) >> 8;
174 g = (((subtitle_color >> 8) & 0xff) *
level) >> 8;
175 b = (((subtitle_color >> 0) & 0xff) *
level) >> 8;
176 rgba_palette[i] = b | (g << 8) | (r << 16) | ((
alpha[i] * 17) << 24);
177 color_used[colormap[i]] = (i + 1);
180 rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
181 ((
alpha[i] * 17) << 24);
187 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
192 int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
193 int big_offsets, offset_size, is_8bit = 0;
194 const uint8_t *yuv_palette = 0;
215 while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
218 av_dlog(NULL,
"cmd_pos=0x%04x next=0x%04x date=%d\n",
219 cmd_pos, next_cmd_pos, date);
220 pos = cmd_pos + 2 + offset_size;
223 x1 = y1 = x2 = y2 = 0;
224 while (pos < buf_size) {
226 av_dlog(NULL,
"cmd=%02x\n", cmd);
242 if ((buf_size - pos) < 2)
244 colormap[3] = buf[pos] >> 4;
245 colormap[2] = buf[pos] & 0x0f;
246 colormap[1] = buf[pos + 1] >> 4;
247 colormap[0] = buf[pos + 1] & 0x0f;
252 if ((buf_size - pos) < 2)
254 alpha[3] = buf[pos] >> 4;
255 alpha[2] = buf[pos] & 0x0f;
256 alpha[1] = buf[pos + 1] >> 4;
257 alpha[0] = buf[pos + 1] & 0x0f;
263 if ((buf_size - pos) < 6)
265 x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
266 x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
267 y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
268 y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
271 av_dlog(NULL,
"x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
275 if ((buf_size - pos) < 4)
278 offset2 =
AV_RB16(buf + pos + 2);
279 av_dlog(NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
283 if ((buf_size - pos) < 8)
286 offset2 =
AV_RB32(buf + pos + 4);
287 av_dlog(NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
293 if ((buf_size - pos) < 768)
295 yuv_palette = buf + pos;
300 if ((buf_size - pos) < 256)
302 for (i = 0; i < 256; i++)
303 alpha[i] = 0xFF - buf[pos+i];
310 av_dlog(NULL,
"unrecognised subpicture command 0x%x\n", cmd);
326 if (w > 0 && h > 0) {
327 if (sub_header->
rects != NULL) {
328 for (i = 0; i < sub_header->
num_rects; i++) {
343 buf, offset1, buf_size, is_8bit);
345 buf, offset2, buf_size, is_8bit);
348 if (yuv_palette == 0)
357 sub_header->
rects[0]->
x = x1;
358 sub_header->
rects[0]->
y = y1;
359 sub_header->
rects[0]->
w = w;
360 sub_header->
rects[0]->
h = h;
366 if (next_cmd_pos < cmd_pos) {
370 if (next_cmd_pos == cmd_pos)
372 cmd_pos = next_cmd_pos;
377 if (sub_header->
rects != NULL) {
378 for (i = 0; i < sub_header->
num_rects; i++) {
393 for(i = 0; i <
n; i++) {
394 if (!transp_color[*buf])
404 uint8_t transp_color[256] = { 0 };
405 int y1, y2, x1, x2,
y, w, h, i;
417 1, s->
rects[0]->
w, transp_color))
419 if (y1 == s->
rects[0]->
h) {
427 s->
rects[0]->
w, transp_color))
431 s->
rects[0]->
h, transp_color))
442 for(y = 0; y < h; y++) {
459 static void ppm_save(
const char *filename,
uint8_t *bitmap,
int w,
int h,
460 uint32_t *rgba_palette)
465 f = fopen(filename,
"w");
474 for(y = 0; y < h; y++) {
475 for(x = 0; x < w; x++) {
476 v = rgba_palette[bitmap[y * w + x]];
477 putc((v >> 16) & 0xff, f);
478 putc((v >> 8) & 0xff, f);
479 putc((v >> 0) & 0xff, f);
487 void *
data,
int *data_size,
492 int buf_size = avpkt->
size;
508 av_dlog(NULL,
"start=%d ms end =%d ms\n",
525 ctx->
palette[i] = strtoul(p, &p, 16);
534 char *dataorig, *
data;
546 int pos = strcspn(
data,
"\n\r");
547 if (pos==0 && *
data==0)
550 if (strncmp(
"palette:",
data, 8) == 0) {
552 }
else if (strncmp(
"size:",
data, 5) == 0) {
554 if (sscanf(
data + 5,
"%dx%d", &w, &h) == 2 &&
588 #define OFFSET(field) offsetof(DVDSubContext, field)
589 #define VD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM