videoscale: Fix resampling of ARGB scanlines

Previously we would read behind the end of the source lines.
This commit is contained in:
Sebastian Dröge 2010-06-24 12:06:05 +02:00
parent c774cdcff0
commit 153b21fc85

View file

@ -219,66 +219,39 @@ vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int src_width,
*accumulator = acc; *accumulator = acc;
} }
#include <stdio.h> void
vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int src_width,
static void int n, int *accumulator, int increment)
oil_resample_linear_argb (uint32_t * d, uint32_t * s, int n, uint32_t * in)
{ {
uint8_t *src = (uint8_t *) s; int acc = *accumulator;
uint8_t *dest = (uint8_t *) d;
int acc = in[0];
int increment = in[1];
int i; int i;
int j; int j;
int x; int x;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
j = acc >> 16; j = acc >> 16;
x = (acc & 0xffff) >> 8; x = acc & 0xffff;
dest[4 * i + 0] = (src[4 * j + 0] * (256 - x) + src[4 * j + 4] * x) >> 8;
dest[4 * i + 1] = (src[4 * j + 1] * (256 - x) + src[4 * j + 5] * x) >> 8; if (j + 1 < src_width) {
dest[4 * i + 2] = (src[4 * j + 2] * (256 - x) + src[4 * j + 6] * x) >> 8; dest[i * 4 + 0] =
dest[4 * i + 3] = (src[4 * j + 3] * (256 - x) + src[4 * j + 7] * x) >> 8; (src[j * 4 + 0] * (65536 - x) + src[j * 4 + 4] * x) >> 16;
dest[i * 4 + 1] =
(src[j * 4 + 1] * (65536 - x) + src[j * 4 + 5] * x) >> 16;
dest[i * 4 + 2] =
(src[j * 4 + 2] * (65536 - x) + src[j * 4 + 6] * x) >> 16;
dest[i * 4 + 3] =
(src[j * 4 + 3] * (65536 - x) + src[j * 4 + 7] * x) >> 16;
} 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;
} }
in[0] = acc; *accumulator = acc;
}
void
vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int src_width,
int n, int *accumulator, int increment)
{
uint32_t vals[2];
vals[0] = *accumulator;
vals[1] = increment;
if (src_width % 2 == 0) {
oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n, vals);
} else if (src_width > 1) {
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 {
int i;
for (i = 0; i < n; i++) {
dest[4 * i + 0] = src[0];
dest[4 * i + 1] = src[1];
dest[4 * i + 2] = src[2];
dest[4 * i + 3] = src[3];
vals[0] += increment;
}
}
*accumulator = vals[0];
} }
void void