34 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
90 for (picture = 0; picture < UINT16_MAX; ++picture) {
109 const uint8_t *buf,
unsigned int buf_size)
112 int pixel_count, line_count;
114 rle_bitmap_end = buf + buf_size;
124 while (buf < rle_bitmap_end && line_count < sub->rects[rect]->h) {
128 color = bytestream_get_byte(&buf);
132 flags = bytestream_get_byte(&buf);
135 run = (run << 8) + bytestream_get_byte(&buf);
136 color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
139 if (run > 0 && pixel_count + run <= sub->rects[rect]->w * sub->
rects[rect]->
h) {
140 memset(sub->
rects[rect]->
pict.
data[0] + pixel_count, color, run);
147 if (pixel_count % sub->
rects[rect]->
w > 0)
149 pixel_count % sub->
rects[rect]->
w, sub->
rects[rect]->
w);
154 if (pixel_count < sub->rects[rect]->w * sub->
rects[rect]->
h) {
159 av_dlog(avctx,
"Pixel Count = %d, Area = %d\n", pixel_count, sub->
rects[rect]->
w * sub->
rects[rect]->
h);
176 const uint8_t *buf,
int buf_size)
188 picture_id = bytestream_get_be16(&buf);
194 sequence_desc = bytestream_get_byte(&buf);
196 if (!(sequence_desc & 0x80)) {
213 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
216 width = bytestream_get_be16(&buf);
217 height = bytestream_get_be16(&buf);
220 if (avctx->
width < width || avctx->
height < height) {
225 if (buf_size > rle_bitmap_len) {
238 memcpy(ctx->
pictures[picture_id].
rle, buf, buf_size);
256 const uint8_t *buf,
int buf_size)
260 const uint8_t *buf_end = buf + buf_size;
264 int r,
g,
b, r_add, g_add, b_add;
269 while (buf < buf_end) {
270 color_id = bytestream_get_byte(&buf);
271 y = bytestream_get_byte(&buf);
272 cr = bytestream_get_byte(&buf);
273 cb = bytestream_get_byte(&buf);
274 alpha = bytestream_get_byte(&buf);
279 av_dlog(avctx,
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
282 ctx->
clut[color_id] =
RGBA(r,g,b,alpha);
298 const uint8_t *buf,
int buf_size,
303 int w = bytestream_get_be16(&buf);
304 int h = bytestream_get_be16(&buf);
306 uint16_t object_index;
310 av_dlog(avctx,
"Video Dimensions %dx%d\n",
334 if (buf_size < ctx->presentation.object_count * 8) {
348 reference->
picture_id = bytestream_get_be16(&buf);
353 reference->
composition = bytestream_get_byte(&buf);
355 reference->
x = bytestream_get_be16(&buf);
356 reference->
y = bytestream_get_be16(&buf);
359 av_dlog(avctx,
"Subtitle Placement ID=%d, x=%d, y=%d\n", reference->
picture_id, reference->
x, reference->
y);
361 if (reference->
x > avctx->
width || reference->
y > avctx->
height) {
362 av_log(avctx,
AV_LOG_ERROR,
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
386 const uint8_t *buf,
int buf_size)
401 memset(sub, 0,
sizeof(*sub));
416 for (rect = 0; rect < sub->
num_rects; ++rect) {
453 int buf_size = avpkt->
size;
461 av_dlog(avctx,
"PGS sub packet:\n");
463 for (i = 0; i < buf_size; i++) {
464 av_dlog(avctx,
"%02x ", buf[i]);
478 buf_end = buf + buf_size;
481 while (buf < buf_end) {
482 segment_type = bytestream_get_byte(&buf);
483 segment_length = bytestream_get_be16(&buf);
485 av_dlog(avctx,
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
490 switch (segment_type) {
515 segment_type, segment_length);
519 buf += segment_length;
525 #define OFFSET(x) offsetof(PGSSubContext, x)
526 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
528 {
"forced_subs_only",
"Only show forced subtitles",
OFFSET(forced_subs_only),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},