mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
videoscale: simplify nearest scaling
Round the accumulator to avoid later checks Remove some bound checks that would never trigger Fix odd width scaling
This commit is contained in:
parent
c8cbcb6f02
commit
d7c02f389f
1 changed files with 46 additions and 95 deletions
|
@ -86,15 +86,12 @@ vs_scanline_resample_nearest_Y16 (uint8_t * dest, uint8_t * src, int src_width,
|
||||||
int n, int *accumulator, int increment)
|
int n, int *accumulator, int increment)
|
||||||
{
|
{
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
uint16_t *d = (uint16_t *) dest, *s = (uint16_t *) src;
|
uint16_t *d = (uint16_t *) dest, *s = (uint16_t *) src;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
d[i] = s[j];
|
||||||
d[i] = (x < 32768 || j + 1 >= src_width) ? s[j] : s[j + 1];
|
|
||||||
|
|
||||||
acc += increment;
|
acc += increment;
|
||||||
}
|
}
|
||||||
|
@ -203,17 +200,13 @@ vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int src_width,
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int x;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
|
||||||
dest[i * 3 + 0] = (x < 32768
|
dest[i * 3 + 0] = src[j * 3 + 0];
|
||||||
|| j + 1 >= src_width) ? src[j * 3 + 0] : src[j * 3 + 3];
|
dest[i * 3 + 1] = src[j * 3 + 1];
|
||||||
dest[i * 3 + 1] = (x < 32768
|
dest[i * 3 + 2] = src[j * 3 + 2];
|
||||||
|| 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;
|
||||||
}
|
}
|
||||||
|
@ -283,34 +276,22 @@ vs_scanline_resample_nearest_YUYV (uint8_t * dest, uint8_t * src, int src_width,
|
||||||
int n, int *accumulator, int increment)
|
int n, int *accumulator, int increment)
|
||||||
{
|
{
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
int quads = (n + 1) / 2;
|
|
||||||
|
|
||||||
for (i = 0; i < quads; i++) {
|
for (i = 0; i < n; i += 2) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
dest[i * 2 + 0] = src[j * 2 + 0];
|
||||||
dest[i * 4 + 0] = (x < 32768
|
|
||||||
|| j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
|
|
||||||
|
|
||||||
j = acc >> 17;
|
j >>= 1;
|
||||||
x = acc & 0x1ffff;
|
dest[i * 2 + 1] = src[j * 4 + 1];
|
||||||
dest[i * 4 + 1] = (x < 65536
|
dest[i * 2 + 3] = src[j * 4 + 3];
|
||||||
|| 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;
|
if (i < n - 1) {
|
||||||
x = acc & 0xffff;
|
j = (acc + 0x8000) >> 16;
|
||||||
|
dest[i * 2 + 2] = src[j * 2 + 0];
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,36 +393,22 @@ vs_scanline_resample_nearest_UYVY (uint8_t * dest, uint8_t * src, int src_width,
|
||||||
int n, int *accumulator, int increment)
|
int n, int *accumulator, int increment)
|
||||||
{
|
{
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
int quads = (n + 1) / 2;
|
|
||||||
|
|
||||||
for (i = 0; i < quads; i++) {
|
for (i = 0; i < n; i += 2) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
dest[i * 2 + 1] = src[j * 2 + 1];
|
||||||
|
|
||||||
dest[i * 4 + 1] = (x < 32768
|
j >>= 1;
|
||||||
|| j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
|
dest[i * 2 + 0] = src[j * 4 + 0];
|
||||||
|
dest[i * 2 + 2] = src[j * 4 + 2];
|
||||||
j = acc >> 17;
|
|
||||||
x = acc & 0x1ffff;
|
|
||||||
|
|
||||||
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;
|
if (i < n - 1) {
|
||||||
x = acc & 0xffff;
|
j = (acc + 0x8000) >> 16;
|
||||||
|
dest[i * 2 + 3] = src[j * 2 + 1];
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,18 +505,13 @@ vs_scanline_resample_nearest_NV12 (uint8_t * dest, uint8_t * src, int src_width,
|
||||||
int n, int *accumulator, int increment)
|
int n, int *accumulator, int increment)
|
||||||
{
|
{
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
|
||||||
|
|
||||||
dest[i * 2 + 0] = (x < 32768
|
dest[i * 2 + 0] = src[j * 2 + 0];
|
||||||
|| j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
|
dest[i * 2 + 1] = src[j * 2 + 1];
|
||||||
dest[i * 2 + 1] = (x < 32768
|
|
||||||
|| j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
|
|
||||||
|
|
||||||
acc += increment;
|
acc += increment;
|
||||||
}
|
}
|
||||||
|
@ -634,14 +596,11 @@ vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8,
|
||||||
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;
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
dest[i] = src[j];
|
||||||
dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
|
|
||||||
|
|
||||||
acc += increment;
|
acc += increment;
|
||||||
}
|
}
|
||||||
|
@ -732,14 +691,12 @@ vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8,
|
||||||
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;
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
|
||||||
dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
|
dest[i] = src[j];
|
||||||
|
|
||||||
acc += increment;
|
acc += increment;
|
||||||
}
|
}
|
||||||
|
@ -802,21 +759,15 @@ vs_scanline_resample_nearest_AYUV64 (uint8_t * dest8, uint8_t * src8,
|
||||||
guint16 *dest = (guint16 *) dest8;
|
guint16 *dest = (guint16 *) dest8;
|
||||||
guint16 *src = (guint16 *) src8;
|
guint16 *src = (guint16 *) src8;
|
||||||
int acc = *accumulator;
|
int acc = *accumulator;
|
||||||
int i;
|
int i, j;
|
||||||
int j;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
j = acc >> 16;
|
j = (acc + 0x8000) >> 16;
|
||||||
x = acc & 0xffff;
|
|
||||||
dest[i * 4 + 0] = (x < 32768
|
dest[i * 4 + 0] = src[j * 4 + 0];
|
||||||
|| j + 1 >= src_width) ? src[j * 4 + 0] : src[j * 4 + 4];
|
dest[i * 4 + 1] = src[j * 4 + 1];
|
||||||
dest[i * 4 + 1] = (x < 32768
|
dest[i * 4 + 2] = src[j * 4 + 2];
|
||||||
|| j + 1 >= src_width) ? src[j * 4 + 1] : src[j * 4 + 5];
|
dest[i * 4 + 3] = src[j * 4 + 3];
|
||||||
dest[i * 4 + 2] = (x < 32768
|
|
||||||
|| j + 1 >= src_width) ? src[j * 4 + 2] : src[j * 4 + 6];
|
|
||||||
dest[i * 4 + 3] = (x < 32768
|
|
||||||
|| j + 1 >= src_width) ? src[j * 4 + 3] : src[j * 4 + 7];
|
|
||||||
|
|
||||||
acc += increment;
|
acc += increment;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue