Open hpjansson opened 1 year ago
Hi, I was trying to benchmark image resizing and ran into an issue. With certain parameters, stbir_resize_uint8_generic() will fail an assertion and abort. The following program triggers it here:
stbir_resize_uint8_generic()
#include <stdlib.h> #define STB_IMAGE_RESIZE_IMPLEMENTATION #include "stb_image_resize.h" #define IN_W 2000 #define IN_H 2000 #define OUT_W 1304 #define OUT_H 1304 int main (int argc, char *argv []) { void *in = calloc (IN_W * IN_H, 4); void *out = malloc (OUT_W * OUT_H * 4); stbir_resize_uint8_generic (in, IN_W, IN_H, 0, out, OUT_W, OUT_H, 0, 4, 0, STBIR_FLAG_ALPHA_PREMULTIPLIED, STBIR_EDGE_ZERO, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, NULL); return 0; }
Output:
$ gcc -g -lm stbir-test-case.c -o stbir-test-case $ ./stbir-test-case stbir-test-case: stb_image_resize.h:1150: stbir__normalize_downsample_coefficients: Assertion `total < 1.1f' failed. Aborted (core dumped)
Trace:
#0 0x00007ffff7d296bc in __pthread_kill_implementation () from /lib64/libc.so.6 #1 0x00007ffff7cd66f6 in raise () from /lib64/libc.so.6 #2 0x00007ffff7cbf814 in abort () from /lib64/libc.so.6 #3 0x00007ffff7cbf72b in __assert_fail_base.cold () from /lib64/libc.so.6 #4 0x00007ffff7cceb26 in __assert_fail () from /lib64/libc.so.6 #5 0x000000000040240e in stbir__normalize_downsample_coefficients ( contributors=0x7ffff6687010, coefficients=0x7ffff668aeb0, filter=STBIR_FILTER_TRIANGLE, scale_ratio=0.65200001, input_size=2000, output_size=1304) at stb_image_resize.h:1150 #6 0x0000000000402908 in stbir__calculate_filters ( contributors=0x7ffff6687010, coefficients=0x7ffff668aeb0, filter=STBIR_FILTER_TRIANGLE, scale_ratio=0.65200001, shift=0, input_size=2000, output_size=1304) at stb_image_resize.h:1239 #7 0x000000000040726d in stbir__resize_allocated (info=0x7fffffffd8a0, input_data=0x7ffff6d3b010, input_stride_in_bytes=0, output_data=0x7ffff66be010, output_stride_in_bytes=0, alpha_channel=0, flags=1, type=STBIR_TYPE_UINT8, edge_horizontal=STBIR_EDGE_ZERO, edge_vertical=STBIR_EDGE_ZERO, colorspace=STBIR_COLORSPACE_LINEAR, tempmem=0x7ffff6687010, tempmem_size_in_bytes=221376) at stb_image_resize.h:2405 #8 0x000000000040743a in stbir__resize_arbitrary (alloc_context=0x0, input_data=0x7ffff6d3b010, input_w=2000, input_h=2000, input_stride_in_bytes=0, output_data=0x7ffff66be010, output_w=1304, output_h=1304, output_stride_in_bytes=0, s0=0, t0=0, s1=1, t1=1, transform=0x0, channels=4, alpha_channel=0, flags=1, type=STBIR_TYPE_UINT8, h_filter=STBIR_FILTER_TRIANGLE, v_filter=STBIR_FILTER_TRIANGLE, edge_horizontal=STBIR_EDGE_ZERO, edge_vertical=STBIR_EDGE_ZERO, colorspace=STBIR_COLORSPACE_LINEAR) at stb_image_resize.h:2451 #9 0x000000000040771f in stbir_resize_uint8_generic ( input_pixels=0x7ffff6d3b010 "", input_w=2000, input_h=2000, input_stride_in_bytes=0, output_pixels=0x7ffff66be010 "", output_w=1304, output_h=1304, output_stride_in_bytes=0, num_channels=4, alpha_channel=0, flags=1, edge_wrap_mode=STBIR_EDGE_ZERO, filter=STBIR_FILTER_TRIANGLE, space=STBIR_COLORSPACE_LINEAR, alloc_context=0x0) at stb_image_resize.h:2509 #10 0x0000000000407b25 in main (argc=1, argv=0x7fffffffdc08 "\364\340\377\377\377\177") at stbir-test-case.c:17
Hi, I was trying to benchmark image resizing and ran into an issue. With certain parameters,
stbir_resize_uint8_generic()
will fail an assertion and abort. The following program triggers it here:Output:
Trace: