41 int r_add, g_add, b_add;
43 for (i = num_values; i > 0; i--) {
49 *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
58 for (t = 1; v < t && t <= 0x40; t <<= 2)
90 const uint8_t *buf,
int start,
int buf_size,
int is_8bit)
97 bit_len = (buf_size - start) * 8;
110 len =
FFMIN(len, w - x);
111 memset(d + x, color, len);
127 uint32_t *rgba_palette,
130 uint32_t subtitle_color)
132 uint8_t color_used[16] = { 0 };
133 int nb_opaque_colors, i,
level, j,
r,
g,
b;
136 for (i = 0; i < 4; i++)
137 rgba_palette[i] = (ctx->
palette[colormap[i]] & 0x00ffffff)
138 | ((alpha[i] * 17) << 24);
142 for(i = 0; i < 4; i++)
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;
153 if (nb_opaque_colors == 0)
156 j = nb_opaque_colors;
157 memset(color_used, 0, 16);
158 for(i = 0; i < 4; i++) {
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);
169 rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
170 ((alpha[i] * 17) << 24);
176 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a)) 179 const uint8_t *buf,
int buf_size)
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 };
188 int64_t offset1, offset2;
192 memset(sub_header, 0,
sizeof(*sub_header));
206 while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
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;
214 x1 = y1 = x2 = y2 = 0;
215 while (pos < buf_size) {
233 if ((buf_size - pos) < 2)
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;
243 if ((buf_size - pos) < 2)
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;
250 av_dlog(
NULL,
"alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
254 if ((buf_size - pos) < 6)
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];
262 av_dlog(
NULL,
"x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
266 if ((buf_size - pos) < 4)
269 offset2 =
AV_RB16(buf + pos + 2);
270 av_dlog(
NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
274 if ((buf_size - pos) < 8)
277 offset2 =
AV_RB32(buf + pos + 4);
278 av_dlog(
NULL,
"offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
284 if ((buf_size - pos) < 768)
286 yuv_palette = buf + pos;
291 if ((buf_size - pos) < 256)
293 for (i = 0; i < 256; i++)
294 alpha[i] = 0xFF - buf[pos+i];
301 av_dlog(
NULL,
"unrecognised subpicture command 0x%x\n", cmd);
306 if (offset1 >= buf_size || offset2 >= buf_size)
320 if (w > 0 && h > 0) {
321 if (sub_header->
rects) {
322 for (i = 0; i < sub_header->
num_rects; i++) {
337 buf, offset1, buf_size, is_8bit);
339 buf, offset2, buf_size, is_8bit);
342 if (yuv_palette == 0)
350 colormap, alpha, 0xffff00);
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;
360 if (next_cmd_pos == cmd_pos)
362 cmd_pos = next_cmd_pos;
367 if (!sub_header->
rects) {
368 for (i = 0; i < sub_header->
num_rects; i++) {
383 for(i = 0; i < n; i++) {
384 if (!transp_color[*buf])
394 uint8_t transp_color[256] = { 0 };
395 int y1, y2, x1, x2, y, w, h, i;
407 1, s->
rects[0]->
w, transp_color))
409 if (y1 == s->
rects[0]->
h) {
417 s->
rects[0]->
w, transp_color))
421 s->
rects[0]->
h, transp_color))
432 for(y = 0; y < h; y++) {
446 static void ppm_save(
const char *filename,
uint8_t *bitmap,
int w,
int h,
447 uint32_t *rgba_palette)
452 f = fopen(filename,
"w");
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);
474 void *
data,
int *data_size,
479 int buf_size = avpkt->
size;
523 if (strncmp(
"palette:", cur, 8) == 0) {
527 for (i = 0; i < 16; i++) {
528 ctx->
palette[i] = strtoul(p, &p, 16);
532 }
else if (!strncmp(
"size:", cur, 5)) {
534 if (sscanf(cur + 5,
"%dx%d", &w, &h) == 2) {
540 cur += strcspn(cur,
"\n\r");
541 cur += strspn(cur,
"\n\r");
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
int x
top left corner of pict, undefined when pict is not set
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define YUV_TO_RGB1_CCIR(cb1, cr1)
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.
int nb_colors
number of colors in pict, undefined when pict is not set
Various defines for YUV<->RGB conversion.
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 ...
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, 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)
int w
width of pict, undefined when pict is not set
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
uint8_t * data[AV_NUM_DATA_POINTERS]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void guess_palette(DVDSubContext *ctx, uint32_t *rgba_palette, uint8_t *colormap, uint8_t *alpha, uint32_t subtitle_color)
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
int h
height of pict, undefined when pict is not set
static av_cold int dvdsub_init(AVCodecContext *avctx)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int y
top left corner of pict, undefined when pict is not set
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
uint32_t end_display_time
static int decode_run_8bit(GetBitContext *gb, int *color)
A bitmap, pict will be set.
AVPicture pict
data+linesize for the bitmap of this subtitle.
static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values)
static int is_transp(const uint8_t *buf, int pitch, int n, const uint8_t *transp_color)
AVCodec ff_dvdsub_decoder
Libavcodec external API header.
main external API structure.
static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, const uint8_t *buf, int buf_size)
static unsigned int get_bits1(GetBitContext *s)
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int decode_run_2bit(GetBitContext *gb, int *color)
static int find_smallest_bounding_rectangle(AVSubtitle *s)
common internal api header.
uint32_t start_display_time
static const uint8_t color[]
static av_cold int init(AVCodecParserContext *s)
static int dvdsub_decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
static const uint8_t * align_get_bits(GetBitContext *s)
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)