summaryrefslogtreecommitdiffstats
path: root/sub/av_sub.c
diff options
context:
space:
mode:
Diffstat (limited to 'sub/av_sub.c')
-rw-r--r--sub/av_sub.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/sub/av_sub.c b/sub/av_sub.c
index 3a9e1b4f26..56acfc63ca 100644
--- a/sub/av_sub.c
+++ b/sub/av_sub.c
@@ -32,6 +32,47 @@ void reset_avsub(struct sh_sub *sh)
}
}
+static void avsub_to_spudec(AVSubtitleRect **rects, int num_rects,
+ double pts, double endpts)
+{
+ int i, xmin = INT_MAX, ymin = INT_MAX, xmax = INT_MIN, ymax = INT_MIN;
+ struct spu_packet_t *packet;
+
+ if (num_rects == 1) {
+ spudec_set_paletted(vo_spudec,
+ rects[0]->pict.data[0],
+ rects[0]->pict.linesize[0],
+ rects[0]->pict.data[1],
+ rects[0]->x,
+ rects[0]->y,
+ rects[0]->w,
+ rects[0]->h,
+ pts,
+ endpts);
+ return;
+ }
+ for (i = 0; i < num_rects; i++) {
+ xmin = FFMIN(xmin, rects[i]->x);
+ ymin = FFMIN(ymin, rects[i]->y);
+ xmax = FFMAX(xmax, rects[i]->x + rects[i]->w);
+ ymax = FFMAX(ymax, rects[i]->y + rects[i]->h);
+ }
+ packet = spudec_packet_create(xmin, ymin, xmax - xmin, ymax - ymin);
+ if (!packet)
+ return;
+ spudec_packet_clear(packet);
+ for (i = 0; i < num_rects; i++)
+ spudec_packet_fill(packet,
+ rects[i]->pict.data[0],
+ rects[i]->pict.linesize[0],
+ rects[i]->pict.data[1],
+ rects[i]->x - xmin,
+ rects[i]->y - ymin,
+ rects[i]->w,
+ rects[i]->h);
+ spudec_packet_send(vo_spudec, packet, pts, endpts);
+}
+
/**
* Decode a subtitle packet via libavcodec.
* \return < 0 on error, > 0 if further processing is needed
@@ -96,16 +137,7 @@ int decode_avsub(struct sh_sub *sh, uint8_t *data, int size,
case SUBTITLE_BITMAP:
if (!vo_spudec)
vo_spudec = spudec_new_scaled(NULL, ctx->width, ctx->height, NULL, 0);
- spudec_set_paletted(vo_spudec,
- sub.rects[0]->pict.data[0],
- sub.rects[0]->pict.linesize[0],
- sub.rects[0]->pict.data[1],
- sub.rects[0]->x,
- sub.rects[0]->y,
- sub.rects[0]->w,
- sub.rects[0]->h,
- pts,
- endpts);
+ avsub_to_spudec(sub.rects, sub.num_rects, pts, endpts);
vo_osd_changed(OSDTYPE_SPU);
break;
default: