Skip to content
Myr

Merge branch 'resize_latest' of https://github.com/jeffrbig2/stb into working

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

authored by Sean Barrett · committed by Sean Barrett · parents 6e9f34d, 2a58424 · Browse files · 2 files+250 added−52 removed
This commit

State

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

Diff stats

2 files+250 added−52 removed

  • other:+250 added−52 removed

2 files+250 added−52 removed

modified:stb_image_resize2.h+244 added-49 removed
1/* stb_image_resize2 - v2.07 - public domain image resizing1/* stb_image_resize2 - v2.09 - public domain image resizing23 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5
313 unmodified lines
319 all the SIMD stuff always and dynamically dispatch?320321 CONTRIBUTORS322 Jeff Roberts: 2.0 implementation, optimizations, SIMD323 Martins Mozeiko: NEON simd, WASM simd, clang and GCC whisperer.323 Martins Mozeiko: NEON simd, WASM simd, clang and GCC whisperer324 Fabian Giesen: half float and srgb converters325 Sean Barrett: API design, optimizations326 Jorge L Rodriguez: Original 1.0 implementation327 Aras Pranckevicius: bugfixes328 Nathan Reed: warning fixes for 1.0329330 REVISIONS331 2.09 (2024-06-19) fix the defines for 32-bit ARM GCC builds (was selecting332 hardware half floats).333 2.08 (2024-06-10) fix for RGB->BGR three channel flips and add SIMD (thanks334 to Ryan Salsbury), fix for sub-rect resizes, use the335 pragmas to control unrolling when they are available.336 2.07 (2024-05-24) fix for slow final split during threaded conversions of very 337 wide scanlines when downsampling (caused by extra input 338 converting), fix for wide scanline resamples with many 339 splits (int overflow), fix GCC warning.340 2.06 (2024-02-10) fix for identical width/height 3x or more down-scaling 336 undersampling a single row on rare resize ratios (about 1%)337 2.05 (2024-02-07) fix for 2 pixel to 1 pixel resizes with wrap (thanks Aras)338 fix for output callback (thanks Julien Koenen)341 undersampling a single row on rare resize ratios (about 1%).342 2.05 (2024-02-07) fix for 2 pixel to 1 pixel resizes with wrap (thanks Aras),343 fix for output callback (thanks Julien Koenen).344 2.04 (2023-11-17) fix for rare AVX bug, shadowed symbol (thanks Nikola Smiljanic).345 2.03 (2023-11-01) ASAN and TSAN warnings fixed, minor tweaks.346 2.00 (2023-10-10) mostly new source: new api, optimizations, simd, vertical-first, etc342 (2x-5x faster without simd, 4x-12x faster with simd)343 (in some cases, 20x to 40x faster - resizing to very small for example)347 2x-5x faster without simd, 4x-12x faster with simd,348 in some cases, 20x to 40x faster esp resizing large to very small.349 0.96 (2019-03-04) fixed warnings350 0.95 (2017-07-23) fixed warnings351 0.94 (2017-03-18) fixed warnings352 0.93 (2017-03-03) fixed bug with certain combinations of heights
61 unmodified lines
414 #endif415 #endif416#endif417413#if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || defined(_M_ARM) || (__ARM_NEON_FP & 4) != 0 && __ARM_FP16_FORMAT_IEEE != 0418#if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || ((__ARM_NEON_FP & 4) != 0) || defined(__ARM_NEON__)419#ifndef STBIR_NEON420#define STBIR_NEON421#endif422#endif423419#if defined(_M_ARM)424#if defined(_M_ARM) || defined(__arm__)425#ifdef STBIR_USE_FMA426#undef STBIR_USE_FMA // no FMA for 32-bit arm on MSVC427#endif428#endif
669 unmodified lines
1098#define stbir__max_uint16_as_float_inverted (1.0f/65535.0f)1099#define stbir__small_float ((float)1 / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20))11001101// min/max friendly1097#define STBIR_CLAMP(x, xmin, xmax) do { \1102#define STBIR_CLAMP(x, xmin, xmax) for(;;) { \1103 if ( (x) < (xmin) ) (x) = (xmin); \1104 if ( (x) > (xmax) ) (x) = (xmax); \1100} while (0)1105 break; \1106}11071108static stbir__inline int stbir__min(int a, int b)1109{1110 return a < b ? a : b;
88 unmodified lines
1199#ifndef STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS1200#define STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS 4 // when threading, what is the minimum number of scanlines for a split?1201#endif12021197// restrict pointers for the output pointers1203// restrict pointers for the output pointers, other loop and unroll control1204#if defined( _MSC_VER ) && !defined(__clang__)1205 #define STBIR_STREAMOUT_PTR( star ) star __restrict1206 #define STBIR_NO_UNROLL( ptr ) __assume(ptr) // this oddly keeps msvc from unrolling a loop1207 #if _MSC_VER >= 19001208 #define STBIR_NO_UNROLL_LOOP_START __pragma(loop( no_vector )) 1209 #else1210 #define STBIR_NO_UNROLL_LOOP_START 1211 #endif1201#elif defined( __clang__ )1212#elif defined( __clang__ )1213 #define STBIR_STREAMOUT_PTR( star ) star __restrict__1203 #define STBIR_NO_UNROLL( ptr ) __asm__ (""::"r"(ptr))1204#elif defined( __GNUC__ )1214 #define STBIR_NO_UNROLL( ptr ) __asm__ (""::"r"(ptr)) 1215 #if ( __clang_major__ >= 4 ) || ( ( __clang_major__ >= 3 ) && ( __clang_minor__ >= 5 ) )1216 #define STBIR_NO_UNROLL_LOOP_START _Pragma("clang loop unroll(disable)") _Pragma("clang loop vectorize(disable)")1217 #else1218 #define STBIR_NO_UNROLL_LOOP_START1219 #endif 1220#elif defined( __GNUC__ )1221 #define STBIR_STREAMOUT_PTR( star ) star __restrict__1222 #define STBIR_NO_UNROLL( ptr ) __asm__ (""::"r"(ptr))1223 #if __GNUC__ >= 141224 #define STBIR_NO_UNROLL_LOOP_START _Pragma("GCC unroll 0") _Pragma("GCC novector")1225 #else1226 #define STBIR_NO_UNROLL_LOOP_START1227 #endif1228#else1229 #define STBIR_STREAMOUT_PTR( star ) star1230 #define STBIR_NO_UNROLL( ptr )1231 #define STBIR_NO_UNROLL_LOOP_START1232#endif12331234#ifdef STBIR_NO_SIMD // force simd off for whatever reason1235
543 unmodified lines
1779 vcreate_u8( (4*a+0) | ((4*a+1)<<8) | ((4*a+2)<<16) | ((4*a+3)<<24) | \1780 ((stbir_uint64)(4*b+0)<<32) | ((stbir_uint64)(4*b+1)<<40) | ((stbir_uint64)(4*b+2)<<48) | ((stbir_uint64)(4*b+3)<<56)), \1781 vcreate_u8( (4*c+0) | ((4*c+1)<<8) | ((4*c+2)<<16) | ((4*c+3)<<24) | \1782 ((stbir_uint64)(4*d+0)<<32) | ((stbir_uint64)(4*d+1)<<40) | ((stbir_uint64)(4*d+2)<<48) | ((stbir_uint64)(4*d+3)<<56) ) )17831784 static stbir__inline uint8x16x2_t stbir_make16x2(float32x4_t rega,float32x4_t regb)1785 {1786 uint8x16x2_t r = { vreinterpretq_u8_f32(rega), vreinterpretq_u8_f32(regb) };1787 return r;1788 }1789 #else1790 #define stbir_make16(a,b,c,d) (uint8x16_t){4*a+0,4*a+1,4*a+2,4*a+3,4*b+0,4*b+1,4*b+2,4*b+3,4*c+0,4*c+1,4*c+2,4*c+3,4*d+0,4*d+1,4*d+2,4*d+3}1791 #define stbir_make16x2(a,b) (uint8x16x2_t){{vreinterpretq_u8_f32(a),vreinterpretq_u8_f32(b)}}1792 #endif17931794 #define stbir__simdf_swiz( reg, one, two, three, four ) vreinterpretq_f32_u8( vqtbl1q_u8( vreinterpretq_u8_f32(reg), stbir_make16(one, two, three, four) ) )1795 #define stbir__simdf_swiz2( rega, regb, one, two, three, four ) vreinterpretq_f32_u8( vqtbl2q_u8( stbir_make16x2(rega,regb), stbir_make16(one, two, three, four) ) )17961797 #define stbir__simdi_16madd( out, reg0, reg1 ) \1798 { \1799 int16x8_t r0 = vreinterpretq_s16_u32(reg0); \
375 unmodified lines
2175 #define stbir__simdfX_0123to2103 stbir__simdf_0123to21032176#endif217721782149#if defined(STBIR_NEON) && !defined(_M_ARM)2179#if defined(STBIR_NEON) && !defined(_M_ARM) && !defined(__arm__)21802181 #if defined( _MSC_VER ) && !defined(__clang__)2182 typedef __int16 stbir__FP16;2183 #else
8 unmodified lines
2192 } stbir__FP16;21932194#endif21952166#if !defined(STBIR_NEON) && !defined(STBIR_FP16C) || defined(STBIR_NEON) && defined(_M_ARM)2196#if (!defined(STBIR_NEON) && !defined(STBIR_FP16C)) || (defined(STBIR_NEON) && defined(_M_ARM)) || (defined(STBIR_NEON) && defined(__arm__))21972198 // Fabian's half float routines, see: https://gist.github.com/rygorous/215666821992200 static stbir__inline float stbir__half_to_float( stbir__FP16 h )
218 unmodified lines
2419 final = _mm_packs_epi32(final, final2);2420 stbir__simdi_store( output,final );2421 }24222393#elif defined(STBIR_WASM) || (defined(STBIR_NEON) && defined(_MSC_VER) && defined(_M_ARM)) // WASM or 32-bit ARM on MSVC/clang2423#elif defined(STBIR_WASM) || (defined(STBIR_NEON) && (defined(_MSC_VER) || defined(_M_ARM) || defined(__arm__))) // WASM or 32-bit ARM on MSVC/clang24242425 static stbir__inline void stbir__half_to_float_SIMD(float * output, stbir__FP16 const * input)2426 {2427 for (int i=0; i<8; i++)
37 unmodified lines
2465 {2466 return vget_lane_f16(vcvt_f16_f32(vdupq_n_f32(f)), 0).n16_u16[0];2467 }24682439#elif defined(STBIR_NEON) // 64-bit ARM2469#elif defined(STBIR_NEON) && ( defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) ) // 64-bit ARM24702471 static stbir__inline void stbir__half_to_float_SIMD(float * output, stbir__FP16 const * input)2472 {2473 float16x8_t in = vld1q_f16(input);
69 unmodified lines
2543// the non-simd remnant loops to be unroll because they only run a few times2544// Adding this switch saves about 5K on clang which is Captain Unroll the 3rd.2545#define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )2546#define STBIR_SIMD_NO_UNROLL(ptr) STBIR_NO_UNROLL(ptr)2547#define STBIR_SIMD_NO_UNROLL_LOOP_START STBIR_NO_UNROLL_LOOP_START25482549#ifdef STBIR_MEMCPY2550#undef STBIR_MEMCPY2551#endif
14 unmodified lines
2566 if ( bytes < 16 )2567 {2568 if ( bytes )2569 {2570 STBIR_SIMD_NO_UNROLL_LOOP_START2571 do2572 {2573 STBIR_SIMD_NO_UNROLL(d);2574 d[ 0 ] = d[ ofs_to_src ];
8 unmodified lines
2583 stbir__simdf_load( x, ( d + ofs_to_src ) );2584 stbir__simdf_store( d, x );2585 d = (char*)( ( ( (size_t)d ) + 16 ) & ~15 );25862587 STBIR_SIMD_NO_UNROLL_LOOP_START2588 for(;;)2589 {2590 STBIR_SIMD_NO_UNROLL(d);2591
24 unmodified lines
2616 stbir__simdfX_store( d + 8*stbir__simdfX_float_count, x2 );2617 stbir__simdfX_store( d + 12*stbir__simdfX_float_count, x3 );2618 d = (char*)( ( ( (size_t)d ) + (16*stbir__simdfX_float_count) ) & ~((16*stbir__simdfX_float_count)-1) );26192620 STBIR_SIMD_NO_UNROLL_LOOP_START2621 for(;;)2622 {2623 STBIR_SIMD_NO_UNROLL(d);2624
28 unmodified lines
26532654 if ( ofs_to_dest >= 16 ) // is the overlap more than 16 away?2655 {2656 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end16 = ((char*) src) + (bytes&~15);2657 STBIR_SIMD_NO_UNROLL_LOOP_START2658 do2659 {2660 stbir__simdf x;2661 STBIR_SIMD_NO_UNROLL(sd);
18 unmodified lines
26802681// when in scalar mode, we let unrolling happen, so this macro just does the __restrict2682#define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )2683#define STBIR_SIMD_NO_UNROLL(ptr)2684#define STBIR_SIMD_NO_UNROLL_LOOP_START26852686#endif // SSE226872688
103 unmodified lines
2792#endif27932794#ifndef STBIR_SIMD27952760// memcpy that is specically intentionally overlapping (src is smaller then dest, so can be2796// memcpy that is specifically intentionally overlapping (src is smaller then dest, so can be2797// a normal forward copy, bytes is divisible by 4 and bytes is greater than or equal to2798// the diff between dest and src)2799static void stbir_overlapping_memcpy( void * dest, void const * src, size_t bytes )2800{
3 unmodified lines
28042805 if ( ofs_to_dest >= 8 ) // is the overlap more than 8 away?2806 {2807 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end8 = ((char*) src) + (bytes&~7);2808 STBIR_NO_UNROLL_LOOP_START2809 do2810 {2811 STBIR_NO_UNROLL(sd);2812 *(stbir_uint64*)( sd + ofs_to_dest ) = *(stbir_uint64*) sd;
3 unmodified lines
2816 if ( sd == s_end )2817 return;2818 }28192820 STBIR_NO_UNROLL_LOOP_START2821 do2822 {2823 STBIR_NO_UNROLL(sd);2824 *(int*)( sd + ofs_to_dest ) = *(int*) sd;
96 unmodified lines
29212922 return (0.0f);2923}29242887static float stbir__support_zero(float s, void * user_data)2888{2889 STBIR__UNUSED(s);2890 STBIR__UNUSED(user_data);2891 return 0;2892}28932925static float stbir__support_zeropoint5(float s, void * user_data)2926{2927 STBIR__UNUSED(s);2928 STBIR__UNUSED(user_data);
699 unmodified lines
3628 float * pc_end = coefficents + num_contributors * widest;3629 switch( widest )3630 {3631 case 1:3632 STBIR_NO_UNROLL_LOOP_START3633 do {3634 STBIR_MOVE_1( pc, coeffs );3635 ++pc;3636 coeffs += coefficient_width;3637 } while ( pc < pc_end );3638 break;3639 case 2:3640 STBIR_NO_UNROLL_LOOP_START3641 do {3642 STBIR_MOVE_2( pc, coeffs );3643 pc += 2;3644 coeffs += coefficient_width;3645 } while ( pc < pc_end );3646 break;3647 case 3:3648 STBIR_NO_UNROLL_LOOP_START3649 do {3650 STBIR_MOVE_2( pc, coeffs );3651 STBIR_MOVE_1( pc+2, coeffs+2 );3652 pc += 3;3653 coeffs += coefficient_width;3654 } while ( pc < pc_end );3655 break;3656 case 4:3657 STBIR_NO_UNROLL_LOOP_START3658 do {3659 STBIR_MOVE_4( pc, coeffs );3660 pc += 4;3661 coeffs += coefficient_width;3662 } while ( pc < pc_end );3663 break;3664 case 5:3665 STBIR_NO_UNROLL_LOOP_START3666 do {3667 STBIR_MOVE_4( pc, coeffs );3668 STBIR_MOVE_1( pc+4, coeffs+4 );3669 pc += 5;3670 coeffs += coefficient_width;3671 } while ( pc < pc_end );3672 break;3673 case 6:3674 STBIR_NO_UNROLL_LOOP_START3675 do {3676 STBIR_MOVE_4( pc, coeffs );3677 STBIR_MOVE_2( pc+4, coeffs+4 );3678 pc += 6;3679 coeffs += coefficient_width;3680 } while ( pc < pc_end );3681 break;3682 case 7:3683 STBIR_NO_UNROLL_LOOP_START3684 do {3685 STBIR_MOVE_4( pc, coeffs );3686 STBIR_MOVE_2( pc+4, coeffs+4 );3687 STBIR_MOVE_1( pc+6, coeffs+6 );
1 unmodified line
3689 coeffs += coefficient_width;3690 } while ( pc < pc_end );3691 break;3692 case 8:3693 STBIR_NO_UNROLL_LOOP_START3694 do {3695 STBIR_MOVE_4( pc, coeffs );3696 STBIR_MOVE_4( pc+4, coeffs+4 );3697 pc += 8;3698 coeffs += coefficient_width;3699 } while ( pc < pc_end );3700 break;3701 case 9:3702 STBIR_NO_UNROLL_LOOP_START3703 do {3704 STBIR_MOVE_4( pc, coeffs );3705 STBIR_MOVE_4( pc+4, coeffs+4 );3706 STBIR_MOVE_1( pc+8, coeffs+8 );
1 unmodified line
3708 coeffs += coefficient_width;3709 } while ( pc < pc_end );3710 break;3711 case 10:3712 STBIR_NO_UNROLL_LOOP_START3713 do {3714 STBIR_MOVE_4( pc, coeffs );3715 STBIR_MOVE_4( pc+4, coeffs+4 );3716 STBIR_MOVE_2( pc+8, coeffs+8 );
1 unmodified line
3718 coeffs += coefficient_width;3719 } while ( pc < pc_end );3720 break;3721 case 11:3722 STBIR_NO_UNROLL_LOOP_START3723 do {3724 STBIR_MOVE_4( pc, coeffs );3725 STBIR_MOVE_4( pc+4, coeffs+4 );3726 STBIR_MOVE_2( pc+8, coeffs+8 );
2 unmodified lines
3729 coeffs += coefficient_width;3730 } while ( pc < pc_end );3731 break;3732 case 12:3733 STBIR_NO_UNROLL_LOOP_START3734 do {3735 STBIR_MOVE_4( pc, coeffs );3736 STBIR_MOVE_4( pc+4, coeffs+4 );3737 STBIR_MOVE_4( pc+8, coeffs+8 );
1 unmodified line
3739 coeffs += coefficient_width;3740 } while ( pc < pc_end );3741 break;3742 default:3743 STBIR_NO_UNROLL_LOOP_START3744 do {3745 float * copy_end = pc + widest - 4;3746 float * c = coeffs;3747 do {
2 unmodified lines
3750 pc += 4;3751 c += 4;3752 } while ( pc <= copy_end );3753 copy_end += 4;3754 STBIR_NO_UNROLL_LOOP_START3755 while ( pc < copy_end )3756 {3757 STBIR_MOVE_1( pc, c );3758 ++pc; ++c;
302 unmodified lines
4061 #ifdef STBIR_SIMD40624063 #ifdef STBIR_SIMD84064 decode += 16;4065 STBIR_NO_UNROLL_LOOP_START4066 while ( decode <= end_decode )4067 {4068 stbir__simdf8 d0,d1,a0,a1,p0,p1;4069 STBIR_NO_UNROLL(decode);
16 unmodified lines
4086 }4087 decode -= 16;4088 #else4089 decode += 8;4090 STBIR_NO_UNROLL_LOOP_START4091 while ( decode <= end_decode )4092 {4093 stbir__simdf d0,a0,d1,a1,p0,p1;4094 STBIR_NO_UNROLL(decode);
14 unmodified lines
4109 #endif41104111 // might be one last odd pixel4112 #ifdef STBIR_SIMD84113 STBIR_NO_UNROLL_LOOP_START4114 while ( decode < end_decode )4115 #else4116 if ( decode < end_decode )4117 #endif4118 {4119 stbir__simdf d,a,p;4120 STBIR_NO_UNROLL(decode);4121 stbir__simdf_load( d, decode );4122 stbir__simdf_0123to3333( a, d );4123 stbir__simdf_mult( p, a, d );4124 stbir__simdf_store ( out, d );
33 unmodified lines
41584159 decode += 8;4160 if ( decode <= end_decode )4161 {4162 STBIR_NO_UNROLL_LOOP_START4163 do {4164 #ifdef STBIR_SIMD84165 stbir__simdf8 d0,a0,p0;4166 STBIR_NO_UNROLL(decode);
35 unmodified lines
4202 }4203 decode -= 8;4204 #endif42054206 STBIR_SIMD_NO_UNROLL_LOOP_START4207 while( decode < end_decode )4208 {4209 float x = decode[0], y = decode[1];4210 STBIR_SIMD_NO_UNROLL(decode);
12 unmodified lines
4223 float const * end_output = encode_buffer + width_times_channels;42244225 // fancy RGBA is stored internally as R G B A Rpm Gpm Bpm42264227 STBIR_SIMD_NO_UNROLL_LOOP_START4228 do {4229 float alpha = input[3];4230#ifdef STBIR_SIMD4231 stbir__simdf i,ia;
59 unmodified lines
42914292 #ifdef STBIR_SIMD4293 {4294 decode += 2 * stbir__simdfX_float_count;4295 STBIR_NO_UNROLL_LOOP_START4296 while ( decode <= end_decode )4297 {4298 stbir__simdfX d0,a0,d1,a1;4299 STBIR_NO_UNROLL(decode);
10 unmodified lines
4310 decode -= 2 * stbir__simdfX_float_count;43114312 // few last pixels remnants4313 #ifdef STBIR_SIMD84314 STBIR_NO_UNROLL_LOOP_START4315 while ( decode < end_decode )4316 #else4317 if ( decode < end_decode )4318 #endif
27 unmodified lines
4346 float const * end_decode = decode_buffer + width_times_channels;43474348 #ifdef STBIR_SIMD4349 decode += 2 * stbir__simdfX_float_count;4350 STBIR_NO_UNROLL_LOOP_START4351 while ( decode <= end_decode )4352 {4353 stbir__simdfX d0,a0,d1,a1;4354 STBIR_NO_UNROLL(decode);
9 unmodified lines
4364 }4365 decode -= 2 * stbir__simdfX_float_count;4366 #endif43674368 STBIR_SIMD_NO_UNROLL_LOOP_START4369 while( decode < end_decode )4370 {4371 float alpha = decode[1];4372 STBIR_SIMD_NO_UNROLL(decode);
6 unmodified lines
4379{4380 float STBIR_SIMD_STREAMOUT_PTR(*) encode = encode_buffer;4381 float const * end_output = encode_buffer + width_times_channels;43824383 STBIR_SIMD_NO_UNROLL_LOOP_START4384 do {4385 float alpha = encode[3];43864387#ifdef STBIR_SIMD
39 unmodified lines
4427{4428 float STBIR_STREAMOUT_PTR(*) decode = decode_buffer;4429 float const * end_decode = decode_buffer + width_times_channels;44304431#ifdef STBIR_SIMD4432 #ifdef stbir__simdf_swiz2 // do we have two argument swizzles?4433 end_decode -= 12; 4434 STBIR_NO_UNROLL_LOOP_START4435 while( decode <= end_decode )4436 {4437 // on arm64 8 instructions, no overlapping stores4438 stbir__simdf a,b,c,na,nb;4439 STBIR_SIMD_NO_UNROLL(decode);4440 stbir__simdf_load( a, decode );4441 stbir__simdf_load( b, decode+4 );4442 stbir__simdf_load( c, decode+8 );44434444 na = stbir__simdf_swiz2( a, b, 2, 1, 0, 5 ); 4445 b = stbir__simdf_swiz2( a, b, 4, 3, 6, 7 ); 4446 nb = stbir__simdf_swiz2( b, c, 0, 1, 4, 3 ); 4447 c = stbir__simdf_swiz2( b, c, 2, 7, 6, 5 ); 44484449 stbir__simdf_store( decode, na );4450 stbir__simdf_store( decode+4, nb ); 4451 stbir__simdf_store( decode+8, c );4374 decode += 12;4452 decode += 12;4453 }4454 end_decode += 12;4455 #else4456 end_decode -= 24;4457 STBIR_NO_UNROLL_LOOP_START4458 while( decode <= end_decode )4459 {4460 // 26 instructions on x644461 stbir__simdf a,b,c,d,e,f,g;4462 float i21, i23;4463 STBIR_SIMD_NO_UNROLL(decode);4464 stbir__simdf_load( a, decode );4465 stbir__simdf_load( b, decode+3 );4466 stbir__simdf_load( c, decode+6 );4467 stbir__simdf_load( d, decode+9 );4468 stbir__simdf_load( e, decode+12 );4469 stbir__simdf_load( f, decode+15 );4470 stbir__simdf_load( g, decode+18 );44714472 a = stbir__simdf_swiz( a, 2, 1, 0, 3 ); 4473 b = stbir__simdf_swiz( b, 2, 1, 0, 3 ); 4474 c = stbir__simdf_swiz( c, 2, 1, 0, 3 ); 4475 d = stbir__simdf_swiz( d, 2, 1, 0, 3 ); 4476 e = stbir__simdf_swiz( e, 2, 1, 0, 3 ); 4477 f = stbir__simdf_swiz( f, 2, 1, 0, 3 ); 4478 g = stbir__simdf_swiz( g, 2, 1, 0, 3 ); 44794480 // stores overlap, need to be in order, 4481 stbir__simdf_store( decode, a );4482 i21 = decode[21];4483 stbir__simdf_store( decode+3, b ); 4484 i23 = decode[23];4485 stbir__simdf_store( decode+6, c );4486 stbir__simdf_store( decode+9, d );4487 stbir__simdf_store( decode+12, e );4488 stbir__simdf_store( decode+15, f );4489 stbir__simdf_store( decode+18, g );4490 decode[21] = i23;4491 decode[23] = i21;4492 decode += 24;4493 }4494 end_decode += 24;4495 #endif4496#else4497 end_decode -= 12;4498 STBIR_NO_UNROLL_LOOP_START4499 while( decode <= end_decode )4500 {4501 // 16 instructions4502 float t0,t1,t2,t3;4503 STBIR_NO_UNROLL(decode);4504 t0 = decode[0]; t1 = decode[3]; t2 = decode[6]; t3 = decode[9];4505 decode[0] = decode[2]; decode[3] = decode[5]; decode[6] = decode[8]; decode[9] = decode[11];4506 decode[2] = t0; decode[5] = t1; decode[8] = t2; decode[11] = t3;4507 decode += 12;4508 }4384 decode -= 12;4509 end_decode += 12;4510#endif45114512 STBIR_NO_UNROLL_LOOP_START4513 while( decode < end_decode )4514 {4515 float t = decode[0];4516 STBIR_NO_UNROLL(decode);
2680 unmodified lines
7197 if ( ( !info->vertical.is_gather ) && ( info->ring_buffer_num_entries > conservative_split_output_size ) )7198 info->ring_buffer_num_entries = conservative_split_output_size;7199 STBIR_ASSERT( info->ring_buffer_num_entries <= info->alloc_ring_buffer_num_entries );72007074 // a few of the horizontal gather functions read one dword past the end (but mask it out), so put in a normal value so no snans or denormals accidentally sneak in7201 // a few of the horizontal gather functions read past the end of the decode (but mask it out), 7202 // so put in normal values so no snans or denormals accidentally sneak in (also, in the ring 7203 // buffer for vertical first)7204 for( i = 0 ; i < splits ; i++ )7205 {7077 int width, ofs;7206 int t, ofs, start;72077079 // find the right most span7080 if ( info->scanline_extents.spans[0].n1 > info->scanline_extents.spans[1].n1 )7081 width = info->scanline_extents.spans[0].n1 - info->scanline_extents.spans[0].n0;7082 else7083 width = info->scanline_extents.spans[1].n1 - info->scanline_extents.spans[1].n0;7208 ofs = decode_buffer_size / 4;7209 start = ofs - 4;7210 if ( start < 0 ) start = 0;72117085 // this calc finds the exact end of the decoded scanline for all filter modes.7086 // usually this is just the width * effective channels. But we have to account7087 // for the area to the left of the scanline for wrap filtering and alignment, this7088 // is stored as a negative value in info->scanline_extents.conservative.n0. Next,7089 // we need to skip the exact size of the right hand size filter area (again for7090 // wrap mode), this is in info->scanline_extents.edge_sizes[1]).7091 ofs = ( width + 1 - info->scanline_extents.conservative.n0 + info->scanline_extents.edge_sizes[1] ) * effective_channels;7212 for( t = start ; t < ofs; t++ )7213 info->split_info[i].decode_buffer[ t ] = 9999.0f;72147093 // place a known, but numerically valid value in the decode buffer7094 info->split_info[i].decode_buffer[ ofs ] = 9999.0f;70957096 // if vertical filtering first, place a known, but numerically valid value in the all7097 // of the ring buffer accumulators7215 if ( vertical_first )7216 {7217 int j;7218 for( j = 0; j < info->ring_buffer_num_entries ; j++ )7219 {7220 for( t = start ; t < ofs; t++ )7103 stbir__get_ring_buffer_entry( info, info->split_info + i, j )[ ofs ] = 9999.0f;7221 stbir__get_ring_buffer_entry( info, info->split_info + i, j )[ t ] = 9999.0f;7222 }7223 }7224 }7225 }
970 unmodified lines
8196 unsigned char const * end_input_m16 = input + width_times_channels - 16;8197 if ( width_times_channels >= 16 )8198 {8199 decode_end -= 16;8200 STBIR_NO_UNROLL_LOOP_START8201 for(;;)8202 {8203 #ifdef STBIR_SIMD88204 stbir__simdi i; stbir__simdi8 o0,o1;
47 unmodified lines
82528253 // try to do blocks of 4 when you can8254 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four8255 decode += 4;8256 STBIR_SIMD_NO_UNROLL_LOOP_START8257 while( decode <= decode_end )8258 {8259 STBIR_SIMD_NO_UNROLL(decode);8260 decode[0-4] = ((float)(input[stbir__decode_order0])) * stbir__max_uint8_as_float_inverted;
7 unmodified lines
8268 #endif82698270 // do the remnants8271 #if stbir__coder_min_num < 48272 STBIR_NO_UNROLL_LOOP_START8273 while( decode < decode_end )8274 {8275 STBIR_NO_UNROLL(decode);8276 decode[0] = ((float)(input[stbir__decode_order0])) * stbir__max_uint8_as_float_inverted;
18 unmodified lines
8295 if ( width_times_channels >= stbir__simdfX_float_count*2 )8296 {8297 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;8298 end_output -= stbir__simdfX_float_count*2;8299 STBIR_NO_UNROLL_LOOP_START8300 for(;;)8301 {8302 stbir__simdfX e0, e1;8303 stbir__simdi i;
23 unmodified lines
83278328 // try to do blocks of 4 when you can8329 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four8330 output += 4;8331 STBIR_NO_UNROLL_LOOP_START8332 while( output <= end_output )8333 {8334 stbir__simdf e0;8335 stbir__simdi i0;
10 unmodified lines
8346 #endif83478348 // do the remnants8349 #if stbir__coder_min_num < 48350 STBIR_NO_UNROLL_LOOP_START8351 while( output < end_output )8352 {8353 stbir__simdf e0;8354 STBIR_NO_UNROLL(encode);
28 unmodified lines
8383 #endif83848385 // do the remnants8386 #if stbir__coder_min_num < 48387 STBIR_NO_UNROLL_LOOP_START8388 while( output < end_output )8389 {8390 float f;8391 STBIR_NO_UNROLL(encode);
21 unmodified lines
8413 unsigned char const * end_input_m16 = input + width_times_channels - 16;8414 if ( width_times_channels >= 16 )8415 {8416 decode_end -= 16;8417 STBIR_NO_UNROLL_LOOP_START8418 for(;;)8419 {8420 #ifdef STBIR_SIMD88421 stbir__simdi i; stbir__simdi8 o0,o1;
41 unmodified lines
84638464 // try to do blocks of 4 when you can8465 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four8466 decode += 4;8467 STBIR_SIMD_NO_UNROLL_LOOP_START8468 while( decode <= decode_end )8469 {8470 STBIR_SIMD_NO_UNROLL(decode);8471 decode[0-4] = ((float)(input[stbir__decode_order0]));
7 unmodified lines
8479 #endif84808481 // do the remnants8482 #if stbir__coder_min_num < 48483 STBIR_NO_UNROLL_LOOP_START8484 while( decode < decode_end )8485 {8486 STBIR_NO_UNROLL(decode);8487 decode[0] = ((float)(input[stbir__decode_order0]));
18 unmodified lines
8506 if ( width_times_channels >= stbir__simdfX_float_count*2 )8507 {8508 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;8509 end_output -= stbir__simdfX_float_count*2;8510 STBIR_SIMD_NO_UNROLL_LOOP_START8511 for(;;)8512 {8513 stbir__simdfX e0, e1;8514 stbir__simdi i;
23 unmodified lines
85388539 // try to do blocks of 4 when you can8540 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four8541 output += 4;8542 STBIR_NO_UNROLL_LOOP_START8543 while( output <= end_output )8544 {8545 stbir__simdf e0;8546 stbir__simdi i0;
30 unmodified lines
8577 #endif85788579 // do the remnants8580 #if stbir__coder_min_num < 48581 STBIR_NO_UNROLL_LOOP_START8582 while( output < end_output )8583 {8584 float f;8585 STBIR_NO_UNROLL(encode);
32 unmodified lines
8618 #endif86198620 // do the remnants8621 #if stbir__coder_min_num < 48622 STBIR_NO_UNROLL_LOOP_START8623 while( decode < decode_end )8624 {8625 STBIR_NO_UNROLL(decode);8626 decode[0] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order0 ] ];
82 unmodified lines
8709 if ( width_times_channels >= 16 )8710 {8711 float const * end_encode_m16 = encode + width_times_channels - 16;8712 end_output -= 16;8713 STBIR_SIMD_NO_UNROLL_LOOP_START8714 for(;;)8715 {8716 stbir__simdf f0, f1, f2, f3;8717 stbir__simdi i0, i1, i2, i3;
30 unmodified lines
87488749 // try to do blocks of 4 when you can8750 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four8751 output += 4;8752 STBIR_SIMD_NO_UNROLL_LOOP_START8753 while ( output <= end_output )8754 {8755 STBIR_SIMD_NO_UNROLL(encode);8756
9 unmodified lines
8766 #endif87678768 // do the remnants8769 #if stbir__coder_min_num < 48770 STBIR_NO_UNROLL_LOOP_START8771 while( output < end_output )8772 {8773 STBIR_NO_UNROLL(encode);8774 output[0] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order0] );
37 unmodified lines
8812 if ( width_times_channels >= 16 )8813 {8814 float const * end_encode_m16 = encode + width_times_channels - 16;8815 end_output -= 16;8816 STBIR_SIMD_NO_UNROLL_LOOP_START8817 for(;;)8818 {8819 stbir__simdf f0, f1, f2, f3;8820 stbir__simdi i0, i1, i2, i3;
27 unmodified lines
8848 return;8849 }8850 #endif88518852 STBIR_SIMD_NO_UNROLL_LOOP_START8853 do {8854 float f;8855 STBIR_SIMD_NO_UNROLL(encode);8856
47 unmodified lines
8904 if ( width_times_channels >= 16 )8905 {8906 float const * end_encode_m16 = encode + width_times_channels - 16;8907 end_output -= 16;8908 STBIR_SIMD_NO_UNROLL_LOOP_START8909 for(;;)8910 {8911 stbir__simdf f0, f1, f2, f3;8912 stbir__simdi i0, i1, i2, i3;
25 unmodified lines
8938 return;8939 }8940 #endif89418942 STBIR_SIMD_NO_UNROLL_LOOP_START8943 do {8944 float f;8945 STBIR_SIMD_NO_UNROLL(encode);8946
20 unmodified lines
8967 unsigned short const * end_input_m8 = input + width_times_channels - 8;8968 if ( width_times_channels >= 8 )8969 {8970 decode_end -= 8;8971 STBIR_NO_UNROLL_LOOP_START8972 for(;;)8973 {8974 #ifdef STBIR_SIMD88975 stbir__simdi i; stbir__simdi8 o;
35 unmodified lines
90119012 // try to do blocks of 4 when you can9013 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9014 decode += 4;9015 STBIR_SIMD_NO_UNROLL_LOOP_START9016 while( decode <= decode_end )9017 {9018 STBIR_SIMD_NO_UNROLL(decode);9019 decode[0-4] = ((float)(input[stbir__decode_order0])) * stbir__max_uint16_as_float_inverted;
7 unmodified lines
9027 #endif90289029 // do the remnants9030 #if stbir__coder_min_num < 49031 STBIR_NO_UNROLL_LOOP_START9032 while( decode < decode_end )9033 {9034 STBIR_NO_UNROLL(decode);9035 decode[0] = ((float)(input[stbir__decode_order0])) * stbir__max_uint16_as_float_inverted;
20 unmodified lines
9056 if ( width_times_channels >= stbir__simdfX_float_count*2 )9057 {9058 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;9059 end_output -= stbir__simdfX_float_count*2;9060 STBIR_SIMD_NO_UNROLL_LOOP_START9061 for(;;)9062 {9063 stbir__simdfX e0, e1;9064 stbir__simdiX i;
19 unmodified lines
90849085 // try to do blocks of 4 when you can9086 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9087 output += 4;9088 STBIR_NO_UNROLL_LOOP_START9089 while( output <= end_output )9090 {9091 stbir__simdf e;9092 stbir__simdi i;
10 unmodified lines
9103 #endif91049105 // do the remnants9106 #if stbir__coder_min_num < 49107 STBIR_NO_UNROLL_LOOP_START9108 while( output < end_output )9109 {9110 stbir__simdf e;9111 STBIR_NO_UNROLL(encode);
13 unmodified lines
91259126 // try to do blocks of 4 when you can9127 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9128 output += 4;9129 STBIR_SIMD_NO_UNROLL_LOOP_START9130 while( output <= end_output )9131 {9132 float f;9133 STBIR_SIMD_NO_UNROLL(encode);
8 unmodified lines
9142 #endif91439144 // do the remnants9145 #if stbir__coder_min_num < 49146 STBIR_NO_UNROLL_LOOP_START9147 while( output < end_output )9148 {9149 float f;9150 STBIR_NO_UNROLL(encode);
21 unmodified lines
9172 unsigned short const * end_input_m8 = input + width_times_channels - 8;9173 if ( width_times_channels >= 8 )9174 {9175 decode_end -= 8;9176 STBIR_NO_UNROLL_LOOP_START9177 for(;;)9178 {9179 #ifdef STBIR_SIMD89180 stbir__simdi i; stbir__simdi8 o;
32 unmodified lines
92139214 // try to do blocks of 4 when you can9215 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9216 decode += 4;9217 STBIR_SIMD_NO_UNROLL_LOOP_START9218 while( decode <= decode_end )9219 {9220 STBIR_SIMD_NO_UNROLL(decode);9221 decode[0-4] = ((float)(input[stbir__decode_order0]));
7 unmodified lines
9229 #endif92309231 // do the remnants9232 #if stbir__coder_min_num < 49233 STBIR_NO_UNROLL_LOOP_START9234 while( decode < decode_end )9235 {9236 STBIR_NO_UNROLL(decode);9237 decode[0] = ((float)(input[stbir__decode_order0]));
19 unmodified lines
9257 if ( width_times_channels >= stbir__simdfX_float_count*2 )9258 {9259 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;9260 end_output -= stbir__simdfX_float_count*2;9261 STBIR_SIMD_NO_UNROLL_LOOP_START9262 for(;;)9263 {9264 stbir__simdfX e0, e1;9265 stbir__simdiX i;
19 unmodified lines
92859286 // try to do blocks of 4 when you can9287 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9288 output += 4;9289 STBIR_NO_UNROLL_LOOP_START9290 while( output <= end_output )9291 {9292 stbir__simdf e;9293 stbir__simdi i;
13 unmodified lines
93079308 // try to do blocks of 4 when you can9309 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9310 output += 4;9311 STBIR_SIMD_NO_UNROLL_LOOP_START9312 while( output <= end_output )9313 {9314 float f;9315 STBIR_SIMD_NO_UNROLL(encode);
10 unmodified lines
9326 #endif93279328 // do the remnants9329 #if stbir__coder_min_num < 49330 STBIR_NO_UNROLL_LOOP_START9331 while( output < end_output )9332 {9333 float f;9334 STBIR_NO_UNROLL(encode);
20 unmodified lines
9355 if ( width_times_channels >= 8 )9356 {9357 stbir__FP16 const * end_input_m8 = input + width_times_channels - 8;9358 decode_end -= 8;9359 STBIR_NO_UNROLL_LOOP_START9360 for(;;)9361 {9362 STBIR_NO_UNROLL(decode);9363
33 unmodified lines
93979398 // try to do blocks of 4 when you can9399 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9400 decode += 4;9401 STBIR_SIMD_NO_UNROLL_LOOP_START9402 while( decode <= decode_end )9403 {9404 STBIR_SIMD_NO_UNROLL(decode);9405 decode[0-4] = stbir__half_to_float(input[stbir__decode_order0]);
7 unmodified lines
9413 #endif94149415 // do the remnants9416 #if stbir__coder_min_num < 49417 STBIR_NO_UNROLL_LOOP_START9418 while( decode < decode_end )9419 {9420 STBIR_NO_UNROLL(decode);9421 decode[0] = stbir__half_to_float(input[stbir__decode_order0]);
18 unmodified lines
9440 if ( width_times_channels >= 8 )9441 {9442 float const * end_encode_m8 = encode + width_times_channels - 8;9443 end_output -= 8;9444 STBIR_SIMD_NO_UNROLL_LOOP_START9445 for(;;)9446 {9447 STBIR_SIMD_NO_UNROLL(encode);9448 #ifdef stbir__decode_swizzle
32 unmodified lines
94819482 // try to do blocks of 4 when you can9483 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9484 output += 4;9485 STBIR_SIMD_NO_UNROLL_LOOP_START9486 while( output <= end_output )9487 {9488 STBIR_SIMD_NO_UNROLL(output);9489 output[0-4] = stbir__float_to_half(encode[stbir__encode_order0]);
7 unmodified lines
9497 #endif94989499 // do the remnants9500 #if stbir__coder_min_num < 49501 STBIR_NO_UNROLL_LOOP_START9502 while( output < end_output )9503 {9504 STBIR_NO_UNROLL(output);9505 output[0] = stbir__float_to_half(encode[stbir__encode_order0]);
20 unmodified lines
9526 if ( width_times_channels >= 16 )9527 {9528 float const * end_input_m16 = input + width_times_channels - 16;9529 decode_end -= 16;9530 STBIR_NO_UNROLL_LOOP_START9531 for(;;)9532 {9533 STBIR_NO_UNROLL(decode);9534 #ifdef stbir__decode_swizzle
40 unmodified lines
95759576 // try to do blocks of 4 when you can9577 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9578 decode += 4;9579 STBIR_SIMD_NO_UNROLL_LOOP_START9580 while( decode <= decode_end )9581 {9582 STBIR_SIMD_NO_UNROLL(decode);9583 decode[0-4] = input[stbir__decode_order0];
7 unmodified lines
9591 #endif95929593 // do the remnants9594 #if stbir__coder_min_num < 49595 STBIR_NO_UNROLL_LOOP_START9596 while( decode < decode_end )9597 {9598 STBIR_NO_UNROLL(decode);9599 decode[0] = input[stbir__decode_order0];
51 unmodified lines
9651 if ( width_times_channels >= ( stbir__simdfX_float_count * 2 ) )9652 {9653 float const * end_encode_m8 = encode + width_times_channels - ( stbir__simdfX_float_count * 2 );9654 end_output -= ( stbir__simdfX_float_count * 2 );9655 STBIR_SIMD_NO_UNROLL_LOOP_START9656 for(;;)9657 {9658 stbir__simdfX e0, e1;9659 STBIR_SIMD_NO_UNROLL(encode);
25 unmodified lines
96859686 // try to do blocks of 4 when you can9687 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9688 output += 4;9689 STBIR_NO_UNROLL_LOOP_START9690 while( output <= end_output )9691 {9692 stbir__simdf e0;9693 STBIR_NO_UNROLL(encode);
16 unmodified lines
97109711 // try to do blocks of 4 when you can9712 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four9713 output += 4;9714 STBIR_SIMD_NO_UNROLL_LOOP_START9715 while( output <= end_output )9716 {9717 float e;9718 STBIR_SIMD_NO_UNROLL(encode);
11 unmodified lines
9730 #endif97319732 // do the remnants9733 #if stbir__coder_min_num < 49734 STBIR_NO_UNROLL_LOOP_START9735 while( output < end_output )9736 {9737 float e;9738 STBIR_NO_UNROLL(encode);
102 unmodified lines
9841 stbIF4(stbir__simdfX c4 = stbir__simdf_frepX( c4s ); )9842 stbIF5(stbir__simdfX c5 = stbir__simdf_frepX( c5s ); )9843 stbIF6(stbir__simdfX c6 = stbir__simdf_frepX( c6s ); )9844 stbIF7(stbir__simdfX c7 = stbir__simdf_frepX( c7s ); )9845 STBIR_SIMD_NO_UNROLL_LOOP_START9846 while ( ( (char*)input_end - (char*) input ) >= (16*stbir__simdfX_float_count) )9847 {9848 stbir__simdfX o0, o1, o2, o3, r0, r1, r2, r3;9849 STBIR_SIMD_NO_UNROLL(output0);
46 unmodified lines
98969897 input += (4*stbir__simdfX_float_count);9898 stbIF0( output0 += (4*stbir__simdfX_float_count); ) stbIF1( output1 += (4*stbir__simdfX_float_count); ) stbIF2( output2 += (4*stbir__simdfX_float_count); ) stbIF3( output3 += (4*stbir__simdfX_float_count); ) stbIF4( output4 += (4*stbir__simdfX_float_count); ) stbIF5( output5 += (4*stbir__simdfX_float_count); ) stbIF6( output6 += (4*stbir__simdfX_float_count); ) stbIF7( output7 += (4*stbir__simdfX_float_count); )9899 }9900 STBIR_SIMD_NO_UNROLL_LOOP_START9901 while ( ( (char*)input_end - (char*) input ) >= 16 )9902 {9903 stbir__simdf o0, r0;9904 STBIR_SIMD_NO_UNROLL(output0);
24 unmodified lines
9929 stbIF0( output0 += 4; ) stbIF1( output1 += 4; ) stbIF2( output2 += 4; ) stbIF3( output3 += 4; ) stbIF4( output4 += 4; ) stbIF5( output5 += 4; ) stbIF6( output6 += 4; ) stbIF7( output7 += 4; )9930 }9931 }9932 #else9933 STBIR_NO_UNROLL_LOOP_START9934 while ( ( (char*)input_end - (char*) input ) >= 16 )9935 {9936 float r0, r1, r2, r3;9937 STBIR_NO_UNROLL(input);
23 unmodified lines
9961 input += 4;9962 stbIF0( output0 += 4; ) stbIF1( output1 += 4; ) stbIF2( output2 += 4; ) stbIF3( output3 += 4; ) stbIF4( output4 += 4; ) stbIF5( output5 += 4; ) stbIF6( output6 += 4; ) stbIF7( output7 += 4; )9963 }9964 #endif9965 STBIR_NO_UNROLL_LOOP_START9966 while ( input < input_end )9967 {9968 float r = input[0];9969 STBIR_NO_UNROLL(output0);
55 unmodified lines
10025 stbIF5(stbir__simdfX c5 = stbir__simdf_frepX( c5s ); )10026 stbIF6(stbir__simdfX c6 = stbir__simdf_frepX( c6s ); )10027 stbIF7(stbir__simdfX c7 = stbir__simdf_frepX( c7s ); )1002810029 STBIR_SIMD_NO_UNROLL_LOOP_START10030 while ( ( (char*)input0_end - (char*) input0 ) >= (16*stbir__simdfX_float_count) )10031 {10032 stbir__simdfX o0, o1, o2, o3, r0, r1, r2, r3;10033 STBIR_SIMD_NO_UNROLL(output);
36 unmodified lines
10070 output += (4*stbir__simdfX_float_count);10071 stbIF0( input0 += (4*stbir__simdfX_float_count); ) stbIF1( input1 += (4*stbir__simdfX_float_count); ) stbIF2( input2 += (4*stbir__simdfX_float_count); ) stbIF3( input3 += (4*stbir__simdfX_float_count); ) stbIF4( input4 += (4*stbir__simdfX_float_count); ) stbIF5( input5 += (4*stbir__simdfX_float_count); ) stbIF6( input6 += (4*stbir__simdfX_float_count); ) stbIF7( input7 += (4*stbir__simdfX_float_count); )10072 }1007310074 STBIR_SIMD_NO_UNROLL_LOOP_START10075 while ( ( (char*)input0_end - (char*) input0 ) >= 16 )10076 {10077 stbir__simdf o0, r0;10078 STBIR_SIMD_NO_UNROLL(output);
16 unmodified lines
10095 stbIF0( input0 += 4; ) stbIF1( input1 += 4; ) stbIF2( input2 += 4; ) stbIF3( input3 += 4; ) stbIF4( input4 += 4; ) stbIF5( input5 += 4; ) stbIF6( input6 += 4; ) stbIF7( input7 += 4; )10096 }10097 }10098 #else10099 STBIR_NO_UNROLL_LOOP_START10100 while ( ( (char*)input0_end - (char*) input0 ) >= 16 )10101 {10102 float o0, o1, o2, o3;10103 STBIR_NO_UNROLL(output);
13 unmodified lines
10117 output += 4;10118 stbIF0( input0 += 4; ) stbIF1( input1 += 4; ) stbIF2( input2 += 4; ) stbIF3( input3 += 4; ) stbIF4( input4 += 4; ) stbIF5( input5 += 4; ) stbIF6( input6 += 4; ) stbIF7( input7 += 4; )10119 }10120 #endif10121 STBIR_NO_UNROLL_LOOP_START10122 while ( input0 < input0_end )10123 {10124 float o0;10125 STBIR_NO_UNROLL(output);
84 unmodified lines
10210static void STBIR_chans( stbir__horizontal_gather_,_channels_with_1_coeff)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10211{10212 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10213 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10214 STBIR_SIMD_NO_UNROLL_LOOP_START10215 do {10216 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10217 float const * hc = horizontal_coefficients;10218 stbir__1_coeff_only();
4 unmodified lines
10223static void STBIR_chans( stbir__horizontal_gather_,_channels_with_2_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10224{10225 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10226 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10227 STBIR_SIMD_NO_UNROLL_LOOP_START10228 do {10229 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10230 float const * hc = horizontal_coefficients;10231 stbir__2_coeff_only();
4 unmodified lines
10236static void STBIR_chans( stbir__horizontal_gather_,_channels_with_3_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10237{10238 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10239 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10240 STBIR_SIMD_NO_UNROLL_LOOP_START10241 do {10242 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10243 float const * hc = horizontal_coefficients;10244 stbir__3_coeff_only();
4 unmodified lines
10249static void STBIR_chans( stbir__horizontal_gather_,_channels_with_4_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10250{10251 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10252 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10253 STBIR_SIMD_NO_UNROLL_LOOP_START10254 do {10255 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10256 float const * hc = horizontal_coefficients;10257 stbir__4_coeff_start();
4 unmodified lines
10262static void STBIR_chans( stbir__horizontal_gather_,_channels_with_5_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10263{10264 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10265 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10266 STBIR_SIMD_NO_UNROLL_LOOP_START10267 do {10268 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10269 float const * hc = horizontal_coefficients;10270 stbir__4_coeff_start();
5 unmodified lines
10276static void STBIR_chans( stbir__horizontal_gather_,_channels_with_6_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10277{10278 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10279 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10280 STBIR_SIMD_NO_UNROLL_LOOP_START10281 do {10282 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10283 float const * hc = horizontal_coefficients;10284 stbir__4_coeff_start();
6 unmodified lines
10291{10292 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10293 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10294 stbir__3_coeff_setup();10295 STBIR_SIMD_NO_UNROLL_LOOP_START10296 do {10297 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10298 float const * hc = horizontal_coefficients;10299
6 unmodified lines
10306static void STBIR_chans( stbir__horizontal_gather_,_channels_with_8_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10307{10308 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10309 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10310 STBIR_SIMD_NO_UNROLL_LOOP_START10311 do {10312 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10313 float const * hc = horizontal_coefficients;10314 stbir__4_coeff_start();
5 unmodified lines
10320static void STBIR_chans( stbir__horizontal_gather_,_channels_with_9_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10321{10322 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10323 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10324 STBIR_SIMD_NO_UNROLL_LOOP_START10325 do {10326 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10327 float const * hc = horizontal_coefficients;10328 stbir__4_coeff_start();
6 unmodified lines
10335static void STBIR_chans( stbir__horizontal_gather_,_channels_with_10_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10336{10337 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10338 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10339 STBIR_SIMD_NO_UNROLL_LOOP_START10340 do {10341 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10342 float const * hc = horizontal_coefficients;10343 stbir__4_coeff_start();
7 unmodified lines
10351{10352 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10353 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10354 stbir__3_coeff_setup();10355 STBIR_SIMD_NO_UNROLL_LOOP_START10356 do {10357 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10358 float const * hc = horizontal_coefficients;10359 stbir__4_coeff_start();
6 unmodified lines
10366static void STBIR_chans( stbir__horizontal_gather_,_channels_with_12_coeffs)( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10367{10368 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10369 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10370 STBIR_SIMD_NO_UNROLL_LOOP_START10371 do {10372 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10373 float const * hc = horizontal_coefficients;10374 stbir__4_coeff_start();
6 unmodified lines
10381static void STBIR_chans( stbir__horizontal_gather_,_channels_with_n_coeffs_mod0 )( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10382{10383 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10384 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10385 STBIR_SIMD_NO_UNROLL_LOOP_START10386 do {10387 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10388 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 4 + 3 ) >> 2;10389 float const * hc = horizontal_coefficients;1039010391 stbir__4_coeff_start();10392 STBIR_SIMD_NO_UNROLL_LOOP_START10393 do {10394 hc += 4;10395 decode += STBIR__horizontal_channels * 4;10396 stbir__4_coeff_continue_from_4( 0 );
6 unmodified lines
10403static void STBIR_chans( stbir__horizontal_gather_,_channels_with_n_coeffs_mod1 )( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10404{10405 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10406 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10407 STBIR_SIMD_NO_UNROLL_LOOP_START10408 do {10409 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10410 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 5 + 3 ) >> 2;10411 float const * hc = horizontal_coefficients;1041210413 stbir__4_coeff_start();10414 STBIR_SIMD_NO_UNROLL_LOOP_START10415 do {10416 hc += 4;10417 decode += STBIR__horizontal_channels * 4;10418 stbir__4_coeff_continue_from_4( 0 );
7 unmodified lines
10426static void STBIR_chans( stbir__horizontal_gather_,_channels_with_n_coeffs_mod2 )( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer, stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width )10427{10428 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10429 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10430 STBIR_SIMD_NO_UNROLL_LOOP_START10431 do {10432 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10433 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 6 + 3 ) >> 2;10434 float const * hc = horizontal_coefficients;1043510436 stbir__4_coeff_start();10437 STBIR_SIMD_NO_UNROLL_LOOP_START10438 do {10439 hc += 4;10440 decode += STBIR__horizontal_channels * 4;10441 stbir__4_coeff_continue_from_4( 0 );
9 unmodified lines
10451{10452 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;10453 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;10454 stbir__3_coeff_setup();10455 STBIR_SIMD_NO_UNROLL_LOOP_START10456 do {10457 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;10458 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 7 + 3 ) >> 2;10459 float const * hc = horizontal_coefficients;1046010461 stbir__4_coeff_start();10462 STBIR_SIMD_NO_UNROLL_LOOP_START10463 do {10464 hc += 4;10465 decode += STBIR__horizontal_channels * 4;10466 stbir__4_coeff_continue_from_4( 0 );
95 unmodified lines
modified:stb_image.h+6 added-3 removed
1/* stb_image - v2.29 - public domain image loader - http://nothings.org/stb1/* stb_image - v2.30 - public domain image loader - http://nothings.org/stb2 no warranty implied; use at your own risk34 Do this:5 #define STB_IMAGE_IMPLEMENTATION
41 unmodified lines
47 See end of file for license information.4849RECENT REVISION HISTORY:5051 2.30 (2024-05-31) avoid erroneous gcc warning52 2.29 (2023-05-xx) optimizations53 2.28 (2023-01-29) many error fixes, security errors, just tons of stuff54 2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes55 2.26 (2020-07-13) many minor fixes
5103 unmodified lines
5159 has_trans = 1;5160 // non-paletted with tRNS = constant alpha. if header-scanning, we can stop now.5161 if (scan == STBI__SCAN_header) { ++s->img_n; return 1; }5162 if (z->depth == 16) {5162 for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is5163 for (k = 0; k < s->img_n && k < 3; ++k) // extra loop test to suppress false GCC warning5164 tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is5165 } else {5166 for (k = 0; k < s->img_n && k < 3; ++k)5164 for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger5167 tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger5168 }5169 }5170 break;5171 }
2817 unmodified lines