videoscale: Implement 4-tap scaling for RGB and BGR
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 26 Mar 2009 21:14:53 +0000 (22:14 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 26 Mar 2009 21:14:53 +0000 (22:14 +0100)
gst/videoscale/vs_4tap.c
gst/videoscale/vs_4tap.h

index 463d57a..a55e946 100644 (file)
@@ -330,3 +330,126 @@ vs_image_scale_4tap_RGBA (const VSImage * dest, const VSImage * src,
     yacc += y_increment;
   }
 }
+
+void
+vs_scanline_resample_4tap_RGB (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 < 3; off++) {
+      if (j - 1 >= 0 && j + 2 < src_width) {
+        y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 3 + off, 0)];
+        y += vs_4tap_taps[x][1] * src[j * 3 + off];
+        y += vs_4tap_taps[x][2] * src[(j + 1) * 3 + off];
+        y += vs_4tap_taps[x][3] * src[(j + 2) * 3 + off];
+      } else {
+        y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 3 + off, 0,
+                3 * (src_width - 1) + off)];
+        y += vs_4tap_taps[x][1] * src[CLAMP (j * 3 + off, 0,
+                3 * (src_width - 1) + off)];
+        y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 3 + off, 0,
+                3 * (src_width - 1) + off)];
+        y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 3 + off, 0,
+                3 * (src_width - 1) + off)];
+      }
+      y += (1 << (SHIFT - 1));
+      dest[i * 3 + off] = CLAMP (y >> SHIFT, 0, 255);
+    }
+    acc += increment;
+  }
+  *xacc = acc;
+}
+
+void
+vs_scanline_merge_4tap_RGB (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 < 3; off++) {
+      y = a * src1[i * 3 + off];
+      y += b * src2[i * 3 + off];
+      y += c * src3[i * 3 + off];
+      y += d * src4[i * 3 + off];
+      y += (1 << (SHIFT - 1));
+      dest[i * 3 + off] = CLAMP (y >> SHIFT, 0, 255);
+    }
+  }
+}
+
+void
+vs_image_scale_4tap_RGB (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_RGB (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_RGB (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_RGB (dest->pixels + i * dest->stride,
+        t0, t1, t2, t3, dest->width, yacc & 0xffff);
+
+    yacc += y_increment;
+  }
+}
index 266f719..0127ae0 100644 (file)
@@ -47,5 +47,12 @@ void vs_scanline_merge_4tap_RGBA (uint8_t *dest, uint8_t *src1, uint8_t *src2,
 void vs_image_scale_4tap_RGBA (const VSImage * dest, const VSImage * src,
     uint8_t * tmpbuf);
 
+void vs_scanline_resample_4tap_RGB (uint8_t *dest, uint8_t *src,
+    int n, int src_width, int *xacc, int increment);
+void vs_scanline_merge_4tap_RGB (uint8_t *dest, uint8_t *src1, uint8_t *src2,
+    uint8_t *src3, uint8_t *src4, int n, int acc);
+void vs_image_scale_4tap_RGB (const VSImage * dest, const VSImage * src,
+    uint8_t * tmpbuf);
+
 #endif