mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
videoscale: Implement 4-tap scaling for YUY2 and YVYU
This commit is contained in:
parent
2045a89350
commit
435e9f8b38
2 changed files with 130 additions and 0 deletions
|
@ -453,3 +453,126 @@ vs_image_scale_4tap_RGB (const VSImage * dest, const VSImage * src,
|
|||
yacc += y_increment;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
vs_scanline_resample_4tap_YUYV (uint8_t * dest, uint8_t * src,
|
||||
int n, int src_width, int *xacc, int increment)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int acc;
|
||||
int x;
|
||||
int y;
|
||||
int off;
|
||||
|
||||
acc = *xacc;
|
||||
for (i = 0; i < n; i++) {
|
||||
j = acc >> 16;
|
||||
x = (acc & 0xffff) >> 8;
|
||||
|
||||
for (off = 0; off < 4; off++) {
|
||||
if (j - 1 >= 0 && j + 2 < src_width) {
|
||||
y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 4 + off, 0)];
|
||||
y += vs_4tap_taps[x][1] * src[j * 4 + off];
|
||||
y += vs_4tap_taps[x][2] * src[(j + 1) * 4 + off];
|
||||
y += vs_4tap_taps[x][3] * src[(j + 2) * 4 + off];
|
||||
} else {
|
||||
y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 4 + off, 0,
|
||||
4 * (src_width - 1) + off)];
|
||||
y += vs_4tap_taps[x][1] * src[CLAMP (j * 4 + off, 0,
|
||||
4 * (src_width - 1) + off)];
|
||||
y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 4 + off, 0,
|
||||
4 * (src_width - 1) + off)];
|
||||
y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 4 + off, 0,
|
||||
4 * (src_width - 1) + off)];
|
||||
}
|
||||
y += (1 << (SHIFT - 1));
|
||||
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
|
||||
}
|
||||
acc += increment;
|
||||
}
|
||||
*xacc = acc;
|
||||
}
|
||||
|
||||
void
|
||||
vs_scanline_merge_4tap_YUYV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
|
||||
uint8_t * src3, uint8_t * src4, int n, int acc)
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
int off;
|
||||
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; i++) {
|
||||
for (off = 0; off < 4; off++) {
|
||||
y = a * src1[i * 4 + off];
|
||||
y += b * src2[i * 4 + off];
|
||||
y += c * src3[i * 4 + off];
|
||||
y += d * src4[i * 4 + off];
|
||||
y += (1 << (SHIFT - 1));
|
||||
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
vs_image_scale_4tap_YUYV (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;
|
||||
for (i = 0; i < 4; i++) {
|
||||
xacc = 0;
|
||||
vs_scanline_resample_4tap_YUYV (tmpbuf + i * dest->stride,
|
||||
src->pixels + i * src->stride, dest->stride / 4, src->stride / 4,
|
||||
&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_YUYV (tmpbuf + ((k + 3) & 3) * dest->stride,
|
||||
src->pixels + (k + 3) * src->stride,
|
||||
dest->stride / 4, src->stride / 4, &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_YUYV (dest->pixels + i * dest->stride,
|
||||
t0, t1, t2, t3, dest->stride / 4, yacc & 0xffff);
|
||||
|
||||
yacc += y_increment;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,5 +54,12 @@ void vs_scanline_merge_4tap_RGB (uint8_t *dest, uint8_t *src1, uint8_t *src2,
|
|||
void vs_image_scale_4tap_RGB (const VSImage * dest, const VSImage * src,
|
||||
uint8_t * tmpbuf);
|
||||
|
||||
void vs_scanline_resample_4tap_YUYV (uint8_t *dest, uint8_t *src,
|
||||
int n, int src_width, int *xacc, int increment);
|
||||
void vs_scanline_merge_4tap_YUYV (uint8_t *dest, uint8_t *src1, uint8_t *src2,
|
||||
uint8_t *src3, uint8_t *src4, int n, int acc);
|
||||
void vs_image_scale_4tap_YUYV (const VSImage * dest, const VSImage * src,
|
||||
uint8_t * tmpbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue