<commit_before>/*
 * libvidcap - a cross-platform video capture library
 *
 * Copyright 2007 Wimba, Inc.
 *
 * Contributors:
 * <NAME> <<EMAIL>>
 * <NAME> <<EMAIL>>
 *
 * libvidcap is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * libvidcap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <vidcap/converters.h>
#include "logging.h"

/* NOTE: size of dest buffer must be >= width * height * 2 */

int
vidcap_rgb32_to_yuy2(int width, int height, const char * src, char * dest)
{
	log_error("vidcap_rgb32_to_yuy2() not implemented\n");
	return -1;
}

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;
}

int
conv_2vuy_to_yuy2(int width, int height, const char * src, char * dest)
{
	int i;
	unsigned int * d = (unsigned int *)dest;
	const unsigned int * s = (const unsigned int *)src;

	for ( i = 0; i < width * height / 2; ++i )
	{
		*d++ = ((*s & 0xff000000) >> 8) |
			((*s & 0x00ff0000) << 8) |
			((*s & 0x0000ff00) >> 8) |
			((*s & 0x000000ff) << 8);
		++s;
	}

	return 0;
}<commit_msg>Add function to convert from i420 to yuy2.<commit_after>/*
 * libvidcap - a cross-platform video capture library
 *
 * Copyright 2007 Wimba, Inc.
 *
 * Contributors:
 * <NAME> <<EMAIL>>
 * <NAME> <<EMAIL>>
 *
 * libvidcap is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * libvidcap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <vidcap/converters.h>
#include "logging.h"

/* NOTE: size of dest buffer must be >= width * height * 2 */

int
vidcap_rgb32_to_yuy2(int width, int height, const char * src, char * dest)
{
	log_error("vidcap_rgb32_to_yuy2() not implemented\n");
	return -1;
}

int
vidcap_i420_to_yuy2(int width, int height, const char * src, char * dest)
{
	/* 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
conv_2vuy_to_yuy2(int width, int height, const char * src, char * dest)
{
	int i;
	unsigned int * d = (unsigned int *)dest;
	const unsigned int * s = (const unsigned int *)src;

	for ( i = 0; i < width * height / 2; ++i )
	{
		*d++ = ((*s & 0xff000000) >> 8) |
			((*s & 0x00ff0000) << 8) |
			((*s & 0x0000ff00) >> 8) |
			((*s & 0x000000ff) << 8);
		++s;
	}

	return 0;
}
{'fraction_non_alphanumeric': 0.1308252427184466, 'fraction_numerical': 0.03203883495145631, 'mean_word_length': 3.319706498951782, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311596', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1451, 'n_words': 528}