diff --git a/gst/videoscale/vs_4tap.c b/gst/videoscale/vs_4tap.c index 931aeec594..463d57a24a 100644 --- a/gst/videoscale/vs_4tap.c +++ b/gst/videoscale/vs_4tap.c @@ -207,3 +207,126 @@ vs_image_scale_4tap_Y (const VSImage * dest, const VSImage * src, yacc += y_increment; } } + +void +vs_scanline_resample_4tap_RGBA (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_RGBA (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_RGBA (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_RGBA (tmpbuf + i * dest->stride, + src->pixels + i * 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_RGBA (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_RGBA (dest->pixels + i * dest->stride, + t0, t1, t2, t3, dest->width, yacc & 0xffff); + + yacc += y_increment; + } +} diff --git a/gst/videoscale/vs_4tap.h b/gst/videoscale/vs_4tap.h index aae3850eb7..266f71934e 100644 --- a/gst/videoscale/vs_4tap.h +++ b/gst/videoscale/vs_4tap.h @@ -40,5 +40,12 @@ void vs_scanline_merge_4tap_Y (uint8_t *dest, uint8_t *src1, uint8_t *src2, void vs_image_scale_4tap_Y (const VSImage * dest, const VSImage * src, uint8_t * tmpbuf); +void vs_scanline_resample_4tap_RGBA (uint8_t *dest, uint8_t *src, + int n, int src_width, int *xacc, int increment); +void vs_scanline_merge_4tap_RGBA (uint8_t *dest, uint8_t *src1, uint8_t *src2, + uint8_t *src3, uint8_t *src4, int n, int acc); +void vs_image_scale_4tap_RGBA (const VSImage * dest, const VSImage * src, + uint8_t * tmpbuf); + #endif