示例#1
0
static void
preproc_rgb2yuv(cv::Mat *dst,
		cv::Mat *src)
{
	int w = src->size().width;
	int h = src->size().height;

	float div = 1.0f / src_max;

	for (int yi=0; yi<h; yi++) {
		const SRC_TYPE *src_line = (SRC_TYPE*)src->ptr(yi);
		float *dst_line = (float*)dst->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float b = src_line[xi*3 + bidx] * div;
			float g = src_line[xi*3 + 1] * div;
			float r = src_line[xi*3 + ridx] * div;

			float Y = clipf(0.0f, b*0.114f + g*0.587f + r*0.299f, 1.0f);
			float U = clipf(0.0f, (b-Y) * 0.492f + 0.5f,          1.0f);
			float V = clipf(0.0f, (r-Y) * 0.877f + 0.5f,          1.0f);

			dst_line[xi*3 + 0] = Y;
			dst_line[xi*3 + 1] = U;
			dst_line[xi*3 + 2] = V;
		}
	}
}
示例#2
0
static void
postproc_yuv2rgb(cv::Mat *dst,
		 cv::Mat *src_yuv)
{
	int w = dst->size().width;
	int h = dst->size().height;

	for (int yi=0; yi<h; yi++) {
		const float *src_yuv_line = (float*)src_yuv->ptr(yi);
		DST_TYPE *dst_line = (DST_TYPE*)dst->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float y = src_yuv_line[xi*3 + 0];
			float cr = src_yuv_line[xi*3 + 1];
			float cb = src_yuv_line[xi*3 + 2];

			float C0 = 2.032f, C1 = -0.395f, C2 = -0.581f, C3 = 1.140f;

			float b = y + (cb-0.5f)*C3;
			float g = y + (cb-0.5f)*C2 + (cr-0.5f)*C1;
			float r = y + (cr-0.5f)*C0;

			r = clipf(0.0f, r * dst_max, dst_max);
			g = clipf(0.0f, g * dst_max, dst_max);
			b = clipf(0.0f, b * dst_max, dst_max);

			dst_line[xi*3 + ridx] = (DST_TYPE)r;
			dst_line[xi*3 + 1] = (DST_TYPE)g;
			dst_line[xi*3 + bidx] = (DST_TYPE)b;
		}
	}
	
}
示例#3
0
static void
postproc_rgb2rgb(cv::Mat *dst,
		 cv::Mat *src_rgb)
{
	int w = dst->size().width;
	int h = dst->size().height;

	for (int yi=0; yi<h; yi++) {
		const float *src_rgb_line = (float*)src_rgb->ptr(yi);
		DST_TYPE *dst_line = (DST_TYPE*)dst->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float r = src_rgb_line[xi*3 + 0];
			float g = src_rgb_line[xi*3 + 1];
			float b = src_rgb_line[xi*3 + 2];

			r = clipf(0.0f, r * dst_max, dst_max);
			g = clipf(0.0f, g * dst_max, dst_max);
			b = clipf(0.0f, b * dst_max, dst_max);

			dst_line[xi*3 + ridx] = (DST_TYPE)r;
			dst_line[xi*3 + 1] = (DST_TYPE)g;
			dst_line[xi*3 + bidx] = (DST_TYPE)b;
		}
	}
}
示例#4
0
static void
postproc_rgb2rgba(cv::Mat *dst,
		  cv::Mat *src_rgb,
		  cv::Mat *src_alpha,
		  float bkgd_r,
		  float bkgd_g,
		  float bkgd_b)
{
	int w = dst->size().width;
	int h = dst->size().height;

	for (int yi=0; yi<h; yi++) {
		const float *src_rgb_line = (float*)src_rgb->ptr(yi);
		const float *src_alpha_line = (float*)src_alpha->ptr(yi);
		DST_TYPE *dst_line = (DST_TYPE*)dst->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float r = src_rgb_line[xi*3 + 0];
			float g = src_rgb_line[xi*3 + 1];
			float b = src_rgb_line[xi*3 + 2];
			float a = src_alpha_line[xi];

			/*       data = src*alpha + bkgd*(1-alpha)    */
			/* -src*alpha = bkgd*(1-alpha) - data         */
			/*  src*alpha = data - bkgd*(1-alpha)         */
			/*  src*alpha = data - bkgd + bkgd * alpha    */
			/*        src = (data - bkgd)/alpha+bkgd      */

			r = (r - bkgd_r)/a + bkgd_r;
			g = (g - bkgd_g)/a + bkgd_g;
			b = (b - bkgd_b)/a + bkgd_b;

			r = clipf(0.0f, r * dst_max, dst_max);
			g = clipf(0.0f, g * dst_max, dst_max);
			b = clipf(0.0f, b * dst_max, dst_max);
			a = clipf(0.0f, a * dst_max, dst_max);

			dst_line[xi*4 + ridx] = (DST_TYPE)r;
			dst_line[xi*4 + 1] = (DST_TYPE)g;
			dst_line[xi*4 + bidx] = (DST_TYPE)b;
			dst_line[xi*4 + 3] = (DST_TYPE)a;
		}
	}
}
示例#5
0
static void
postproc_yuv2rgba(cv::Mat *dst,
		  cv::Mat *src_yuv,
		  cv::Mat *src_alpha,
		  float bkgd_r,
		  float bkgd_g,
		  float bkgd_b)
{
	int w = dst->size().width;
	int h = dst->size().height;

	for (int yi=0; yi<h; yi++) {
		const float *src_yuv_line = (float*)src_yuv->ptr(yi);
		const float *src_alpha_line = (float*)src_alpha->ptr(yi);
		DST_TYPE *dst_line = (DST_TYPE*)dst->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float a = src_alpha_line[xi];
			float y = src_yuv_line[xi*3 + 0];
			float cr = src_yuv_line[xi*3 + 1];
			float cb = src_yuv_line[xi*3 + 2];
			float C0 = 2.032f, C1 = -0.395f, C2 = -0.581f, C3 = 1.140f;

			float b = y + (cb-0.5f)*C3;
			float g = y + (cb-0.5f)*C2 + (cr-0.5f)*C1;
			float r = y + (cr-0.5f)*C0;

			r = (r - bkgd_r)/a + bkgd_r;
			g = (g - bkgd_g)/a + bkgd_g;
			b = (b - bkgd_b)/a + bkgd_b;

			r = clipf(0.0f, r * dst_max, dst_max);
			g = clipf(0.0f, g * dst_max, dst_max);
			b = clipf(0.0f, b * dst_max, dst_max);
			a = clipf(0.0f, a * dst_max, dst_max);

			dst_line[xi*4 + ridx] = (DST_TYPE)r;
			dst_line[xi*4 + 1] = (DST_TYPE)g;
			dst_line[xi*4 + bidx] = (DST_TYPE)b;
			dst_line[xi*4 + 3] = (DST_TYPE)a;
		}
	}
}
示例#6
0
void sound_SetMusicVolume(float volume)
{
	// Keep volume in the range of 0.0 - 1.0
	music_volume = clipf(volume, 0.0f, 1.0f);

	// Change the volume of the current stream as well (if any)
	if (cdStream)
	{
		sound_SetStreamVolume(cdStream, music_volume);
	}
}
示例#7
0
static void
preproc_rgba2yuv(cv::Mat *dst_yuv,
		 cv::Mat *dst_alpha,
		 cv::Mat *src,
		 float bkgd_r,
		 float bkgd_g,
		 float bkgd_b)
{
	int w = src->size().width;
	int h = src->size().height;

	float div = 1.0f / src_max;
	float alpha_coef = 1.0f / src_max;

	for (int yi=0; yi<h; yi++) {
		const SRC_TYPE *src_line = (SRC_TYPE*)src->ptr(yi);
		const SRC_TYPE *src_line0 = NULL, *src_line2 = NULL;

		if (yi != 0) {
			src_line0 = (SRC_TYPE*)src->ptr(yi-1);
		}

		if (yi != h-1) {
			src_line2 = (SRC_TYPE*)src->ptr(yi+1);
		}

		float *dst_yuv_line = (float*)dst_yuv->ptr(yi);
		float *dst_alpha_line = (float*)dst_alpha->ptr(yi);

		for (int xi=0; xi<w; xi++) {
			float r = src_line[xi*4 + ridx] * div;
			float g = src_line[xi*4 + 1] * div;
			float b = src_line[xi*4 + bidx] * div;
			SRC_TYPE a = src_line[xi*4 + 3];
			if (a == 0) {
				r = bkgd_r;
				g = bkgd_g;
				b = bkgd_b;

#if 0
				if (yi == 0 || yi == h-1 || xi == 0 || xi == w-1) {
					/* xx */
					r = bkgd_r;
					g = bkgd_g;
					b = bkgd_b;
				} else {
					/* set nearest non-transparental color */
					SRC_TYPE near_a;
					bool set = false;

					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line0, xi-1);
					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line0, xi);
					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line0, xi+1);

					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line,  xi-1);
					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line,  xi+1);

					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line2, xi-1);
					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line2, xi);
					if (!set) set = set_nearest_nontransparent<SRC_TYPE,ridx,bidx>(&r, &g, &b, src_line2, xi+1);

					if (set) {
						r *= div;
						g *= div;
						b *= div;
					} else {
						r = bkgd_r;
						g = bkgd_g;
						b = bkgd_b;
					}
				}
#endif

			} else {
				SRC_TYPE ra = src_max - a;
				r = r * (a * alpha_coef) + bkgd_r * (ra * alpha_coef);
				g = g * (a * alpha_coef) + bkgd_g * (ra * alpha_coef);
				b = b * (a * alpha_coef) + bkgd_b * (ra * alpha_coef);
			}
			float Y = clipf(0.0f, b*0.114f + g*0.587f + r*0.299f, 1.0f);
			float U = clipf(0.0f, (b-Y) * 0.492f + 0.5f,          1.0f);
			float V = clipf(0.0f, (r-Y) * 0.877f + 0.5f,          1.0f);

			dst_yuv_line[xi*3 + 0] = Y;
			dst_yuv_line[xi*3 + 1] = U;
			dst_yuv_line[xi*3 + 2] = V;
			dst_alpha_line[xi] = a * div;
		}
	}
}