Commit e52b9c34 authored by fbarchard@google.com's avatar fbarchard@google.com

make box filter upsampler consider a pixel width of less than 1 to be 1. This…

make box filter upsampler consider a pixel width of less than 1 to be 1.  This makes it behave as a point sampler.
BUG=428
TESTED=set LIBYUV_WIDTH=1900 && out\release\libyuv_unittest.exe
R=tpsiaki@google.com

Review URL: https://webrtc-codereview.appspot.com/49709004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@1372 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 8eb887f5
...@@ -587,6 +587,8 @@ static void ScalePlaneDown38_16(int src_width, int src_height, ...@@ -587,6 +587,8 @@ static void ScalePlaneDown38_16(int src_width, int src_height,
} }
} }
#define MIN1(x) ((x) < 1 ? 1 : (x))
static __inline uint32 SumBox(int iboxwidth, int iboxheight, static __inline uint32 SumBox(int iboxwidth, int iboxheight,
ptrdiff_t src_stride, const uint8* src_ptr) { ptrdiff_t src_stride, const uint8* src_ptr) {
uint32 sum = 0u; uint32 sum = 0u;
...@@ -627,7 +629,7 @@ static void ScalePlaneBoxRow_C(int dst_width, int boxheight, ...@@ -627,7 +629,7 @@ static void ScalePlaneBoxRow_C(int dst_width, int boxheight,
for (i = 0; i < dst_width; ++i) { for (i = 0; i < dst_width; ++i) {
int ix = x >> 16; int ix = x >> 16;
x += dx; x += dx;
boxwidth = (x >> 16) - ix; boxwidth = MIN1((x >> 16) - ix);
*dst_ptr++ = SumBox(boxwidth, boxheight, src_stride, src_ptr + ix) / *dst_ptr++ = SumBox(boxwidth, boxheight, src_stride, src_ptr + ix) /
(boxwidth * boxheight); (boxwidth * boxheight);
} }
...@@ -641,7 +643,7 @@ static void ScalePlaneBoxRow_16_C(int dst_width, int boxheight, ...@@ -641,7 +643,7 @@ static void ScalePlaneBoxRow_16_C(int dst_width, int boxheight,
for (i = 0; i < dst_width; ++i) { for (i = 0; i < dst_width; ++i) {
int ix = x >> 16; int ix = x >> 16;
x += dx; x += dx;
boxwidth = (x >> 16) - ix; boxwidth = MIN1((x >> 16) - ix);
*dst_ptr++ = SumBox_16(boxwidth, boxheight, src_stride, src_ptr + ix) / *dst_ptr++ = SumBox_16(boxwidth, boxheight, src_stride, src_ptr + ix) /
(boxwidth * boxheight); (boxwidth * boxheight);
} }
...@@ -671,15 +673,15 @@ static void ScaleAddCols2_C(int dst_width, int boxheight, int x, int dx, ...@@ -671,15 +673,15 @@ static void ScaleAddCols2_C(int dst_width, int boxheight, int x, int dx,
const uint16* src_ptr, uint8* dst_ptr) { const uint16* src_ptr, uint8* dst_ptr) {
int i; int i;
int scaletbl[2]; int scaletbl[2];
int minboxwidth = (dx >> 16); int minboxwidth = dx >> 16;
int* scaleptr = scaletbl - minboxwidth; int* scaleptr = scaletbl - minboxwidth;
int boxwidth; int boxwidth;
scaletbl[0] = 65536 / (minboxwidth * boxheight); scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight);
scaletbl[1] = 65536 / ((minboxwidth + 1) * boxheight); scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight);
for (i = 0; i < dst_width; ++i) { for (i = 0; i < dst_width; ++i) {
int ix = x >> 16; int ix = x >> 16;
x += dx; x += dx;
boxwidth = (x >> 16) - ix; boxwidth = MIN1((x >> 16) - ix);
*dst_ptr++ = SumPixels(boxwidth, src_ptr + ix) * scaleptr[boxwidth] >> 16; *dst_ptr++ = SumPixels(boxwidth, src_ptr + ix) * scaleptr[boxwidth] >> 16;
} }
} }
...@@ -688,17 +690,17 @@ static void ScaleAddCols2_16_C(int dst_width, int boxheight, int x, int dx, ...@@ -688,17 +690,17 @@ static void ScaleAddCols2_16_C(int dst_width, int boxheight, int x, int dx,
const uint32* src_ptr, uint16* dst_ptr) { const uint32* src_ptr, uint16* dst_ptr) {
int i; int i;
int scaletbl[2]; int scaletbl[2];
int minboxwidth = (dx >> 16); int minboxwidth = dx >> 16;
int* scaleptr = scaletbl - minboxwidth; int* scaleptr = scaletbl - minboxwidth;
int boxwidth; int boxwidth;
scaletbl[0] = 65536 / (minboxwidth * boxheight); scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight);
scaletbl[1] = 65536 / ((minboxwidth + 1) * boxheight); scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight);
for (i = 0; i < dst_width; ++i) { for (i = 0; i < dst_width; ++i) {
int ix = x >> 16; int ix = x >> 16;
x += dx; x += dx;
boxwidth = (x >> 16) - ix; boxwidth = MIN1((x >> 16) - ix);
*dst_ptr++ = SumPixels_16(boxwidth, src_ptr + ix) * *dst_ptr++ =
scaleptr[boxwidth] >> 16; SumPixels_16(boxwidth, src_ptr + ix) * scaleptr[boxwidth] >> 16;
} }
} }
...@@ -714,7 +716,7 @@ static void ScaleAddCols0_C(int dst_width, int boxheight, int x, int, ...@@ -714,7 +716,7 @@ static void ScaleAddCols0_C(int dst_width, int boxheight, int x, int,
static void ScaleAddCols1_C(int dst_width, int boxheight, int x, int dx, static void ScaleAddCols1_C(int dst_width, int boxheight, int x, int dx,
const uint16* src_ptr, uint8* dst_ptr) { const uint16* src_ptr, uint8* dst_ptr) {
int boxwidth = (dx >> 16); int boxwidth = MIN1(dx >> 16);
int scaleval = 65536 / (boxwidth * boxheight); int scaleval = 65536 / (boxwidth * boxheight);
int i; int i;
x >>= 16; x >>= 16;
...@@ -726,7 +728,7 @@ static void ScaleAddCols1_C(int dst_width, int boxheight, int x, int dx, ...@@ -726,7 +728,7 @@ static void ScaleAddCols1_C(int dst_width, int boxheight, int x, int dx,
static void ScaleAddCols1_16_C(int dst_width, int boxheight, int x, int dx, static void ScaleAddCols1_16_C(int dst_width, int boxheight, int x, int dx,
const uint32* src_ptr, uint16* dst_ptr) { const uint32* src_ptr, uint16* dst_ptr) {
int boxwidth = (dx >> 16); int boxwidth = MIN1(dx >> 16);
int scaleval = 65536 / (boxwidth * boxheight); int scaleval = 65536 / (boxwidth * boxheight);
int i; int i;
for (i = 0; i < dst_width; ++i) { for (i = 0; i < dst_width; ++i) {
...@@ -768,7 +770,7 @@ static void ScalePlaneBox(int src_width, int src_height, ...@@ -768,7 +770,7 @@ static void ScalePlaneBox(int src_width, int src_height,
if (y > max_y) { if (y > max_y) {
y = max_y; y = max_y;
} }
boxheight = (y >> 16) - iy; boxheight = MIN1((y >> 16) - iy);
ScalePlaneBoxRow_C(dst_width, boxheight, x, dx, src_stride, src, dst); ScalePlaneBoxRow_C(dst_width, boxheight, x, dx, src_stride, src, dst);
dst += dst_stride; dst += dst_stride;
} }
...@@ -807,7 +809,7 @@ static void ScalePlaneBox(int src_width, int src_height, ...@@ -807,7 +809,7 @@ static void ScalePlaneBox(int src_width, int src_height,
if (y > (src_height << 16)) { if (y > (src_height << 16)) {
y = (src_height << 16); y = (src_height << 16);
} }
boxheight = (y >> 16) - iy; boxheight = MIN1((y >> 16) - iy);
ScaleAddRows(src, src_stride, (uint16*)(row16), src_width, boxheight); ScaleAddRows(src, src_stride, (uint16*)(row16), src_width, boxheight);
ScaleAddCols(dst_width, boxheight, x, dx, (uint16*)(row16), dst_ptr); ScaleAddCols(dst_width, boxheight, x, dx, (uint16*)(row16), dst_ptr);
dst_ptr += dst_stride; dst_ptr += dst_stride;
...@@ -830,8 +832,8 @@ static void ScalePlaneBox_16(int src_width, int src_height, ...@@ -830,8 +832,8 @@ static void ScalePlaneBox_16(int src_width, int src_height,
ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox, ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox,
&x, &y, &dx, &dy); &x, &y, &dx, &dy);
src_width = Abs(src_width); src_width = Abs(src_width);
// TODO(fbarchard): Remove this and make AddRows handle boxheight 1. // TODO(fbarchard): Remove this and make AddRows handle odd width.
if (!IS_ALIGNED(src_width, 16) || dst_height * 2 > src_height) { if (!IS_ALIGNED(src_width, 16)) {
uint16* dst = dst_ptr; uint16* dst = dst_ptr;
int j; int j;
for (j = 0; j < dst_height; ++j) { for (j = 0; j < dst_height; ++j) {
...@@ -842,7 +844,7 @@ static void ScalePlaneBox_16(int src_width, int src_height, ...@@ -842,7 +844,7 @@ static void ScalePlaneBox_16(int src_width, int src_height,
if (y > max_y) { if (y > max_y) {
y = max_y; y = max_y;
} }
boxheight = (y >> 16) - iy; boxheight = MIN1((y >> 16) - iy);
ScalePlaneBoxRow_16_C(dst_width, boxheight, x, dx, src_stride, src, dst); ScalePlaneBoxRow_16_C(dst_width, boxheight, x, dx, src_stride, src, dst);
dst += dst_stride; dst += dst_stride;
} }
...@@ -871,7 +873,7 @@ static void ScalePlaneBox_16(int src_width, int src_height, ...@@ -871,7 +873,7 @@ static void ScalePlaneBox_16(int src_width, int src_height,
if (y > (src_height << 16)) { if (y > (src_height << 16)) {
y = (src_height << 16); y = (src_height << 16);
} }
boxheight = (y >> 16) - iy; boxheight = MIN1((y >> 16) - iy);
ScaleAddRows(src, src_stride, (uint32*)(row32), ScaleAddRows(src, src_stride, (uint32*)(row32),
src_width, boxheight); src_width, boxheight);
ScaleAddCols(dst_width, boxheight, x, dx, (uint32*)(row32), ScaleAddCols(dst_width, boxheight, x, dx, (uint32*)(row32),
......
...@@ -218,8 +218,7 @@ static int ARGBClipTestFilter(int src_width, int src_height, ...@@ -218,8 +218,7 @@ static int ARGBClipTestFilter(int src_width, int src_height,
#define TEST_FACTOR(name, hfactor, vfactor) \ #define TEST_FACTOR(name, hfactor, vfactor) \
TEST_FACTOR1(name, None, hfactor, vfactor, 2) \ TEST_FACTOR1(name, None, hfactor, vfactor, 2) \
TEST_FACTOR1(name, Linear, hfactor, vfactor, 2) \ TEST_FACTOR1(name, Linear, hfactor, vfactor, 2) \
TEST_FACTOR1(name, Bilinear, hfactor, vfactor, 2) \ TEST_FACTOR1(name, Bilinear, hfactor, vfactor, 2)
TEST_FACTOR1(name, Box, hfactor, vfactor, 2)
TEST_FACTOR(2, 1 / 2, 1 / 2) TEST_FACTOR(2, 1 / 2, 1 / 2)
TEST_FACTOR(4, 1 / 4, 1 / 4) TEST_FACTOR(4, 1 / 4, 1 / 4)
...@@ -262,8 +261,7 @@ TEST_FACTOR(3, 1 / 3, 1 / 3) ...@@ -262,8 +261,7 @@ TEST_FACTOR(3, 1 / 3, 1 / 3)
#define TEST_SCALETO(name, width, height) \ #define TEST_SCALETO(name, width, height) \
TEST_SCALETO1(name, width, height, None, 0) \ TEST_SCALETO1(name, width, height, None, 0) \
TEST_SCALETO1(name, width, height, Linear, 3) \ TEST_SCALETO1(name, width, height, Linear, 3) \
TEST_SCALETO1(name, width, height, Bilinear, 3) \ TEST_SCALETO1(name, width, height, Bilinear, 3)
TEST_SCALETO1(name, width, height, Box, 3)
TEST_SCALETO(ARGBScale, 1, 1) TEST_SCALETO(ARGBScale, 1, 1)
TEST_SCALETO(ARGBScale, 320, 240) TEST_SCALETO(ARGBScale, 320, 240)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment