summaryrefslogtreecommitdiff
path: root/gst/dvdsub
diff options
context:
space:
mode:
authorBrendan Le Foll <blefoll@fluendo.com>2011-03-14 18:39:35 +0100
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2011-03-14 18:40:40 +0100
commita72cc73798938a88c1da3a4d74d17eb2df7f6b02 (patch)
treed3709ea9df56d4805200352d63b3469a1e695fa5 /gst/dvdsub
parent65565c8a1e586585bb6ff74545d3e52d979a8e56 (diff)
dvdsubdec: Implement clipping if the video size is smaller than the subpicture size
Fixes bug #644704.
Diffstat (limited to 'gst/dvdsub')
-rw-r--r--gst/dvdsub/gstdvdsubdec.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/gst/dvdsub/gstdvdsubdec.c b/gst/dvdsub/gstdvdsubdec.c
index e1ab6570..5a2a24ed 100644
--- a/gst/dvdsub/gstdvdsubdec.c
+++ b/gst/dvdsub/gstdvdsubdec.c
@@ -317,16 +317,10 @@ gst_dvd_sub_dec_parse_subpic (GstDvdSubDec * dec)
case SPU_SET_SIZE: /* image coordinates */
PARSE_BYTES_NEEDED (7);
- dec->left =
- CLAMP ((((guint) buf[1]) << 4) | (buf[2] >> 4), 0,
- (dec->in_width - 1));
- dec->top =
- CLAMP ((((guint) buf[4]) << 4) | (buf[5] >> 4), 0,
- (dec->in_height - 1));
- dec->right =
- CLAMP ((((buf[2] & 0x0f) << 8) | buf[3]), 0, (dec->in_width - 1));
- dec->bottom =
- CLAMP ((((buf[5] & 0x0f) << 8) | buf[6]), 0, (dec->in_height - 1));
+ dec->top = ((buf[4] & 0x3f) << 4) | ((buf[5] & 0xe0) >> 4);
+ dec->left = ((buf[1] & 0x3f) << 4) | ((buf[2] & 0xf0) >> 4);
+ dec->right = ((buf[2] & 0x03) << 8) | buf[3];
+ dec->bottom = ((buf[5] & 0x03) << 8) | buf[6];
GST_DEBUG_OBJECT (dec, "SPU SET_SIZE left %d, top %d, right %d, "
"bottom %d", dec->left, dec->top, dec->right, dec->bottom);
@@ -594,6 +588,50 @@ gst_dvd_sub_dec_merge_title (GstDvdSubDec * dec, GstBuffer * buf)
state.offset[0] = dec->offset[0];
state.offset[1] = dec->offset[1];
+ /* center the image when display rectangle exceeds the video width */
+ if (dec->in_width <= dec->right) {
+ gint left, disp_width;
+
+ disp_width = dec->right - dec->left + 1;
+ left = (dec->in_width - disp_width) / 2;
+ dec->left = left;
+ dec->right = left + disp_width - 1;
+
+ /* if it clips to the right, shift it left, but only till zero */
+ if (dec->right >= dec->in_width) {
+ gint shift = dec->right - dec->in_width - 1;
+ if (shift > dec->left)
+ shift = dec->left;
+ dec->left -= shift;
+ dec->right -= shift;
+ }
+
+ GST_DEBUG_OBJECT (dec, "clipping width to %d,%d",
+ dec->left, dec->in_width - 1);
+ }
+
+ /* for the height, bring it up till it fits as well as it can. We
+ * assume the picture is in the lower part. We should better check where it
+ * is and do something more clever. */
+ if (dec->in_height <= dec->bottom) {
+
+ /* shift it up, but only till zero */
+ gint shift = dec->bottom - dec->in_height - 1;
+ if (shift > dec->top)
+ shift = dec->top;
+ dec->top -= shift;
+ dec->bottom -= shift;
+
+ /* start on even line */
+ if (dec->top & 1) {
+ dec->top--;
+ dec->bottom--;
+ }
+
+ GST_DEBUG_OBJECT (dec, "clipping height to %d,%d",
+ dec->top, dec->in_height - 1);
+ }
+
if (dec->current_button) {
hl_top = dec->hl_top;
hl_bottom = dec->hl_bottom;