Add edge reflect mode.

This commit is contained in:
Jorge Rodriguez 2014-07-26 19:11:02 -07:00
parent 6cd81d4dd5
commit 8723567439

View File

@ -37,6 +37,7 @@ typedef enum
typedef enum typedef enum
{ {
STBR_EDGE_CLAMP = 1, STBR_EDGE_CLAMP = 1,
STBR_EDGE_REFLECT = 2,
} stbr_edge; } stbr_edge;
typedef enum typedef enum
@ -347,17 +348,38 @@ stbr_inline static float* stbr__get_coefficient(stbr__info* stbr_info, int n, in
stbr_inline static int stbr__edge_wrap(stbr_edge edge, int n, int max) stbr_inline static int stbr__edge_wrap(stbr_edge edge, int n, int max)
{ {
STBR_UNIMPLEMENTED(edge != STBR_EDGE_CLAMP);
switch (edge) switch (edge)
{ {
default:
case STBR_EDGE_CLAMP: case STBR_EDGE_CLAMP:
if (n < 0) if (n < 0)
return 0; return 0;
if (n >= max) if (n >= max)
return max - 1; return max - 1;
return n; return n;
case STBR_EDGE_REFLECT:
{
if (n < 0)
{
if (n < max)
return -n;
else
return max - 1;
}
if (n >= max)
{
int max2 = max * 2;
if (n < max2)
return 0;
else
return max2 - n - 1;
}
return n;
}
default:
STBR_UNIMPLEMENTED("Unimplemented edge type");
return 0;
} }
} }