36 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
92 for (picture = 0; picture < UINT16_MAX; ++picture) {
114 int pixel_count, line_count;
116 rle_bitmap_end = buf + buf_size;
126 while (buf < rle_bitmap_end && line_count < sub->rects[rect]->h) {
130 color = bytestream_get_byte(&buf);
134 flags = bytestream_get_byte(&buf);
137 run = (run << 8) + bytestream_get_byte(&buf);
138 color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
141 if (run > 0 && pixel_count + run <= sub->rects[rect]->w * sub->
rects[rect]->
h) {
142 memset(sub->
rects[rect]->
pict.
data[0] + pixel_count, color, run);
149 if (pixel_count % sub->
rects[rect]->
w > 0)
151 pixel_count % sub->
rects[rect]->
w, sub->
rects[rect]->
w);
156 if (pixel_count < sub->rects[rect]->w * sub->
rects[rect]->
h) {
161 av_dlog(avctx,
"Pixel Count = %d, Area = %d\n", pixel_count, sub->
rects[rect]->
w * sub->
rects[rect]->
h);
190 picture_id = bytestream_get_be16(&buf);
196 sequence_desc = bytestream_get_byte(&buf);
198 if (!(sequence_desc & 0x80)) {
215 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
218 width = bytestream_get_be16(&buf);
219 height = bytestream_get_be16(&buf);
222 if (avctx->
width < width || avctx->
height < height) {
227 if (buf_size > rle_bitmap_len) {
240 memcpy(ctx->
pictures[picture_id].
rle, buf, buf_size);
262 const uint8_t *buf_end = buf + buf_size;
266 int r,
g,
b, r_add, g_add, b_add;
271 while (buf < buf_end) {
272 color_id = bytestream_get_byte(&buf);
273 y = bytestream_get_byte(&buf);
274 cr = bytestream_get_byte(&buf);
275 cb = bytestream_get_byte(&buf);
276 alpha = bytestream_get_byte(&buf);
281 av_dlog(avctx,
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
284 ctx->
clut[color_id] =
RGBA(r,g,b,alpha);
306 int w = bytestream_get_be16(&buf);
307 int h = bytestream_get_be16(&buf);
309 uint16_t object_index;
313 av_dlog(avctx,
"Video Dimensions %dx%d\n",
338 if (buf_size < ctx->presentation.object_count * 8) {
352 reference->
picture_id = bytestream_get_be16(&buf);
357 reference->
composition = bytestream_get_byte(&buf);
359 reference->
x = bytestream_get_be16(&buf);
360 reference->
y = bytestream_get_be16(&buf);
363 av_dlog(avctx,
"Subtitle Placement ID=%d, x=%d, y=%d\n", reference->
picture_id, reference->
x, reference->
y);
365 if (reference->
x > avctx->
width || reference->
y > avctx->
height) {
366 av_log(avctx,
AV_LOG_ERROR,
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
407 memset(sub, 0,
sizeof(*sub));
422 for (rect = 0; rect < sub->
num_rects; ++rect) {
459 int buf_size = avpkt->
size;
467 av_dlog(avctx,
"PGS sub packet:\n");
469 for (i = 0; i < buf_size; i++) {
470 av_dlog(avctx,
"%02x ", buf[i]);
484 buf_end = buf + buf_size;
487 while (buf < buf_end) {
488 segment_type = bytestream_get_byte(&buf);
489 segment_length = bytestream_get_be16(&buf);
491 av_dlog(avctx,
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
496 switch (segment_type) {
523 segment_type, segment_length);
527 buf += segment_length;
533 #define OFFSET(x) offsetof(PGSSubContext, x)
534 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
536 {
"forced_subs_only",
"Only show forced subtitles",
OFFSET(forced_subs_only),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
556 .priv_class = &pgsdec_class,