videoscale: Implement 4-tap scaling for UYVY

This commit is contained in:
Sebastian Dröge 2009-03-27 10:47:39 +01:00
parent 435e9f8b38
commit c1653fc5b0
2 changed files with 131 additions and 0 deletions

View file

@ -576,3 +576,126 @@ vs_image_scale_4tap_YUYV (const VSImage * dest, const VSImage * src,
yacc += y_increment;
}
}
void
vs_scanline_resample_4tap_UYVY (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_UYVY (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_UYVY (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_UYVY (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_UYVY (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_UYVY (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->stride / 4, yacc & 0xffff);
yacc += y_increment;
}
}

View file

@ -61,5 +61,13 @@ void vs_scanline_merge_4tap_YUYV (uint8_t *dest, uint8_t *src1, uint8_t *src2,
void vs_image_scale_4tap_YUYV (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf);
void vs_scanline_resample_4tap_UYVY (uint8_t *dest, uint8_t *src,
int n, int src_width, int *xacc, int increment);
void vs_scanline_merge_4tap_UYVY (uint8_t *dest, uint8_t *src1, uint8_t *src2,
uint8_t *src3, uint8_t *src4, int n, int acc);
void vs_image_scale_4tap_UYVY (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf);
#endif