videoscale: Rewrite YUYV (and friends) scaling and don't read/write over line ends

Partially fixes bug #577054, there's just one issue left now.
This commit is contained in:
Sebastian Dröge 2009-03-28 16:08:44 +01:00
parent 5545a9704e
commit 9d586e0475
3 changed files with 310 additions and 211 deletions

View file

@ -64,7 +64,8 @@ vs_image_scale_nearest_RGBA (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_RGBA (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_RGBA (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, dest->width, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -105,8 +106,8 @@ vs_image_scale_linear_RGBA (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_RGBA (tmp1, src->pixels, dest->width, &xacc, vs_scanline_resample_linear_RGBA (tmp1, src->pixels, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -120,7 +121,7 @@ vs_image_scale_linear_RGBA (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGBA (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGBA (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -129,8 +130,8 @@ vs_image_scale_linear_RGBA (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGBA (tmp2, vs_scanline_resample_linear_RGBA (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride,
@ -139,8 +140,8 @@ vs_image_scale_linear_RGBA (const VSImage * dest, const VSImage * src,
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGBA (tmp1, vs_scanline_resample_linear_RGBA (tmp1,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride,
@ -148,11 +149,11 @@ vs_image_scale_linear_RGBA (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGBA (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGBA (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGBA (tmp2, vs_scanline_resample_linear_RGBA (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width, &xacc,
x_increment); x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGBA (dest->pixels + i * dest->stride,
@ -194,7 +195,8 @@ vs_image_scale_nearest_RGB (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_RGB (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_RGB (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, dest->width, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -235,8 +237,8 @@ vs_image_scale_linear_RGB (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_RGB (tmp1, src->pixels, dest->width, &xacc, vs_scanline_resample_linear_RGB (tmp1, src->pixels, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -250,7 +252,7 @@ vs_image_scale_linear_RGB (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -259,8 +261,8 @@ vs_image_scale_linear_RGB (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB (tmp2, vs_scanline_resample_linear_RGB (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride,
@ -269,8 +271,8 @@ vs_image_scale_linear_RGB (const VSImage * dest, const VSImage * src,
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB (tmp1, vs_scanline_resample_linear_RGB (tmp1,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride,
@ -278,11 +280,11 @@ vs_image_scale_linear_RGB (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB (tmp2, vs_scanline_resample_linear_RGB (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width, &xacc,
x_increment); x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB (dest->pixels + i * dest->stride,
@ -307,7 +309,6 @@ vs_image_scale_nearest_YUYV (const VSImage * dest, const VSImage * src,
int j; int j;
int x; int x;
int xacc; int xacc;
int n_quads;
if (dest->height == 1) if (dest->height == 1)
y_increment = 0; y_increment = 0;
@ -319,7 +320,6 @@ vs_image_scale_nearest_YUYV (const VSImage * dest, const VSImage * src,
else else
x_increment = ((src->width - 1) << 16) / (dest->width - 1); x_increment = ((src->width - 1) << 16) / (dest->width - 1);
n_quads = ROUND_UP_2 (dest->width) / 2;
acc = 0; acc = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -327,7 +327,8 @@ vs_image_scale_nearest_YUYV (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_YUYV (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_YUYV (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, n_quads, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -348,7 +349,6 @@ vs_image_scale_linear_YUYV (const VSImage * dest, const VSImage * src,
int j; int j;
int x; int x;
int dest_size; int dest_size;
int n_quads;
int xacc; int xacc;
if (dest->height == 1) if (dest->height == 1)
@ -362,7 +362,6 @@ vs_image_scale_linear_YUYV (const VSImage * dest, const VSImage * src,
x_increment = ((src->width - 1) << 16) / (dest->width - 1); x_increment = ((src->width - 1) << 16) / (dest->width - 1);
dest_size = ROUND_UP_4 (dest->width * 2); dest_size = ROUND_UP_4 (dest->width * 2);
n_quads = ROUND_UP_2 (dest->width) / 2;
tmp1 = tmpbuf; tmp1 = tmpbuf;
tmp2 = tmpbuf + dest_size; tmp2 = tmpbuf + dest_size;
@ -370,8 +369,8 @@ vs_image_scale_linear_YUYV (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_YUYV (tmp1, src->pixels, n_quads, &xacc, vs_scanline_resample_linear_YUYV (tmp1, src->pixels, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -385,7 +384,7 @@ vs_image_scale_linear_YUYV (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_YUYV (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_YUYV (tmp1, src->pixels + j * src->stride,
n_quads, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -394,31 +393,34 @@ vs_image_scale_linear_YUYV (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_YUYV (tmp2, vs_scanline_resample_linear_YUYV (tmp2,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride, vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride,
tmp1, tmp2, n_quads, x); tmp1, tmp2, dest->width, x);
} else if (j == y2) { } else if (j == y2) {
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_YUYV (tmp1, vs_scanline_resample_linear_YUYV (tmp1,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride, vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride,
tmp2, tmp1, n_quads, x); tmp2, tmp1, dest->width, x);
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_YUYV (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_YUYV (tmp1, src->pixels + j * src->stride,
n_quads, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_YUYV (tmp2, vs_scanline_resample_linear_YUYV (tmp2,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride, vs_scanline_merge_linear_YUYV (dest->pixels + i * dest->stride,
tmp1, tmp2, n_quads, x); tmp1, tmp2, dest->width, x);
} }
} }
@ -439,7 +441,6 @@ vs_image_scale_nearest_UYVY (const VSImage * dest, const VSImage * src,
int j; int j;
int x; int x;
int xacc; int xacc;
int n_quads;
if (dest->height == 1) if (dest->height == 1)
y_increment = 0; y_increment = 0;
@ -451,7 +452,6 @@ vs_image_scale_nearest_UYVY (const VSImage * dest, const VSImage * src,
else else
x_increment = ((src->width - 1) << 16) / (dest->width - 1); x_increment = ((src->width - 1) << 16) / (dest->width - 1);
n_quads = (dest->width + 1) / 2;
acc = 0; acc = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -459,7 +459,8 @@ vs_image_scale_nearest_UYVY (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_UYVY (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_UYVY (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, n_quads, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -480,7 +481,6 @@ vs_image_scale_linear_UYVY (const VSImage * dest, const VSImage * src,
int j; int j;
int x; int x;
int dest_size; int dest_size;
int n_quads;
int xacc; int xacc;
if (dest->height == 1) if (dest->height == 1)
@ -494,7 +494,6 @@ vs_image_scale_linear_UYVY (const VSImage * dest, const VSImage * src,
x_increment = ((src->width - 1) << 16) / (dest->width - 1); x_increment = ((src->width - 1) << 16) / (dest->width - 1);
dest_size = ROUND_UP_4 (dest->width * 2); dest_size = ROUND_UP_4 (dest->width * 2);
n_quads = ROUND_UP_2 (dest->width) / 2;
tmp1 = tmpbuf; tmp1 = tmpbuf;
tmp2 = tmpbuf + dest_size; tmp2 = tmpbuf + dest_size;
@ -502,8 +501,8 @@ vs_image_scale_linear_UYVY (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_UYVY (tmp1, src->pixels, n_quads, &xacc, vs_scanline_resample_linear_UYVY (tmp1, src->pixels, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -517,7 +516,7 @@ vs_image_scale_linear_UYVY (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_UYVY (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_UYVY (tmp1, src->pixels + j * src->stride,
n_quads, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -526,31 +525,34 @@ vs_image_scale_linear_UYVY (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_UYVY (tmp2, vs_scanline_resample_linear_UYVY (tmp2,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride, vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride,
tmp1, tmp2, n_quads, x); tmp1, tmp2, dest->width, x);
} else if (j == y2) { } else if (j == y2) {
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_UYVY (tmp1, vs_scanline_resample_linear_UYVY (tmp1,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride, vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride,
tmp2, tmp1, n_quads, x); tmp2, tmp1, dest->width, x);
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_UYVY (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_UYVY (tmp1, src->pixels + j * src->stride,
n_quads, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_UYVY (tmp2, vs_scanline_resample_linear_UYVY (tmp2,
src->pixels + (j + 1) * src->stride, n_quads, &xacc, x_increment); src->pixels + (j + 1) * src->stride, src->width, dest->width,
&xacc, x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride, vs_scanline_merge_linear_UYVY (dest->pixels + i * dest->stride,
tmp1, tmp2, n_quads, x); tmp1, tmp2, dest->width, x);
} }
} }
@ -589,7 +591,8 @@ vs_image_scale_nearest_Y (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_Y (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_Y (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, dest->width, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -630,8 +633,8 @@ vs_image_scale_linear_Y (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_Y (tmp1, src->pixels, dest->width, &xacc, vs_scanline_resample_linear_Y (tmp1, src->pixels, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -645,7 +648,7 @@ vs_image_scale_linear_Y (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_Y (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_Y (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -654,8 +657,8 @@ vs_image_scale_linear_Y (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_Y (tmp2, vs_scanline_resample_linear_Y (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride, vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride,
@ -664,8 +667,8 @@ vs_image_scale_linear_Y (const VSImage * dest, const VSImage * src,
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_Y (tmp1, vs_scanline_resample_linear_Y (tmp1,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride, vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride,
@ -673,11 +676,11 @@ vs_image_scale_linear_Y (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_Y (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_Y (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_Y (tmp2, vs_scanline_resample_linear_Y (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width, &xacc,
x_increment); x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride, vs_scanline_merge_linear_Y (dest->pixels + i * dest->stride,
@ -720,7 +723,8 @@ vs_image_scale_nearest_RGB565 (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_RGB565 (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_RGB565 (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, dest->width, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -761,8 +765,8 @@ vs_image_scale_linear_RGB565 (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_RGB565 (tmp1, src->pixels, dest->width, &xacc, vs_scanline_resample_linear_RGB565 (tmp1, src->pixels, src->width,
x_increment); dest->width, &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -776,7 +780,7 @@ vs_image_scale_linear_RGB565 (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB565 (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB565 (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -785,8 +789,8 @@ vs_image_scale_linear_RGB565 (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB565 (tmp2, vs_scanline_resample_linear_RGB565 (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride,
@ -795,8 +799,8 @@ vs_image_scale_linear_RGB565 (const VSImage * dest, const VSImage * src,
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB565 (tmp1, vs_scanline_resample_linear_RGB565 (tmp1,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride,
@ -804,11 +808,11 @@ vs_image_scale_linear_RGB565 (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB565 (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB565 (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB565 (tmp2, vs_scanline_resample_linear_RGB565 (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width, &xacc,
x_increment); x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB565 (dest->pixels + i * dest->stride,
@ -851,7 +855,8 @@ vs_image_scale_nearest_RGB555 (const VSImage * dest, const VSImage * src,
xacc = 0; xacc = 0;
vs_scanline_resample_nearest_RGB555 (dest->pixels + i * dest->stride, vs_scanline_resample_nearest_RGB555 (dest->pixels + i * dest->stride,
src->pixels + j * src->stride, dest->width, &xacc, x_increment); src->pixels + j * src->stride, src->width, dest->width, &xacc,
x_increment);
acc += y_increment; acc += y_increment;
} }
@ -892,8 +897,8 @@ vs_image_scale_linear_RGB555 (const VSImage * dest, const VSImage * src,
acc = 0; acc = 0;
xacc = 0; xacc = 0;
y2 = -1; y2 = -1;
vs_scanline_resample_linear_RGB555 (tmp1, src->pixels, dest->width, &xacc, vs_scanline_resample_linear_RGB555 (tmp1, src->pixels, src->width,
x_increment); dest->width, &xacc, x_increment);
y1 = 0; y1 = 0;
for (i = 0; i < dest->height; i++) { for (i = 0; i < dest->height; i++) {
j = acc >> 16; j = acc >> 16;
@ -907,7 +912,7 @@ vs_image_scale_linear_RGB555 (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB555 (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB555 (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
memcpy (dest->pixels + i * dest->stride, tmp1, dest_size); memcpy (dest->pixels + i * dest->stride, tmp1, dest_size);
} }
@ -916,8 +921,8 @@ vs_image_scale_linear_RGB555 (const VSImage * dest, const VSImage * src,
if (j + 1 != y2) { if (j + 1 != y2) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB555 (tmp2, vs_scanline_resample_linear_RGB555 (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y2 = j + 1; y2 = j + 1;
} }
vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride,
@ -926,8 +931,8 @@ vs_image_scale_linear_RGB555 (const VSImage * dest, const VSImage * src,
if (j + 1 != y1) { if (j + 1 != y1) {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB555 (tmp1, vs_scanline_resample_linear_RGB555 (tmp1,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width,
x_increment); &xacc, x_increment);
y1 = j + 1; y1 = j + 1;
} }
vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride,
@ -935,11 +940,11 @@ vs_image_scale_linear_RGB555 (const VSImage * dest, const VSImage * src,
} else { } else {
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB555 (tmp1, src->pixels + j * src->stride, vs_scanline_resample_linear_RGB555 (tmp1, src->pixels + j * src->stride,
dest->width, &xacc, x_increment); src->width, dest->width, &xacc, x_increment);
y1 = j; y1 = j;
xacc = 0; xacc = 0;
vs_scanline_resample_linear_RGB555 (tmp2, vs_scanline_resample_linear_RGB555 (tmp2,
src->pixels + (j + 1) * src->stride, dest->width, &xacc, src->pixels + (j + 1) * src->stride, src->width, dest->width, &xacc,
x_increment); x_increment);
y2 = (j + 1); y2 = (j + 1);
vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride, vs_scanline_merge_linear_RGB555 (dest->pixels + i * dest->stride,

View file

@ -42,8 +42,8 @@ vs_scanline_downsample_Y (uint8_t * dest, uint8_t * src, int n)
} }
void void
vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
@ -53,7 +53,7 @@ vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i] = (x < 32768) ? src[j] : src[j + 1]; dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
acc += increment; acc += increment;
} }
@ -62,15 +62,24 @@ vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int n,
} }
void void
vs_scanline_resample_linear_Y (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_linear_Y (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
uint32_t vals[2]; uint32_t vals[2];
vals[0] = *accumulator; vals[0] = *accumulator;
vals[1] = increment; vals[1] = increment;
if (src_width % 2 == 0) {
oil_resample_linear_u8 (dest, src, n, vals); oil_resample_linear_u8 (dest, src, n, vals);
} else if (src_width > 1) {
if (n > 1)
oil_resample_linear_u8 (dest, src, n - 1, vals);
dest[n - 1] = src[vals[0] >> 16];
vals[0] += increment;
} else {
oil_splat_u8 (dest, 1, &src[0], n);
}
*accumulator = vals[0]; *accumulator = vals[0];
} }
@ -101,8 +110,8 @@ vs_scanline_downsample_RGBA (uint8_t * dest, uint8_t * src, int n)
} }
void void
vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
@ -112,10 +121,18 @@ vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (j + 1 < src_width) {
dest[i * 4 + 0] = (x < 32768) ? src[j * 4 + 0] : src[j * 4 + 4]; dest[i * 4 + 0] = (x < 32768) ? src[j * 4 + 0] : src[j * 4 + 4];
dest[i * 4 + 1] = (x < 32768) ? src[j * 4 + 1] : src[j * 4 + 5]; dest[i * 4 + 1] = (x < 32768) ? src[j * 4 + 1] : src[j * 4 + 5];
dest[i * 4 + 2] = (x < 32768) ? src[j * 4 + 2] : src[j * 4 + 6]; dest[i * 4 + 2] = (x < 32768) ? src[j * 4 + 2] : src[j * 4 + 6];
dest[i * 4 + 3] = (x < 32768) ? src[j * 4 + 3] : src[j * 4 + 7]; dest[i * 4 + 3] = (x < 32768) ? src[j * 4 + 3] : src[j * 4 + 7];
} else {
dest[i * 4 + 0] = src[j * 4 + 0];
dest[i * 4 + 1] = src[j * 4 + 1];
dest[i * 4 + 2] = src[j * 4 + 2];
dest[i * 4 + 3] = src[j * 4 + 3];
}
acc += increment; acc += increment;
} }
@ -125,18 +142,25 @@ vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int n,
#include <stdio.h> #include <stdio.h>
void void
vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
if (increment != 0) {
uint32_t vals[2]; uint32_t vals[2];
vals[0] = *accumulator; vals[0] = *accumulator;
vals[1] = increment; vals[1] = increment;
if (src_width % 2 == 0) {
oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n, vals); oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n, vals);
} else if (src_width > 1) {
*accumulator = vals[0]; if (n > 1)
oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n - 1,
vals);
dest[4 * (n - 1) + 0] = src[(vals[0] >> 16) + 0];
dest[4 * (n - 1) + 1] = src[(vals[0] >> 16) + 1];
dest[4 * (n - 1) + 2] = src[(vals[0] >> 16) + 2];
dest[4 * (n - 1) + 3] = src[(vals[0] >> 16) + 3];
vals[0] += increment;
} else { } else {
int i; int i;
@ -145,8 +169,11 @@ vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int n,
dest[4 * i + 1] = src[1]; dest[4 * i + 1] = src[1];
dest[4 * i + 2] = src[2]; dest[4 * i + 2] = src[2];
dest[4 * i + 3] = src[3]; dest[4 * i + 3] = src[3];
vals[0] += increment;
} }
} }
*accumulator = vals[0];
} }
void void
@ -175,8 +202,8 @@ vs_scanline_downsample_RGB (uint8_t * dest, uint8_t * src, int n)
} }
void void
vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
@ -186,9 +213,12 @@ vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i * 3 + 0] = (x < 32768) ? src[j * 3 + 0] : src[j * 3 + 3]; dest[i * 3 + 0] = (x < 32768
dest[i * 3 + 1] = (x < 32768) ? src[j * 3 + 1] : src[j * 3 + 4]; || j + 1 >= src_width) ? src[j * 3 + 0] : src[j * 3 + 3];
dest[i * 3 + 2] = (x < 32768) ? src[j * 3 + 2] : src[j * 3 + 5]; dest[i * 3 + 1] = (x < 32768
|| j + 1 >= src_width) ? src[j * 3 + 1] : src[j * 3 + 4];
dest[i * 3 + 2] = (x < 32768
|| j + 1 >= src_width) ? src[j * 3 + 2] : src[j * 3 + 5];
acc += increment; acc += increment;
} }
@ -197,34 +227,33 @@ vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int n,
} }
void void
vs_scanline_resample_linear_RGB (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_linear_RGB (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
int j; int j;
int x; int x;
if (increment != 0) {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (j + 1 < src_width) {
dest[i * 3 + 0] = dest[i * 3 + 0] =
(src[j * 3 + 0] * (65536 - x) + src[j * 3 + 3] * x) >> 16; (src[j * 3 + 0] * (65536 - x) + src[j * 3 + 3] * x) >> 16;
dest[i * 3 + 1] = dest[i * 3 + 1] =
(src[j * 3 + 1] * (65536 - x) + src[j * 3 + 4] * x) >> 16; (src[j * 3 + 1] * (65536 - x) + src[j * 3 + 4] * x) >> 16;
dest[i * 3 + 2] = dest[i * 3 + 2] =
(src[j * 3 + 2] * (65536 - x) + src[j * 3 + 5] * x) >> 16; (src[j * 3 + 2] * (65536 - x) + src[j * 3 + 5] * x) >> 16;
} else {
dest[i * 3 + 0] = src[j * 3 + 0];
dest[i * 3 + 1] = src[j * 3 + 1];
dest[i * 3 + 2] = src[j * 3 + 2];
}
acc += increment; acc += increment;
} }
} else {
for (i = 0; i < n; i++) {
dest[i * 3 + 0] = src[0];
dest[i * 3 + 1] = src[1];
dest[i * 3 + 2] = src[2];
}
}
*accumulator = acc; *accumulator = acc;
} }
@ -241,7 +270,7 @@ vs_scanline_merge_linear_RGB (uint8_t * dest, uint8_t * src1, uint8_t * src2,
/* YUYV */ /* YUYV */
/* n is the number of bi-pixels */ /* n is the number of pixels */
/* increment is per Y pixel */ /* increment is per Y pixel */
void void
@ -258,64 +287,79 @@ vs_scanline_downsample_YUYV (uint8_t * dest, uint8_t * src, int n)
} }
void void
vs_scanline_resample_nearest_YUYV (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_nearest_YUYV (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
int j; int j;
int x; int x;
int quads = (n + 1) / 2;
for (i = 0; i < n; i++) { for (i = 0; i < quads; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i * 4 + 0] = (x < 32768) ? src[j * 2 + 0] : src[j * 2 + 2]; dest[i * 4 + 0] = (x < 32768
|| j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
j = acc >> 17; j = acc >> 17;
x = acc & 0x1ffff; x = acc & 0x1ffff;
dest[i * 4 + 1] = (x < 65536) ? src[j * 4 + 1] : src[j * 4 + 5]; dest[i * 4 + 1] = (x < 65536
dest[i * 4 + 3] = (x < 65536) ? src[j * 4 + 3] : src[j * 4 + 7]; || 2 * (j + 2) >= src_width) ? src[j * 4 + 1] : src[j * 4 + 5];
if (2 * i + 1 < n && 2 * (j + 1) < src_width)
dest[i * 4 + 3] = (x < 65536
|| 2 * (j + 3) >= src_width) ? src[j * 4 + 3] : src[j * 4 + 7];
acc += increment; acc += increment;
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i * 4 + 2] = (x < 32768) ? src[j * 2 + 0] : src[j * 2 + 2];
if (2 * i + 1 < n && j < src_width) {
dest[i * 4 + 2] = (x < 32768
|| j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
acc += increment; acc += increment;
} }
}
*accumulator = acc; *accumulator = acc;
} }
void void
vs_scanline_resample_linear_YUYV (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_linear_YUYV (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
int j; int j;
int x; int x;
int quads = (n + 1) / 2;
for (i = 0; i < n; i++) { for (i = 0; i < quads; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (increment != 0) if (j + 1 < src_width)
dest[i * 4 + 0] = dest[i * 4 + 0] =
(src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16; (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
else else
dest[i * 4 + 0] = src[0]; dest[i * 4 + 0] = src[j * 2 + 0];
j = acc >> 17; j = acc >> 17;
x = acc & 0x1ffff; x = acc & 0x1ffff;
if (i < n - 1 && increment != 0) { if (2 * (j + 2) < src_width)
dest[i * 4 + 1] = dest[i * 4 + 1] =
(src[j * 4 + 1] * (131072 - x) + src[j * 4 + 5] * x) >> 17; (src[j * 4 + 1] * (131072 - x) + src[j * 4 + 5] * x) >> 17;
else
dest[i * 4 + 1] = src[j * 4 + 1];
if (2 * i + 1 < n && 2 * (j + 1) < src_width) {
if (2 * (j + 3) < src_width)
dest[i * 4 + 3] = dest[i * 4 + 3] =
(src[j * 4 + 3] * (131072 - x) + src[j * 4 + 7] * x) >> 17; (src[j * 4 + 3] * (131072 - x) + src[j * 4 + 7] * x) >> 17;
} else { else
dest[i * 4 + 1] = src[j * 4 + 1];
dest[i * 4 + 3] = src[j * 4 + 3]; dest[i * 4 + 3] = src[j * 4 + 3];
} }
@ -323,14 +367,17 @@ vs_scanline_resample_linear_YUYV (uint8_t * dest, uint8_t * src, int n,
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (increment != 0)
if (2 * i + 1 < n && j < src_width) {
if (j + 1 < src_width)
dest[i * 4 + 2] = dest[i * 4 + 2] =
(src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16; (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
else else
dest[i * 4 + 2] = src[0]; dest[i * 4 + 2] = src[j * 2 + 0];
acc += increment; acc += increment;
} }
}
*accumulator = acc; *accumulator = acc;
} }
@ -340,17 +387,21 @@ vs_scanline_merge_linear_YUYV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
int n, int x) int n, int x)
{ {
int i; int i;
int quads = (n + 1) / 2;
for (i = 0; i < n; i++) { for (i = 0; i < quads; i++) {
dest[i * 4 + 0] = dest[i * 4 + 0] =
(src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16; (src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16;
dest[i * 4 + 1] = dest[i * 4 + 1] =
(src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16; (src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16;
if (2 * i + 1 < n) {
dest[i * 4 + 2] = dest[i * 4 + 2] =
(src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16; (src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16;
dest[i * 4 + 3] = dest[i * 4 + 3] =
(src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16; (src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16;
} }
}
} }
@ -373,64 +424,80 @@ vs_scanline_downsample_UYVY (uint8_t * dest, uint8_t * src, int n)
} }
void void
vs_scanline_resample_nearest_UYVY (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_nearest_UYVY (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
int j; int j;
int x; int x;
int quads = (n + 1) / 2;
for (i = 0; i < n; i++) { for (i = 0; i < quads; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i * 4 + 1] = (x < 32768) ? src[j * 2 + 1] : src[j * 2 + 3];
dest[i * 4 + 1] = (x < 32768
|| j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
j = acc >> 17; j = acc >> 17;
x = acc & 0x1ffff; x = acc & 0x1ffff;
dest[i * 4 + 0] = (x < 65536) ? src[j * 4 + 0] : src[j * 4 + 4];
dest[i * 4 + 2] = (x < 65536) ? src[j * 4 + 2] : src[j * 4 + 6]; dest[i * 4 + 0] = (x < 65536
|| 2 * (j + 2) >= src_width) ? src[j * 4 + 0] : src[j * 4 + 4];
if (2 * i + 1 < n && 2 * (j + 1) < src_width)
dest[i * 4 + 2] = (x < 65536
|| 2 * (j + 3) >= src_width) ? src[j * 4 + 2] : src[j * 4 + 6];
acc += increment; acc += increment;
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i * 4 + 3] = (x < 32768) ? src[j * 2 + 1] : src[j * 2 + 3];
if (2 * i + 1 < n && j < src_width) {
dest[i * 4 + 3] = (x < 32768
|| j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
acc += increment; acc += increment;
} }
}
*accumulator = acc; *accumulator = acc;
} }
void void
vs_scanline_resample_linear_UYVY (uint8_t * dest, uint8_t * src, int n, vs_scanline_resample_linear_UYVY (uint8_t * dest, uint8_t * src, int src_width,
int *accumulator, int increment) int n, int *accumulator, int increment)
{ {
int acc = *accumulator; int acc = *accumulator;
int i; int i;
int j; int j;
int x; int x;
int quads = (n + 1) / 2;
for (i = 0; i < n; i++) { for (i = 0; i < quads; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (increment != 0) if (j + 1 < src_width)
dest[i * 4 + 1] = dest[i * 4 + 1] =
(src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16; (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
else else
dest[i * 4 + 1] = src[1]; dest[i * 4 + 1] = src[j * 2 + 1];
j = acc >> 17; j = acc >> 17;
x = acc & 0x1ffff; x = acc & 0x1ffff;
if (2 * (j + 2) < src_width)
if (i < n - 1 && increment != 0) {
dest[i * 4 + 0] = dest[i * 4 + 0] =
(src[j * 4 + 0] * (131072 - x) + src[j * 4 + 4] * x) >> 17; (src[j * 4 + 0] * (131072 - x) + src[j * 4 + 4] * x) >> 17;
else
dest[i * 4 + 0] = src[j * 4 + 0];
if (i * 2 + 1 < n && 2 * (j + 1) < src_width) {
if (2 * (j + 3) < src_width)
dest[i * 4 + 2] = dest[i * 4 + 2] =
(src[j * 4 + 2] * (131072 - x) + src[j * 4 + 6] * x) >> 17; (src[j * 4 + 2] * (131072 - x) + src[j * 4 + 6] * x) >> 17;
} else { else
dest[i * 4 + 0] = src[j * 4 + 0];
dest[i * 4 + 2] = src[j * 4 + 2]; dest[i * 4 + 2] = src[j * 4 + 2];
} }
@ -438,25 +505,40 @@ vs_scanline_resample_linear_UYVY (uint8_t * dest, uint8_t * src, int n,
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (increment != 0)
if (2 * i + 1 < n && j < src_width) {
if (j + 1 < src_width)
dest[i * 4 + 3] = dest[i * 4 + 3] =
(src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16; (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
else else
dest[i * 4 + 3] = src[1]; dest[i * 4 + 3] = src[j * 2 + 1];
acc += increment; acc += increment;
} }
}
*accumulator = acc; *accumulator = acc;
} }
void void
vs_scanline_merge_linear_UYVY (uint8_t * dest, uint8_t * src1, uint8_t * src2, vs_scanline_merge_linear_UYVY (uint8_t * dest, uint8_t * src1,
int n, int x) uint8_t * src2, int n, int x)
{ {
uint32_t value = x >> 8; int i;
int quads = (n + 1) / 2;
oil_merge_linear_argb ((uint32_t *) dest, (uint32_t *) src1, for (i = 0; i < quads; i++) {
(uint32_t *) src2, &value, n); dest[i * 4 + 0] =
(src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16;
dest[i * 4 + 1] =
(src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16;
if (2 * i + 1 < n) {
dest[i * 4 + 2] =
(src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16;
dest[i * 4 + 3] =
(src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16;
}
}
} }
@ -488,8 +570,8 @@ vs_scanline_downsample_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n)
} }
void void
vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n, vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8,
int *accumulator, int increment) int src_width, int n, int *accumulator, int increment)
{ {
uint16_t *dest = (uint16_t *) dest_u8; uint16_t *dest = (uint16_t *) dest_u8;
uint16_t *src = (uint16_t *) src_u8; uint16_t *src = (uint16_t *) src_u8;
@ -501,7 +583,7 @@ vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i] = (x < 32768) ? src[j] : src[j + 1]; dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
acc += increment; acc += increment;
} }
@ -510,8 +592,8 @@ vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n,
} }
void void
vs_scanline_resample_linear_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n, vs_scanline_resample_linear_RGB565 (uint8_t * dest_u8, uint8_t * src_u8,
int *accumulator, int increment) int src_width, int n, int *accumulator, int increment)
{ {
uint16_t *dest = (uint16_t *) dest_u8; uint16_t *dest = (uint16_t *) dest_u8;
uint16_t *src = (uint16_t *) src_u8; uint16_t *src = (uint16_t *) src_u8;
@ -523,10 +605,16 @@ vs_scanline_resample_linear_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (j + 1 < src_width) {
dest[i] = RGB565 ( dest[i] = RGB565 (
(RGB565_R (src[j]) * (65536 - x) + RGB565_R (src[j + 1]) * x) >> 16, (RGB565_R (src[j]) * (65536 - x) + RGB565_R (src[j + 1]) * x) >> 16,
(RGB565_G (src[j]) * (65536 - x) + RGB565_G (src[j + 1]) * x) >> 16, (RGB565_G (src[j]) * (65536 - x) + RGB565_G (src[j + 1]) * x) >> 16,
(RGB565_B (src[j]) * (65536 - x) + RGB565_B (src[j + 1]) * x) >> 16); (RGB565_B (src[j]) * (65536 - x) + RGB565_B (src[j + 1]) * x) >> 16);
} else {
dest[i] = RGB565 (RGB565_R (src[j]),
RGB565_G (src[j]), RGB565_B (src[j]));
}
acc += increment; acc += increment;
} }
@ -580,8 +668,8 @@ vs_scanline_downsample_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n)
} }
void void
vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n, vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8,
int *accumulator, int increment) int src_width, int n, int *accumulator, int increment)
{ {
uint16_t *dest = (uint16_t *) dest_u8; uint16_t *dest = (uint16_t *) dest_u8;
uint16_t *src = (uint16_t *) src_u8; uint16_t *src = (uint16_t *) src_u8;
@ -593,7 +681,7 @@ vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
dest[i] = (x < 32768) ? src[j] : src[j + 1]; dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
acc += increment; acc += increment;
} }
@ -602,8 +690,8 @@ vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n,
} }
void void
vs_scanline_resample_linear_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n, vs_scanline_resample_linear_RGB555 (uint8_t * dest_u8, uint8_t * src_u8,
int *accumulator, int increment) int src_width, int n, int *accumulator, int increment)
{ {
uint16_t *dest = (uint16_t *) dest_u8; uint16_t *dest = (uint16_t *) dest_u8;
uint16_t *src = (uint16_t *) src_u8; uint16_t *src = (uint16_t *) src_u8;
@ -615,10 +703,16 @@ vs_scanline_resample_linear_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = acc & 0xffff; x = acc & 0xffff;
if (j + 1 < src_width) {
dest[i] = RGB555 ( dest[i] = RGB555 (
(RGB555_R (src[j]) * (65536 - x) + RGB555_R (src[j + 1]) * x) >> 16, (RGB555_R (src[j]) * (65536 - x) + RGB555_R (src[j + 1]) * x) >> 16,
(RGB555_G (src[j]) * (65536 - x) + RGB555_G (src[j + 1]) * x) >> 16, (RGB555_G (src[j]) * (65536 - x) + RGB555_G (src[j + 1]) * x) >> 16,
(RGB555_B (src[j]) * (65536 - x) + RGB555_B (src[j + 1]) * x) >> 16); (RGB555_B (src[j]) * (65536 - x) + RGB555_B (src[j + 1]) * x) >> 16);
} else {
dest[i] = RGB555 (RGB555_R (src[j]),
RGB555_G (src[j]), RGB555_B (src[j]));
}
acc += increment; acc += increment;
} }

View file

@ -31,38 +31,38 @@
#include <liboil/liboil-stdint.h> #include <liboil/liboil-stdint.h>
void vs_scanline_downsample_Y (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_Y (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_Y (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_Y (uint8_t *dest, uint8_t *src, int n, int src_width, int *accumulator, int increment);
void vs_scanline_resample_linear_Y (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_Y (uint8_t *dest, uint8_t *src, int n, int src_width, int *accumulator, int increment);
void vs_scanline_merge_linear_Y (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_Y (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_RGBA (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_RGBA (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_RGBA (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_RGBA (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_RGBA (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_RGBA (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_RGBA (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_RGBA (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_RGB (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_RGB (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_RGB (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_RGB (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_RGB (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_RGB (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_RGB (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_RGB (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_YUYV (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_YUYV (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_YUYV (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_YUYV (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_YUYV (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_YUYV (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_YUYV (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_YUYV (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_UYVY (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_UYVY (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_UYVY (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_UYVY (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_UYVY (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_UYVY (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_UYVY (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_UYVY (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_RGB565 (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_RGB565 (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_RGB565 (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_RGB565 (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_RGB565 (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_RGB565 (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_RGB565 (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_RGB565 (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);
void vs_scanline_downsample_RGB555 (uint8_t *dest, uint8_t *src, int n); void vs_scanline_downsample_RGB555 (uint8_t *dest, uint8_t *src, int n);
void vs_scanline_resample_nearest_RGB555 (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_nearest_RGB555 (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_resample_linear_RGB555 (uint8_t *dest, uint8_t *src, int n, int *accumulator, int increment); void vs_scanline_resample_linear_RGB555 (uint8_t *dest, uint8_t *src, int src_width, int n, int *accumulator, int increment);
void vs_scanline_merge_linear_RGB555 (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x); void vs_scanline_merge_linear_RGB555 (uint8_t *dest, uint8_t *src1, uint8_t *src2, int n, int x);