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;
 
  282     width  = bytestream_get_be16(&buf);
 
  283     height = bytestream_get_be16(&buf);
 
  286     if (avctx->
width < width || avctx->
height < height) {
 
  291     if (buf_size > rle_bitmap_len) {
 
  304     memcpy(object->
rle, buf, buf_size);
 
  305     object->rle_data_len = buf_size;
 
  306     object->rle_remaining_len = rle_bitmap_len - buf_size;
 
  327     const uint8_t *buf_end = buf + buf_size;
 
  331     int r, 
g, 
b, r_add, g_add, b_add;
 
  334     id  = bytestream_get_byte(&buf);
 
  348     while (buf < buf_end) {
 
  349         color_id  = bytestream_get_byte(&buf);
 
  350         y         = bytestream_get_byte(&buf);
 
  351         cr        = bytestream_get_byte(&buf);
 
  352         cb        = bytestream_get_byte(&buf);
 
  353         alpha     = bytestream_get_byte(&buf);
 
  358         av_dlog(avctx, 
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
 
  361         palette->
clut[color_id] = 
RGBA(r,g,b,alpha);
 
  383     const uint8_t *buf_end = buf + buf_size;
 
  386     int w = bytestream_get_be16(&buf);
 
  387     int h = bytestream_get_be16(&buf);
 
  391     av_dlog(avctx, 
"Video Dimensions %dx%d\n",
 
  411     state = bytestream_get_byte(&buf) >> 6;
 
  424                "Invalid number of presentation objects %d\n",
 
  436         if (buf_end - buf < 8) {
 
  457         av_dlog(avctx, 
"Subtitle Placement x=%d, y=%d\n",
 
  462             av_log(avctx, 
AV_LOG_ERROR, 
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
 
  497     memset(sub, 0, 
sizeof(*sub));
 
  526         if (!sub->
rects[i]) {
 
  551         sub->
rects[i]->
w    = 
object->w;
 
  552         sub->
rects[i]->
h    = 
object->h;
 
  596     int buf_size       = avpkt->
size;
 
  603     av_dlog(avctx, 
"PGS sub packet:\n");
 
  605     for (i = 0; i < buf_size; i++) {
 
  606         av_dlog(avctx, 
"%02x ", buf[i]);
 
  620     buf_end = buf + buf_size;
 
  623     while (buf < buf_end) {
 
  624         segment_type   = bytestream_get_byte(&buf);
 
  625         segment_length = bytestream_get_be16(&buf);
 
  627         av_dlog(avctx, 
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
 
  633         switch (segment_type) {
 
  660                    segment_type, segment_length);
 
  667         buf += segment_length;
 
  673 #define OFFSET(x) offsetof(PGSSubContext, x) 
  674 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM 
  676     {
"forced_subs_only", 
"Only show forced subtitles", 
OFFSET(forced_subs_only), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, 
SD},
 
  696     .priv_class     = &pgsdec_class,