resize 2.14 - fix off edge nans leaking in on some resize types
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jeff Roberts (LA) · committed by Jeff Roberts (LA) · parent f056911 · Browse files · 1 file·+16 added−5 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+16 added−5 removed
- other:+16 added−5 removed
Provenance
- Commit
8cfb160- Tree
ad664af- Author
Jeff Roberts (LA) <jeffr@radgametools.com>- Committer
Jeff Roberts (LA) <jeffr@radgametools.com>- Parent
f056911
1 file changed+16 added−5 removed
modified:stb_image_resize2.h+16 added-5 removed
1-/* stb_image_resize2 - v2.13 - public domain image resizing1+/* stb_image_resize2 - v2.14 - public domain image resizing2 3 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5 322 unmodified lines328 Aras Pranckevicius: bugfixes329 Nathan Reed: warning fixes for 1.0330 331 REVISIONS332+ 2.14 (2025-05-09) fixed a bug using downsampling gather horizontal first, and 333+ scatter with vertical first.334 2.13 (2025-02-27) fixed a bug when using input callbacks, turned off simd for 335 tiny-c, fixed some variables that should have been static,336 fixes a bug when calculating temp memory with resizes that337 exceed 2GB of temp memory (very large resizes).712 unmodified lines1050 1051 1052 #define stbir__max_uint8_as_float 255.0f1053 #define stbir__max_uint16_as_float 65535.0f1052-#define stbir__max_uint8_as_float_inverted (1.0f/255.0f)1053-#define stbir__max_uint16_as_float_inverted (1.0f/65535.0f)1054+#define stbir__max_uint8_as_float_inverted 3.9215689e-03f // (1.0f/255.0f)1055+#define stbir__max_uint16_as_float_inverted 1.5259022e-05f // (1.0f/65535.0f)1056 #define stbir__small_float ((float)1 / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20))1057 1058 // min/max friendly1059 #define STBIR_CLAMP(x, xmin, xmax) for(;;) { \5180 unmodified lines6240 6241 if ( vertical_first )6242 {6243 // Now resample the gathered vertical data in the horizontal axis into the encode buffer6244+ decode_buffer[ width_times_channels ] = 0.0f; // clear two over for horizontals with a remnant of 36245+ decode_buffer[ width_times_channels+1 ] = 0.0f; 6246 stbir__resample_horizontal_gather(stbir_info, encode_buffer, decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6247 }6248 6249 stbir__encode_scanline( stbir_info, ( (char *) stbir_info->output_data ) + ((size_t)n * (size_t)stbir_info->output_stride_bytes),163 unmodified lines6413 stbir__handle_scanline_for_scatter_func * handle_scanline_for_scatter;6414 void * scanline_scatter_buffer;6415 void * scanline_scatter_buffer_end;6416 int on_first_input_y, last_input_y;6417+ int width = (stbir_info->vertical_first) ? ( stbir_info->scanline_extents.conservative.n1-stbir_info->scanline_extents.conservative.n0+1 ) : stbir_info->horizontal.scale_info.output_sub_size;6418+ int width_times_channels = stbir_info->effective_channels * width;6419 6420 STBIR_ASSERT( !stbir_info->vertical.is_gather );6421 6422 start_output_y = split_info->start_output_y;26 unmodified lines6449 split_info->ring_buffer_begin_index = -1;6450 6451 // mark all the buffers as empty to start6452 for( y = 0 ; y < stbir_info->ring_buffer_num_entries ; y++ )6447- stbir__get_ring_buffer_entry( stbir_info, split_info, y )[0] = STBIR__FLOAT_EMPTY_MARKER; // only used on scatter6453+ {6454+ float * decode_buffer = stbir__get_ring_buffer_entry( stbir_info, split_info, y );6455+ decode_buffer[ width_times_channels ] = 0.0f; // clear two over for horizontals with a remnant of 36456+ decode_buffer[ width_times_channels+1 ] = 0.0f; 6457+ decode_buffer[0] = STBIR__FLOAT_EMPTY_MARKER; // only used on scatter6458+ }6459 6460 // do the loop in input space6461 on_first_input_y = 1; last_input_y = start_input_y;6462 for (y = start_input_y ; y < end_input_y; y++)559 unmodified lines7022 if ( effective_channels == 3 )7023 decode_buffer_size += sizeof(float); // avx in 3 channel mode needs one float at the start of the buffer (only with separate allocations)7024 #endif7025 7015- ring_buffer_length_bytes = (size_t)horizontal->scale_info.output_sub_size * (size_t)effective_channels * sizeof(float) + sizeof(float); // extra float for padding7026+ ring_buffer_length_bytes = (size_t)horizontal->scale_info.output_sub_size * (size_t)effective_channels * sizeof(float) + sizeof(float)*STBIR_INPUT_CALLBACK_PADDING; // extra floats for padding7027 7028 // if we do vertical first, the ring buffer holds a whole decoded line7029 if ( vertical_first )7030 ring_buffer_length_bytes = ( decode_buffer_size + 15 ) & ~15;3597 unmodified lines