More fixing shorts.

pull/32/head
Jorge Rodriguez 2014-07-30 00:34:25 -07:00
parent 1fcbe0daaf
commit 11897fbf96
2 changed files with 47 additions and 25 deletions

View File

@ -610,9 +610,8 @@ static void stbr__check_downsample_coefficients(stbr__info* stbr_info)
break;
}
STBR_DEBUG_ASSERT(stbr_info->type == STBR_TYPE_UINT8); // Assert below should be 1 + 1/(2^n-1) where n is bits per int.
STBR_DEBUG_ASSERT(total > 0.9f);
STBR_DEBUG_ASSERT(total <= 1.0f + 1.0f / 255);
STBR_DEBUG_ASSERT(total <= 1.0f + 1.0f / (pow(2.0f, 8.0f * stbr__type_size[stbr_info->type]) - 1));
}
}
#endif
@ -958,14 +957,12 @@ static void stbr__resample_vertical_upsample(stbr__info* stbr_info, int n, int i
int ring_buffer_last_scanline = stbr_info->ring_buffer_last_scanline;
int ring_buffer_length = stbr_info->ring_buffer_length_bytes/sizeof(float);
STBR_UNIMPLEMENTED(stbr_info->type != STBR_TYPE_UINT8);
stbr__calculate_coefficients_upsample(stbr_info, in_first_scanline, in_last_scanline, in_center_of_out, vertical_contributors, vertical_coefficients);
int n0 = vertical_contributors->n0;
int n1 = vertical_contributors->n1;
int output_row_index = n * stbr_info->output_stride_bytes;
int output_row_index = n * stbr_info->output_stride_bytes / stbr__type_size[type];
STBR_DEBUG_ASSERT(stbr__use_height_upsampling(stbr_info));
STBR_DEBUG_ASSERT(n0 >= in_first_scanline);

View File

@ -133,6 +133,39 @@ void convert_image(const F* input, T* output, int length)
output[i] = (T)(((float)input[i]) * f);
}
template <typename T>
void test_format(const char* file, float width_percent, float height_percent, stbr_type type, stbr_colorspace colorspace)
{
int w, h, n;
unsigned char* input_data = stbi_load(file, &w, &h, &n, 0);
int new_w = (int)(w * width_percent);
int new_h = (int)(h * height_percent);
T* T_data = (T*)malloc(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));
size_t required = stbr_calculate_memory(w, h, new_w, new_h, n, STBR_FILTER_CATMULLROM);
void* extra_memory = malloc(required);
stbr_resize_arbitrary(T_data, w, h, 0, output_data, new_w, new_h, 0, n, type, STBR_FILTER_CATMULLROM, STBR_EDGE_CLAMP, colorspace, extra_memory, required);
free(extra_memory);
free(T_data);
stbi_image_free(input_data);
char* char_data = (char*)malloc(new_w * new_h * n * sizeof(char));
convert_image<T, char>(output_data, char_data, new_w * new_h * n);
char output[200];
sprintf(output, "test-output/type-%d-%d-%d-%d-%s", type, colorspace, new_w, new_h, file);
stbi_write_png(output, new_w, new_h, n, char_data, 0);
free(char_data);
free(output_data);
}
void test_suite()
{
// sRGB tests
@ -175,28 +208,20 @@ void test_suite()
resize_image("barbara.png", 100 / (float)i, (float)i / 100, STBR_FILTER_CATMULLROM, STBR_EDGE_CLAMP, outname);
}
{
int w, h, n;
unsigned char* input_data = stbi_load("barbara.png", &w, &h, &n, 0);
test_format<unsigned short>("barbara.png", 0.5, 2.0, STBR_TYPE_UINT16, STBR_COLORSPACE_SRGB);
test_format<unsigned short>("barbara.png", 0.5, 2.0, STBR_TYPE_UINT16, STBR_COLORSPACE_LINEAR);
test_format<unsigned short>("barbara.png", 2.0, 0.5, STBR_TYPE_UINT16, STBR_COLORSPACE_SRGB);
test_format<unsigned short>("barbara.png", 2.0, 0.5, STBR_TYPE_UINT16, STBR_COLORSPACE_LINEAR);
unsigned short* short_data = (unsigned short*)malloc(w * h * n * sizeof(unsigned short));
convert_image<unsigned char, unsigned short>(input_data, short_data, w * h * n);
test_format<unsigned int>("barbara.png", 0.5, 2.0, STBR_TYPE_UINT32, STBR_COLORSPACE_SRGB);
test_format<unsigned int>("barbara.png", 0.5, 2.0, STBR_TYPE_UINT32, STBR_COLORSPACE_LINEAR);
test_format<unsigned int>("barbara.png", 2.0, 0.5, STBR_TYPE_UINT32, STBR_COLORSPACE_SRGB);
test_format<unsigned int>("barbara.png", 2.0, 0.5, STBR_TYPE_UINT32, STBR_COLORSPACE_LINEAR);
unsigned short* output_data = (unsigned short*)malloc(w * h * n * sizeof(unsigned short));
stbr_resize_srgb_uint16(short_data, w, h, output_data, w * 2, h / 2, n, STBR_FILTER_CATMULLROM, STBR_EDGE_CLAMP);
free(short_data);
stbi_image_free(input_data);
char* char_data = (char*)malloc(w * h * n * sizeof(char));
convert_image<unsigned short, char>(output_data, char_data, w * h * n);
stbi_write_png("test-output/barbara-short.png", w * 2, h / 2, n, char_data, 0);
free(char_data);
free(output_data);
}
test_format<float>("barbara.png", 0.5, 2.0, STBR_TYPE_FLOAT, STBR_COLORSPACE_SRGB);
test_format<float>("barbara.png", 0.5, 2.0, STBR_TYPE_FLOAT, STBR_COLORSPACE_LINEAR);
test_format<float>("barbara.png", 2.0, 0.5, STBR_TYPE_FLOAT, STBR_COLORSPACE_SRGB);
test_format<float>("barbara.png", 2.0, 0.5, STBR_TYPE_FLOAT, STBR_COLORSPACE_LINEAR);
}