36 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
37 #define MAX_EPOCH_PALETTES 8 // Max 8 allowed per PGS epoch
38 #define MAX_EPOCH_OBJECTS 64 // Max 64 allowed per PGS epoch
39 #define MAX_OBJECT_REFS 2 // Max objects per display set
119 for (i = 0; i < objects->
count; i++) {
121 return &objects->
object[i];
130 for (i = 0; i < palettes->
count; i++) {
165 int pixel_count, line_count;
167 rle_bitmap_end = buf + buf_size;
177 while (buf < rle_bitmap_end && line_count < rect->h) {
181 color = bytestream_get_byte(&buf);
185 flags = bytestream_get_byte(&buf);
188 run = (run << 8) + bytestream_get_byte(&buf);
189 color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
192 if (run > 0 && pixel_count + run <= rect->w * rect->
h) {
193 memset(rect->
pict.
data[0] + pixel_count, color, run);
200 if (pixel_count % rect->
w > 0) {
202 pixel_count % rect->
w, rect->
w);
211 if (pixel_count < rect->w * rect->
h) {
216 av_dlog(avctx,
"Pixel Count = %d, Area = %d\n", pixel_count, rect->
w * rect->
h);
245 id = bytestream_get_be16(&buf);
260 sequence_desc = bytestream_get_byte(&buf);
262 if (!(sequence_desc & 0x80)) {
268 object->rle_data_len += buf_size;
269 object->rle_remaining_len -= buf_size;
279 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
281 if (buf_size > rle_bitmap_len) {
283 "Buffer dimension %d larger than the expected RLE data %d\n",
284 buf_size, rle_bitmap_len);
289 width = bytestream_get_be16(&buf);
290 height = bytestream_get_be16(&buf);
293 if (avctx->
width < width || avctx->
height < height) {
306 memcpy(object->
rle, buf, buf_size);
307 object->rle_data_len = buf_size;
308 object->rle_remaining_len = rle_bitmap_len - buf_size;
329 const uint8_t *buf_end = buf + buf_size;
333 int r,
g,
b, r_add, g_add, b_add;
336 id = bytestream_get_byte(&buf);
350 while (buf < buf_end) {
351 color_id = bytestream_get_byte(&buf);
352 y = bytestream_get_byte(&buf);
353 cr = bytestream_get_byte(&buf);
354 cb = bytestream_get_byte(&buf);
355 alpha = bytestream_get_byte(&buf);
360 av_dlog(avctx,
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
363 palette->
clut[color_id] =
RGBA(r,g,b,alpha);
385 const uint8_t *buf_end = buf + buf_size;
388 int w = bytestream_get_be16(&buf);
389 int h = bytestream_get_be16(&buf);
393 av_dlog(avctx,
"Video Dimensions %dx%d\n",
413 state = bytestream_get_byte(&buf) >> 6;
426 "Invalid number of presentation objects %d\n",
438 if (buf_end - buf < 8) {
459 av_dlog(avctx,
"Subtitle Placement x=%d, y=%d\n",
464 av_log(avctx,
AV_LOG_ERROR,
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
499 memset(sub, 0,
sizeof(*sub));
528 if (!sub->
rects[i]) {
553 sub->
rects[i]->
w =
object->w;
554 sub->
rects[i]->
h =
object->h;
598 int buf_size = avpkt->
size;
605 av_dlog(avctx,
"PGS sub packet:\n");
607 for (i = 0; i < buf_size; i++) {
608 av_dlog(avctx,
"%02x ", buf[i]);
622 buf_end = buf + buf_size;
625 while (buf < buf_end) {
626 segment_type = bytestream_get_byte(&buf);
627 segment_length = bytestream_get_be16(&buf);
629 av_dlog(avctx,
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
635 switch (segment_type) {
662 segment_type, segment_length);
669 buf += segment_length;
675 #define OFFSET(x) offsetof(PGSSubContext, x)
676 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
678 {
"forced_subs_only",
"Only show forced subtitles",
OFFSET(forced_subs_only),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
698 .priv_class = &pgsdec_class,