rename NEAREST to BOX

write test for BOX
This commit is contained in:
Sean Barrett 2014-09-07 03:19:18 -07:00
parent 41555b5d53
commit cd1fbacbb6
2 changed files with 79 additions and 16 deletions

View File

@ -136,7 +136,7 @@ STBIRDEF int stbir_resize_uint8_srgb_edgemode(const unsigned char *input_pixels
typedef enum
{
STBIR_FILTER_DEFAULT = 0, // use same filter type that easy-to-use API chooses
STBIR_FILTER_NEAREST = 1,
STBIR_FILTER_BOX = 1,
STBIR_FILTER_BILINEAR = 2,
STBIR_FILTER_BICUBIC = 3, // A cubic b spline
STBIR_FILTER_CATMULLROM = 4,
@ -487,9 +487,9 @@ static unsigned char stbir__linear_to_srgb_uchar(float f)
return (unsigned char) v;
}
static float stbir__filter_nearest(float x)
static float stbir__filter_box(float x)
{
if (x <= -0.5f)
if (x < -0.5f)
return 0;
else if (x > 0.5f)
return 0;
@ -545,7 +545,7 @@ static float stbir__filter_mitchell(float x)
static stbir__filter_info stbir__filter_info_table[] = {
{ NULL, 0.0f },
{ stbir__filter_nearest, 0.5f }, // 0.000001?
{ stbir__filter_box , 0.5f },
{ stbir__filter_bilinear, 1.0f },
{ stbir__filter_bicubic, 2.0f },
{ stbir__filter_catmullrom, 2.0f },

View File

@ -377,7 +377,7 @@ void test_subpixel_1()
mtsrand(0);
for (int i = 0; i < sizeof(image); i++)
image[i] = mtrand() % 255;
image[i] = mtrand() & 255;
unsigned char output_data[16 * 16];
@ -407,7 +407,7 @@ void test_subpixel_2()
mtsrand(0);
for (int i = 0; i < sizeof(image); i++)
image[i] = mtrand() % 255;
image[i] = mtrand() & 255;
unsigned char large_image[32 * 32];
@ -444,7 +444,7 @@ void test_subpixel_3()
mtsrand(0);
for (int i = 0; i < sizeof(image); i++)
image[i] = mtrand() % 255;
image[i] = mtrand() & 255;
unsigned char output_data_1[32 * 32];
unsigned char output_data_2[32 * 32];
@ -467,7 +467,7 @@ void test_subpixel_4()
mtsrand(0);
for (int i = 0; i < sizeof(image); i++)
image[i] = mtrand() % 255;
image[i] = mtrand() & 255;
unsigned char output[8 * 8];
@ -475,6 +475,67 @@ void test_subpixel_4()
STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0);
}
static unsigned char image88 [8][8];
static unsigned char output88[8][8];
static unsigned char output44[4][4];
static unsigned char output22[2][2];
static unsigned char output11[1][1];
void resample_88(stbir_filter filter)
{
stbir_resize_uint8_generic(image88[0],8,8,0, output88[0],8,8,0, 1,-1,0, STBIR_EDGE_CLAMP, filter, STBIR_COLORSPACE_LINEAR, NULL);
stbir_resize_uint8_generic(image88[0],8,8,0, output44[0],4,4,0, 1,-1,0, STBIR_EDGE_CLAMP, filter, STBIR_COLORSPACE_LINEAR, NULL);
stbir_resize_uint8_generic(image88[0],8,8,0, output22[0],2,2,0, 1,-1,0, STBIR_EDGE_CLAMP, filter, STBIR_COLORSPACE_LINEAR, NULL);
stbir_resize_uint8_generic(image88[0],8,8,0, output11[0],1,1,0, 1,-1,0, STBIR_EDGE_CLAMP, filter, STBIR_COLORSPACE_LINEAR, NULL);
}
void verify_box(void)
{
int i,j,t;
resample_88(STBIR_FILTER_BOX);
for (i=0; i < sizeof(image88); ++i)
STBIR_ASSERT(image88[0][i] == output88[0][i]);
t = 0;
for (j=0; j < 4; ++j)
for (i=0; i < 4; ++i) {
int n = image88[j*2+0][i*2+0]
+ image88[j*2+0][i*2+1]
+ image88[j*2+1][i*2+0]
+ image88[j*2+1][i*2+1];
STBIR_ASSERT(output44[j][i] == ((n+2)>>2));
t += n;
}
STBIR_ASSERT(output11[j][i] == ((t+32)>>6));
}
void test_filters(void)
{
int i,j;
for (i=0; i < sizeof(image88); ++i)
image88[0][i] = mtrand() & 255;
verify_box();
for (i=0; i < sizeof(image88); ++i)
image88[0][i] = 0;
image88[4][4] = 255;
verify_box();
for (j=0; j < 8; ++j)
for (i=0; i < 8; ++i)
image88[j][i] = (j^i)&1 ? 255 : 0;
verify_box();
for (j=0; j < 8; ++j)
for (i=0; i < 8; ++i)
image88[j][i] = i&2 ? 255 : 0;
verify_box();
}
void test_suite(int argc, char **argv)
{
int i;
@ -496,6 +557,8 @@ void test_suite(int argc, char **argv)
}
#endif
test_filters();
test_subpixel_1();
test_subpixel_2();
test_subpixel_3();
@ -527,17 +590,17 @@ void test_suite(int argc, char **argv)
test_channels(barbara, 2, 2, 4);
// filter tests
resize_image(barbara, 2, 2, STBIR_FILTER_NEAREST, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-nearest.png");
resize_image(barbara, 2, 2, STBIR_FILTER_BILINEAR, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-bilinear.png");
resize_image(barbara, 2, 2, STBIR_FILTER_BICUBIC, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-bicubic.png");
resize_image(barbara, 2, 2, STBIR_FILTER_BOX , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-nearest.png");
resize_image(barbara, 2, 2, STBIR_FILTER_BILINEAR , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-bilinear.png");
resize_image(barbara, 2, 2, STBIR_FILTER_BICUBIC , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-bicubic.png");
resize_image(barbara, 2, 2, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-catmullrom.png");
resize_image(barbara, 2, 2, STBIR_FILTER_MITCHELL, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-mitchell.png");
resize_image(barbara, 2, 2, STBIR_FILTER_MITCHELL , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-upsample-mitchell.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_NEAREST, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-nearest.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_BILINEAR, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-bilinear.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_BICUBIC, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-bicubic.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_BOX , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-nearest.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_BILINEAR , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-bilinear.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_BICUBIC , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-bicubic.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-catmullrom.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_MITCHELL, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-mitchell.png");
resize_image(barbara, 0.5f, 0.5f, STBIR_FILTER_MITCHELL , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-mitchell.png");
for (i = 10; i < 100; i++)
{