image resize 2.07
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 ae721c5 · Browse files · 1 file·+23 added−22 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+23 added−22 removed
- other:+23 added−22 removed
Provenance
- Commit
43201e7- Tree
bf3dce4- Author
Jeff Roberts (Bellevue) <jeffr@radgametools.com>- Committer
Jeff Roberts (Bellevue) <jeffr@radgametools.com>- Parent
ae721c5
1 file changed+23 added−22 removed
modified:stb_image_resize2.h+23 added-22 removed
1-/* stb_image_resize2 - v2.06 - public domain image resizing1+/* stb_image_resize2 - v2.07 - public domain image resizing2 3 by Jeff Roberts (v2) and Jorge L Rodriguez4 http://github.com/nothings/stb5 321 unmodified lines327 Aras Pranckevicius: bugfixes328 Nathan Reed: warning fixes for 1.0329 330 REVISIONS331+ 2.07 (2024-05-24) fix for slow final split during threaded conversions of very 332+ wide scanlines when downsampling (caused by extra input 333+ converting), fix for wide scanline resamples with many 334+ splits (int overflow), fix GCC warning.331- 2.06 (2024-02-10) fix for indentical width/height 3x or more down-scaling 335+ 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)339 2.04 (2023-11-17) fix for rare AVX bug, shadowed symbol (thanks Nikola Smiljanic).731 unmodified lines1071 stbir__horizontal_gather_channels_func * horizontal_gather_channels;1072 stbir__alpha_unweight_func * alpha_unweight;1073 stbir__encode_pixels_func * encode_pixels;1074 1071- int alloced_total;1075+ int alloc_ring_buffer_num_entries; // Number of entries in the ring buffer that will be allocated1076 int splits; // count of splits1077 1078 stbir_internal_pixel_layout input_pixel_layout_internal;1079 stbir_internal_pixel_layout output_pixel_layout_internal;2 unmodified lines1082 int offset_x, offset_y; // offset within output_data1083 int vertical_first;1084 int channels;1085 int effective_channels; // same as channels, except on RGBA/ARGB (7), or XA/AX (3)1082- int alloc_ring_buffer_num_entries; // Number of entries in the ring buffer that will be allocated1086+ size_t alloced_total;1087 };1088 1089 1090 #define stbir__max_uint8_as_float 255.0f1425 unmodified lines2516 #define STBIR_SIMD_NO_UNROLL(ptr) STBIR_NO_UNROLL(ptr)2517 2518 #ifdef STBIR_MEMCPY2519 #undef STBIR_MEMCPY2516-#define STBIR_MEMCPY stbir_simd_memcpy2520 #endif2521+#define STBIR_MEMCPY stbir_simd_memcpy2522 2523 // override normal use of memcpy with much simpler copy (faster and smaller with our sized copies)2524 static void stbir_simd_memcpy( void * dest, void const * src, size_t bytes )2525 {23 unmodified lines2549 stbir__simdf x;2550 // do one unaligned to get us aligned for the stream out below2551 stbir__simdf_load( x, ( d + ofs_to_src ) );2552 stbir__simdf_store( d, x );2549- d = (char*)( ( ( (ptrdiff_t)d ) + 16 ) & ~15 );2553+ d = (char*)( ( ( (size_t)d ) + 16 ) & ~15 );2554 2555 for(;;)2556 {2557 STBIR_SIMD_NO_UNROLL(d);23 unmodified lines2581 stbir__simdfX_store( d + 0*stbir__simdfX_float_count, x0 );2582 stbir__simdfX_store( d + 4*stbir__simdfX_float_count, x1 );2583 stbir__simdfX_store( d + 8*stbir__simdfX_float_count, x2 );2584 stbir__simdfX_store( d + 12*stbir__simdfX_float_count, x3 );2581- d = (char*)( ( ( (ptrdiff_t)d ) + (16*stbir__simdfX_float_count) ) & ~((16*stbir__simdfX_float_count)-1) );2585+ d = (char*)( ( ( (size_t)d ) + (16*stbir__simdfX_float_count) ) & ~((16*stbir__simdfX_float_count)-1) );2586 2587 for(;;)2588 {2589 STBIR_SIMD_NO_UNROLL(d);1812 unmodified lines4402 int input_sample_in_bytes = stbir__type_size[stbir_info->input_type] * channels;4403 stbir_edge edge_horizontal = stbir_info->horizontal.edge;4404 stbir_edge edge_vertical = stbir_info->vertical.edge;4405 int row = stbir__edge_wrap(edge_vertical, n, stbir_info->vertical.scale_info.input_full_size);4402- const void* input_plane_data = ( (char *) stbir_info->input_data ) + (ptrdiff_t)row * (ptrdiff_t) stbir_info->input_stride_bytes;4406+ const void* input_plane_data = ( (char *) stbir_info->input_data ) + (size_t)row * (size_t) stbir_info->input_stride_bytes;4407 stbir__span const * spans = stbir_info->scanline_extents.spans;4408 float* full_decode_buffer = output_buffer - stbir_info->scanline_extents.conservative.n0 * effective_channels;4409 4410 // if we are on edge_zero, and we get in here with an out of bounds n, then the calculate filters has failed1644 unmodified lines6055 // Now resample the gathered vertical data in the horizontal axis into the encode buffer6056 stbir__resample_horizontal_gather(stbir_info, encode_buffer, decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6057 }6058 6055- stbir__encode_scanline( stbir_info, ( (char *) stbir_info->output_data ) + ((ptrdiff_t)n * (ptrdiff_t)stbir_info->output_stride_bytes),6059+ stbir__encode_scanline( stbir_info, ( (char *) stbir_info->output_data ) + ((size_t)n * (size_t)stbir_info->output_stride_bytes),6060 encode_buffer, n STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6061 }6062 6063 static void stbir__decode_and_resample_for_vertical_gather_loop(stbir__info const * stbir_info, stbir__per_split_info* split_info, int n)32 unmodified lines6096 vertical_coefficients += start_output_y * stbir_info->vertical.coefficient_width;6097 6098 // initialize the ring buffer for gathering6099 split_info->ring_buffer_begin_index = 0;6096- split_info->ring_buffer_first_scanline = stbir_info->vertical.extent_info.lowest;6100+ split_info->ring_buffer_first_scanline = vertical_contributors->n0;6101 split_info->ring_buffer_last_scanline = split_info->ring_buffer_first_scanline - 1; // means "empty"6102 6103 for (y = start_output_y; y < end_output_y; y++)6104 {45 unmodified lines6150 // evict a scanline out into the output buffer6151 float* ring_buffer_entry = stbir__get_ring_buffer_entry(stbir_info, split_info, split_info->ring_buffer_begin_index );6152 6153 // dump the scanline out6150- stbir__encode_scanline( stbir_info, ( (char *)stbir_info->output_data ) + ( (ptrdiff_t)split_info->ring_buffer_first_scanline * (ptrdiff_t)stbir_info->output_stride_bytes ), ring_buffer_entry, split_info->ring_buffer_first_scanline STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6154+ stbir__encode_scanline( stbir_info, ( (char *)stbir_info->output_data ) + ( (size_t)split_info->ring_buffer_first_scanline * (size_t)stbir_info->output_stride_bytes ), ring_buffer_entry, split_info->ring_buffer_first_scanline STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6155 6156 // mark it as empty6157 ring_buffer_entry[ 0 ] = STBIR__FLOAT_EMPTY_MARKER;6158 12 unmodified lines6171 // Now resample it into the buffer.6172 stbir__resample_horizontal_gather( stbir_info, split_info->vertical_buffer, ring_buffer_entry STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6173 6174 // dump the scanline out6171- stbir__encode_scanline( stbir_info, ( (char *)stbir_info->output_data ) + ( (ptrdiff_t)split_info->ring_buffer_first_scanline * (ptrdiff_t)stbir_info->output_stride_bytes ), split_info->vertical_buffer, split_info->ring_buffer_first_scanline STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6175+ stbir__encode_scanline( stbir_info, ( (char *)stbir_info->output_data ) + ( (size_t)split_info->ring_buffer_first_scanline * (size_t)stbir_info->output_stride_bytes ), split_info->vertical_buffer, split_info->ring_buffer_first_scanline STBIR_ONLY_PROFILE_SET_SPLIT_INFO );6176 6177 // mark it as empty6178 ring_buffer_entry[ 0 ] = STBIR__FLOAT_EMPTY_MARKER;6179 588 unmodified lines6768 static char stbir_channel_count_index[8]={ 9,0,1,2, 3,9,9,4 };6769 6770 stbir__info * info = 0;6771 void * alloced = 0;6768- int alloced_total = 0;6772+ size_t alloced_total = 0;6773 int vertical_first;6774 int decode_buffer_size, ring_buffer_length_bytes, ring_buffer_size, vertical_buffer_size, alloc_ring_buffer_num_entries;6775 6776 int alpha_weighting_type = 0; // 0=none, 1=simple, 2=fancy334 unmodified lines7111 7112 // is this the first time through loop?7113 if ( info == 0 )7114 {7111- alloced_total = (int) ( 15 + (size_t)advance_mem );7115+ alloced_total = ( 15 + (size_t)advance_mem );7116 alloced = STBIR_MALLOC( alloced_total, user_data );7117 if ( alloced == 0 )7118 return 0;7119 }108 unmodified lines7228 if ( info->output_stride_bytes == 0 )7229 info->output_stride_bytes = info->channels * info->horizontal.scale_info.output_sub_size * stbir__type_size[output_type];7230 7231 // calc offset7228- info->output_data = ( (char*) resize->output_pixels ) + ( (ptrdiff_t) info->offset_y * (ptrdiff_t) resize->output_stride_in_bytes ) + ( info->offset_x * info->channels * stbir__type_size[output_type] );7232+ info->output_data = ( (char*) resize->output_pixels ) + ( (size_t) info->offset_y * (size_t) resize->output_stride_in_bytes ) + ( info->offset_x * info->channels * stbir__type_size[output_type] );7233 7234 info->in_pixels_cb = resize->input_cb;7235 info->user_data = resize->user_data;7236 info->out_pixels_cb = resize->output_cb;563 unmodified lines7800 7801 if ( output_stride_in_bytes < pitch )7802 return 0;7803 7800- size = output_stride_in_bytes * output_h;7804+ size = (size_t)output_stride_in_bytes * (size_t)output_h;7805 if ( size == 0 )7806 return 0;7807 7808 *ret_ptr = 0;763 unmodified lines8572 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (unsigned char*) outputp;8573 unsigned char * end_output = ( (unsigned char*) output ) + width_times_channels;8574 8575 #ifdef STBIR_SIMD8572- stbir_uint32 const * to_srgb = fp32_to_srgb8_tab4 - (127-13)*8;8576 8577 if ( width_times_channels >= 16 )8578 {8579 float const * end_encode_m16 = encode + width_times_channels - 16;10 unmodified lines8590 stbir__min_max_shift20( i1, f1 );8591 stbir__min_max_shift20( i2, f2 );8592 stbir__min_max_shift20( i3, f3 );8593 8591- stbir__simdi_table_lookup4( i0, i1, i2, i3, to_srgb );8594+ stbir__simdi_table_lookup4( i0, i1, i2, i3, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );8595 8596 stbir__linear_to_srgb_finish( i0, f0 );8597 stbir__linear_to_srgb_finish( i1, f1 );8598 stbir__linear_to_srgb_finish( i2, f2 );73 unmodified lines8672 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (unsigned char*) outputp;8673 unsigned char * end_output = ( (unsigned char*) output ) + width_times_channels;8674 8675 #ifdef STBIR_SIMD8673- stbir_uint32 const * to_srgb = fp32_to_srgb8_tab4 - (127-13)*8;8676 8677 if ( width_times_channels >= 16 )8678 {8679 float const * end_encode_m16 = encode + width_times_channels - 16;10 unmodified lines8690 stbir__min_max_shift20( i1, f1 );8691 stbir__min_max_shift20( i2, f2 );8692 stbir__scale_and_convert( i3, f3 );8693 8692- stbir__simdi_table_lookup3( i0, i1, i2, to_srgb );8694+ stbir__simdi_table_lookup3( i0, i1, i2, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );8695 8696 stbir__linear_to_srgb_finish( i0, f0 );8697 stbir__linear_to_srgb_finish( i1, f1 );8698 stbir__linear_to_srgb_finish( i2, f2 );63 unmodified lines8762 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (unsigned char*) outputp;8763 unsigned char * end_output = ( (unsigned char*) output ) + width_times_channels;8764 8765 #ifdef STBIR_SIMD8764- stbir_uint32 const * to_srgb = fp32_to_srgb8_tab4 - (127-13)*8;8766 8767 if ( width_times_channels >= 16 )8768 {8769 float const * end_encode_m16 = encode + width_times_channels - 16;10 unmodified lines8780 stbir__scale_and_convert( i1, f1 );8781 stbir__min_max_shift20( i2, f2 );8782 stbir__scale_and_convert( i3, f3 );8783 8783- stbir__simdi_table_lookup2( i0, i2, to_srgb );8784+ stbir__simdi_table_lookup2( i0, i2, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );8785 8786 stbir__linear_to_srgb_finish( i0, f0 );8787 stbir__linear_to_srgb_finish( i2, f2 );8788 1578 unmodified lines