changeset 18055:d1c6b9abbc73

New mode for tinterlace filter patch by Walter Belhaven <wbelhaven at yahoo >
author iive
date Sat, 08 Apr 2006 15:30:09 +0000
parents a75d8f4b3563
children 5151706a00e8
files libmpcodecs/vf_tinterlace.c
diffstat 1 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_tinterlace.c	Sat Apr 08 13:53:02 2006 +0000
+++ b/libmpcodecs/vf_tinterlace.c	Sat Apr 08 15:30:09 2006 +0000
@@ -35,6 +35,22 @@
 	mp_image_t *dmpi;
 };
 
+// Copied verbatim from vf_telecine.c:
+static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
+{
+	int i;
+	void *retval=dst;
+
+	for(i=0; i<height; i++)
+	{
+		memcpy(dst, src, bytesPerLine);
+		src+= srcStride;
+		dst+= dstStride;
+	}
+
+	return retval;
+}
+
 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
 {
 	int ret = 0;
@@ -116,6 +132,57 @@
 		}
 		ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
 		break;
+	case 4:
+		// Interleave even lines (only) from Frame 'i' with odd
+		// lines (only) from Frame 'i+1', halving the Frame
+		// rate and preserving image height.
+
+		dmpi = vf->priv->dmpi;
+		
+		// @@ Need help:  Should I set dmpi->fields to indicate
+		// that the (new) frame will be interlaced!?  E.g. ...
+		// dmpi->fields |= MP_IMGFIELD_INTERLACED;
+		// dmpi->fields |= MP_IMGFIELD_TOP_FIRST;
+		// etc.
+		
+		if (dmpi == NULL) {
+			dmpi = vf_get_image(vf->next, mpi->imgfmt,
+					    MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+					    MP_IMGFLAG_PRESERVE,
+					    mpi->width, mpi->height);
+
+			vf->priv->dmpi = dmpi;
+
+			my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
+				      dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
+					      mpi->chroma_width, mpi->chroma_height/2,
+					      dmpi->stride[1]*2, mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
+					      mpi->chroma_width, mpi->chroma_height/2,
+					      dmpi->stride[2]*2, mpi->stride[2]*2);
+			}
+		} else {
+			vf->priv->dmpi = NULL;
+
+			my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], 
+				      mpi->planes[0]+mpi->stride[0],
+				      mpi->w, mpi->h/2, 
+				      dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], 
+					      mpi->planes[1]+mpi->stride[1],
+					      mpi->chroma_width, mpi->chroma_height/2,
+					      dmpi->stride[1]*2, mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], 
+					      mpi->planes[2]+mpi->stride[2],
+					      mpi->chroma_width, mpi->chroma_height/2,
+					      dmpi->stride[2]*2, mpi->stride[2]*2);
+			}
+			ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
+		}
+		break;
 	}
 
 	vf->priv->frame++;
@@ -145,6 +212,7 @@
 		return vf_next_config(vf,width,height*2,d_width,d_height*2,flags,outfmt);
 	case 1:			/* odd frames */
 	case 2:			/* even frames */
+	case 4:			/* alternate frame (height-preserving) interlacing */
 		return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
 	}
 	return 0;