rename filters, document them
This commit is contained in:
parent
da2aa8f6b7
commit
29b36b3dea
@ -135,7 +135,7 @@
|
|||||||
and modify this file as you see fit.
|
and modify this file as you see fit.
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
Don't decode all of the image data when only processing a subtile
|
Don't decode all of the image data when only processing a partial tile
|
||||||
Installable filters?
|
Installable filters?
|
||||||
Resize that respects alpha test coverage
|
Resize that respects alpha test coverage
|
||||||
(Reference code: FloatImage::alphaTestCoverage and FloatImage::scaleAlphaToCoverage:
|
(Reference code: FloatImage::alphaTestCoverage and FloatImage::scaleAlphaToCoverage:
|
||||||
@ -247,11 +247,11 @@ STBIRDEF int stbir_resize_uint8_srgb_edgemode(const unsigned char *input_pixels
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
STBIR_FILTER_DEFAULT = 0, // use same filter type that easy-to-use API chooses
|
STBIR_FILTER_DEFAULT = 0, // use same filter type that easy-to-use API chooses
|
||||||
STBIR_FILTER_BOX = 1, // Is actually a trapezoid. See https://developer.nvidia.com/content/non-power-two-mipmapping
|
STBIR_FILTER_BOX = 1, // Actually a trapezoid. See https://developer.nvidia.com/content/non-power-two-mipmapping
|
||||||
STBIR_FILTER_BILINEAR = 2,
|
STBIR_FILTER_TRIANGLE = 2, // On upsampling, produces same results as bilinear texture filtering
|
||||||
STBIR_FILTER_BICUBIC = 3, // A cubic b spline
|
STBIR_FILTER_CUBIC = 3, // A cubic b-spline: why this one ????????????
|
||||||
STBIR_FILTER_CATMULLROM = 4,
|
STBIR_FILTER_CATMULLROM = 4, // interpolating cubic spline
|
||||||
STBIR_FILTER_MITCHELL = 5,
|
STBIR_FILTER_MITCHELL = 5, // Mitchell-Netrevalli filter with B=1/3, C=1/3
|
||||||
} stbir_filter;
|
} stbir_filter;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@ -651,7 +651,7 @@ static float stbir__support_trapezoid(float scale)
|
|||||||
return 0.5f + scale / 2;
|
return 0.5f + scale / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float stbir__filter_bilinear(float x, float s)
|
static float stbir__filter_triangle(float x, float s)
|
||||||
{
|
{
|
||||||
STBIR__UNUSED_PARAM(s);
|
STBIR__UNUSED_PARAM(s);
|
||||||
|
|
||||||
@ -663,7 +663,7 @@ static float stbir__filter_bilinear(float x, float s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float stbir__filter_bicubic(float x, float s)
|
static float stbir__filter_cubic(float x, float s)
|
||||||
{
|
{
|
||||||
STBIR__UNUSED_PARAM(s);
|
STBIR__UNUSED_PARAM(s);
|
||||||
|
|
||||||
@ -726,8 +726,8 @@ static float stbir__support_two(float s)
|
|||||||
static stbir__filter_info stbir__filter_info_table[] = {
|
static stbir__filter_info stbir__filter_info_table[] = {
|
||||||
{ NULL, stbir__support_zero },
|
{ NULL, stbir__support_zero },
|
||||||
{ stbir__filter_trapezoid, stbir__support_trapezoid },
|
{ stbir__filter_trapezoid, stbir__support_trapezoid },
|
||||||
{ stbir__filter_bilinear, stbir__support_one },
|
{ stbir__filter_triangle, stbir__support_one },
|
||||||
{ stbir__filter_bicubic, stbir__support_two },
|
{ stbir__filter_cubic, stbir__support_two },
|
||||||
{ stbir__filter_catmullrom, stbir__support_two },
|
{ stbir__filter_catmullrom, stbir__support_two },
|
||||||
{ stbir__filter_mitchell, stbir__support_two },
|
{ stbir__filter_mitchell, stbir__support_two },
|
||||||
};
|
};
|
||||||
|
@ -584,7 +584,7 @@ void test_subpixel_4()
|
|||||||
|
|
||||||
unsigned char output[8 * 8];
|
unsigned char output[8 * 8];
|
||||||
|
|
||||||
stbir_resize_region(image, 8, 8, 0, output, 8, 8, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BILINEAR, STBIR_FILTER_BILINEAR, STBIR_COLORSPACE_LINEAR, &g_context, 0, 0, 1, 1);
|
stbir_resize_region(image, 8, 8, 0, output, 8, 8, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, &g_context, 0, 0, 1, 1);
|
||||||
STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0);
|
STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,26 +672,26 @@ void test_filters(void)
|
|||||||
image88_int[j][i] = value;
|
image88_int[j][i] = value;
|
||||||
|
|
||||||
verify_filter_normalized(STBIR_FILTER_BOX, 8, value);
|
verify_filter_normalized(STBIR_FILTER_BOX, 8, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BILINEAR, 8, value);
|
verify_filter_normalized(STBIR_FILTER_TRIANGLE, 8, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BICUBIC, 8, value);
|
verify_filter_normalized(STBIR_FILTER_CUBIC, 8, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 8, value);
|
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 8, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_MITCHELL, 8, value);
|
verify_filter_normalized(STBIR_FILTER_MITCHELL, 8, value);
|
||||||
|
|
||||||
verify_filter_normalized(STBIR_FILTER_BOX, 4, value);
|
verify_filter_normalized(STBIR_FILTER_BOX, 4, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BILINEAR, 4, value);
|
verify_filter_normalized(STBIR_FILTER_TRIANGLE, 4, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BICUBIC, 4, value);
|
verify_filter_normalized(STBIR_FILTER_CUBIC, 4, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 4, value);
|
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 4, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_MITCHELL, 4, value);
|
verify_filter_normalized(STBIR_FILTER_MITCHELL, 4, value);
|
||||||
|
|
||||||
verify_filter_normalized(STBIR_FILTER_BOX, 2, value);
|
verify_filter_normalized(STBIR_FILTER_BOX, 2, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BILINEAR, 2, value);
|
verify_filter_normalized(STBIR_FILTER_TRIANGLE, 2, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BICUBIC, 2, value);
|
verify_filter_normalized(STBIR_FILTER_CUBIC, 2, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 2, value);
|
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 2, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_MITCHELL, 2, value);
|
verify_filter_normalized(STBIR_FILTER_MITCHELL, 2, value);
|
||||||
|
|
||||||
verify_filter_normalized(STBIR_FILTER_BOX, 1, value);
|
verify_filter_normalized(STBIR_FILTER_BOX, 1, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BILINEAR, 1, value);
|
verify_filter_normalized(STBIR_FILTER_TRIANGLE, 1, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_BICUBIC, 1, value);
|
verify_filter_normalized(STBIR_FILTER_CUBIC, 1, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 1, value);
|
verify_filter_normalized(STBIR_FILTER_CATMULLROM, 1, value);
|
||||||
verify_filter_normalized(STBIR_FILTER_MITCHELL, 1, value);
|
verify_filter_normalized(STBIR_FILTER_MITCHELL, 1, value);
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ void test_filters(void)
|
|||||||
for (j = 0; j < 100 * 100; ++j)
|
for (j = 0; j < 100 * 100; ++j)
|
||||||
input[j] = v;
|
input[j] = v;
|
||||||
|
|
||||||
stbir_resize(input, 100, 100, 0, output, 11, 11, 0, STBIR_TYPE_UINT32, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BILINEAR, STBIR_FILTER_BILINEAR, STBIR_COLORSPACE_LINEAR, NULL);
|
stbir_resize(input, 100, 100, 0, output, 11, 11, 0, STBIR_TYPE_UINT32, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, NULL);
|
||||||
|
|
||||||
for (j = 0; j < 11 * 11; ++j)
|
for (j = 0; j < 11 * 11; ++j)
|
||||||
STBIR_ASSERT(v == output[j]);
|
STBIR_ASSERT(v == output[j]);
|
||||||
@ -821,8 +821,8 @@ void test_suite(int argc, char **argv)
|
|||||||
for (o = -5; o <= 5; ++o) {
|
for (o = -5; o <= 5; ++o) {
|
||||||
sums[0] += stbir__filter_mitchell(x + o, 1);
|
sums[0] += stbir__filter_mitchell(x + o, 1);
|
||||||
sums[1] += stbir__filter_catmullrom(x + o, 1);
|
sums[1] += stbir__filter_catmullrom(x + o, 1);
|
||||||
sums[2] += stbir__filter_bicubic(x + o, 1);
|
sums[2] += stbir__filter_cubic(x + o, 1);
|
||||||
sums[3] += stbir__filter_bilinear(x + o, 1);
|
sums[3] += stbir__filter_triangle(x + o, 1);
|
||||||
sums[4] += stbir__filter_trapezoid(x + o, 0.5f);
|
sums[4] += stbir__filter_trapezoid(x + o, 0.5f);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 5; ++i)
|
for (i = 0; i < 5; ++i)
|
||||||
@ -837,9 +837,9 @@ void test_suite(int argc, char **argv)
|
|||||||
for (o = -5; o <= 5; o += y) {
|
for (o = -5; o <= 5; o += y) {
|
||||||
sums[0] += y * stbir__filter_mitchell(x + o, 1);
|
sums[0] += y * stbir__filter_mitchell(x + o, 1);
|
||||||
sums[1] += y * stbir__filter_catmullrom(x + o, 1);
|
sums[1] += y * stbir__filter_catmullrom(x + o, 1);
|
||||||
sums[2] += y * stbir__filter_bicubic(x + o, 1);
|
sums[2] += y * stbir__filter_cubic(x + o, 1);
|
||||||
sums[4] += y * stbir__filter_trapezoid(x + o, 0.5f);
|
sums[4] += y * stbir__filter_trapezoid(x + o, 0.5f);
|
||||||
sums[3] += y * stbir__filter_bilinear(x + o, 1);
|
sums[3] += y * stbir__filter_triangle(x + o, 1);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i)
|
||||||
STBIR_ASSERT(sums[i] >= 1.0 - 0.0170 && sums[i] <= 1.0 + 0.0170);
|
STBIR_ASSERT(sums[i] >= 1.0 - 0.0170 && sums[i] <= 1.0 + 0.0170);
|
||||||
@ -916,14 +916,14 @@ void test_suite(int argc, char **argv)
|
|||||||
|
|
||||||
// filter tests
|
// filter tests
|
||||||
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_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_TRIANGLE , 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_CUBIC , 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_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_BOX , STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB, "test-output/barbara-downsample-nearest.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_TRIANGLE , 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_CUBIC , 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_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");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user