don't encode alpha channel twice when alpha is different colorspace from other channels

This commit is contained in:
Sean Barrett
2014-09-15 07:23:22 -07:00
parent bdbf1e0ef4
commit dd28033b34
2 changed files with 91 additions and 25 deletions

View File

@ -148,25 +148,26 @@ static void performance(int argc, char **argv)
int w, h, count;
int n, i;
int out_w, out_h, srgb=1;
input_pixels = stbi_load(argv[1], &w, &h, &n, 0);
#if 1
input_pixels = stbi_load(argv[1], &w, &h, &n, 4);
n=4;
#if 0
out_w = w/4; out_h = h/4; count=100; // 1
#elif 0
out_w = w*2; out_h = h/4; count=20; // 2 // note this is structured pessimily, would be much faster to downsample vertically first
#elif 0
out_w = w/4; out_h = h*2; count=50; // 3
#elif 0
out_w = w*3; out_h = h*3; count=5; srgb=0; // 4
out_w = w*3; out_h = h*3; count=2; srgb=0; // 4
#else
out_w = w*3; out_h = h*3; count=3; // 5 // this is dominated by linear->sRGB conversion
out_w = w*3; out_h = h*3; count=1; // 5 // this is dominated by linear->sRGB conversion
#endif
output_pixels = (unsigned char*) malloc(out_w*out_h*n);
for (i=0; i < count; ++i)
if (srgb)
stbir_resize_uint8_srgb(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n, -1,0);
stbir_resize_uint8_srgb(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n, 3,0);
else
stbir_resize_uint8(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n);
stbir_resize(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, STBIR_TYPE_UINT8, n, 3, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT, STBIR_COLORSPACE_LINEAR, NULL);
exit(0);
}
@ -228,6 +229,7 @@ void test_format(const char* file, float width_percent, float height_percent, st
int new_h = (int)(h * height_percent);
T* T_data = (T*)malloc(w * h * n * sizeof(T));
memset(T_data, 0, w*h*n*sizeof(T));
convert_image<unsigned char, T>(input_data, T_data, w * h * n);
T* output_data = (T*)malloc(new_w * new_h * n * sizeof(T));
@ -792,13 +794,15 @@ void test_suite(int argc, char **argv)
_mkdir("test-output");
test_32();
if (argc > 1)
barbara = argv[1];
else
barbara = "barbara.png";
test_format<unsigned short>(barbara, 0.5, 2.0, STBIR_TYPE_UINT16, STBIR_COLORSPACE_SRGB);
test_32();
// check what cases we need normalization for
#if 1
{