It does nothing now but I want to support edge behavior in the future.

This commit is contained in:
Jorge Rodriguez 2014-07-21 16:14:32 -07:00
parent c27c5b6fbe
commit 06b7b00696
2 changed files with 9 additions and 4 deletions

View File

@ -18,7 +18,7 @@ Initial implementation by Jorge L Rodriguez
#define STBR_INCLUDE_STB_RESAMPLE_H #define STBR_INCLUDE_STB_RESAMPLE_H
// Basic usage: // Basic usage:
// result = stbr_resize(input_data, input_w, input_h, input_components, STBR_FILTER_NEAREST, output_data, output_w, output_h); // result = stbr_resize(input_data, input_w, input_h, input_components, output_data, output_w, output_h, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP);
// //
// input_data is your supplied texels. // input_data is your supplied texels.
// output_data will be the resized texels. It should be of size output_w * output_h * input_components. // output_data will be the resized texels. It should be of size output_w * output_h * input_components.
@ -29,6 +29,11 @@ typedef enum
STBR_FILTER_NEAREST = 1, STBR_FILTER_NEAREST = 1,
} stbr_filter; } stbr_filter;
typedef enum
{
STBR_EDGE_CLAMP = 1,
} stbr_edge;
typedef unsigned char stbr_uc; typedef unsigned char stbr_uc;
@ -47,7 +52,7 @@ extern "C" {
// PRIMARY API - resize an image // PRIMARY API - resize an image
// //
STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, stbr_filter filter, stbr_uc* output_data, int output_w, int output_h); STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, stbr_uc* output_data, int output_w, int output_h, stbr_filter filter, stbr_edge edge);
#ifdef __cplusplus #ifdef __cplusplus
@ -154,7 +159,7 @@ static void stbr__filter_nearest_n(const stbr_uc* input_data, stbr_uc* output_da
typedef void (stbr__filter_fn)(const stbr_uc* input_data, stbr_uc* output_data, size_t input_texel_index, size_t output_texel_index, size_t n); typedef void (stbr__filter_fn)(const stbr_uc* input_data, stbr_uc* output_data, size_t input_texel_index, size_t output_texel_index, size_t n);
STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, stbr_filter filter, stbr_uc* output_data, int output_w, int output_h) STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, stbr_uc* output_data, int output_w, int output_h, stbr_filter filter, stbr_edge edge)
{ {
int x, y; int x, y;
int width_stride_input = input_components * input_w; int width_stride_input = input_components * input_w;

View File

@ -39,7 +39,7 @@ int main(int argc, char** argv)
output_data = malloc(out_w * out_h * n); output_data = malloc(out_w * out_h * n);
stbr_resize(input_data, w, h, n, STBR_FILTER_NEAREST, output_data, out_w, out_h); stbr_resize(input_data, w, h, n, output_data, out_w, out_h, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP);
stbi_write_png("output.png", out_w, out_h, n, output_data, out_w * n); stbi_write_png("output.png", out_w, out_h, n, output_data, out_w * n);