Resize 2.13 -
Before adoption: this commit came in with the history the project adopted, so no landing records it.
fixed a bug when using input callbacks, turned off simd for tiny-c, fixed some variables that should have been static, fixes a bug when calculating temp memory with resizes that exceed 2GB of temp memory (very large resizes).
authored by Jeff Roberts (LA) · committed by Jeff Roberts (LA) · parent 5c20573 · Browse files · 1 file·+144 added−129 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+144 added−129 removed
- other:+144 added−129 removed
Provenance
- Commit
adc1672- Tree
6899e37- Author
Jeff Roberts (LA) <jeffr@radgametools.com>- Committer
Jeff Roberts (LA) <jeffr@radgametools.com>- Parent
5c20573
1 file changed+144 added−129 removed
modified:stb_image_resize2.h+144 added-129 removed
1-/* stb_image_resize2 - v2.12 - public domain image resizing1+/* stb_image_resize2 - v2.13 - public domain image resizing2 3 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5 247 unmodified lines253 filters, see the stbir_filter enum. You can install your own filters by254 using the stbir_set_filter_callbacks function.255 256 PROGRESS257- For interactive use with slow resize operations, you can use the the257+ For interactive use with slow resize operations, you can use the 258 scanline callbacks in the extended API. It would have to be a *very* large259 image resample to need progress though - we're very fast.260 261 CEIL and FLOOR44 unmodified lines306 L2 cache. Maybe do chunks of 1K pixels at a time. There would be307 some pixel reconversion, but probably dwarfed by things falling out308 of cache. Probably also something possible with alternating between309 scattering and gathering at high resize scales?310+ * Should we have a multiple MIPs at the same time function (could keep311+ more memory in cache during multiple resizes)?312 * Rewrite the coefficient generator to do many at once.313 * AVX-512 vertical kernels - worried about downclocking here.314 * Convert the reincludes to macros when we know they aren't changing.315 * Experiment with pivoting the horizontal and always using the12 unmodified lines328 Aras Pranckevicius: bugfixes329 Nathan Reed: warning fixes for 1.0330 331 REVISIONS332+ 2.13 (2025-02-27) fixed a bug when using input callbacks, turned off simd for 333+ tiny-c, fixed some variables that should have been static,334+ fixes a bug when calculating temp memory with resizes that335+ exceed 2GB of temp memory (very large resizes).336 2.12 (2024-10-18) fix incorrect use of user_data with STBIR_FREE337 2.11 (2024-09-08) fix harmless asan warnings in 2-channel and 3-channel mode338 with AVX-2, fix some weird scaling edge conditions with339 point sample mode.47 unmodified lines387 typedef uint32_t stbir_uint32;388 typedef uint64_t stbir_uint64;389 #endif390 385-#ifdef _M_IX86_FP386-#if ( _M_IX86_FP >= 1 )387-#ifndef STBIR_SSE388-#define STBIR_SSE389-#endif390-#endif391-#endif392-393-#if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(_M_AMD64) || defined(__SSE2__) || defined(STBIR_SSE) || defined(STBIR_SSE2)394- #ifndef STBIR_SSE2395- #define STBIR_SSE2396- #endif397- #if defined(__AVX__) || defined(STBIR_AVX2)398- #ifndef STBIR_AVX399- #ifndef STBIR_NO_AVX400- #define STBIR_AVX401- #endif402- #endif403- #endif404- #if defined(__AVX2__) || defined(STBIR_AVX2)405- #ifndef STBIR_NO_AVX2406- #ifndef STBIR_AVX2407- #define STBIR_AVX2408- #endif409- #if defined( _MSC_VER ) && !defined(__clang__)410- #ifndef STBIR_FP16C // FP16C instructions are on all AVX2 cpus, so we can autoselect it here on microsoft - clang needs -m16c411- #define STBIR_FP16C412- #endif413- #endif414- #endif415- #endif416- #ifdef __F16C__417- #ifndef STBIR_FP16C // turn on FP16C instructions if the define is set (for clang and gcc)418- #define STBIR_FP16C419- #endif420- #endif421-#endif422-423-#if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || ((__ARM_NEON_FP & 4) != 0) || defined(__ARM_NEON__)424-#ifndef STBIR_NEON425-#define STBIR_NEON426-#endif427-#endif428-429-#if defined(_M_ARM) || defined(__arm__)430-#ifdef STBIR_USE_FMA431-#undef STBIR_USE_FMA // no FMA for 32-bit arm on MSVC432-#endif433-#endif434-435-#if defined(__wasm__) && defined(__wasm_simd128__)436-#ifndef STBIR_WASM437-#define STBIR_WASM438-#endif439-#endif440-391 #ifndef STBIRDEF392 #ifdef STB_IMAGE_RESIZE_STATIC393 #define STBIRDEF static394 #else590 unmodified lines985 986 char no_cache_straddle[64];987 } stbir__per_split_info;988 1039-typedef void stbir__decode_pixels_func( float * decode, int width_times_channels, void const * input );989+typedef float * stbir__decode_pixels_func( float * decode, int width_times_channels, void const * input );990 typedef void stbir__alpha_weight_func( float * decode_buffer, int width_times_channels );991 typedef void stbir__horizontal_gather_channels_func( float * output_buffer, unsigned int output_sub_size, float const * decode_buffer,992 stbir__contributors const * horizontal_contributors, float const * horizontal_coefficients, int coefficient_width );993 typedef void stbir__alpha_unweight_func(float * encode_buffer, int width_times_channels );160 unmodified lines1154 #ifndef STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS1155 #define STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS 4 // when threading, what is the minimum number of scanlines for a split?1156 #endif1157 1158+#define STBIR_INPUT_CALLBACK_PADDING 31159+1160+#ifdef _M_IX86_FP1161+#if ( _M_IX86_FP >= 1 )1162+#ifndef STBIR_SSE1163+#define STBIR_SSE1164+#endif1165+#endif1166+#endif1167+1168+#ifdef __TINYC__1169+ // tiny c has no intrinsics yet - this can become a version check if they add them1170+ #define STBIR_NO_SIMD1171+#endif1172+1173+#if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(_M_AMD64) || defined(__SSE2__) || defined(STBIR_SSE) || defined(STBIR_SSE2)1174+ #ifndef STBIR_SSE21175+ #define STBIR_SSE21176+ #endif1177+ #if defined(__AVX__) || defined(STBIR_AVX2)1178+ #ifndef STBIR_AVX1179+ #ifndef STBIR_NO_AVX1180+ #define STBIR_AVX1181+ #endif1182+ #endif1183+ #endif1184+ #if defined(__AVX2__) || defined(STBIR_AVX2)1185+ #ifndef STBIR_NO_AVX21186+ #ifndef STBIR_AVX21187+ #define STBIR_AVX21188+ #endif1189+ #if defined( _MSC_VER ) && !defined(__clang__)1190+ #ifndef STBIR_FP16C // FP16C instructions are on all AVX2 cpus, so we can autoselect it here on microsoft - clang needs -m16c1191+ #define STBIR_FP16C1192+ #endif1193+ #endif1194+ #endif1195+ #endif1196+ #ifdef __F16C__1197+ #ifndef STBIR_FP16C // turn on FP16C instructions if the define is set (for clang and gcc)1198+ #define STBIR_FP16C1199+ #endif1200+ #endif1201+#endif1202+1203+#if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || ((__ARM_NEON_FP & 4) != 0) || defined(__ARM_NEON__)1204+#ifndef STBIR_NEON1205+#define STBIR_NEON1206+#endif1207+#endif1208+1209+#if defined(_M_ARM) || defined(__arm__)1210+#ifdef STBIR_USE_FMA1211+#undef STBIR_USE_FMA // no FMA for 32-bit arm on MSVC1212+#endif1213+#endif1214+1215+#if defined(__wasm__) && defined(__wasm_simd128__)1216+#ifndef STBIR_WASM1217+#define STBIR_WASM1218+#endif1219+#endif1220+1221 // restrict pointers for the output pointers, other loop and unroll control1222 #if defined( _MSC_VER ) && !defined(__clang__)1223 #define STBIR_STREAMOUT_PTR( star ) star __restrict1224 #define STBIR_NO_UNROLL( ptr ) __assume(ptr) // this oddly keeps msvc from unrolling a loop238 unmodified lines1463 #if defined(STBIR_AVX) || defined(__SSE4_1__)1464 #include <smmintrin.h>1465 #define stbir__simdf_pack_to_8words(out,reg0,reg1) out = _mm_packus_epi32(_mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(reg0,STBIR__CONSTF(STBIR_max_uint16_as_float)),_mm_setzero_ps())), _mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(reg1,STBIR__CONSTF(STBIR_max_uint16_as_float)),_mm_setzero_ps())))1466 #else1454- STBIR__SIMDI_CONST(stbir__s32_32768, 32768);1455- STBIR__SIMDI_CONST(stbir__s16_32768, ((32768<<16)|32768));1467+ static STBIR__SIMDI_CONST(stbir__s32_32768, 32768);1468+ static STBIR__SIMDI_CONST(stbir__s16_32768, ((32768<<16)|32768));1469 1470 #define stbir__simdf_pack_to_8words(out,reg0,reg1) \1471 { \1472 stbir__simdi tmp0,tmp1; \1756 unmodified lines3229 newspan->pixel_offset_for_input = min_left;3230 newspan->n0 = -left_margin;3231 newspan->n1 = ( max_left - min_left ) - left_margin;3232 scanline_extents->edge_sizes[0] = 0; // don't need to copy the left margin, since we are directly decoding into the margin3220- return;3233 }3222-3234 // if we can't merge the min_left range, add it as a second range3235+ else 3236 if ( ( right_margin ) && ( min_right != 0x7fffffff ) )3237 {3238 stbir__span * newspan = scanline_extents->spans + 1;3239 if ( min_right < scanline_extents->spans[0].n0 )6 unmodified lines3246 newspan->pixel_offset_for_input = min_right;3247 newspan->n0 = scanline_extents->spans[1].n1 + 1;3248 newspan->n1 = scanline_extents->spans[1].n1 + 1 + ( max_right - min_right );3249 scanline_extents->edge_sizes[1] = 0; // don't need to copy the right margin, since we are directly decoding into the margin3238- return;3250 }3251+3252+ // sort the spans into write output order3253+ if ( ( scanline_extents->spans[1].n1 > scanline_extents->spans[1].n0 ) && ( scanline_extents->spans[0].n0 > scanline_extents->spans[1].n0 ) )3254+ {3255+ stbir__span tspan = scanline_extents->spans[0];3256+ scanline_extents->spans[0] = scanline_extents->spans[1];3257+ scanline_extents->spans[1] = tspan;3258+ }3259 }3260 3261 static void stbir__calculate_in_pixel_range( int * first_pixel, int * last_pixel, float out_pixel_center, float out_filter_radius, float inv_scale, float out_shift, int input_size, stbir_edge edge )3262 {1315 unmodified lines4578 stbir_edge edge_vertical = stbir_info->vertical.edge;4579 int row = stbir__edge_wrap(edge_vertical, n, stbir_info->vertical.scale_info.input_full_size);4580 const void* input_plane_data = ( (char *) stbir_info->input_data ) + (size_t)row * (size_t) stbir_info->input_stride_bytes;4581 stbir__span const * spans = stbir_info->scanline_extents.spans;4563- float* full_decode_buffer = output_buffer - stbir_info->scanline_extents.conservative.n0 * effective_channels;4582+ float * full_decode_buffer = output_buffer - stbir_info->scanline_extents.conservative.n0 * effective_channels;4583+ float * last_decoded = 0;4584 4585 // if we are on edge_zero, and we get in here with an out of bounds n, then the calculate filters has failed4586 STBIR_ASSERT( !(edge_vertical == STBIR_EDGE_ZERO && (n < 0 || n >= stbir_info->vertical.scale_info.input_full_size)) );4587 19 unmodified lines4607 // if we have an input callback, call it to get the input data4608 if ( stbir_info->in_pixels_cb )4609 {4610 // call the callback with a temp buffer (that they can choose to use or not). the temp is just right aligned memory in the decode_buffer itself4591- input_data = stbir_info->in_pixels_cb( ( (char*) end_decode ) - ( width * input_sample_in_bytes ), input_plane_data, width, spans->pixel_offset_for_input, row, stbir_info->user_data );4611+ input_data = stbir_info->in_pixels_cb( ( (char*) end_decode ) - ( width * input_sample_in_bytes ) + sizeof(float)*STBIR_INPUT_CALLBACK_PADDING, input_plane_data, width, spans->pixel_offset_for_input, row, stbir_info->user_data );4612 }4613 4614 STBIR_PROFILE_START( decode );4615 // convert the pixels info the float decode_buffer, (we index from end_decode, so that when channels<effective_channels, we are right justified in the buffer)4596- stbir_info->decode_pixels( (float*)end_decode - width_times_channels, width_times_channels, input_data );4616+ last_decoded = stbir_info->decode_pixels( (float*)end_decode - width_times_channels, width_times_channels, input_data );4617 STBIR_PROFILE_END( decode );4618 4619 if (stbir_info->alpha_weight)4620 {26 unmodified lines4647 int x = start_x[e];4648 float * marg = full_decode_buffer + x * effective_channels;4649 float const * src = full_decode_buffer + stbir__edge_wrap(edge_horizontal, x, input_full_size) * effective_channels;4650 STBIR_MEMCPY( marg, src, margin * effective_channels * sizeof(float) );4651+ if ( e == 1 ) last_decoded = marg + margin * effective_channels;4652 }4653 }4654 }4655+ 4656+ // some of the horizontal gathers read one float off the edge (which is masked out), but we force a zero here to make sure no NaNs leak in4657+ // (we can't pre-zero it, because the input callback can use that area as padding)4658+ last_decoded[0] = 0.0f; 4659+4660+ // we clear this extra float, because the final output pixel filter kernel might have used one less coeff than the max filter width4661+ // when this happens, we do read that pixel from the input, so it too could be Nan, so just zero an extra one.4662+ // this fits because each scanline is padded by three floats (STBIR_INPUT_CALLBACK_PADDING)4663+ last_decoded[1] = 0.0f;4664 }4665 4666 4667 //=================1923 unmodified lines6591 6592 samp->num_contributors = stbir__get_contributors(samp, samp->is_gather);6593 6594 samp->contributors_size = samp->num_contributors * sizeof(stbir__contributors);6565- samp->coefficients_size = samp->num_contributors * samp->coefficient_width * sizeof(float) + sizeof(float); // extra sizeof(float) is padding6595+ samp->coefficients_size = samp->num_contributors * samp->coefficient_width * sizeof(float) + sizeof(float)*STBIR_INPUT_CALLBACK_PADDING; // extra sizeof(float) is padding6596 6597 samp->gather_prescatter_contributors = 0;6598 samp->gather_prescatter_coefficients = 0;6599 if ( samp->is_gather == 0 )356 unmodified lines6956 stbir__info * info = 0;6957 void * alloced = 0;6958 size_t alloced_total = 0;6959 int vertical_first;6930- int decode_buffer_size, ring_buffer_length_bytes, ring_buffer_size, vertical_buffer_size, alloc_ring_buffer_num_entries;6960+ size_t decode_buffer_size, ring_buffer_length_bytes, ring_buffer_size, vertical_buffer_size;6961+ int alloc_ring_buffer_num_entries;6962 6963 int alpha_weighting_type = 0; // 0=none, 1=simple, 2=fancy6964 int conservative_split_output_size = stbir__get_max_split( splits, vertical->scale_info.output_sub_size );6965 stbir_internal_pixel_layout input_pixel_layout = stbir__pixel_layout_convert_public_to_internal[ input_pixel_layout_public ];36 unmodified lines7002 // get vertical first7003 vertical_first = stbir__should_do_vertical_first( stbir__compute_weights[ (int)stbir_channel_count_index[ effective_channels ] ], horizontal->filter_pixel_width, horizontal->scale_info.scale, horizontal->scale_info.output_sub_size, vertical->filter_pixel_width, vertical->scale_info.scale, vertical->scale_info.output_sub_size, vertical->is_gather, STBIR__V_FIRST_INFO_POINTER );7004 7005 // sometimes read one float off in some of the unrolled loops (with a weight of zero coeff, so it doesn't have an effect)7006+ // we use a few extra floats instead of just 1, so that input callback buffer can overlap with the decode buffer without7007+ // the conversion routines overwriting the callback input data.6975- decode_buffer_size = ( conservative->n1 - conservative->n0 + 1 ) * effective_channels * sizeof(float) + sizeof(float); // extra float for padding7008+ decode_buffer_size = ( conservative->n1 - conservative->n0 + 1 ) * effective_channels * sizeof(float) + sizeof(float)*STBIR_INPUT_CALLBACK_PADDING; // extra floats for input callback stagger7009 7010 #if defined( STBIR__SEPARATE_ALLOCATIONS ) && defined(STBIR_SIMD8)7011 if ( effective_channels == 3 )7012 decode_buffer_size += sizeof(float); // avx in 3 channel mode needs one float at the start of the buffer (only with separate allocations)7013 #endif7014 6982- ring_buffer_length_bytes = horizontal->scale_info.output_sub_size * effective_channels * sizeof(float) + sizeof(float); // extra float for padding7015+ ring_buffer_length_bytes = (size_t)horizontal->scale_info.output_sub_size * (size_t)effective_channels * sizeof(float) + sizeof(float); // extra float for padding7016 7017 // if we do vertical first, the ring buffer holds a whole decoded line7018 if ( vertical_first )7019 ring_buffer_length_bytes = ( decode_buffer_size + 15 ) & ~15;6 unmodified lines7026 // we never need more ring buffer entries than the scanlines we're outputting when in scatter mode7027 if ( ( !vertical->is_gather ) && ( alloc_ring_buffer_num_entries > conservative_split_output_size ) )7028 alloc_ring_buffer_num_entries = conservative_split_output_size;7029 6997- ring_buffer_size = alloc_ring_buffer_num_entries * ring_buffer_length_bytes;7030+ ring_buffer_size = (size_t)alloc_ring_buffer_num_entries * (size_t)ring_buffer_length_bytes;7031 7032 // The vertical buffer is used differently, depending on whether we are scattering7033 // the vertical scanlines, or gathering them.7034 // If scattering, it's used at the temp buffer to accumulate each output.7035 // If gathering, it's just the output buffer.7003- vertical_buffer_size = horizontal->scale_info.output_sub_size * effective_channels * sizeof(float) + sizeof(float); // extra float for padding7036+ vertical_buffer_size = (size_t)horizontal->scale_info.output_sub_size * (size_t)effective_channels * sizeof(float) + sizeof(float); // extra float for padding7037 7038 // we make two passes through this loop, 1st to add everything up, 2nd to allocate and init7039 for(;;)7040 {27 unmodified lines7068 info->effective_channels = effective_channels;7069 7070 info->offset_x = new_x;7071 info->offset_y = new_y;7039- info->alloc_ring_buffer_num_entries = alloc_ring_buffer_num_entries;7072+ info->alloc_ring_buffer_num_entries = (int)alloc_ring_buffer_num_entries;7073 info->ring_buffer_num_entries = 0;7041- info->ring_buffer_length_bytes = ring_buffer_length_bytes;7074+ info->ring_buffer_length_bytes = (int)ring_buffer_length_bytes;7075 info->splits = splits;7076 info->vertical_first = vertical_first;7077 7078 info->input_pixel_layout_internal = input_pixel_layout;72 unmodified lines7151 7152 // alloc memory for to-be-pivoted coeffs (if necessary)7153 if ( vertical->is_gather == 0 )7154 {7122- int both;7123- int temp_mem_amt;7155+ size_t both;7156+ size_t temp_mem_amt;7157 7158 // when in vertical scatter mode, we first build the coefficients in gather mode, and then pivot after,7159 // that means we need two buffers, so we try to use the decode buffer and ring buffer for this. if that7160 // is too small, we just allocate extra memory to use as this temp.7161 7129- both = vertical->gather_prescatter_contributors_size + vertical->gather_prescatter_coefficients_size;7162+ both = (size_t)vertical->gather_prescatter_contributors_size + (size_t)vertical->gather_prescatter_coefficients_size;7163 7164 #ifdef STBIR__SEPARATE_ALLOCATIONS7165 temp_mem_amt = decode_buffer_size;7166 1 unmodified line7168 if ( effective_channels == 3 )7169 --temp_mem_amt; // avx in 3 channel mode needs one float at the start of the buffer7170 #endif7171 #else7139- temp_mem_amt = ( decode_buffer_size + ring_buffer_size + vertical_buffer_size ) * splits;7172+ temp_mem_amt = (size_t)( decode_buffer_size + ring_buffer_size + vertical_buffer_size ) * (size_t)splits;7173 #endif7174 if ( temp_mem_amt >= both )7175 {7176 if ( info )86 unmodified lines7263 // we never need more ring buffer entries than the scanlines we're outputting7264 if ( ( !info->vertical.is_gather ) && ( info->ring_buffer_num_entries > conservative_split_output_size ) )7265 info->ring_buffer_num_entries = conservative_split_output_size;7266 STBIR_ASSERT( info->ring_buffer_num_entries <= info->alloc_ring_buffer_num_entries );7234-7235- // a few of the horizontal gather functions read past the end of the decode (but mask it out), 7236- // so put in normal values so no snans or denormals accidentally sneak in (also, in the ring 7237- // buffer for vertical first)7238- for( i = 0 ; i < splits ; i++ )7239- {7240- int t, ofs, start;7241-7242- ofs = decode_buffer_size / 4;7243-7244- #if defined( STBIR__SEPARATE_ALLOCATIONS ) && defined(STBIR_SIMD8)7245- if ( effective_channels == 3 ) 7246- --ofs; // avx in 3 channel mode needs one float at the start of the buffer, so we snap back for clearing7247- #endif7248-7249- start = ofs - 4;7250- if ( start < 0 ) start = 0;7251-7252- for( t = start ; t < ofs; t++ )7253- info->split_info[i].decode_buffer[ t ] = 9999.0f;7254-7255- if ( vertical_first )7256- {7257- int j;7258- for( j = 0; j < info->ring_buffer_num_entries ; j++ )7259- {7260- for( t = start ; t < ofs; t++ )7261- stbir__get_ring_buffer_entry( info, info->split_info + i, j )[ t ] = 9999.0f;7262- }7263- }7264- }7267 }7266-7268 #undef STBIR__NEXT_PTR7269 7270 7271 // is this the first time through loop?954 unmodified lines8226 #else8227 #define stbir__encode_simdfX_unflip stbir__encode_simdf4_unflip8228 #endif8229 8229-static void STBIR__CODER_NAME( stbir__decode_uint8_linear_scaled )( float * decodep, int width_times_channels, void const * inputp )8230+static float * STBIR__CODER_NAME( stbir__decode_uint8_linear_scaled )( float * decodep, int width_times_channels, void const * inputp )8231 {8232 float STBIR_STREAMOUT_PTR( * ) decode = decodep;8233 float * decode_end = (float*) decode + width_times_channels;8234 unsigned char const * input = (unsigned char const*)inputp;51 unmodified lines8286 break;8287 decode = decode_end; // backup and do last couple8288 input = end_input_m16;8289 }8289- return;8290+ return decode_end + 16;8291 }8292 #endif8293 8294 // try to do blocks of 4 when you can29 unmodified lines8324 decode += stbir__coder_min_num;8325 input += stbir__coder_min_num;8326 }8327 #endif8328+8329+ return decode_end;8330 }8331 8332 static void STBIR__CODER_NAME( stbir__encode_uint8_linear_scaled )( void * outputp, int width_times_channels, float const * encode )8333 {111 unmodified lines8445 #endif8446 #endif8447 }8448 8446-static void STBIR__CODER_NAME(stbir__decode_uint8_linear)( float * decodep, int width_times_channels, void const * inputp )8449+static float * STBIR__CODER_NAME(stbir__decode_uint8_linear)( float * decodep, int width_times_channels, void const * inputp )8450 {8451 float STBIR_STREAMOUT_PTR( * ) decode = decodep;8452 float * decode_end = (float*) decode + width_times_channels;8453 unsigned char const * input = (unsigned char const*)inputp;45 unmodified lines8499 break;8500 decode = decode_end; // backup and do last couple8501 input = end_input_m16;8502 }8500- return;8503+ return decode_end + 16;8504 }8505 #endif8506 8507 // try to do blocks of 4 when you can29 unmodified lines8537 decode += stbir__coder_min_num;8538 input += stbir__coder_min_num;8539 }8540 #endif8541+ return decode_end;8542 }8543 8544 static void STBIR__CODER_NAME( stbir__encode_uint8_linear )( void * outputp, int width_times_channels, float const * encode )8545 {93 unmodified lines8639 }8640 #endif8641 }8642 8639-static void STBIR__CODER_NAME(stbir__decode_uint8_srgb)( float * decodep, int width_times_channels, void const * inputp )8643+static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb)( float * decodep, int width_times_channels, void const * inputp )8644 {8645 float STBIR_STREAMOUT_PTR( * ) decode = decodep;8642- float const * decode_end = (float*) decode + width_times_channels;8646+ float * decode_end = (float*) decode + width_times_channels;8647 unsigned char const * input = (unsigned char const *)inputp;8648 8649 // try to do blocks of 4 when you can8650 #if stbir__coder_min_num != 3 // doesn't divide cleanly by four26 unmodified lines8677 decode += stbir__coder_min_num;8678 input += stbir__coder_min_num;8679 }8680 #endif8681+ return decode_end;8682 }8683 8684 #define stbir__min_max_shift20( i, f ) \8685 stbir__simdf_max( f, f, stbir_simdf_casti(STBIR__CONSTI( STBIR_almost_zero )) ); \144 unmodified lines8830 }8831 8832 #if ( stbir__coder_min_num == 4 ) || ( ( stbir__coder_min_num == 1 ) && ( !defined(stbir__decode_swizzle) ) )8833 8829-static void STBIR__CODER_NAME(stbir__decode_uint8_srgb4_linearalpha)( float * decodep, int width_times_channels, void const * inputp )8834+static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb4_linearalpha)( float * decodep, int width_times_channels, void const * inputp )8835 {8836 float STBIR_STREAMOUT_PTR( * ) decode = decodep;8832- float const * decode_end = (float*) decode + width_times_channels;8837+ float * decode_end = (float*) decode + width_times_channels;8838 unsigned char const * input = (unsigned char const *)inputp;8839+8840 do {8841 decode[0] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0] ];8842 decode[1] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order1] ];8843 decode[2] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order2] ];8844 decode[3] = ( (float) input[stbir__decode_order3] ) * stbir__max_uint8_as_float_inverted;8845 input += 4;8846 decode += 4;8847 } while( decode < decode_end );8848+ return decode_end;8849 }8850 8851 8852 static void STBIR__CODER_NAME( stbir__encode_uint8_srgb4_linearalpha )( void * outputp, int width_times_channels, float const * encode )64 unmodified lines8917 #endif8918 8919 #if ( stbir__coder_min_num == 2 ) || ( ( stbir__coder_min_num == 1 ) && ( !defined(stbir__decode_swizzle) ) )8920 8914-static void STBIR__CODER_NAME(stbir__decode_uint8_srgb2_linearalpha)( float * decodep, int width_times_channels, void const * inputp )8921+static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb2_linearalpha)( float * decodep, int width_times_channels, void const * inputp )8922 {8923 float STBIR_STREAMOUT_PTR( * ) decode = decodep;8917- float const * decode_end = (float*) decode + width_times_channels;8924+ float * decode_end = (float*) decode + width_times_channels;8925 unsigned char const * input = (unsigned char const *)inputp;8926+8927 decode += 4;8928 while( decode <= decode_end )8929 {8930 decode[0-4] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0] ];8 unmodified lines8939 {8940 decode[0] = stbir__srgb_uchar_to_linear_float[ stbir__decode_order0 ];8941 decode[1] = ( (float) input[stbir__decode_order1] ) * stbir__max_uint8_as_float_inverted;8942 }8943+ return decode_end;8944 }8945 8946 static void STBIR__CODER_NAME( stbir__encode_uint8_srgb2_linearalpha )( void * outputp, int width_times_channels, float const * encode )8947 {57 unmodified lines9005 }9006 9007 #endif9008 9000-static void STBIR__CODER_NAME(stbir__decode_uint16_linear_scaled)( float * decodep, int width_times_channels, void const * inputp )9009+static float * STBIR__CODER_NAME(stbir__decode_uint16_linear_scaled)( float * decodep, int width_times_channels, void const * inputp )9010 {9011 float STBIR_STREAMOUT_PTR( * ) decode = decodep;9012 float * decode_end = (float*) decode + width_times_channels;9013 unsigned short const * input = (unsigned short const *)inputp;39 unmodified lines9053 break;9054 decode = decode_end; // backup and do last couple9055 input = end_input_m8;9056 }9048- return;9057+ return decode_end + 8;9058 }9059 #endif9060 9061 // try to do blocks of 4 when you can29 unmodified lines9091 decode += stbir__coder_min_num;9092 input += stbir__coder_min_num;9093 }9094 #endif9095+ return decode_end;9096 }9097 9098 9099 static void STBIR__CODER_NAME(stbir__encode_uint16_linear_scaled)( void * outputp, int width_times_channels, float const * encode )111 unmodified lines9211 #endif9212 #endif9213 }9214 9205-static void STBIR__CODER_NAME(stbir__decode_uint16_linear)( float * decodep, int width_times_channels, void const * inputp )9215+static float * STBIR__CODER_NAME(stbir__decode_uint16_linear)( float * decodep, int width_times_channels, void const * inputp )9216 {9217 float STBIR_STREAMOUT_PTR( * ) decode = decodep;9218 float * decode_end = (float*) decode + width_times_channels;9219 unsigned short const * input = (unsigned short const *)inputp;36 unmodified lines9256 break;9257 decode = decode_end; // backup and do last couple9258 input = end_input_m8;9259 }9250- return;9260+ return decode_end + 8;9261 }9262 #endif9263 9264 // try to do blocks of 4 when you can29 unmodified lines9294 decode += stbir__coder_min_num;9295 input += stbir__coder_min_num;9296 }9297 #endif9298+ return decode_end;9299 }9300 9301 static void STBIR__CODER_NAME(stbir__encode_uint16_linear)( void * outputp, int width_times_channels, float const * encode )9302 {92 unmodified lines9395 }9396 #endif9397 }9398 9388-static void STBIR__CODER_NAME(stbir__decode_half_float_linear)( float * decodep, int width_times_channels, void const * inputp )9399+static float * STBIR__CODER_NAME(stbir__decode_half_float_linear)( float * decodep, int width_times_channels, void const * inputp )9400 {9401 float STBIR_STREAMOUT_PTR( * ) decode = decodep;9402 float * decode_end = (float*) decode + width_times_channels;9403 stbir__FP16 const * input = (stbir__FP16 const *)inputp;37 unmodified lines9441 break;9442 decode = decode_end; // backup and do last couple9443 input = end_input_m8;9444 }9434- return;9445+ return decode_end + 8;9446 }9447 #endif9448 9449 // try to do blocks of 4 when you can29 unmodified lines9479 decode += stbir__coder_min_num;9480 input += stbir__coder_min_num;9481 }9482 #endif9483+ return decode_end;9484 }9485 9486 static void STBIR__CODER_NAME( stbir__encode_half_float_linear )( void * outputp, int width_times_channels, float const * encode )9487 {78 unmodified lines9566 }9567 #endif9568 }9569 9558-static void STBIR__CODER_NAME(stbir__decode_float_linear)( float * decodep, int width_times_channels, void const * inputp )9570+static float * STBIR__CODER_NAME(stbir__decode_float_linear)( float * decodep, int width_times_channels, void const * inputp )9571 {9572 #ifdef stbir__decode_swizzle9573 float STBIR_STREAMOUT_PTR( * ) decode = decodep;9574 float * decode_end = (float*) decode + width_times_channels;45 unmodified lines9620 break;9621 decode = decode_end; // backup and do last couple9622 input = end_input_m16;9623 }9612- return;9624+ return decode_end + 16;9625 }9626 #endif9627 9628 // try to do blocks of 4 when you can29 unmodified lines9658 decode += stbir__coder_min_num;9659 input += stbir__coder_min_num;9660 }9661 #endif9662+ return decode_end;9663 9664 #else9665 9666 if ( (void*)decodep != inputp )9667 STBIR_MEMCPY( decodep, inputp, width_times_channels * sizeof( float ) );9668 9669+ return decodep + width_times_channels;9670+9671 #endif9672 }9673 9674 static void STBIR__CODER_NAME( stbir__encode_float_linear )( void * outputp, int width_times_channels, float const * encode )942 unmodified lines