Skip to content
Myr

Fix bug in coeff generation on more than 3x downsamples with width and height scale equal

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jeff Roberts (Bellevue) · committed by Jeff Roberts (Bellevue) · parent b7cf124 · Browse files · 1 file+39 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+39 added−21 removed

  • other:+39 added−21 removed

1 file+39 added−21 removed

modified:stb_image_resize2.h+39 added-21 removed
1/* stb_image_resize2 - v2.05 - public domain image resizing1/* stb_image_resize2 - v2.06 - public domain image resizing23 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5
321 unmodified lines
327 Aras Pranckevicius: bugfixes328 Nathan Reed: warning fixes for 1.0329330 REVISIONS331 2.06 (2024-02-10) fix for indentical width/height 3x or more down-scaling 332 undersampling a single row on rare resize ratios (about 1%)331 2.05 (2024-02-24) fix for 2 pixel to 1 pixel resizes with wrap (thanks Aras)333 2.05 (2024-02-07) fix for 2 pixel to 1 pixel resizes with wrap (thanks Aras)334 fix for output callback (thanks Julien Koenen)335 2.04 (2023-11-17) fix for rare AVX bug, shadowed symbol (thanks Nikola Smiljanic).336 2.03 (2023-11-01) ASAN and TSAN warnings fixed, minor tweaks.337 2.00 (2023-10-10) mostly new source: new api, optimizations, simd, vertical-first, etc
3056 unmodified lines
3394 }3395 }3396 }3397}3398#define STBIR_RENORMALIZE_IN_FLOAT3399#ifdef STBIR_RENORMALIZE_IN_FLOAT3400#define STBIR_RENORM_TYPE float3401#else3402#define STBIR_RENORM_TYPE double3403#endif34043405static void stbir__cleanup_gathered_coefficients( stbir_edge edge, stbir__filter_extent_info* filter_info, stbir__scale_info * scale_info, int num_contributors, stbir__contributors* contributors, float * coefficient_group, int coefficient_width )3406{3407 int input_size = scale_info->input_full_size;
14 unmodified lines
3422 end = num_contributors; if ( polyphase ) end = numerator;3423 for (n = 0; n < end; n++)3424 {3425 int i;3418 float filter_scale, total_filter = 0;3426 STBIR_RENORM_TYPE filter_scale, total_filter = 0;3427 int e;34283429 // add all contribs3430 e = contribs->n1 - contribs->n0;3431 for( i = 0 ; i <= e ; i++ )3432 {3425 total_filter += coeffs[i];3433 total_filter += (STBIR_RENORM_TYPE) coeffs[i];3434 STBIR_ASSERT( ( coeffs[i] >= -2.0f ) && ( coeffs[i] <= 2.0f ) ); // check for wonky weights3435 }34363437 // rescale
7 unmodified lines
3445 {3446 // if the total isn't 1.0, rescale everything3447 if ( ( total_filter < (1.0f-stbir__small_float) ) || ( total_filter > (1.0f+stbir__small_float) ) )3448 {3441 filter_scale = 1.0f / total_filter;3449 filter_scale = ((STBIR_RENORM_TYPE)1.0) / total_filter;34503451 // scale them all3452 for (i = 0; i <= e; i++)3444 coeffs[i] *= filter_scale;3453 coeffs[i] = (float) ( coeffs[i] * filter_scale );3454 }3455 }3456 ++contribs;3457 coeffs += coefficient_width;
112 unmodified lines
3570 filter_info->highest = highest;3571 filter_info->widest = widest;3572}35733574#undef STBIR_RENORM_TYPE 35753576static int stbir__pack_coefficients( int num_contributors, stbir__contributors* contributors, float * coefficents, int coefficient_width, int widest, int row0, int row1 ) 3577{3578 #define STBIR_MOVE_1( dest, src ) { STBIR_NO_UNROLL(dest); ((stbir_uint32*)(dest))[0] = ((stbir_uint32*)(src))[0]; }3579 #define STBIR_MOVE_2( dest, src ) { STBIR_NO_UNROLL(dest); ((stbir_uint64*)(dest))[0] = ((stbir_uint64*)(src))[0]; }
299 unmodified lines
38793880 for (k = gn0 ; k <= gn1 ; k++ )3881 {3882 float gc = *g_coeffs++;3872 if ( ( k > highest_set ) || ( scatter_contributors->n0 > scatter_contributors->n1 ) )3883 3884 // skip zero and denormals - must skip zeros to avoid adding coeffs beyond scatter_coefficient_width3885 // (which happens when pivoting from horizontal, which might have dummy zeros)3886 if ( ( ( gc >= stbir__small_float ) || ( gc <= -stbir__small_float ) ) )3887 {3888 if ( ( k > highest_set ) || ( scatter_contributors->n0 > scatter_contributors->n1 ) )3889 {3875 // if we are skipping over several contributors, we need to clear the skipped ones3876 stbir__contributors * clear_contributors = samp->contributors + ( highest_set + filter_pixel_margin + 1);3877 while ( clear_contributors < scatter_contributors )3890 {3891 // if we are skipping over several contributors, we need to clear the skipped ones3892 stbir__contributors * clear_contributors = samp->contributors + ( highest_set + filter_pixel_margin + 1);3893 while ( clear_contributors < scatter_contributors )3894 {3879 clear_contributors->n0 = 0;3880 clear_contributors->n1 = -1;3881 ++clear_contributors;3895 clear_contributors->n0 = 0;3896 clear_contributors->n1 = -1;3897 ++clear_contributors;3898 }3899 }3900 scatter_contributors->n0 = n;3901 scatter_contributors->n1 = n;3902 scatter_coeffs[0] = gc;3903 highest_set = k;3904 }3884 scatter_contributors->n0 = n;3885 scatter_contributors->n1 = n;3886 scatter_coeffs[0] = gc;3887 highest_set = k;3905 else3906 {3907 stbir__insert_coeff( scatter_contributors, scatter_coeffs, n, gc );3908 }3909 STBIR_ASSERT( ( scatter_contributors->n1 - scatter_contributors->n0 + 1 ) <= scatter_coefficient_width );3910 }3889 else3890 {3891 stbir__insert_coeff( scatter_contributors, scatter_coeffs, n, gc );3892 }3911 ++scatter_contributors;3912 scatter_coeffs += scatter_coefficient_width;3913 }3914
6451 unmodified lines