We are going to support SRGB.

This commit is contained in:
Jorge Rodriguez 2014-07-21 19:51:11 -07:00
parent ba861fa493
commit 0155bd3ab6
2 changed files with 10 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, 0, output_data, output_w, output_h, 0, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP); // result = stbr_resize(input_data, input_w, input_h, input_components, 0, output_data, output_w, output_h, 0, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP, STBR_COLORSPACE_SRGB);
// //
// 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 (or output_h * output_stride if you provided a stride.) // output_data will be the resized texels. It should be of size output_w * output_h * input_components (or output_h * output_stride if you provided a stride.)
@ -35,6 +35,12 @@ typedef enum
STBR_EDGE_CLAMP = 1, STBR_EDGE_CLAMP = 1,
} stbr_edge; } stbr_edge;
typedef enum
{
STBR_COLORSPACE_LINEAR = 1,
STBR_COLORSPACE_SRGB = 1,
} stbr_colorspace;
typedef unsigned char stbr_uc; typedef unsigned char stbr_uc;
@ -53,7 +59,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, int input_stride, stbr_uc* output_data, int output_w, int output_h, int output_stride, stbr_filter filter, stbr_edge edge); STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, int input_stride, stbr_uc* output_data, int output_w, int output_h, int output_stride, stbr_filter filter, stbr_edge edge, stbr_colorspace colorspace);
#ifdef __cplusplus #ifdef __cplusplus
@ -160,7 +166,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, int input_stride, stbr_uc* output_data, int output_w, int output_h, int output_stride, stbr_filter filter, stbr_edge edge) STBRDEF int stbr_resize(const stbr_uc* input_data, int input_w, int input_h, int input_components, int input_stride, stbr_uc* output_data, int output_w, int output_h, int output_stride, stbr_filter filter, stbr_edge edge, stbr_colorspace colorspace)
{ {
int x, y; int x, y;
int width_stride_input = input_stride ? input_stride : input_components * input_w; int width_stride_input = input_stride ? input_stride : input_components * input_w;

View File

@ -41,7 +41,7 @@ int main(int argc, char** argv)
output_data = malloc(out_stride * out_h); output_data = malloc(out_stride * out_h);
// Cut out the outside 64 pixels all around to test the stride. // Cut out the outside 64 pixels all around to test the stride.
stbr_resize(input_data + w*64*n + 64*n, w - 128, h - 128, n, w*n, output_data, out_w, out_h, out_stride, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP); stbr_resize(input_data + w*64*n + 64*n, w - 128, h - 128, n, w*n, output_data, out_w, out_h, out_stride, STBR_FILTER_NEAREST, STBR_EDGE_CLAMP, STBR_COLORSPACE_SRGB);
stbi_write_png("output.png", out_w, out_h, n, output_data, out_stride); stbi_write_png("output.png", out_w, out_h, n, output_data, out_stride);