videoscale: Added NV support for 4Tap resize

https://bugzilla.gnome.org/show_bug.cgi?id=736845
This commit is contained in:
Sanjay NM 2014-09-18 15:45:43 +05:30 committed by Sebastian Dröge
parent 2133a98eb1
commit 6babe786f7
3 changed files with 141 additions and 1 deletions

View file

@ -413,7 +413,7 @@ get_formats_filter (GstVideoScaleMethod method)
"ARGB, BGRA, ABGR, AYUV, ARGB64, AYUV64, "
"RGB, BGR, v308, YUY2, YVYU, UYVY, "
"GRAY8, GRAY16_LE, GRAY16_BE, I420, YV12, "
"Y444, Y42B, Y41B, RGB16, RGB15 }");
"Y444, Y42B, Y41B, RGB16, RGB15, NV12, NV21 }");
return gst_static_caps_get (&fourtap_filter);
}
case GST_VIDEO_SCALE_LANCZOS:
@ -1392,6 +1392,10 @@ do_scale (GstVideoFilter * filter, VSImage dest[4], VSImage src[4])
vs_image_scale_linear_Y (&dest[0], &src[0], videoscale->tmp_buf);
vs_image_scale_linear_NV12 (&dest[1], &src[1], videoscale->tmp_buf);
break;
case GST_VIDEO_SCALE_4TAP:
vs_image_scale_4tap_Y (&dest[0], &src[0], videoscale->tmp_buf);
vs_image_scale_4tap_NV12 (&dest[1], &src[1], videoscale->tmp_buf);
break;
default:
goto unknown_mode;
}

View file

@ -86,6 +86,11 @@ static void vs_scanline_resample_4tap_AYUV64 (uint16_t * dest, uint16_t * src,
static void vs_scanline_merge_4tap_AYUV64 (uint16_t * dest, uint16_t * src1,
uint16_t * src2, uint16_t * src3, uint16_t * src4, int n, int acc);
static void vs_scanline_merge_4tap_NV (uint8_t * dest, uint8_t * src1,
uint8_t * src2, uint8_t * src3, uint8_t * src4, int n, int acc);
static void vs_scanline_resample_4tap_NV (uint8_t * dest, uint8_t * src, int n,
int src_width, int *xacc, int increment);
static double
vs_4tap_func (double x)
{
@ -188,6 +193,133 @@ vs_scanline_merge_4tap_Y (uint8_t * dest, uint8_t * src1, uint8_t * src2,
}
static void
vs_scanline_resample_4tap_NV (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int u, v;
int stride = src_width * 2;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
j *= 2;
x = (acc & 0xff00) >> 8;
if (j - 1 >= 0 && j + 2 < src_width) {
u = vs_4tap_taps[x][0] * src[j - 2];
v = vs_4tap_taps[x][0] * src[j - 1];
u += vs_4tap_taps[x][1] * src[j];
v += vs_4tap_taps[x][1] * src[j + 1];
u += vs_4tap_taps[x][2] * src[j + 2];
v += vs_4tap_taps[x][2] * src[j + 3];
u += vs_4tap_taps[x][3] * src[j + 4];
v += vs_4tap_taps[x][3] * src[j + 5];
} else {
u = vs_4tap_taps[x][0] * src[CLAMP (j - 2, 0, stride - 1)];
v = vs_4tap_taps[x][0] * src[CLAMP (j - 1, 0, stride - 1)];
u += vs_4tap_taps[x][1] * src[CLAMP (j, 0, stride - 1)];
v += vs_4tap_taps[x][1] * src[CLAMP (j + 1, 0, stride - 1)];
u += vs_4tap_taps[x][2] * src[CLAMP (j + 2, 0, stride - 1)];
v += vs_4tap_taps[x][2] * src[CLAMP (j + 3, 0, stride - 1)];
u += vs_4tap_taps[x][3] * src[CLAMP (j + 4, 0, stride - 1)];
v += vs_4tap_taps[x][3] * src[CLAMP (j + 5, 0, stride - 1)];
}
u += (1 << (SHIFT - 1));
v += (1 << (SHIFT - 1));
dest[i * 2] = CLAMP (u >> SHIFT, 0, 255);
dest[i * 2 + 1] = CLAMP (v >> SHIFT, 0, 255);
acc += increment;
}
*xacc = acc;
}
static void
vs_scanline_merge_4tap_NV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int val;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < (n * 2); i++) {
val = a * src1[i];
val += b * src2[i];
val += c * src3[i];
val += d * src4[i];
val += (1 << (SHIFT - 1));
dest[i] = CLAMP (val >> SHIFT, 0, 255);
}
}
void
vs_image_scale_4tap_NV12 (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
/* The below loop is to initialize the 4 buffers present in tmpbuf
For scaling there are used in cyclic way, so they need to be
initialized before entering the main loop */
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_NV (tmpbuf + i * dest->stride,
src->pixels + CLAMP (i, 0, src->height - 1) * src->stride, dest->width,
src->width, &xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_NV (tmpbuf + ((k + 3) & 3) * dest->stride,
src->pixels + (k + 3) * src->stride,
dest->width, src->width, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->stride;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->stride;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->stride;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->stride;
vs_scanline_merge_4tap_NV (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->width, yacc & 0xffff);
yacc += y_increment;
}
}
void
vs_image_scale_4tap_Y (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)

View file

@ -36,6 +36,10 @@ G_GNUC_INTERNAL void vs_image_scale_4tap_Y (const VSImage * dest,
const VSImage * src,
uint8_t * tmpbuf);
G_GNUC_INTERNAL void vs_image_scale_4tap_NV12 (const VSImage * dest,
const VSImage * src,
uint8_t * tmpbuf);
G_GNUC_INTERNAL void vs_image_scale_4tap_RGBA (const VSImage * dest,
const VSImage * src,
uint8_t * tmpbuf);