|
From: libvidcap c. m. <lib...@li...> - 2007-09-25 13:15:27
|
Revision: 30
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=30&view=rev
Author: bcholew
Date: 2007-09-25 06:15:23 -0700 (Tue, 25 Sep 2007)
Log Message:
-----------
Add function to convert from i420 to yuy2.
Modified Paths:
--------------
trunk/src/conv_to_yuy2.c
Modified: trunk/src/conv_to_yuy2.c
===================================================================
--- trunk/src/conv_to_yuy2.c 2007-09-24 18:49:27 UTC (rev 29)
+++ trunk/src/conv_to_yuy2.c 2007-09-25 13:15:23 UTC (rev 30)
@@ -38,8 +38,44 @@
int
vidcap_i420_to_yuy2(int width, int height, const char * src, char * dest)
{
- log_error("vidcap_i420_to_yuy2() not implemented\n");
- return -1;
+ /* convert from a planar structure to a packed structure */
+ const char * src_y_even = src;
+ const char * src_y_odd = src + width;
+ const char * src_u = src + width * height;
+ const char * src_v = src_u + width * height / 4;
+ char * dst_even = dest;
+ char * dst_odd = dest + width * 2;
+
+ int i, j;
+
+ /* i420 has a vertical sampling period (for u and v)
+ * double that for yuy2. Will re-use
+ * U and V data during repackaging.
+ */
+ for ( i = 0; i < height / 2; ++i )
+ {
+ for ( j = 0; j < width / 2; ++j )
+ {
+ *dst_even++ = *src_y_even++;
+ *dst_odd++ = *src_y_odd++;
+
+ *dst_even++ = *src_u;
+ *dst_odd++ = *src_u++;
+
+ *dst_even++ = *src_y_even++;
+ *dst_odd++ = *src_y_odd++;
+
+ *dst_even++ = *src_v;
+ *dst_odd++ = *src_v++;
+ }
+
+ src_y_even += width;
+ src_y_odd += width;
+ dst_even += width * 2;
+ dst_odd += width * 2;
+ }
+
+ return 0;
}
int
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|