386#if !defined(STB_IMAGE_RESIZE_DO_HORIZONTALS) && !defined(STB_IMAGE_RESIZE_DO_VERTICALS) && !defined(STB_IMAGE_RESIZE_DO_CODERS)
388#ifndef STBIR_INCLUDE_STB_IMAGE_RESIZE2_H
389#define STBIR_INCLUDE_STB_IMAGE_RESIZE2_H
406#ifdef STB_IMAGE_RESIZE_STATIC
407#define STBIRDEF static
410#define STBIRDEF extern "C"
412#define STBIRDEF extern
473 unsigned char *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
477 unsigned char *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
481 float *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
527 void *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
562typedef void const *
stbir_input_callback(
void * optional_output,
void const * input_ptr,
int num_pixels,
int x,
int y,
void * context );
607 const void *input_pixels,
int input_w,
int input_h,
int input_stride_in_bytes,
608 void *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
753typedef struct STBIR_PROFILE_INFO
760 char const ** descriptions;
767STBIRDEF void stbir_resize_build_profile_info( STBIR_PROFILE_INFO * out_info,
STBIR_RESIZE const * resize );
770STBIRDEF void stbir_resize_extended_profile_info( STBIR_PROFILE_INFO * out_info,
STBIR_RESIZE const * resize );
773STBIRDEF void stbir_resize_split_profile_info( STBIR_PROFILE_INFO * out_info,
STBIR_RESIZE const * resize,
int split_start,
int split_num );
783#if defined(STB_IMAGE_RESIZE_IMPLEMENTATION) || defined(STB_IMAGE_RESIZE2_IMPLEMENTATION)
787#define STBIR_ASSERT(x) assert(x)
792#define STBIR_MALLOC(size,user_data) ((void)(user_data), malloc(size))
793#define STBIR_FREE(ptr,user_data) ((void)(user_data), free(ptr))
799#define stbir__inline __forceinline
803#define stbir__inline __inline__
806#if defined(__has_feature)
807 #if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
808 #ifndef STBIR__SEPARATE_ALLOCATIONS
809 #define STBIR__SEPARATE_ALLOCATIONS
817#if defined(__SANITIZE_ADDRESS__)
818 #ifndef STBIR__SEPARATE_ALLOCATIONS
819 #define STBIR__SEPARATE_ALLOCATIONS
825#ifndef STBIR_DONT_CHANGE_FP_CONTRACT
826#if defined(_MSC_VER) && !defined(__clang__)
828#pragma fp_contract(off)
830#elif defined(__GNUC__) && !defined(__clang__)
831#pragma GCC optimize("fp-contract=off")
833#pragma STDC FP_CONTRACT OFF
838#define STBIR__UNUSED(v) (void)(v)
840#define STBIR__UNUSED(v) (void)sizeof(v)
843#define STBIR__ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0]))
846#ifndef STBIR_DEFAULT_FILTER_UPSAMPLE
847#define STBIR_DEFAULT_FILTER_UPSAMPLE STBIR_FILTER_CATMULLROM
850#ifndef STBIR_DEFAULT_FILTER_DOWNSAMPLE
851#define STBIR_DEFAULT_FILTER_DOWNSAMPLE STBIR_FILTER_MITCHELL
855#ifndef STBIR__HEADER_FILENAME
856#define STBIR__HEADER_FILENAME "stb_image_resize2.h"
882} stbir_internal_pixel_layout;
885#define STBIR_BGR bad_dont_use_in_implementation
886#define STBIR_1CHANNEL STBIR_BGR
887#define STBIR_2CHANNEL STBIR_BGR
888#define STBIR_RGB STBIR_BGR
889#define STBIR_RGBA STBIR_BGR
890#define STBIR_4CHANNEL STBIR_BGR
891#define STBIR_BGRA STBIR_BGR
892#define STBIR_ARGB STBIR_BGR
893#define STBIR_ABGR STBIR_BGR
894#define STBIR_RA STBIR_BGR
895#define STBIR_AR STBIR_BGR
896#define STBIR_RGBA_PM STBIR_BGR
897#define STBIR_BGRA_PM STBIR_BGR
898#define STBIR_ARGB_PM STBIR_BGR
899#define STBIR_ABGR_PM STBIR_BGR
900#define STBIR_RA_PM STBIR_BGR
901#define STBIR_AR_PM STBIR_BGR
904static unsigned char stbir__type_size[] = {
914} stbir__contributors;
921} stbir__filter_extent_info;
927 int pixel_offset_for_input;
930typedef struct stbir__scale_info
937 int scale_is_rational;
943 stbir__contributors * contributors;
945 stbir__contributors * gather_prescatter_contributors;
946 float * gather_prescatter_coefficients;
947 stbir__scale_info scale_info;
953 int coefficient_width;
954 int filter_pixel_width;
955 int filter_pixel_margin;
956 int num_contributors;
957 int contributors_size;
958 int coefficients_size;
959 stbir__filter_extent_info extent_info;
961 int gather_prescatter_num_contributors;
962 int gather_prescatter_coefficient_width;
963 int gather_prescatter_contributors_size;
964 int gather_prescatter_coefficients_size;
969 stbir__contributors conservative;
971 stbir__span spans[2];
979 struct {
stbir_uint64 total, looping, vertical, horizontal, decode, encode,
alpha, unalpha; } named;
984 float* decode_buffer;
986 int ring_buffer_first_scanline;
987 int ring_buffer_last_scanline;
988 int ring_buffer_begin_index;
989 int start_output_y, end_output_y;
990 int start_input_y, end_input_y;
992 #ifdef STBIR__SEPARATE_ALLOCATIONS
993 float** ring_buffers;
998 float* vertical_buffer;
1000 char no_cache_straddle[64];
1001} stbir__per_split_info;
1003typedef float * stbir__decode_pixels_func(
float * decode,
int width_times_channels,
void const * input );
1004typedef void stbir__alpha_weight_func(
float * decode_buffer,
int width_times_channels );
1005typedef void stbir__horizontal_gather_channels_func(
float * output_buffer,
unsigned int output_sub_size,
float const * decode_buffer,
1006 stbir__contributors
const * horizontal_contributors,
float const * horizontal_coefficients,
int coefficient_width );
1007typedef void stbir__alpha_unweight_func(
float * encode_buffer,
int width_times_channels );
1008typedef void stbir__encode_pixels_func(
void * output,
int width_times_channels,
float const * encode );
1015 struct {
stbir_uint64 total, build, alloc, horizontal, vertical, cleanup, pivot; } named;
1020 stbir__sampler horizontal;
1021 stbir__sampler vertical;
1023 void const * input_data;
1026 int input_stride_bytes;
1027 int output_stride_bytes;
1028 int ring_buffer_length_bytes;
1029 int ring_buffer_num_entries;
1038 stbir__extents scanline_extents;
1041 stbir__per_split_info * split_info;
1043 stbir__decode_pixels_func * decode_pixels;
1044 stbir__alpha_weight_func * alpha_weight;
1045 stbir__horizontal_gather_channels_func * horizontal_gather_channels;
1046 stbir__alpha_unweight_func * alpha_unweight;
1047 stbir__encode_pixels_func * encode_pixels;
1049 int alloc_ring_buffer_num_entries;
1052 stbir_internal_pixel_layout input_pixel_layout_internal;
1053 stbir_internal_pixel_layout output_pixel_layout_internal;
1055 int input_color_and_type;
1056 int offset_x, offset_y;
1059 int effective_channels;
1060 size_t alloced_total;
1064#define stbir__max_uint8_as_float 255.0f
1065#define stbir__max_uint16_as_float 65535.0f
1066#define stbir__max_uint8_as_float_inverted 3.9215689e-03f
1067#define stbir__max_uint16_as_float_inverted 1.5259022e-05f
1068#define stbir__small_float ((float)1 / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20))
1071#define STBIR_CLAMP(x, xmin, xmax) for(;;) { \
1072 if ( (x) < (xmin) ) (x) = (xmin); \
1073 if ( (x) > (xmax) ) (x) = (xmax); \
1077static stbir__inline
int stbir__min(
int a,
int b)
1079 return a < b ? a : b;
1082static stbir__inline
int stbir__max(
int a,
int b)
1084 return a > b ? a : b;
1087static float stbir__srgb_uchar_to_linear_float[256] = {
1088 0.000000f, 0.000304f, 0.000607f, 0.000911f, 0.001214f, 0.001518f, 0.001821f, 0.002125f, 0.002428f, 0.002732f, 0.003035f,
1089 0.003347f, 0.003677f, 0.004025f, 0.004391f, 0.004777f, 0.005182f, 0.005605f, 0.006049f, 0.006512f, 0.006995f, 0.007499f,
1090 0.008023f, 0.008568f, 0.009134f, 0.009721f, 0.010330f, 0.010960f, 0.011612f, 0.012286f, 0.012983f, 0.013702f, 0.014444f,
1091 0.015209f, 0.015996f, 0.016807f, 0.017642f, 0.018500f, 0.019382f, 0.020289f, 0.021219f, 0.022174f, 0.023153f, 0.024158f,
1092 0.025187f, 0.026241f, 0.027321f, 0.028426f, 0.029557f, 0.030713f, 0.031896f, 0.033105f, 0.034340f, 0.035601f, 0.036889f,
1093 0.038204f, 0.039546f, 0.040915f, 0.042311f, 0.043735f, 0.045186f, 0.046665f, 0.048172f, 0.049707f, 0.051269f, 0.052861f,
1094 0.054480f, 0.056128f, 0.057805f, 0.059511f, 0.061246f, 0.063010f, 0.064803f, 0.066626f, 0.068478f, 0.070360f, 0.072272f,
1095 0.074214f, 0.076185f, 0.078187f, 0.080220f, 0.082283f, 0.084376f, 0.086500f, 0.088656f, 0.090842f, 0.093059f, 0.095307f,
1096 0.097587f, 0.099899f, 0.102242f, 0.104616f, 0.107023f, 0.109462f, 0.111932f, 0.114435f, 0.116971f, 0.119538f, 0.122139f,
1097 0.124772f, 0.127438f, 0.130136f, 0.132868f, 0.135633f, 0.138432f, 0.141263f, 0.144128f, 0.147027f, 0.149960f, 0.152926f,
1098 0.155926f, 0.158961f, 0.162029f, 0.165132f, 0.168269f, 0.171441f, 0.174647f, 0.177888f, 0.181164f, 0.184475f, 0.187821f,
1099 0.191202f, 0.194618f, 0.198069f, 0.201556f, 0.205079f, 0.208637f, 0.212231f, 0.215861f, 0.219526f, 0.223228f, 0.226966f,
1100 0.230740f, 0.234551f, 0.238398f, 0.242281f, 0.246201f, 0.250158f, 0.254152f, 0.258183f, 0.262251f, 0.266356f, 0.270498f,
1101 0.274677f, 0.278894f, 0.283149f, 0.287441f, 0.291771f, 0.296138f, 0.300544f, 0.304987f, 0.309469f, 0.313989f, 0.318547f,
1102 0.323143f, 0.327778f, 0.332452f, 0.337164f, 0.341914f, 0.346704f, 0.351533f, 0.356400f, 0.361307f, 0.366253f, 0.371238f,
1103 0.376262f, 0.381326f, 0.386430f, 0.391573f, 0.396755f, 0.401978f, 0.407240f, 0.412543f, 0.417885f, 0.423268f, 0.428691f,
1104 0.434154f, 0.439657f, 0.445201f, 0.450786f, 0.456411f, 0.462077f, 0.467784f, 0.473532f, 0.479320f, 0.485150f, 0.491021f,
1105 0.496933f, 0.502887f, 0.508881f, 0.514918f, 0.520996f, 0.527115f, 0.533276f, 0.539480f, 0.545725f, 0.552011f, 0.558340f,
1106 0.564712f, 0.571125f, 0.577581f, 0.584078f, 0.590619f, 0.597202f, 0.603827f, 0.610496f, 0.617207f, 0.623960f, 0.630757f,
1107 0.637597f, 0.644480f, 0.651406f, 0.658375f, 0.665387f, 0.672443f, 0.679543f, 0.686685f, 0.693872f, 0.701102f, 0.708376f,
1108 0.715694f, 0.723055f, 0.730461f, 0.737911f, 0.745404f, 0.752942f, 0.760525f, 0.768151f, 0.775822f, 0.783538f, 0.791298f,
1109 0.799103f, 0.806952f, 0.814847f, 0.822786f, 0.830770f, 0.838799f, 0.846873f, 0.854993f, 0.863157f, 0.871367f, 0.879622f,
1110 0.887923f, 0.896269f, 0.904661f, 0.913099f, 0.921582f, 0.930111f, 0.938686f, 0.947307f, 0.955974f, 0.964686f, 0.973445f,
1111 0.982251f, 0.991102f, 1.0f
1123 0x0073000d, 0x007a000d, 0x0080000d, 0x0087000d, 0x008d000d, 0x0094000d, 0x009a000d, 0x00a1000d,
1124 0x00a7001a, 0x00b4001a, 0x00c1001a, 0x00ce001a, 0x00da001a, 0x00e7001a, 0x00f4001a, 0x0101001a,
1125 0x010e0033, 0x01280033, 0x01410033, 0x015b0033, 0x01750033, 0x018f0033, 0x01a80033, 0x01c20033,
1126 0x01dc0067, 0x020f0067, 0x02430067, 0x02760067, 0x02aa0067, 0x02dd0067, 0x03110067, 0x03440067,
1127 0x037800ce, 0x03df00ce, 0x044600ce, 0x04ad00ce, 0x051400ce, 0x057b00c5, 0x05dd00bc, 0x063b00b5,
1128 0x06970158, 0x07420142, 0x07e30130, 0x087b0120, 0x090b0112, 0x09940106, 0x0a1700fc, 0x0a9500f2,
1129 0x0b0f01cb, 0x0bf401ae, 0x0ccb0195, 0x0d950180, 0x0e56016e, 0x0f0d015e, 0x0fbc0150, 0x10630143,
1130 0x11070264, 0x1238023e, 0x1357021d, 0x14660201, 0x156601e9, 0x165a01d3, 0x174401c0, 0x182401af,
1131 0x18fe0331, 0x1a9602fe, 0x1c1502d2, 0x1d7e02ad, 0x1ed4028d, 0x201a0270, 0x21520256, 0x227d0240,
1132 0x239f0443, 0x25c003fe, 0x27bf03c4, 0x29a10392, 0x2b6a0367, 0x2d1d0341, 0x2ebe031f, 0x304d0300,
1133 0x31d105b0, 0x34a80555, 0x37520507, 0x39d504c5, 0x3c37048b, 0x3e7c0458, 0x40a8042a, 0x42bd0401,
1134 0x44c20798, 0x488e071e, 0x4c1c06b6, 0x4f76065d, 0x52a50610, 0x55ac05cc, 0x5892058f, 0x5b590559,
1135 0x5e0c0a23, 0x631c0980, 0x67db08f6, 0x6c55087f, 0x70940818, 0x74a007bd, 0x787d076c, 0x7c330723,
1138static stbir__inline
stbir_uint8 stbir__linear_to_srgb_uchar(
float in)
1140 static const stbir__FP32 almostone = { 0x3f7fffff };
1141 static const stbir__FP32 minval = { (127-13) << 23 };
1148 if (!(in > minval.f))
1150 if (in > almostone.f)
1155 tab = fp32_to_srgb8_tab4[(f.u - minval.u) >> 20];
1156 bias = (tab >> 16) << 9;
1157 scale = tab & 0xffff;
1160 t = (f.u >> 12) & 0xff;
1161 return (
unsigned char) ((bias + scale*t) >> 16);
1164#ifndef STBIR_FORCE_GATHER_FILTER_SCANLINES_AMOUNT
1165#define STBIR_FORCE_GATHER_FILTER_SCANLINES_AMOUNT 32
1168#ifndef STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS
1169#define STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS 4
1172#define STBIR_INPUT_CALLBACK_PADDING 3
1175#if ( _M_IX86_FP >= 1 )
1184 #define STBIR_NO_SIMD
1187#if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(_M_AMD64) || defined(__SSE2__) || defined(STBIR_SSE) || defined(STBIR_SSE2)
1191 #if defined(__AVX__) || defined(STBIR_AVX2)
1193 #ifndef STBIR_NO_AVX
1198 #if defined(__AVX2__) || defined(STBIR_AVX2)
1199 #ifndef STBIR_NO_AVX2
1203 #if defined( _MSC_VER ) && !defined(__clang__)
1217#if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || ((__ARM_NEON_FP & 4) != 0) || defined(__ARM_NEON__)
1223#if defined(_M_ARM) || defined(__arm__)
1229#if defined(__wasm__) && defined(__wasm_simd128__)
1236#if defined( _MSC_VER ) && !defined(__clang__)
1237 #define STBIR_STREAMOUT_PTR( star ) star __restrict
1238 #define STBIR_NO_UNROLL( ptr ) __assume(ptr)
1239 #if _MSC_VER >= 1900
1240 #define STBIR_NO_UNROLL_LOOP_START __pragma(loop( no_vector ))
1242 #define STBIR_NO_UNROLL_LOOP_START
1244#elif defined( __clang__ )
1245 #define STBIR_STREAMOUT_PTR( star ) star __restrict__
1246 #define STBIR_NO_UNROLL( ptr ) __asm__ (""::"r"(ptr))
1247 #if ( __clang_major__ >= 4 ) || ( ( __clang_major__ >= 3 ) && ( __clang_minor__ >= 5 ) )
1248 #define STBIR_NO_UNROLL_LOOP_START _Pragma("clang loop unroll(disable)") _Pragma("clang loop vectorize(disable)")
1250 #define STBIR_NO_UNROLL_LOOP_START
1252#elif defined( __GNUC__ )
1253 #define STBIR_STREAMOUT_PTR( star ) star __restrict__
1254 #define STBIR_NO_UNROLL( ptr ) __asm__ (""::"r"(ptr))
1256 #define STBIR_NO_UNROLL_LOOP_START _Pragma("GCC unroll 0") _Pragma("GCC novector")
1258 #define STBIR_NO_UNROLL_LOOP_START
1260 #define STBIR_NO_UNROLL_LOOP_START_INF_FOR
1262 #define STBIR_STREAMOUT_PTR( star ) star
1263 #define STBIR_NO_UNROLL( ptr )
1264 #define STBIR_NO_UNROLL_LOOP_START
1267#ifndef STBIR_NO_UNROLL_LOOP_START_INF_FOR
1268#define STBIR_NO_UNROLL_LOOP_START_INF_FOR STBIR_NO_UNROLL_LOOP_START
1306 #include <emmintrin.h>
1308 #define stbir__simdf __m128
1309 #define stbir__simdi __m128i
1311 #define stbir_simdi_castf( reg ) _mm_castps_si128(reg)
1312 #define stbir_simdf_casti( reg ) _mm_castsi128_ps(reg)
1314 #define stbir__simdf_load( reg, ptr ) (reg) = _mm_loadu_ps( (float const*)(ptr) )
1315 #define stbir__simdi_load( reg, ptr ) (reg) = _mm_loadu_si128 ( (stbir__simdi const*)(ptr) )
1316 #define stbir__simdf_load1( out, ptr ) (out) = _mm_load_ss( (float const*)(ptr) )
1317 #define stbir__simdi_load1( out, ptr ) (out) = _mm_castps_si128( _mm_load_ss( (float const*)(ptr) ))
1318 #define stbir__simdf_load1z( out, ptr ) (out) = _mm_load_ss( (float const*)(ptr) )
1319 #define stbir__simdf_frep4( fvar ) _mm_set_ps1( fvar )
1320 #define stbir__simdf_load1frep4( out, fvar ) (out) = _mm_set_ps1( fvar )
1321 #define stbir__simdf_load2( out, ptr ) (out) = _mm_castsi128_ps( _mm_loadl_epi64( (__m128i*)(ptr)) )
1322 #define stbir__simdf_load2z( out, ptr ) (out) = _mm_castsi128_ps( _mm_loadl_epi64( (__m128i*)(ptr)) )
1323 #define stbir__simdf_load2hmerge( out, reg, ptr ) (out) = _mm_castpd_ps(_mm_loadh_pd( _mm_castps_pd(reg), (double*)(ptr) ))
1325 #define stbir__simdf_zeroP() _mm_setzero_ps()
1326 #define stbir__simdf_zero( reg ) (reg) = _mm_setzero_ps()
1328 #define stbir__simdf_store( ptr, reg ) _mm_storeu_ps( (float*)(ptr), reg )
1329 #define stbir__simdf_store1( ptr, reg ) _mm_store_ss( (float*)(ptr), reg )
1330 #define stbir__simdf_store2( ptr, reg ) _mm_storel_epi64( (__m128i*)(ptr), _mm_castps_si128(reg) )
1331 #define stbir__simdf_store2h( ptr, reg ) _mm_storeh_pd( (double*)(ptr), _mm_castps_pd(reg) )
1333 #define stbir__simdi_store( ptr, reg ) _mm_storeu_si128( (__m128i*)(ptr), reg )
1334 #define stbir__simdi_store1( ptr, reg ) _mm_store_ss( (float*)(ptr), _mm_castsi128_ps(reg) )
1335 #define stbir__simdi_store2( ptr, reg ) _mm_storel_epi64( (__m128i*)(ptr), (reg) )
1337 #define stbir__prefetch( ptr ) _mm_prefetch((char*)(ptr), _MM_HINT_T0 )
1339 #define stbir__simdi_expand_u8_to_u32(out0,out1,out2,out3,ireg) \
1341 stbir__simdi zero = _mm_setzero_si128(); \
1342 out2 = _mm_unpacklo_epi8( ireg, zero ); \
1343 out3 = _mm_unpackhi_epi8( ireg, zero ); \
1344 out0 = _mm_unpacklo_epi16( out2, zero ); \
1345 out1 = _mm_unpackhi_epi16( out2, zero ); \
1346 out2 = _mm_unpacklo_epi16( out3, zero ); \
1347 out3 = _mm_unpackhi_epi16( out3, zero ); \
1350#define stbir__simdi_expand_u8_to_1u32(out,ireg) \
1352 stbir__simdi zero = _mm_setzero_si128(); \
1353 out = _mm_unpacklo_epi8( ireg, zero ); \
1354 out = _mm_unpacklo_epi16( out, zero ); \
1357 #define stbir__simdi_expand_u16_to_u32(out0,out1,ireg) \
1359 stbir__simdi zero = _mm_setzero_si128(); \
1360 out0 = _mm_unpacklo_epi16( ireg, zero ); \
1361 out1 = _mm_unpackhi_epi16( ireg, zero ); \
1364 #define stbir__simdf_convert_float_to_i32( i, f ) (i) = _mm_cvttps_epi32(f)
1365 #define stbir__simdf_convert_float_to_int( f ) _mm_cvtt_ss2si(f)
1366 #define stbir__simdf_convert_float_to_uint8( f ) ((unsigned char)_mm_cvtsi128_si32(_mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(f,STBIR__CONSTF(STBIR_max_uint8_as_float)),_mm_setzero_ps()))))
1367 #define stbir__simdf_convert_float_to_short( f ) ((unsigned short)_mm_cvtsi128_si32(_mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(f,STBIR__CONSTF(STBIR_max_uint16_as_float)),_mm_setzero_ps()))))
1369 #define stbir__simdi_to_int( i ) _mm_cvtsi128_si32(i)
1370 #define stbir__simdi_convert_i32_to_float(out, ireg) (out) = _mm_cvtepi32_ps( ireg )
1371 #define stbir__simdf_add( out, reg0, reg1 ) (out) = _mm_add_ps( reg0, reg1 )
1372 #define stbir__simdf_mult( out, reg0, reg1 ) (out) = _mm_mul_ps( reg0, reg1 )
1373 #define stbir__simdf_mult_mem( out, reg, ptr ) (out) = _mm_mul_ps( reg, _mm_loadu_ps( (float const*)(ptr) ) )
1374 #define stbir__simdf_mult1_mem( out, reg, ptr ) (out) = _mm_mul_ss( reg, _mm_load_ss( (float const*)(ptr) ) )
1375 #define stbir__simdf_add_mem( out, reg, ptr ) (out) = _mm_add_ps( reg, _mm_loadu_ps( (float const*)(ptr) ) )
1376 #define stbir__simdf_add1_mem( out, reg, ptr ) (out) = _mm_add_ss( reg, _mm_load_ss( (float const*)(ptr) ) )
1378 #ifdef STBIR_USE_FMA
1379 #include <immintrin.h>
1380 #define stbir__simdf_madd( out, add, mul1, mul2 ) (out) = _mm_fmadd_ps( mul1, mul2, add )
1381 #define stbir__simdf_madd1( out, add, mul1, mul2 ) (out) = _mm_fmadd_ss( mul1, mul2, add )
1382 #define stbir__simdf_madd_mem( out, add, mul, ptr ) (out) = _mm_fmadd_ps( mul, _mm_loadu_ps( (float const*)(ptr) ), add )
1383 #define stbir__simdf_madd1_mem( out, add, mul, ptr ) (out) = _mm_fmadd_ss( mul, _mm_load_ss( (float const*)(ptr) ), add )
1385 #define stbir__simdf_madd( out, add, mul1, mul2 ) (out) = _mm_add_ps( add, _mm_mul_ps( mul1, mul2 ) )
1386 #define stbir__simdf_madd1( out, add, mul1, mul2 ) (out) = _mm_add_ss( add, _mm_mul_ss( mul1, mul2 ) )
1387 #define stbir__simdf_madd_mem( out, add, mul, ptr ) (out) = _mm_add_ps( add, _mm_mul_ps( mul, _mm_loadu_ps( (float const*)(ptr) ) ) )
1388 #define stbir__simdf_madd1_mem( out, add, mul, ptr ) (out) = _mm_add_ss( add, _mm_mul_ss( mul, _mm_load_ss( (float const*)(ptr) ) ) )
1391 #define stbir__simdf_add1( out, reg0, reg1 ) (out) = _mm_add_ss( reg0, reg1 )
1392 #define stbir__simdf_mult1( out, reg0, reg1 ) (out) = _mm_mul_ss( reg0, reg1 )
1394 #define stbir__simdf_and( out, reg0, reg1 ) (out) = _mm_and_ps( reg0, reg1 )
1395 #define stbir__simdf_or( out, reg0, reg1 ) (out) = _mm_or_ps( reg0, reg1 )
1397 #define stbir__simdf_min( out, reg0, reg1 ) (out) = _mm_min_ps( reg0, reg1 )
1398 #define stbir__simdf_max( out, reg0, reg1 ) (out) = _mm_max_ps( reg0, reg1 )
1399 #define stbir__simdf_min1( out, reg0, reg1 ) (out) = _mm_min_ss( reg0, reg1 )
1400 #define stbir__simdf_max1( out, reg0, reg1 ) (out) = _mm_max_ss( reg0, reg1 )
1402 #define stbir__simdf_0123ABCDto3ABx( out, reg0, reg1 ) (out)=_mm_castsi128_ps( _mm_shuffle_epi32( _mm_castps_si128( _mm_shuffle_ps( reg1,reg0, (0<<0) + (1<<2) + (2<<4) + (3<<6) )), (3<<0) + (0<<2) + (1<<4) + (2<<6) ) )
1403 #define stbir__simdf_0123ABCDto23Ax( out, reg0, reg1 ) (out)=_mm_castsi128_ps( _mm_shuffle_epi32( _mm_castps_si128( _mm_shuffle_ps( reg1,reg0, (0<<0) + (1<<2) + (2<<4) + (3<<6) )), (2<<0) + (3<<2) + (0<<4) + (1<<6) ) )
1405 static const stbir__simdf STBIR_zeroones = { 0.0f,1.0f,0.0f,1.0f };
1406 static const stbir__simdf STBIR_onezeros = { 1.0f,0.0f,1.0f,0.0f };
1407 #define stbir__simdf_aaa1( out, alp, ones ) (out)=_mm_castsi128_ps( _mm_shuffle_epi32( _mm_castps_si128( _mm_movehl_ps( ones, alp ) ), (1<<0) + (1<<2) + (1<<4) + (2<<6) ) )
1408 #define stbir__simdf_1aaa( out, alp, ones ) (out)=_mm_castsi128_ps( _mm_shuffle_epi32( _mm_castps_si128( _mm_movelh_ps( ones, alp ) ), (0<<0) + (2<<2) + (2<<4) + (2<<6) ) )
1409 #define stbir__simdf_a1a1( out, alp, ones) (out) = _mm_or_ps( _mm_castsi128_ps( _mm_srli_epi64( _mm_castps_si128(alp), 32 ) ), STBIR_zeroones )
1410 #define stbir__simdf_1a1a( out, alp, ones) (out) = _mm_or_ps( _mm_castsi128_ps( _mm_slli_epi64( _mm_castps_si128(alp), 32 ) ), STBIR_onezeros )
1412 #define stbir__simdf_swiz( reg, one, two, three, four ) _mm_castsi128_ps( _mm_shuffle_epi32( _mm_castps_si128( reg ), (one<<0) + (two<<2) + (three<<4) + (four<<6) ) )
1414 #define stbir__simdi_and( out, reg0, reg1 ) (out) = _mm_and_si128( reg0, reg1 )
1415 #define stbir__simdi_or( out, reg0, reg1 ) (out) = _mm_or_si128( reg0, reg1 )
1416 #define stbir__simdi_16madd( out, reg0, reg1 ) (out) = _mm_madd_epi16( reg0, reg1 )
1418 #define stbir__simdf_pack_to_8bytes(out,aa,bb) \
1420 stbir__simdf af,bf; \
1422 af = _mm_min_ps( aa, STBIR_max_uint8_as_float ); \
1423 bf = _mm_min_ps( bb, STBIR_max_uint8_as_float ); \
1424 af = _mm_max_ps( af, _mm_setzero_ps() ); \
1425 bf = _mm_max_ps( bf, _mm_setzero_ps() ); \
1426 a = _mm_cvttps_epi32( af ); \
1427 b = _mm_cvttps_epi32( bf ); \
1428 a = _mm_packs_epi32( a, b ); \
1429 out = _mm_packus_epi16( a, a ); \
1432 #define stbir__simdf_load4_transposed( o0, o1, o2, o3, ptr ) \
1433 stbir__simdf_load( o0, (ptr) ); \
1434 stbir__simdf_load( o1, (ptr)+4 ); \
1435 stbir__simdf_load( o2, (ptr)+8 ); \
1436 stbir__simdf_load( o3, (ptr)+12 ); \
1438 __m128 tmp0, tmp1, tmp2, tmp3; \
1439 tmp0 = _mm_unpacklo_ps(o0, o1); \
1440 tmp2 = _mm_unpacklo_ps(o2, o3); \
1441 tmp1 = _mm_unpackhi_ps(o0, o1); \
1442 tmp3 = _mm_unpackhi_ps(o2, o3); \
1443 o0 = _mm_movelh_ps(tmp0, tmp2); \
1444 o1 = _mm_movehl_ps(tmp2, tmp0); \
1445 o2 = _mm_movelh_ps(tmp1, tmp3); \
1446 o3 = _mm_movehl_ps(tmp3, tmp1); \
1449 #define stbir__interleave_pack_and_store_16_u8( ptr, r0, r1, r2, r3 ) \
1450 r0 = _mm_packs_epi32( r0, r1 ); \
1451 r2 = _mm_packs_epi32( r2, r3 ); \
1452 r1 = _mm_unpacklo_epi16( r0, r2 ); \
1453 r3 = _mm_unpackhi_epi16( r0, r2 ); \
1454 r0 = _mm_unpacklo_epi16( r1, r3 ); \
1455 r2 = _mm_unpackhi_epi16( r1, r3 ); \
1456 r0 = _mm_packus_epi16( r0, r2 ); \
1457 stbir__simdi_store( ptr, r0 ); \
1459 #define stbir__simdi_32shr( out, reg, imm ) out = _mm_srli_epi32( reg, imm )
1461 #if defined(_MSC_VER) && !defined(__clang__)
1463 #define STBIR__CONST_32_TO_8( v ) (char)(unsigned char)((v)&255),(char)(unsigned char)(((v)>>8)&255),(char)(unsigned char)(((v)>>16)&255),(char)(unsigned char)(((v)>>24)&255)
1464 #define STBIR__CONST_4_32i( v ) STBIR__CONST_32_TO_8( v ), STBIR__CONST_32_TO_8( v ), STBIR__CONST_32_TO_8( v ), STBIR__CONST_32_TO_8( v )
1465 #define STBIR__CONST_4d_32i( v0, v1, v2, v3 ) STBIR__CONST_32_TO_8( v0 ), STBIR__CONST_32_TO_8( v1 ), STBIR__CONST_32_TO_8( v2 ), STBIR__CONST_32_TO_8( v3 )
1468 #define STBIR__CONST_4_32i( v ) (long long)((((stbir_uint64)(stbir_uint32)(v))<<32)|((stbir_uint64)(stbir_uint32)(v))),(long long)((((stbir_uint64)(stbir_uint32)(v))<<32)|((stbir_uint64)(stbir_uint32)(v)))
1469 #define STBIR__CONST_4d_32i( v0, v1, v2, v3 ) (long long)((((stbir_uint64)(stbir_uint32)(v1))<<32)|((stbir_uint64)(stbir_uint32)(v0))),(long long)((((stbir_uint64)(stbir_uint32)(v3))<<32)|((stbir_uint64)(stbir_uint32)(v2)))
1472 #define STBIR__SIMDF_CONST(var, x) stbir__simdf var = { x, x, x, x }
1473 #define STBIR__SIMDI_CONST(var, x) stbir__simdi var = { STBIR__CONST_4_32i(x) }
1474 #define STBIR__CONSTF(var) (var)
1475 #define STBIR__CONSTI(var) (var)
1477 #if defined(STBIR_AVX) || defined(__SSE4_1__)
1478 #include <smmintrin.h>
1479 #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())))
1481 static STBIR__SIMDI_CONST(stbir__s32_32768, 32768);
1482 static STBIR__SIMDI_CONST(stbir__s16_32768, ((32768<<16)|32768));
1484 #define stbir__simdf_pack_to_8words(out,reg0,reg1) \
1486 stbir__simdi tmp0,tmp1; \
1487 tmp0 = _mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(reg0,STBIR__CONSTF(STBIR_max_uint16_as_float)),_mm_setzero_ps())); \
1488 tmp1 = _mm_cvttps_epi32(_mm_max_ps(_mm_min_ps(reg1,STBIR__CONSTF(STBIR_max_uint16_as_float)),_mm_setzero_ps())); \
1489 tmp0 = _mm_sub_epi32( tmp0, stbir__s32_32768 ); \
1490 tmp1 = _mm_sub_epi32( tmp1, stbir__s32_32768 ); \
1491 out = _mm_packs_epi32( tmp0, tmp1 ); \
1492 out = _mm_sub_epi16( out, stbir__s16_32768 ); \
1501 #include <immintrin.h>
1503 #define stbir__simdf8 __m256
1504 #define stbir__simdi8 __m256i
1505 #define stbir__simdf8_load( out, ptr ) (out) = _mm256_loadu_ps( (float const *)(ptr) )
1506 #define stbir__simdi8_load( out, ptr ) (out) = _mm256_loadu_si256( (__m256i const *)(ptr) )
1507 #define stbir__simdf8_mult( out, a, b ) (out) = _mm256_mul_ps( (a), (b) )
1508 #define stbir__simdf8_store( ptr, out ) _mm256_storeu_ps( (float*)(ptr), out )
1509 #define stbir__simdi8_store( ptr, reg ) _mm256_storeu_si256( (__m256i*)(ptr), reg )
1510 #define stbir__simdf8_frep8( fval ) _mm256_set1_ps( fval )
1512 #define stbir__simdf8_min( out, reg0, reg1 ) (out) = _mm256_min_ps( reg0, reg1 )
1513 #define stbir__simdf8_max( out, reg0, reg1 ) (out) = _mm256_max_ps( reg0, reg1 )
1515 #define stbir__simdf8_add4halves( out, bot4, top8 ) (out) = _mm_add_ps( bot4, _mm256_extractf128_ps( top8, 1 ) )
1516 #define stbir__simdf8_mult_mem( out, reg, ptr ) (out) = _mm256_mul_ps( reg, _mm256_loadu_ps( (float const*)(ptr) ) )
1517 #define stbir__simdf8_add_mem( out, reg, ptr ) (out) = _mm256_add_ps( reg, _mm256_loadu_ps( (float const*)(ptr) ) )
1518 #define stbir__simdf8_add( out, a, b ) (out) = _mm256_add_ps( a, b )
1519 #define stbir__simdf8_load1b( out, ptr ) (out) = _mm256_broadcast_ss( ptr )
1520 #define stbir__simdf_load1rep4( out, ptr ) (out) = _mm_broadcast_ss( ptr )
1522 #define stbir__simdi8_convert_i32_to_float(out, ireg) (out) = _mm256_cvtepi32_ps( ireg )
1523 #define stbir__simdf8_convert_float_to_i32( i, f ) (i) = _mm256_cvttps_epi32(f)
1525 #define stbir__simdf8_bot4s( out, a, b ) (out) = _mm256_permute2f128_ps(a,b, (0<<0)+(2<<4) )
1526 #define stbir__simdf8_top4s( out, a, b ) (out) = _mm256_permute2f128_ps(a,b, (1<<0)+(3<<4) )
1528 #define stbir__simdf8_gettop4( reg ) _mm256_extractf128_ps(reg,1)
1532 #define stbir__simdi8_expand_u8_to_u32(out0,out1,ireg) \
1534 stbir__simdi8 a, zero =_mm256_setzero_si256();\
1535 a = _mm256_permute4x64_epi64( _mm256_unpacklo_epi8( _mm256_permute4x64_epi64(_mm256_castsi128_si256(ireg),(0<<0)+(2<<2)+(1<<4)+(3<<6)), zero ),(0<<0)+(2<<2)+(1<<4)+(3<<6)); \
1536 out0 = _mm256_unpacklo_epi16( a, zero ); \
1537 out1 = _mm256_unpackhi_epi16( a, zero ); \
1540 #define stbir__simdf8_pack_to_16bytes(out,aa,bb) \
1543 stbir__simdf8 af,bf; \
1544 stbir__simdi8 a,b; \
1545 af = _mm256_min_ps( aa, STBIR_max_uint8_as_floatX ); \
1546 bf = _mm256_min_ps( bb, STBIR_max_uint8_as_floatX ); \
1547 af = _mm256_max_ps( af, _mm256_setzero_ps() ); \
1548 bf = _mm256_max_ps( bf, _mm256_setzero_ps() ); \
1549 a = _mm256_cvttps_epi32( af ); \
1550 b = _mm256_cvttps_epi32( bf ); \
1551 t = _mm256_permute4x64_epi64( _mm256_packs_epi32( a, b ), (0<<0)+(2<<2)+(1<<4)+(3<<6) ); \
1552 out = _mm256_castsi256_si128( _mm256_permute4x64_epi64( _mm256_packus_epi16( t, t ), (0<<0)+(2<<2)+(1<<4)+(3<<6) ) ); \
1555 #define stbir__simdi8_expand_u16_to_u32(out,ireg) out = _mm256_unpacklo_epi16( _mm256_permute4x64_epi64(_mm256_castsi128_si256(ireg),(0<<0)+(2<<2)+(1<<4)+(3<<6)), _mm256_setzero_si256() );
1557 #define stbir__simdf8_pack_to_16words(out,aa,bb) \
1559 stbir__simdf8 af,bf; \
1560 stbir__simdi8 a,b; \
1561 af = _mm256_min_ps( aa, STBIR_max_uint16_as_floatX ); \
1562 bf = _mm256_min_ps( bb, STBIR_max_uint16_as_floatX ); \
1563 af = _mm256_max_ps( af, _mm256_setzero_ps() ); \
1564 bf = _mm256_max_ps( bf, _mm256_setzero_ps() ); \
1565 a = _mm256_cvttps_epi32( af ); \
1566 b = _mm256_cvttps_epi32( bf ); \
1567 (out) = _mm256_permute4x64_epi64( _mm256_packus_epi32(a, b), (0<<0)+(2<<2)+(1<<4)+(3<<6) ); \
1572 #define stbir__simdi8_expand_u8_to_u32(out0,out1,ireg) \
1574 stbir__simdi a,zero = _mm_setzero_si128(); \
1575 a = _mm_unpacklo_epi8( ireg, zero ); \
1576 out0 = _mm256_setr_m128i( _mm_unpacklo_epi16( a, zero ), _mm_unpackhi_epi16( a, zero ) ); \
1577 a = _mm_unpackhi_epi8( ireg, zero ); \
1578 out1 = _mm256_setr_m128i( _mm_unpacklo_epi16( a, zero ), _mm_unpackhi_epi16( a, zero ) ); \
1581 #define stbir__simdf8_pack_to_16bytes(out,aa,bb) \
1584 stbir__simdf8 af,bf; \
1585 stbir__simdi8 a,b; \
1586 af = _mm256_min_ps( aa, STBIR_max_uint8_as_floatX ); \
1587 bf = _mm256_min_ps( bb, STBIR_max_uint8_as_floatX ); \
1588 af = _mm256_max_ps( af, _mm256_setzero_ps() ); \
1589 bf = _mm256_max_ps( bf, _mm256_setzero_ps() ); \
1590 a = _mm256_cvttps_epi32( af ); \
1591 b = _mm256_cvttps_epi32( bf ); \
1592 out = _mm_packs_epi32( _mm256_castsi256_si128(a), _mm256_extractf128_si256( a, 1 ) ); \
1593 out = _mm_packus_epi16( out, out ); \
1594 t = _mm_packs_epi32( _mm256_castsi256_si128(b), _mm256_extractf128_si256( b, 1 ) ); \
1595 t = _mm_packus_epi16( t, t ); \
1596 out = _mm_castps_si128( _mm_shuffle_ps( _mm_castsi128_ps(out), _mm_castsi128_ps(t), (0<<0)+(1<<2)+(0<<4)+(1<<6) ) ); \
1599 #define stbir__simdi8_expand_u16_to_u32(out,ireg) \
1601 stbir__simdi a,b,zero = _mm_setzero_si128(); \
1602 a = _mm_unpacklo_epi16( ireg, zero ); \
1603 b = _mm_unpackhi_epi16( ireg, zero ); \
1604 out = _mm256_insertf128_si256( _mm256_castsi128_si256( a ), b, 1 ); \
1607 #define stbir__simdf8_pack_to_16words(out,aa,bb) \
1609 stbir__simdi t0,t1; \
1610 stbir__simdf8 af,bf; \
1611 stbir__simdi8 a,b; \
1612 af = _mm256_min_ps( aa, STBIR_max_uint16_as_floatX ); \
1613 bf = _mm256_min_ps( bb, STBIR_max_uint16_as_floatX ); \
1614 af = _mm256_max_ps( af, _mm256_setzero_ps() ); \
1615 bf = _mm256_max_ps( bf, _mm256_setzero_ps() ); \
1616 a = _mm256_cvttps_epi32( af ); \
1617 b = _mm256_cvttps_epi32( bf ); \
1618 t0 = _mm_packus_epi32( _mm256_castsi256_si128(a), _mm256_extractf128_si256( a, 1 ) ); \
1619 t1 = _mm_packus_epi32( _mm256_castsi256_si128(b), _mm256_extractf128_si256( b, 1 ) ); \
1620 out = _mm256_setr_m128i( t0, t1 ); \
1625 static __m256i stbir_00001111 = { STBIR__CONST_4d_32i( 0, 0, 0, 0 ), STBIR__CONST_4d_32i( 1, 1, 1, 1 ) };
1626 #define stbir__simdf8_0123to00001111( out, in ) (out) = _mm256_permutevar_ps ( in, stbir_00001111 )
1628 static __m256i stbir_22223333 = { STBIR__CONST_4d_32i( 2, 2, 2, 2 ), STBIR__CONST_4d_32i( 3, 3, 3, 3 ) };
1629 #define stbir__simdf8_0123to22223333( out, in ) (out) = _mm256_permutevar_ps ( in, stbir_22223333 )
1631 #define stbir__simdf8_0123to2222( out, in ) (out) = stbir__simdf_swiz(_mm256_castps256_ps128(in), 2,2,2,2 )
1633 #define stbir__simdf8_load4b( out, ptr ) (out) = _mm256_broadcast_ps( (__m128 const *)(ptr) )
1635 static __m256i stbir_00112233 = { STBIR__CONST_4d_32i( 0, 0, 1, 1 ), STBIR__CONST_4d_32i( 2, 2, 3, 3 ) };
1636 #define stbir__simdf8_0123to00112233( out, in ) (out) = _mm256_permutevar_ps ( in, stbir_00112233 )
1637 #define stbir__simdf8_add4( out, a8, b ) (out) = _mm256_add_ps( a8, _mm256_castps128_ps256( b ) )
1639 static __m256i stbir_load6 = { STBIR__CONST_4_32i( 0x80000000 ), STBIR__CONST_4d_32i( 0x80000000, 0x80000000, 0, 0 ) };
1640 #define stbir__simdf8_load6z( out, ptr ) (out) = _mm256_maskload_ps( ptr, stbir_load6 )
1642 #define stbir__simdf8_0123to00000000( out, in ) (out) = _mm256_shuffle_ps ( in, in, (0<<0)+(0<<2)+(0<<4)+(0<<6) )
1643 #define stbir__simdf8_0123to11111111( out, in ) (out) = _mm256_shuffle_ps ( in, in, (1<<0)+(1<<2)+(1<<4)+(1<<6) )
1644 #define stbir__simdf8_0123to22222222( out, in ) (out) = _mm256_shuffle_ps ( in, in, (2<<0)+(2<<2)+(2<<4)+(2<<6) )
1645 #define stbir__simdf8_0123to33333333( out, in ) (out) = _mm256_shuffle_ps ( in, in, (3<<0)+(3<<2)+(3<<4)+(3<<6) )
1646 #define stbir__simdf8_0123to21032103( out, in ) (out) = _mm256_shuffle_ps ( in, in, (2<<0)+(1<<2)+(0<<4)+(3<<6) )
1647 #define stbir__simdf8_0123to32103210( out, in ) (out) = _mm256_shuffle_ps ( in, in, (3<<0)+(2<<2)+(1<<4)+(0<<6) )
1648 #define stbir__simdf8_0123to12301230( out, in ) (out) = _mm256_shuffle_ps ( in, in, (1<<0)+(2<<2)+(3<<4)+(0<<6) )
1649 #define stbir__simdf8_0123to10321032( out, in ) (out) = _mm256_shuffle_ps ( in, in, (1<<0)+(0<<2)+(3<<4)+(2<<6) )
1650 #define stbir__simdf8_0123to30123012( out, in ) (out) = _mm256_shuffle_ps ( in, in, (3<<0)+(0<<2)+(1<<4)+(2<<6) )
1652 #define stbir__simdf8_0123to11331133( out, in ) (out) = _mm256_shuffle_ps ( in, in, (1<<0)+(1<<2)+(3<<4)+(3<<6) )
1653 #define stbir__simdf8_0123to00220022( out, in ) (out) = _mm256_shuffle_ps ( in, in, (0<<0)+(0<<2)+(2<<4)+(2<<6) )
1655 #define stbir__simdf8_aaa1( out, alp, ones ) (out) = _mm256_blend_ps( alp, ones, (1<<0)+(1<<1)+(1<<2)+(0<<3)+(1<<4)+(1<<5)+(1<<6)+(0<<7)); (out)=_mm256_shuffle_ps( out,out, (3<<0) + (3<<2) + (3<<4) + (0<<6) )
1656 #define stbir__simdf8_1aaa( out, alp, ones ) (out) = _mm256_blend_ps( alp, ones, (0<<0)+(1<<1)+(1<<2)+(1<<3)+(0<<4)+(1<<5)+(1<<6)+(1<<7)); (out)=_mm256_shuffle_ps( out,out, (1<<0) + (0<<2) + (0<<4) + (0<<6) )
1657 #define stbir__simdf8_a1a1( out, alp, ones) (out) = _mm256_blend_ps( alp, ones, (1<<0)+(0<<1)+(1<<2)+(0<<3)+(1<<4)+(0<<5)+(1<<6)+(0<<7)); (out)=_mm256_shuffle_ps( out,out, (1<<0) + (0<<2) + (3<<4) + (2<<6) )
1658 #define stbir__simdf8_1a1a( out, alp, ones) (out) = _mm256_blend_ps( alp, ones, (0<<0)+(1<<1)+(0<<2)+(1<<3)+(0<<4)+(1<<5)+(0<<6)+(1<<7)); (out)=_mm256_shuffle_ps( out,out, (1<<0) + (0<<2) + (3<<4) + (2<<6) )
1660 #define stbir__simdf8_zero( reg ) (reg) = _mm256_setzero_ps()
1662 #ifdef STBIR_USE_FMA
1663 #define stbir__simdf8_madd( out, add, mul1, mul2 ) (out) = _mm256_fmadd_ps( mul1, mul2, add )
1664 #define stbir__simdf8_madd_mem( out, add, mul, ptr ) (out) = _mm256_fmadd_ps( mul, _mm256_loadu_ps( (float const*)(ptr) ), add )
1665 #define stbir__simdf8_madd_mem4( out, add, mul, ptr )(out) = _mm256_fmadd_ps( _mm256_setr_m128( mul, _mm_setzero_ps() ), _mm256_setr_m128( _mm_loadu_ps( (float const*)(ptr) ), _mm_setzero_ps() ), add )
1667 #define stbir__simdf8_madd( out, add, mul1, mul2 ) (out) = _mm256_add_ps( add, _mm256_mul_ps( mul1, mul2 ) )
1668 #define stbir__simdf8_madd_mem( out, add, mul, ptr ) (out) = _mm256_add_ps( add, _mm256_mul_ps( mul, _mm256_loadu_ps( (float const*)(ptr) ) ) )
1669 #define stbir__simdf8_madd_mem4( out, add, mul, ptr ) (out) = _mm256_add_ps( add, _mm256_setr_m128( _mm_mul_ps( mul, _mm_loadu_ps( (float const*)(ptr) ) ), _mm_setzero_ps() ) )
1671 #define stbir__if_simdf8_cast_to_simdf4( val ) _mm256_castps256_ps128( val )
1678 #define STBIR_FLOORF stbir_simd_floorf
1679 static stbir__inline
float stbir_simd_floorf(
float x)
1681 #if defined(STBIR_AVX) || defined(__SSE4_1__) || defined(STBIR_SSE41)
1682 __m128 t = _mm_set_ss(x);
1683 return _mm_cvtss_f32( _mm_floor_ss(t, t) );
1685 __m128 f = _mm_set_ss(x);
1686 __m128 t = _mm_cvtepi32_ps(_mm_cvttps_epi32(f));
1687 __m128 r = _mm_add_ss(t, _mm_and_ps(_mm_cmplt_ss(f, t), _mm_set_ss(-1.0f)));
1688 return _mm_cvtss_f32(r);
1695 #define STBIR_CEILF stbir_simd_ceilf
1696 static stbir__inline
float stbir_simd_ceilf(
float x)
1698 #if defined(STBIR_AVX) || defined(__SSE4_1__) || defined(STBIR_SSE41)
1699 __m128 t = _mm_set_ss(x);
1700 return _mm_cvtss_f32( _mm_ceil_ss(t, t) );
1702 __m128 f = _mm_set_ss(x);
1703 __m128 t = _mm_cvtepi32_ps(_mm_cvttps_epi32(f));
1704 __m128 r = _mm_add_ss(t, _mm_and_ps(_mm_cmplt_ss(t, f), _mm_set_ss(1.0f)));
1705 return _mm_cvtss_f32(r);
1709#elif defined(STBIR_NEON)
1711 #include <arm_neon.h>
1713 #define stbir__simdf float32x4_t
1714 #define stbir__simdi uint32x4_t
1716 #define stbir_simdi_castf( reg ) vreinterpretq_u32_f32(reg)
1717 #define stbir_simdf_casti( reg ) vreinterpretq_f32_u32(reg)
1719 #define stbir__simdf_load( reg, ptr ) (reg) = vld1q_f32( (float const*)(ptr) )
1720 #define stbir__simdi_load( reg, ptr ) (reg) = vld1q_u32( (uint32_t const*)(ptr) )
1721 #define stbir__simdf_load1( out, ptr ) (out) = vld1q_dup_f32( (float const*)(ptr) )
1722 #define stbir__simdi_load1( out, ptr ) (out) = vld1q_dup_u32( (uint32_t const*)(ptr) )
1723 #define stbir__simdf_load1z( out, ptr ) (out) = vld1q_lane_f32( (float const*)(ptr), vdupq_n_f32(0), 0 )
1724 #define stbir__simdf_frep4( fvar ) vdupq_n_f32( fvar )
1725 #define stbir__simdf_load1frep4( out, fvar ) (out) = vdupq_n_f32( fvar )
1726 #define stbir__simdf_load2( out, ptr ) (out) = vcombine_f32( vld1_f32( (float const*)(ptr) ), vcreate_f32(0) )
1727 #define stbir__simdf_load2z( out, ptr ) (out) = vcombine_f32( vld1_f32( (float const*)(ptr) ), vcreate_f32(0) )
1728 #define stbir__simdf_load2hmerge( out, reg, ptr ) (out) = vcombine_f32( vget_low_f32(reg), vld1_f32( (float const*)(ptr) ) )
1730 #define stbir__simdf_zeroP() vdupq_n_f32(0)
1731 #define stbir__simdf_zero( reg ) (reg) = vdupq_n_f32(0)
1733 #define stbir__simdf_store( ptr, reg ) vst1q_f32( (float*)(ptr), reg )
1734 #define stbir__simdf_store1( ptr, reg ) vst1q_lane_f32( (float*)(ptr), reg, 0)
1735 #define stbir__simdf_store2( ptr, reg ) vst1_f32( (float*)(ptr), vget_low_f32(reg) )
1736 #define stbir__simdf_store2h( ptr, reg ) vst1_f32( (float*)(ptr), vget_high_f32(reg) )
1738 #define stbir__simdi_store( ptr, reg ) vst1q_u32( (uint32_t*)(ptr), reg )
1739 #define stbir__simdi_store1( ptr, reg ) vst1q_lane_u32( (uint32_t*)(ptr), reg, 0 )
1740 #define stbir__simdi_store2( ptr, reg ) vst1_u32( (uint32_t*)(ptr), vget_low_u32(reg) )
1742 #define stbir__prefetch( ptr )
1744 #define stbir__simdi_expand_u8_to_u32(out0,out1,out2,out3,ireg) \
1746 uint16x8_t l = vmovl_u8( vget_low_u8 ( vreinterpretq_u8_u32(ireg) ) ); \
1747 uint16x8_t h = vmovl_u8( vget_high_u8( vreinterpretq_u8_u32(ireg) ) ); \
1748 out0 = vmovl_u16( vget_low_u16 ( l ) ); \
1749 out1 = vmovl_u16( vget_high_u16( l ) ); \
1750 out2 = vmovl_u16( vget_low_u16 ( h ) ); \
1751 out3 = vmovl_u16( vget_high_u16( h ) ); \
1754 #define stbir__simdi_expand_u8_to_1u32(out,ireg) \
1756 uint16x8_t tmp = vmovl_u8( vget_low_u8( vreinterpretq_u8_u32(ireg) ) ); \
1757 out = vmovl_u16( vget_low_u16( tmp ) ); \
1760 #define stbir__simdi_expand_u16_to_u32(out0,out1,ireg) \
1762 uint16x8_t tmp = vreinterpretq_u16_u32(ireg); \
1763 out0 = vmovl_u16( vget_low_u16 ( tmp ) ); \
1764 out1 = vmovl_u16( vget_high_u16( tmp ) ); \
1767 #define stbir__simdf_convert_float_to_i32( i, f ) (i) = vreinterpretq_u32_s32( vcvtq_s32_f32(f) )
1768 #define stbir__simdf_convert_float_to_int( f ) vgetq_lane_s32(vcvtq_s32_f32(f), 0)
1769 #define stbir__simdi_to_int( i ) (int)vgetq_lane_u32(i, 0)
1770 #define stbir__simdf_convert_float_to_uint8( f ) ((unsigned char)vgetq_lane_s32(vcvtq_s32_f32(vmaxq_f32(vminq_f32(f,STBIR__CONSTF(STBIR_max_uint8_as_float)),vdupq_n_f32(0))), 0))
1771 #define stbir__simdf_convert_float_to_short( f ) ((unsigned short)vgetq_lane_s32(vcvtq_s32_f32(vmaxq_f32(vminq_f32(f,STBIR__CONSTF(STBIR_max_uint16_as_float)),vdupq_n_f32(0))), 0))
1772 #define stbir__simdi_convert_i32_to_float(out, ireg) (out) = vcvtq_f32_s32( vreinterpretq_s32_u32(ireg) )
1773 #define stbir__simdf_add( out, reg0, reg1 ) (out) = vaddq_f32( reg0, reg1 )
1774 #define stbir__simdf_mult( out, reg0, reg1 ) (out) = vmulq_f32( reg0, reg1 )
1775 #define stbir__simdf_mult_mem( out, reg, ptr ) (out) = vmulq_f32( reg, vld1q_f32( (float const*)(ptr) ) )
1776 #define stbir__simdf_mult1_mem( out, reg, ptr ) (out) = vmulq_f32( reg, vld1q_dup_f32( (float const*)(ptr) ) )
1777 #define stbir__simdf_add_mem( out, reg, ptr ) (out) = vaddq_f32( reg, vld1q_f32( (float const*)(ptr) ) )
1778 #define stbir__simdf_add1_mem( out, reg, ptr ) (out) = vaddq_f32( reg, vld1q_dup_f32( (float const*)(ptr) ) )
1780 #ifdef STBIR_USE_FMA
1781 #define stbir__simdf_madd( out, add, mul1, mul2 ) (out) = vfmaq_f32( add, mul1, mul2 )
1782 #define stbir__simdf_madd1( out, add, mul1, mul2 ) (out) = vfmaq_f32( add, mul1, mul2 )
1783 #define stbir__simdf_madd_mem( out, add, mul, ptr ) (out) = vfmaq_f32( add, mul, vld1q_f32( (float const*)(ptr) ) )
1784 #define stbir__simdf_madd1_mem( out, add, mul, ptr ) (out) = vfmaq_f32( add, mul, vld1q_dup_f32( (float const*)(ptr) ) )
1786 #define stbir__simdf_madd( out, add, mul1, mul2 ) (out) = vaddq_f32( add, vmulq_f32( mul1, mul2 ) )
1787 #define stbir__simdf_madd1( out, add, mul1, mul2 ) (out) = vaddq_f32( add, vmulq_f32( mul1, mul2 ) )
1788 #define stbir__simdf_madd_mem( out, add, mul, ptr ) (out) = vaddq_f32( add, vmulq_f32( mul, vld1q_f32( (float const*)(ptr) ) ) )
1789 #define stbir__simdf_madd1_mem( out, add, mul, ptr ) (out) = vaddq_f32( add, vmulq_f32( mul, vld1q_dup_f32( (float const*)(ptr) ) ) )
1792 #define stbir__simdf_add1( out, reg0, reg1 ) (out) = vaddq_f32( reg0, reg1 )
1793 #define stbir__simdf_mult1( out, reg0, reg1 ) (out) = vmulq_f32( reg0, reg1 )
1795 #define stbir__simdf_and( out, reg0, reg1 ) (out) = vreinterpretq_f32_u32( vandq_u32( vreinterpretq_u32_f32(reg0), vreinterpretq_u32_f32(reg1) ) )
1796 #define stbir__simdf_or( out, reg0, reg1 ) (out) = vreinterpretq_f32_u32( vorrq_u32( vreinterpretq_u32_f32(reg0), vreinterpretq_u32_f32(reg1) ) )
1798 #define stbir__simdf_min( out, reg0, reg1 ) (out) = vminq_f32( reg0, reg1 )
1799 #define stbir__simdf_max( out, reg0, reg1 ) (out) = vmaxq_f32( reg0, reg1 )
1800 #define stbir__simdf_min1( out, reg0, reg1 ) (out) = vminq_f32( reg0, reg1 )
1801 #define stbir__simdf_max1( out, reg0, reg1 ) (out) = vmaxq_f32( reg0, reg1 )
1803 #define stbir__simdf_0123ABCDto3ABx( out, reg0, reg1 ) (out) = vextq_f32( reg0, reg1, 3 )
1804 #define stbir__simdf_0123ABCDto23Ax( out, reg0, reg1 ) (out) = vextq_f32( reg0, reg1, 2 )
1806 #define stbir__simdf_a1a1( out, alp, ones ) (out) = vzipq_f32(vuzpq_f32(alp, alp).val[1], ones).val[0]
1807 #define stbir__simdf_1a1a( out, alp, ones ) (out) = vzipq_f32(ones, vuzpq_f32(alp, alp).val[0]).val[0]
1809 #if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ )
1811 #define stbir__simdf_aaa1( out, alp, ones ) (out) = vcopyq_laneq_f32(vdupq_n_f32(vgetq_lane_f32(alp, 3)), 3, ones, 3)
1812 #define stbir__simdf_1aaa( out, alp, ones ) (out) = vcopyq_laneq_f32(vdupq_n_f32(vgetq_lane_f32(alp, 0)), 0, ones, 0)
1814 #if defined( _MSC_VER ) && !defined(__clang__)
1815 #define stbir_make16(a,b,c,d) vcombine_u8( \
1816 vcreate_u8( (4*a+0) | ((4*a+1)<<8) | ((4*a+2)<<16) | ((4*a+3)<<24) | \
1817 ((stbir_uint64)(4*b+0)<<32) | ((stbir_uint64)(4*b+1)<<40) | ((stbir_uint64)(4*b+2)<<48) | ((stbir_uint64)(4*b+3)<<56)), \
1818 vcreate_u8( (4*c+0) | ((4*c+1)<<8) | ((4*c+2)<<16) | ((4*c+3)<<24) | \
1819 ((stbir_uint64)(4*d+0)<<32) | ((stbir_uint64)(4*d+1)<<40) | ((stbir_uint64)(4*d+2)<<48) | ((stbir_uint64)(4*d+3)<<56) ) )
1821 static stbir__inline uint8x16x2_t stbir_make16x2(float32x4_t rega,float32x4_t regb)
1823 uint8x16x2_t r = { vreinterpretq_u8_f32(rega), vreinterpretq_u8_f32(regb) };
1827 #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}
1828 #define stbir_make16x2(a,b) (uint8x16x2_t){{vreinterpretq_u8_f32(a),vreinterpretq_u8_f32(b)}}
1831 #define stbir__simdf_swiz( reg, one, two, three, four ) vreinterpretq_f32_u8( vqtbl1q_u8( vreinterpretq_u8_f32(reg), stbir_make16(one, two, three, four) ) )
1832 #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) ) )
1834 #define stbir__simdi_16madd( out, reg0, reg1 ) \
1836 int16x8_t r0 = vreinterpretq_s16_u32(reg0); \
1837 int16x8_t r1 = vreinterpretq_s16_u32(reg1); \
1838 int32x4_t tmp0 = vmull_s16( vget_low_s16(r0), vget_low_s16(r1) ); \
1839 int32x4_t tmp1 = vmull_s16( vget_high_s16(r0), vget_high_s16(r1) ); \
1840 (out) = vreinterpretq_u32_s32( vpaddq_s32(tmp0, tmp1) ); \
1845 #define stbir__simdf_aaa1( out, alp, ones ) (out) = vsetq_lane_f32(1.0f, vdupq_n_f32(vgetq_lane_f32(alp, 3)), 3)
1846 #define stbir__simdf_1aaa( out, alp, ones ) (out) = vsetq_lane_f32(1.0f, vdupq_n_f32(vgetq_lane_f32(alp, 0)), 0)
1848 #if defined( _MSC_VER ) && !defined(__clang__)
1849 static stbir__inline uint8x8x2_t stbir_make8x2(float32x4_t reg)
1851 uint8x8x2_t r = { { vget_low_u8(vreinterpretq_u8_f32(reg)), vget_high_u8(vreinterpretq_u8_f32(reg)) } };
1854 #define stbir_make8(a,b) vcreate_u8( \
1855 (4*a+0) | ((4*a+1)<<8) | ((4*a+2)<<16) | ((4*a+3)<<24) | \
1856 ((stbir_uint64)(4*b+0)<<32) | ((stbir_uint64)(4*b+1)<<40) | ((stbir_uint64)(4*b+2)<<48) | ((stbir_uint64)(4*b+3)<<56) )
1858 #define stbir_make8x2(reg) (uint8x8x2_t){ { vget_low_u8(vreinterpretq_u8_f32(reg)), vget_high_u8(vreinterpretq_u8_f32(reg)) } }
1859 #define stbir_make8(a,b) (uint8x8_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}
1862 #define stbir__simdf_swiz( reg, one, two, three, four ) vreinterpretq_f32_u8( vcombine_u8( \
1863 vtbl2_u8( stbir_make8x2( reg ), stbir_make8( one, two ) ), \
1864 vtbl2_u8( stbir_make8x2( reg ), stbir_make8( three, four ) ) ) )
1866 #define stbir__simdi_16madd( out, reg0, reg1 ) \
1868 int16x8_t r0 = vreinterpretq_s16_u32(reg0); \
1869 int16x8_t r1 = vreinterpretq_s16_u32(reg1); \
1870 int32x4_t tmp0 = vmull_s16( vget_low_s16(r0), vget_low_s16(r1) ); \
1871 int32x4_t tmp1 = vmull_s16( vget_high_s16(r0), vget_high_s16(r1) ); \
1872 int32x2_t out0 = vpadd_s32( vget_low_s32(tmp0), vget_high_s32(tmp0) ); \
1873 int32x2_t out1 = vpadd_s32( vget_low_s32(tmp1), vget_high_s32(tmp1) ); \
1874 (out) = vreinterpretq_u32_s32( vcombine_s32(out0, out1) ); \
1879 #define stbir__simdi_and( out, reg0, reg1 ) (out) = vandq_u32( reg0, reg1 )
1880 #define stbir__simdi_or( out, reg0, reg1 ) (out) = vorrq_u32( reg0, reg1 )
1882 #define stbir__simdf_pack_to_8bytes(out,aa,bb) \
1884 float32x4_t af = vmaxq_f32( vminq_f32(aa,STBIR__CONSTF(STBIR_max_uint8_as_float) ), vdupq_n_f32(0) ); \
1885 float32x4_t bf = vmaxq_f32( vminq_f32(bb,STBIR__CONSTF(STBIR_max_uint8_as_float) ), vdupq_n_f32(0) ); \
1886 int16x4_t ai = vqmovn_s32( vcvtq_s32_f32( af ) ); \
1887 int16x4_t bi = vqmovn_s32( vcvtq_s32_f32( bf ) ); \
1888 uint8x8_t out8 = vqmovun_s16( vcombine_s16(ai, bi) ); \
1889 out = vreinterpretq_u32_u8( vcombine_u8(out8, out8) ); \
1892 #define stbir__simdf_pack_to_8words(out,aa,bb) \
1894 float32x4_t af = vmaxq_f32( vminq_f32(aa,STBIR__CONSTF(STBIR_max_uint16_as_float) ), vdupq_n_f32(0) ); \
1895 float32x4_t bf = vmaxq_f32( vminq_f32(bb,STBIR__CONSTF(STBIR_max_uint16_as_float) ), vdupq_n_f32(0) ); \
1896 int32x4_t ai = vcvtq_s32_f32( af ); \
1897 int32x4_t bi = vcvtq_s32_f32( bf ); \
1898 out = vreinterpretq_u32_u16( vcombine_u16(vqmovun_s32(ai), vqmovun_s32(bi)) ); \
1901 #define stbir__interleave_pack_and_store_16_u8( ptr, r0, r1, r2, r3 ) \
1903 int16x4x2_t tmp0 = vzip_s16( vqmovn_s32(vreinterpretq_s32_u32(r0)), vqmovn_s32(vreinterpretq_s32_u32(r2)) ); \
1904 int16x4x2_t tmp1 = vzip_s16( vqmovn_s32(vreinterpretq_s32_u32(r1)), vqmovn_s32(vreinterpretq_s32_u32(r3)) ); \
1907 vqmovun_s16( vcombine_s16(tmp0.val[0], tmp0.val[1]) ), \
1908 vqmovun_s16( vcombine_s16(tmp1.val[0], tmp1.val[1]) ), \
1910 vst2_u8(ptr, out); \
1913 #define stbir__simdf_load4_transposed( o0, o1, o2, o3, ptr ) \
1915 float32x4x4_t tmp = vld4q_f32(ptr); \
1922 #define stbir__simdi_32shr( out, reg, imm ) out = vshrq_n_u32( reg, imm )
1924 #if defined( _MSC_VER ) && !defined(__clang__)
1925 #define STBIR__SIMDF_CONST(var, x) __declspec(align(8)) float var[] = { x, x, x, x }
1926 #define STBIR__SIMDI_CONST(var, x) __declspec(align(8)) uint32_t var[] = { x, x, x, x }
1927 #define STBIR__CONSTF(var) (*(const float32x4_t*)var)
1928 #define STBIR__CONSTI(var) (*(const uint32x4_t*)var)
1930 #define STBIR__SIMDF_CONST(var, x) stbir__simdf var = { x, x, x, x }
1931 #define STBIR__SIMDI_CONST(var, x) stbir__simdi var = { x, x, x, x }
1932 #define STBIR__CONSTF(var) (var)
1933 #define STBIR__CONSTI(var) (var)
1939 #define STBIR_FLOORF stbir_simd_floorf
1940 static stbir__inline
float stbir_simd_floorf(
float x)
1942 #if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ )
1943 return vget_lane_f32( vrndm_f32( vdup_n_f32(x) ), 0);
1945 float32x2_t f = vdup_n_f32(x);
1946 float32x2_t t = vcvt_f32_s32(vcvt_s32_f32(f));
1947 uint32x2_t a = vclt_f32(f, t);
1948 uint32x2_t b = vreinterpret_u32_f32(vdup_n_f32(-1.0f));
1949 float32x2_t r = vadd_f32(t, vreinterpret_f32_u32(vand_u32(a, b)));
1950 return vget_lane_f32(r, 0);
1957 #define STBIR_CEILF stbir_simd_ceilf
1958 static stbir__inline
float stbir_simd_ceilf(
float x)
1960 #if defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ )
1961 return vget_lane_f32( vrndp_f32( vdup_n_f32(x) ), 0);
1963 float32x2_t f = vdup_n_f32(x);
1964 float32x2_t t = vcvt_f32_s32(vcvt_s32_f32(f));
1965 uint32x2_t a = vclt_f32(t, f);
1966 uint32x2_t b = vreinterpret_u32_f32(vdup_n_f32(1.0f));
1967 float32x2_t r = vadd_f32(t, vreinterpret_f32_u32(vand_u32(a, b)));
1968 return vget_lane_f32(r, 0);
1974#elif defined(STBIR_WASM)
1976 #include <wasm_simd128.h>
1978 #define stbir__simdf v128_t
1979 #define stbir__simdi v128_t
1981 #define stbir_simdi_castf( reg ) (reg)
1982 #define stbir_simdf_casti( reg ) (reg)
1984 #define stbir__simdf_load( reg, ptr ) (reg) = wasm_v128_load( (void const*)(ptr) )
1985 #define stbir__simdi_load( reg, ptr ) (reg) = wasm_v128_load( (void const*)(ptr) )
1986 #define stbir__simdf_load1( out, ptr ) (out) = wasm_v128_load32_splat( (void const*)(ptr) )
1987 #define stbir__simdi_load1( out, ptr ) (out) = wasm_v128_load32_splat( (void const*)(ptr) )
1988 #define stbir__simdf_load1z( out, ptr ) (out) = wasm_v128_load32_zero( (void const*)(ptr) )
1989 #define stbir__simdf_frep4( fvar ) wasm_f32x4_splat( fvar )
1990 #define stbir__simdf_load1frep4( out, fvar ) (out) = wasm_f32x4_splat( fvar )
1991 #define stbir__simdf_load2( out, ptr ) (out) = wasm_v128_load64_splat( (void const*)(ptr) )
1992 #define stbir__simdf_load2z( out, ptr ) (out) = wasm_v128_load64_zero( (void const*)(ptr) )
1993 #define stbir__simdf_load2hmerge( out, reg, ptr ) (out) = wasm_v128_load64_lane( (void const*)(ptr), reg, 1 )
1995 #define stbir__simdf_zeroP() wasm_f32x4_const_splat(0)
1996 #define stbir__simdf_zero( reg ) (reg) = wasm_f32x4_const_splat(0)
1998 #define stbir__simdf_store( ptr, reg ) wasm_v128_store( (void*)(ptr), reg )
1999 #define stbir__simdf_store1( ptr, reg ) wasm_v128_store32_lane( (void*)(ptr), reg, 0 )
2000 #define stbir__simdf_store2( ptr, reg ) wasm_v128_store64_lane( (void*)(ptr), reg, 0 )
2001 #define stbir__simdf_store2h( ptr, reg ) wasm_v128_store64_lane( (void*)(ptr), reg, 1 )
2003 #define stbir__simdi_store( ptr, reg ) wasm_v128_store( (void*)(ptr), reg )
2004 #define stbir__simdi_store1( ptr, reg ) wasm_v128_store32_lane( (void*)(ptr), reg, 0 )
2005 #define stbir__simdi_store2( ptr, reg ) wasm_v128_store64_lane( (void*)(ptr), reg, 0 )
2007 #define stbir__prefetch( ptr )
2009 #define stbir__simdi_expand_u8_to_u32(out0,out1,out2,out3,ireg) \
2011 v128_t l = wasm_u16x8_extend_low_u8x16 ( ireg ); \
2012 v128_t h = wasm_u16x8_extend_high_u8x16( ireg ); \
2013 out0 = wasm_u32x4_extend_low_u16x8 ( l ); \
2014 out1 = wasm_u32x4_extend_high_u16x8( l ); \
2015 out2 = wasm_u32x4_extend_low_u16x8 ( h ); \
2016 out3 = wasm_u32x4_extend_high_u16x8( h ); \
2019 #define stbir__simdi_expand_u8_to_1u32(out,ireg) \
2021 v128_t tmp = wasm_u16x8_extend_low_u8x16(ireg); \
2022 out = wasm_u32x4_extend_low_u16x8(tmp); \
2025 #define stbir__simdi_expand_u16_to_u32(out0,out1,ireg) \
2027 out0 = wasm_u32x4_extend_low_u16x8 ( ireg ); \
2028 out1 = wasm_u32x4_extend_high_u16x8( ireg ); \
2031 #define stbir__simdf_convert_float_to_i32( i, f ) (i) = wasm_i32x4_trunc_sat_f32x4(f)
2032 #define stbir__simdf_convert_float_to_int( f ) wasm_i32x4_extract_lane(wasm_i32x4_trunc_sat_f32x4(f), 0)
2033 #define stbir__simdi_to_int( i ) wasm_i32x4_extract_lane(i, 0)
2034 #define stbir__simdf_convert_float_to_uint8( f ) ((unsigned char)wasm_i32x4_extract_lane(wasm_i32x4_trunc_sat_f32x4(wasm_f32x4_max(wasm_f32x4_min(f,STBIR_max_uint8_as_float),wasm_f32x4_const_splat(0))), 0))
2035 #define stbir__simdf_convert_float_to_short( f ) ((unsigned short)wasm_i32x4_extract_lane(wasm_i32x4_trunc_sat_f32x4(wasm_f32x4_max(wasm_f32x4_min(f,STBIR_max_uint16_as_float),wasm_f32x4_const_splat(0))), 0))
2036 #define stbir__simdi_convert_i32_to_float(out, ireg) (out) = wasm_f32x4_convert_i32x4(ireg)
2037 #define stbir__simdf_add( out, reg0, reg1 ) (out) = wasm_f32x4_add( reg0, reg1 )
2038 #define stbir__simdf_mult( out, reg0, reg1 ) (out) = wasm_f32x4_mul( reg0, reg1 )
2039 #define stbir__simdf_mult_mem( out, reg, ptr ) (out) = wasm_f32x4_mul( reg, wasm_v128_load( (void const*)(ptr) ) )
2040 #define stbir__simdf_mult1_mem( out, reg, ptr ) (out) = wasm_f32x4_mul( reg, wasm_v128_load32_splat( (void const*)(ptr) ) )
2041 #define stbir__simdf_add_mem( out, reg, ptr ) (out) = wasm_f32x4_add( reg, wasm_v128_load( (void const*)(ptr) ) )
2042 #define stbir__simdf_add1_mem( out, reg, ptr ) (out) = wasm_f32x4_add( reg, wasm_v128_load32_splat( (void const*)(ptr) ) )
2044 #define stbir__simdf_madd( out, add, mul1, mul2 ) (out) = wasm_f32x4_add( add, wasm_f32x4_mul( mul1, mul2 ) )
2045 #define stbir__simdf_madd1( out, add, mul1, mul2 ) (out) = wasm_f32x4_add( add, wasm_f32x4_mul( mul1, mul2 ) )
2046 #define stbir__simdf_madd_mem( out, add, mul, ptr ) (out) = wasm_f32x4_add( add, wasm_f32x4_mul( mul, wasm_v128_load( (void const*)(ptr) ) ) )
2047 #define stbir__simdf_madd1_mem( out, add, mul, ptr ) (out) = wasm_f32x4_add( add, wasm_f32x4_mul( mul, wasm_v128_load32_splat( (void const*)(ptr) ) ) )
2049 #define stbir__simdf_add1( out, reg0, reg1 ) (out) = wasm_f32x4_add( reg0, reg1 )
2050 #define stbir__simdf_mult1( out, reg0, reg1 ) (out) = wasm_f32x4_mul( reg0, reg1 )
2052 #define stbir__simdf_and( out, reg0, reg1 ) (out) = wasm_v128_and( reg0, reg1 )
2053 #define stbir__simdf_or( out, reg0, reg1 ) (out) = wasm_v128_or( reg0, reg1 )
2055 #define stbir__simdf_min( out, reg0, reg1 ) (out) = wasm_f32x4_min( reg0, reg1 )
2056 #define stbir__simdf_max( out, reg0, reg1 ) (out) = wasm_f32x4_max( reg0, reg1 )
2057 #define stbir__simdf_min1( out, reg0, reg1 ) (out) = wasm_f32x4_min( reg0, reg1 )
2058 #define stbir__simdf_max1( out, reg0, reg1 ) (out) = wasm_f32x4_max( reg0, reg1 )
2060 #define stbir__simdf_0123ABCDto3ABx( out, reg0, reg1 ) (out) = wasm_i32x4_shuffle( reg0, reg1, 3, 4, 5, -1 )
2061 #define stbir__simdf_0123ABCDto23Ax( out, reg0, reg1 ) (out) = wasm_i32x4_shuffle( reg0, reg1, 2, 3, 4, -1 )
2063 #define stbir__simdf_aaa1(out,alp,ones) (out) = wasm_i32x4_shuffle(alp, ones, 3, 3, 3, 4)
2064 #define stbir__simdf_1aaa(out,alp,ones) (out) = wasm_i32x4_shuffle(alp, ones, 4, 0, 0, 0)
2065 #define stbir__simdf_a1a1(out,alp,ones) (out) = wasm_i32x4_shuffle(alp, ones, 1, 4, 3, 4)
2066 #define stbir__simdf_1a1a(out,alp,ones) (out) = wasm_i32x4_shuffle(alp, ones, 4, 0, 4, 2)
2068 #define stbir__simdf_swiz( reg, one, two, three, four ) wasm_i32x4_shuffle(reg, reg, one, two, three, four)
2070 #define stbir__simdi_and( out, reg0, reg1 ) (out) = wasm_v128_and( reg0, reg1 )
2071 #define stbir__simdi_or( out, reg0, reg1 ) (out) = wasm_v128_or( reg0, reg1 )
2072 #define stbir__simdi_16madd( out, reg0, reg1 ) (out) = wasm_i32x4_dot_i16x8( reg0, reg1 )
2074 #define stbir__simdf_pack_to_8bytes(out,aa,bb) \
2076 v128_t af = wasm_f32x4_max( wasm_f32x4_min(aa, STBIR_max_uint8_as_float), wasm_f32x4_const_splat(0) ); \
2077 v128_t bf = wasm_f32x4_max( wasm_f32x4_min(bb, STBIR_max_uint8_as_float), wasm_f32x4_const_splat(0) ); \
2078 v128_t ai = wasm_i32x4_trunc_sat_f32x4( af ); \
2079 v128_t bi = wasm_i32x4_trunc_sat_f32x4( bf ); \
2080 v128_t out16 = wasm_i16x8_narrow_i32x4( ai, bi ); \
2081 out = wasm_u8x16_narrow_i16x8( out16, out16 ); \
2084 #define stbir__simdf_pack_to_8words(out,aa,bb) \
2086 v128_t af = wasm_f32x4_max( wasm_f32x4_min(aa, STBIR_max_uint16_as_float), wasm_f32x4_const_splat(0)); \
2087 v128_t bf = wasm_f32x4_max( wasm_f32x4_min(bb, STBIR_max_uint16_as_float), wasm_f32x4_const_splat(0)); \
2088 v128_t ai = wasm_i32x4_trunc_sat_f32x4( af ); \
2089 v128_t bi = wasm_i32x4_trunc_sat_f32x4( bf ); \
2090 out = wasm_u16x8_narrow_i32x4( ai, bi ); \
2093 #define stbir__interleave_pack_and_store_16_u8( ptr, r0, r1, r2, r3 ) \
2095 v128_t tmp0 = wasm_i16x8_narrow_i32x4(r0, r1); \
2096 v128_t tmp1 = wasm_i16x8_narrow_i32x4(r2, r3); \
2097 v128_t tmp = wasm_u8x16_narrow_i16x8(tmp0, tmp1); \
2098 tmp = wasm_i8x16_shuffle(tmp, tmp, 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); \
2099 wasm_v128_store( (void*)(ptr), tmp); \
2102 #define stbir__simdf_load4_transposed( o0, o1, o2, o3, ptr ) \
2104 v128_t t0 = wasm_v128_load( ptr ); \
2105 v128_t t1 = wasm_v128_load( ptr+4 ); \
2106 v128_t t2 = wasm_v128_load( ptr+8 ); \
2107 v128_t t3 = wasm_v128_load( ptr+12 ); \
2108 v128_t s0 = wasm_i32x4_shuffle(t0, t1, 0, 4, 2, 6); \
2109 v128_t s1 = wasm_i32x4_shuffle(t0, t1, 1, 5, 3, 7); \
2110 v128_t s2 = wasm_i32x4_shuffle(t2, t3, 0, 4, 2, 6); \
2111 v128_t s3 = wasm_i32x4_shuffle(t2, t3, 1, 5, 3, 7); \
2112 o0 = wasm_i32x4_shuffle(s0, s2, 0, 1, 4, 5); \
2113 o1 = wasm_i32x4_shuffle(s1, s3, 0, 1, 4, 5); \
2114 o2 = wasm_i32x4_shuffle(s0, s2, 2, 3, 6, 7); \
2115 o3 = wasm_i32x4_shuffle(s1, s3, 2, 3, 6, 7); \
2118 #define stbir__simdi_32shr( out, reg, imm ) out = wasm_u32x4_shr( reg, imm )
2120 typedef float stbir__f32x4 __attribute__((__vector_size__(16), __aligned__(16)));
2121 #define STBIR__SIMDF_CONST(var, x) stbir__simdf var = (v128_t)(stbir__f32x4){ x, x, x, x }
2122 #define STBIR__SIMDI_CONST(var, x) stbir__simdi var = { x, x, x, x }
2123 #define STBIR__CONSTF(var) (var)
2124 #define STBIR__CONSTI(var) (var)
2129 #define STBIR_FLOORF stbir_simd_floorf
2130 static stbir__inline
float stbir_simd_floorf(
float x)
2132 return wasm_f32x4_extract_lane( wasm_f32x4_floor( wasm_f32x4_splat(x) ), 0);
2138 #define STBIR_CEILF stbir_simd_ceilf
2139 static stbir__inline
float stbir_simd_ceilf(
float x)
2141 return wasm_f32x4_extract_lane( wasm_f32x4_ceil( wasm_f32x4_splat(x) ), 0);
2151 #define stbir__simdfX stbir__simdf8
2152 #define stbir__simdiX stbir__simdi8
2153 #define stbir__simdfX_load stbir__simdf8_load
2154 #define stbir__simdiX_load stbir__simdi8_load
2155 #define stbir__simdfX_mult stbir__simdf8_mult
2156 #define stbir__simdfX_add_mem stbir__simdf8_add_mem
2157 #define stbir__simdfX_madd_mem stbir__simdf8_madd_mem
2158 #define stbir__simdfX_store stbir__simdf8_store
2159 #define stbir__simdiX_store stbir__simdi8_store
2160 #define stbir__simdf_frepX stbir__simdf8_frep8
2161 #define stbir__simdfX_madd stbir__simdf8_madd
2162 #define stbir__simdfX_min stbir__simdf8_min
2163 #define stbir__simdfX_max stbir__simdf8_max
2164 #define stbir__simdfX_aaa1 stbir__simdf8_aaa1
2165 #define stbir__simdfX_1aaa stbir__simdf8_1aaa
2166 #define stbir__simdfX_a1a1 stbir__simdf8_a1a1
2167 #define stbir__simdfX_1a1a stbir__simdf8_1a1a
2168 #define stbir__simdfX_convert_float_to_i32 stbir__simdf8_convert_float_to_i32
2169 #define stbir__simdfX_pack_to_words stbir__simdf8_pack_to_16words
2170 #define stbir__simdfX_zero stbir__simdf8_zero
2171 #define STBIR_onesX STBIR_ones8
2172 #define STBIR_max_uint8_as_floatX STBIR_max_uint8_as_float8
2173 #define STBIR_max_uint16_as_floatX STBIR_max_uint16_as_float8
2174 #define STBIR_simd_point5X STBIR_simd_point58
2175 #define stbir__simdfX_float_count 8
2176 #define stbir__simdfX_0123to1230 stbir__simdf8_0123to12301230
2177 #define stbir__simdfX_0123to2103 stbir__simdf8_0123to21032103
2178 static const stbir__simdf8 STBIR_max_uint16_as_float_inverted8 = { stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted,stbir__max_uint16_as_float_inverted };
2179 static const stbir__simdf8 STBIR_max_uint8_as_float_inverted8 = { stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted,stbir__max_uint8_as_float_inverted };
2180 static const stbir__simdf8 STBIR_ones8 = { 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0 };
2181 static const stbir__simdf8 STBIR_simd_point58 = { 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 };
2182 static const stbir__simdf8 STBIR_max_uint8_as_float8 = { stbir__max_uint8_as_float,stbir__max_uint8_as_float,stbir__max_uint8_as_float,stbir__max_uint8_as_float, stbir__max_uint8_as_float,stbir__max_uint8_as_float,stbir__max_uint8_as_float,stbir__max_uint8_as_float };
2183 static const stbir__simdf8 STBIR_max_uint16_as_float8 = { stbir__max_uint16_as_float,stbir__max_uint16_as_float,stbir__max_uint16_as_float,stbir__max_uint16_as_float, stbir__max_uint16_as_float,stbir__max_uint16_as_float,stbir__max_uint16_as_float,stbir__max_uint16_as_float };
2185 #define stbir__simdfX stbir__simdf
2186 #define stbir__simdiX stbir__simdi
2187 #define stbir__simdfX_load stbir__simdf_load
2188 #define stbir__simdiX_load stbir__simdi_load
2189 #define stbir__simdfX_mult stbir__simdf_mult
2190 #define stbir__simdfX_add_mem stbir__simdf_add_mem
2191 #define stbir__simdfX_madd_mem stbir__simdf_madd_mem
2192 #define stbir__simdfX_store stbir__simdf_store
2193 #define stbir__simdiX_store stbir__simdi_store
2194 #define stbir__simdf_frepX stbir__simdf_frep4
2195 #define stbir__simdfX_madd stbir__simdf_madd
2196 #define stbir__simdfX_min stbir__simdf_min
2197 #define stbir__simdfX_max stbir__simdf_max
2198 #define stbir__simdfX_aaa1 stbir__simdf_aaa1
2199 #define stbir__simdfX_1aaa stbir__simdf_1aaa
2200 #define stbir__simdfX_a1a1 stbir__simdf_a1a1
2201 #define stbir__simdfX_1a1a stbir__simdf_1a1a
2202 #define stbir__simdfX_convert_float_to_i32 stbir__simdf_convert_float_to_i32
2203 #define stbir__simdfX_pack_to_words stbir__simdf_pack_to_8words
2204 #define stbir__simdfX_zero stbir__simdf_zero
2205 #define STBIR_onesX STBIR__CONSTF(STBIR_ones)
2206 #define STBIR_simd_point5X STBIR__CONSTF(STBIR_simd_point5)
2207 #define STBIR_max_uint8_as_floatX STBIR__CONSTF(STBIR_max_uint8_as_float)
2208 #define STBIR_max_uint16_as_floatX STBIR__CONSTF(STBIR_max_uint16_as_float)
2209 #define stbir__simdfX_float_count 4
2210 #define stbir__if_simdf8_cast_to_simdf4( val ) ( val )
2211 #define stbir__simdfX_0123to1230 stbir__simdf_0123to1230
2212 #define stbir__simdfX_0123to2103 stbir__simdf_0123to2103
2216#if defined(STBIR_NEON) && !defined(_M_ARM) && !defined(__arm__)
2218 #if defined( _MSC_VER ) && !defined(__clang__)
2219 typedef __int16 stbir__FP16;
2221 typedef float16_t stbir__FP16;
2226 typedef union stbir__FP16
2233#if (!defined(STBIR_NEON) && !defined(STBIR_FP16C)) || (defined(STBIR_NEON) && defined(_M_ARM)) || (defined(STBIR_NEON) && defined(__arm__))
2237 static stbir__inline
float stbir__half_to_float( stbir__FP16 h )
2239 static const stbir__FP32 magic = { (254 - 15) << 23 };
2240 static const stbir__FP32 was_infnan = { (127 + 16) << 23 };
2243 o.u = (h.u & 0x7fff) << 13;
2245 if (o.f >= was_infnan.f)
2247 o.u |= (h.u & 0x8000) << 16;
2251 static stbir__inline stbir__FP16 stbir__float_to_half(
float val)
2253 stbir__FP32 f32infty = { 255 << 23 };
2254 stbir__FP32 f16max = { (127 + 16) << 23 };
2255 stbir__FP32 denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 };
2256 unsigned int sign_mask = 0x80000000u;
2257 stbir__FP16 o = { 0 };
2262 sign = f.u & sign_mask;
2265 if (f.u >= f16max.u)
2266 o.u = (f.u > f32infty.u) ? 0x7e00 : 0x7c00;
2269 if (f.u < (113 << 23))
2274 f.f += denorm_magic.f;
2276 o.u = (
unsigned short) ( f.u - denorm_magic.u );
2280 unsigned int mant_odd = (f.u >> 13) & 1;
2282 f.u = f.u + ((15u - 127) << 23) + 0xfff;
2286 o.u = (
unsigned short) ( f.u >> 13 );
2297#if defined(STBIR_FP16C)
2299 #include <immintrin.h>
2301 static stbir__inline
void stbir__half_to_float_SIMD(
float * output, stbir__FP16
const * input)
2303 _mm256_storeu_ps( (
float*)output, _mm256_cvtph_ps( _mm_loadu_si128( (__m128i
const* )input ) ) );
2306 static stbir__inline
void stbir__float_to_half_SIMD(stbir__FP16 * output,
float const * input)
2308 _mm_storeu_si128( (__m128i*)output, _mm256_cvtps_ph( _mm256_loadu_ps( input ), 0 ) );
2311 static stbir__inline
float stbir__half_to_float( stbir__FP16 h )
2313 return _mm_cvtss_f32( _mm_cvtph_ps( _mm_cvtsi32_si128( (
int)h.u ) ) );
2316 static stbir__inline stbir__FP16 stbir__float_to_half(
float f )
2319 h.u = (
unsigned short) _mm_cvtsi128_si32( _mm_cvtps_ph( _mm_set_ss( f ), 0 ) );
2323#elif defined(STBIR_SSE2)
2326 stbir__inline
static void stbir__half_to_float_SIMD(
float * output,
void const * input)
2328 static const STBIR__SIMDI_CONST(mask_nosign, 0x7fff);
2329 static const STBIR__SIMDI_CONST(smallest_normal, 0x0400);
2330 static const STBIR__SIMDI_CONST(infinity, 0x7c00);
2331 static const STBIR__SIMDI_CONST(expadjust_normal, (127 - 15) << 23);
2332 static const STBIR__SIMDI_CONST(magic_denorm, 113 << 23);
2334 __m128i i = _mm_loadu_si128 ( (__m128i
const*)(input) );
2335 __m128i h = _mm_unpacklo_epi16 ( i, _mm_setzero_si128() );
2336 __m128i mnosign = STBIR__CONSTI(mask_nosign);
2337 __m128i eadjust = STBIR__CONSTI(expadjust_normal);
2338 __m128i smallest = STBIR__CONSTI(smallest_normal);
2339 __m128i infty = STBIR__CONSTI(infinity);
2340 __m128i expmant = _mm_and_si128(mnosign, h);
2341 __m128i justsign = _mm_xor_si128(h, expmant);
2342 __m128i b_notinfnan = _mm_cmpgt_epi32(infty, expmant);
2343 __m128i b_isdenorm = _mm_cmpgt_epi32(smallest, expmant);
2344 __m128i shifted = _mm_slli_epi32(expmant, 13);
2345 __m128i adj_infnan = _mm_andnot_si128(b_notinfnan, eadjust);
2346 __m128i adjusted = _mm_add_epi32(eadjust, shifted);
2347 __m128i den1 = _mm_add_epi32(shifted, STBIR__CONSTI(magic_denorm));
2348 __m128i adjusted2 = _mm_add_epi32(adjusted, adj_infnan);
2349 __m128 den2 = _mm_sub_ps(_mm_castsi128_ps(den1), *(
const __m128 *)&magic_denorm);
2350 __m128 adjusted3 = _mm_and_ps(den2, _mm_castsi128_ps(b_isdenorm));
2351 __m128 adjusted4 = _mm_andnot_ps(_mm_castsi128_ps(b_isdenorm), _mm_castsi128_ps(adjusted2));
2352 __m128 adjusted5 = _mm_or_ps(adjusted3, adjusted4);
2353 __m128i sign = _mm_slli_epi32(justsign, 16);
2354 __m128
final = _mm_or_ps(adjusted5, _mm_castsi128_ps(sign));
2355 stbir__simdf_store( output + 0,
final );
2357 h = _mm_unpackhi_epi16 ( i, _mm_setzero_si128() );
2358 expmant = _mm_and_si128(mnosign, h);
2359 justsign = _mm_xor_si128(h, expmant);
2360 b_notinfnan = _mm_cmpgt_epi32(infty, expmant);
2361 b_isdenorm = _mm_cmpgt_epi32(smallest, expmant);
2362 shifted = _mm_slli_epi32(expmant, 13);
2363 adj_infnan = _mm_andnot_si128(b_notinfnan, eadjust);
2364 adjusted = _mm_add_epi32(eadjust, shifted);
2365 den1 = _mm_add_epi32(shifted, STBIR__CONSTI(magic_denorm));
2366 adjusted2 = _mm_add_epi32(adjusted, adj_infnan);
2367 den2 = _mm_sub_ps(_mm_castsi128_ps(den1), *(
const __m128 *)&magic_denorm);
2368 adjusted3 = _mm_and_ps(den2, _mm_castsi128_ps(b_isdenorm));
2369 adjusted4 = _mm_andnot_ps(_mm_castsi128_ps(b_isdenorm), _mm_castsi128_ps(adjusted2));
2370 adjusted5 = _mm_or_ps(adjusted3, adjusted4);
2371 sign = _mm_slli_epi32(justsign, 16);
2372 final = _mm_or_ps(adjusted5, _mm_castsi128_ps(sign));
2373 stbir__simdf_store( output + 4,
final );
2380 stbir__inline
static void stbir__float_to_half_SIMD(
void * output,
float const * input)
2382 static const STBIR__SIMDI_CONST(mask_sign, 0x80000000u);
2383 static const STBIR__SIMDI_CONST(c_f16max, (127 + 16) << 23);
2384 static const STBIR__SIMDI_CONST(c_nanbit, 0x200);
2385 static const STBIR__SIMDI_CONST(c_infty_as_fp16, 0x7c00);
2386 static const STBIR__SIMDI_CONST(c_min_normal, (127 - 14) << 23);
2387 static const STBIR__SIMDI_CONST(c_subnorm_magic, ((127 - 15) + (23 - 10) + 1) << 23);
2388 static const STBIR__SIMDI_CONST(c_normal_bias, 0xfff - ((127 - 15) << 23));
2390 __m128 f = _mm_loadu_ps(input);
2391 __m128 msign = _mm_castsi128_ps(STBIR__CONSTI(mask_sign));
2392 __m128 justsign = _mm_and_ps(msign, f);
2393 __m128 absf = _mm_xor_ps(f, justsign);
2394 __m128i absf_int = _mm_castps_si128(absf);
2395 __m128i f16max = STBIR__CONSTI(c_f16max);
2396 __m128 b_isnan = _mm_cmpunord_ps(absf, absf);
2397 __m128i b_isregular = _mm_cmpgt_epi32(f16max, absf_int);
2398 __m128i nanbit = _mm_and_si128(_mm_castps_si128(b_isnan), STBIR__CONSTI(c_nanbit));
2399 __m128i inf_or_nan = _mm_or_si128(nanbit, STBIR__CONSTI(c_infty_as_fp16));
2401 __m128i min_normal = STBIR__CONSTI(c_min_normal);
2402 __m128i b_issub = _mm_cmpgt_epi32(min_normal, absf_int);
2405 __m128 subnorm1 = _mm_add_ps(absf, _mm_castsi128_ps(STBIR__CONSTI(c_subnorm_magic)));
2406 __m128i subnorm2 = _mm_sub_epi32(_mm_castps_si128(subnorm1), STBIR__CONSTI(c_subnorm_magic));
2409 __m128i mantoddbit = _mm_slli_epi32(absf_int, 31 - 13);
2410 __m128i mantodd = _mm_srai_epi32(mantoddbit, 31);
2412 __m128i round1 = _mm_add_epi32(absf_int, STBIR__CONSTI(c_normal_bias));
2413 __m128i round2 = _mm_sub_epi32(round1, mantodd);
2414 __m128i normal = _mm_srli_epi32(round2, 13);
2417 __m128i nonspecial = _mm_or_si128(_mm_and_si128(subnorm2, b_issub), _mm_andnot_si128(b_issub, normal));
2420 __m128i joined = _mm_or_si128(_mm_and_si128(nonspecial, b_isregular), _mm_andnot_si128(b_isregular, inf_or_nan));
2422 __m128i sign_shift = _mm_srai_epi32(_mm_castps_si128(justsign), 16);
2423 __m128i final2,
final= _mm_or_si128(joined, sign_shift);
2425 f = _mm_loadu_ps(input+4);
2426 justsign = _mm_and_ps(msign, f);
2427 absf = _mm_xor_ps(f, justsign);
2428 absf_int = _mm_castps_si128(absf);
2429 b_isnan = _mm_cmpunord_ps(absf, absf);
2430 b_isregular = _mm_cmpgt_epi32(f16max, absf_int);
2431 nanbit = _mm_and_si128(_mm_castps_si128(b_isnan), c_nanbit);
2432 inf_or_nan = _mm_or_si128(nanbit, STBIR__CONSTI(c_infty_as_fp16));
2434 b_issub = _mm_cmpgt_epi32(min_normal, absf_int);
2437 subnorm1 = _mm_add_ps(absf, _mm_castsi128_ps(STBIR__CONSTI(c_subnorm_magic)));
2438 subnorm2 = _mm_sub_epi32(_mm_castps_si128(subnorm1), STBIR__CONSTI(c_subnorm_magic));
2441 mantoddbit = _mm_slli_epi32(absf_int, 31 - 13);
2442 mantodd = _mm_srai_epi32(mantoddbit, 31);
2444 round1 = _mm_add_epi32(absf_int, STBIR__CONSTI(c_normal_bias));
2445 round2 = _mm_sub_epi32(round1, mantodd);
2446 normal = _mm_srli_epi32(round2, 13);
2449 nonspecial = _mm_or_si128(_mm_and_si128(subnorm2, b_issub), _mm_andnot_si128(b_issub, normal));
2452 joined = _mm_or_si128(_mm_and_si128(nonspecial, b_isregular), _mm_andnot_si128(b_isregular, inf_or_nan));
2454 sign_shift = _mm_srai_epi32(_mm_castps_si128(justsign), 16);
2455 final2 = _mm_or_si128(joined, sign_shift);
2456 final = _mm_packs_epi32(
final, final2);
2457 stbir__simdi_store( output,
final );
2460#elif defined(STBIR_NEON) && defined(_MSC_VER) && defined(_M_ARM64) && !defined(__clang__)
2462 static stbir__inline
void stbir__half_to_float_SIMD(
float * output, stbir__FP16
const * input)
2464 float16x4_t in0 = vld1_f16(input + 0);
2465 float16x4_t in1 = vld1_f16(input + 4);
2466 vst1q_f32(output + 0, vcvt_f32_f16(in0));
2467 vst1q_f32(output + 4, vcvt_f32_f16(in1));
2470 static stbir__inline
void stbir__float_to_half_SIMD(stbir__FP16 * output,
float const * input)
2472 float16x4_t out0 = vcvt_f16_f32(vld1q_f32(input + 0));
2473 float16x4_t out1 = vcvt_f16_f32(vld1q_f32(input + 4));
2474 vst1_f16(output+0, out0);
2475 vst1_f16(output+4, out1);
2478 static stbir__inline
float stbir__half_to_float( stbir__FP16 h )
2480 return vgetq_lane_f32(vcvt_f32_f16(vld1_dup_f16(&h)), 0);
2483 static stbir__inline stbir__FP16 stbir__float_to_half(
float f )
2485 return vget_lane_f16(vcvt_f16_f32(vdupq_n_f32(f)), 0).n16_u16[0];
2488#elif defined(STBIR_NEON) && ( defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) )
2490 static stbir__inline
void stbir__half_to_float_SIMD(
float * output, stbir__FP16
const * input)
2492 float16x8_t in = vld1q_f16(input);
2493 vst1q_f32(output + 0, vcvt_f32_f16(vget_low_f16(in)));
2494 vst1q_f32(output + 4, vcvt_f32_f16(vget_high_f16(in)));
2497 static stbir__inline
void stbir__float_to_half_SIMD(stbir__FP16 * output,
float const * input)
2499 float16x4_t out0 = vcvt_f16_f32(vld1q_f32(input + 0));
2500 float16x4_t out1 = vcvt_f16_f32(vld1q_f32(input + 4));
2501 vst1q_f16(output, vcombine_f16(out0, out1));
2504 static stbir__inline
float stbir__half_to_float( stbir__FP16 h )
2506 return vgetq_lane_f32(vcvt_f32_f16(vdup_n_f16(h)), 0);
2509 static stbir__inline stbir__FP16 stbir__float_to_half(
float f )
2511 return vget_lane_f16(vcvt_f16_f32(vdupq_n_f32(f)), 0);
2514#elif defined(STBIR_WASM) || (defined(STBIR_NEON) && (defined(_MSC_VER) || defined(_M_ARM) || defined(__arm__)))
2516 static stbir__inline
void stbir__half_to_float_SIMD(
float * output, stbir__FP16
const * input)
2518 for (
int i=0; i<8; i++)
2520 output[i] = stbir__half_to_float(input[i]);
2523 static stbir__inline
void stbir__float_to_half_SIMD(stbir__FP16 * output,
float const * input)
2525 for (
int i=0; i<8; i++)
2527 output[i] = stbir__float_to_half(input[i]);
2536#define stbir__simdf_0123to3333( out, reg ) (out) = stbir__simdf_swiz( reg, 3,3,3,3 )
2537#define stbir__simdf_0123to2222( out, reg ) (out) = stbir__simdf_swiz( reg, 2,2,2,2 )
2538#define stbir__simdf_0123to1111( out, reg ) (out) = stbir__simdf_swiz( reg, 1,1,1,1 )
2539#define stbir__simdf_0123to0000( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,0,0 )
2540#define stbir__simdf_0123to0003( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,0,3 )
2541#define stbir__simdf_0123to0001( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,0,1 )
2542#define stbir__simdf_0123to1122( out, reg ) (out) = stbir__simdf_swiz( reg, 1,1,2,2 )
2543#define stbir__simdf_0123to2333( out, reg ) (out) = stbir__simdf_swiz( reg, 2,3,3,3 )
2544#define stbir__simdf_0123to0023( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,2,3 )
2545#define stbir__simdf_0123to1230( out, reg ) (out) = stbir__simdf_swiz( reg, 1,2,3,0 )
2546#define stbir__simdf_0123to2103( out, reg ) (out) = stbir__simdf_swiz( reg, 2,1,0,3 )
2547#define stbir__simdf_0123to3210( out, reg ) (out) = stbir__simdf_swiz( reg, 3,2,1,0 )
2548#define stbir__simdf_0123to2301( out, reg ) (out) = stbir__simdf_swiz( reg, 2,3,0,1 )
2549#define stbir__simdf_0123to3012( out, reg ) (out) = stbir__simdf_swiz( reg, 3,0,1,2 )
2550#define stbir__simdf_0123to0011( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,1,1 )
2551#define stbir__simdf_0123to1100( out, reg ) (out) = stbir__simdf_swiz( reg, 1,1,0,0 )
2552#define stbir__simdf_0123to2233( out, reg ) (out) = stbir__simdf_swiz( reg, 2,2,3,3 )
2553#define stbir__simdf_0123to1133( out, reg ) (out) = stbir__simdf_swiz( reg, 1,1,3,3 )
2554#define stbir__simdf_0123to0022( out, reg ) (out) = stbir__simdf_swiz( reg, 0,0,2,2 )
2555#define stbir__simdf_0123to1032( out, reg ) (out) = stbir__simdf_swiz( reg, 1,0,3,2 )
2557typedef union stbir__simdi_u32
2561 stbir__simdi m128i_i128;
2564static const int STBIR_mask[9] = { 0,0,0,-1,-1,-1,0,0,0 };
2566static const STBIR__SIMDF_CONST(STBIR_max_uint8_as_float, stbir__max_uint8_as_float);
2567static const STBIR__SIMDF_CONST(STBIR_max_uint16_as_float, stbir__max_uint16_as_float);
2568static const STBIR__SIMDF_CONST(STBIR_max_uint8_as_float_inverted, stbir__max_uint8_as_float_inverted);
2569static const STBIR__SIMDF_CONST(STBIR_max_uint16_as_float_inverted, stbir__max_uint16_as_float_inverted);
2571static const STBIR__SIMDF_CONST(STBIR_simd_point5, 0.5f);
2572static const STBIR__SIMDF_CONST(STBIR_ones, 1.0f);
2573static const STBIR__SIMDI_CONST(STBIR_almost_zero, (127 - 13) << 23);
2574static const STBIR__SIMDI_CONST(STBIR_almost_one, 0x3f7fffff);
2575static const STBIR__SIMDI_CONST(STBIR_mantissa_mask, 0xff);
2576static const STBIR__SIMDI_CONST(STBIR_topscale, 0x02000000);
2581#define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )
2582#define STBIR_SIMD_NO_UNROLL(ptr) STBIR_NO_UNROLL(ptr)
2583#define STBIR_SIMD_NO_UNROLL_LOOP_START STBIR_NO_UNROLL_LOOP_START
2584#define STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR STBIR_NO_UNROLL_LOOP_START_INF_FOR
2589#define STBIR_MEMCPY stbir_simd_memcpy
2592static void stbir_simd_memcpy(
void * dest,
void const * src,
size_t bytes )
2594 char STBIR_SIMD_STREAMOUT_PTR (*) d = (
char*) dest;
2595 char STBIR_SIMD_STREAMOUT_PTR( * ) d_end = ((
char*) dest) + bytes;
2596 ptrdiff_t ofs_to_src = (
char*)src - (
char*)dest;
2599 STBIR_ASSERT( ( ( d >= ( (
char*)src) + bytes ) ) || ( ( d + bytes ) <= (
char*)src ) );
2601 if ( bytes < (16*stbir__simdfX_float_count) )
2607 STBIR_SIMD_NO_UNROLL_LOOP_START
2610 STBIR_SIMD_NO_UNROLL(d);
2611 d[ 0 ] = d[ ofs_to_src ];
2613 }
while ( d < d_end );
2620 stbir__simdf_load( x, ( d + ofs_to_src ) );
2621 stbir__simdf_store( d, x );
2622 d = (
char*)( ( ( (
size_t)d ) + 16 ) & ~15 );
2624 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
2627 STBIR_SIMD_NO_UNROLL(d);
2629 if ( d > ( d_end - 16 ) )
2636 stbir__simdf_load( x, ( d + ofs_to_src ) );
2637 stbir__simdf_store( d, x );
2644 stbir__simdfX x0,x1,x2,x3;
2647 stbir__simdfX_load( x0, ( d + ofs_to_src ) + 0*stbir__simdfX_float_count );
2648 stbir__simdfX_load( x1, ( d + ofs_to_src ) + 4*stbir__simdfX_float_count );
2649 stbir__simdfX_load( x2, ( d + ofs_to_src ) + 8*stbir__simdfX_float_count );
2650 stbir__simdfX_load( x3, ( d + ofs_to_src ) + 12*stbir__simdfX_float_count );
2651 stbir__simdfX_store( d + 0*stbir__simdfX_float_count, x0 );
2652 stbir__simdfX_store( d + 4*stbir__simdfX_float_count, x1 );
2653 stbir__simdfX_store( d + 8*stbir__simdfX_float_count, x2 );
2654 stbir__simdfX_store( d + 12*stbir__simdfX_float_count, x3 );
2655 d = (
char*)( ( ( (
size_t)d ) + (16*stbir__simdfX_float_count) ) & ~((16*stbir__simdfX_float_count)-1) );
2657 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
2660 STBIR_SIMD_NO_UNROLL(d);
2662 if ( d > ( d_end - (16*stbir__simdfX_float_count) ) )
2666 d = d_end - (16*stbir__simdfX_float_count);
2669 stbir__simdfX_load( x0, ( d + ofs_to_src ) + 0*stbir__simdfX_float_count );
2670 stbir__simdfX_load( x1, ( d + ofs_to_src ) + 4*stbir__simdfX_float_count );
2671 stbir__simdfX_load( x2, ( d + ofs_to_src ) + 8*stbir__simdfX_float_count );
2672 stbir__simdfX_load( x3, ( d + ofs_to_src ) + 12*stbir__simdfX_float_count );
2673 stbir__simdfX_store( d + 0*stbir__simdfX_float_count, x0 );
2674 stbir__simdfX_store( d + 4*stbir__simdfX_float_count, x1 );
2675 stbir__simdfX_store( d + 8*stbir__simdfX_float_count, x2 );
2676 stbir__simdfX_store( d + 12*stbir__simdfX_float_count, x3 );
2677 d += (16*stbir__simdfX_float_count);
2685static void stbir_overlapping_memcpy(
void * dest,
void const * src,
size_t bytes )
2687 char STBIR_SIMD_STREAMOUT_PTR (*) sd = (
char*) src;
2688 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end = ((
char*) src) + bytes;
2689 ptrdiff_t ofs_to_dest = (
char*)dest - (
char*)src;
2691 if ( ofs_to_dest >= 16 )
2693 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end16 = ((
char*) src) + (bytes&~15);
2694 STBIR_SIMD_NO_UNROLL_LOOP_START
2698 STBIR_SIMD_NO_UNROLL(sd);
2699 stbir__simdf_load( x, sd );
2700 stbir__simdf_store( ( sd + ofs_to_dest ), x );
2702 }
while ( sd < s_end16 );
2710 STBIR_SIMD_NO_UNROLL(sd);
2711 *(
int*)( sd + ofs_to_dest ) = *(
int*) sd;
2713 }
while ( sd < s_end );
2719#define STBIR_SIMD_STREAMOUT_PTR( star ) STBIR_STREAMOUT_PTR( star )
2720#define STBIR_SIMD_NO_UNROLL(ptr)
2721#define STBIR_SIMD_NO_UNROLL_LOOP_START
2722#define STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
2729#ifndef STBIR_PROFILE_FUNC
2731#if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(__SSE2__) || defined(STBIR_SSE) || defined( _M_IX86_FP ) || defined(__i386) || defined( __i386__ ) || defined( _M_IX86 ) || defined( _X86_ )
2736 #define STBIR_PROFILE_FUNC() __rdtsc()
2743 asm volatile (
"rdtsc" :
"=a" (lo),
"=d" (hi) );
2749#elif defined( _M_ARM64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || defined(__ARM_NEON__)
2751#if defined( _MSC_VER ) && !defined(__clang__)
2753 #define STBIR_PROFILE_FUNC() _ReadStatusReg(ARM64_CNTVCT)
2760 asm volatile(
"mrs %0, cntvct_el0" :
"=r" (tsc));
2768#error Unknown platform for profiling.
2774#define STBIR_ONLY_PROFILE_GET_SPLIT_INFO ,stbir__per_split_info * split_info
2775#define STBIR_ONLY_PROFILE_SET_SPLIT_INFO ,split_info
2777#define STBIR_ONLY_PROFILE_BUILD_GET_INFO ,stbir__info * profile_info
2778#define STBIR_ONLY_PROFILE_BUILD_SET_INFO ,profile_info
2781#define STBIR_PROFILE_START_ll( info, wh ) { stbir_uint64 wh##thiszonetime = STBIR_PROFILE_FUNC(); stbir_uint64 * wh##save_parent_excluded_ptr = info->current_zone_excluded_ptr; stbir_uint64 wh##current_zone_excluded = 0; info->current_zone_excluded_ptr = &wh##current_zone_excluded;
2782#define STBIR_PROFILE_END_ll( info, wh ) wh##thiszonetime = STBIR_PROFILE_FUNC() - wh##thiszonetime; info->profile.named.wh += wh##thiszonetime - wh##current_zone_excluded; *wh##save_parent_excluded_ptr += wh##thiszonetime; info->current_zone_excluded_ptr = wh##save_parent_excluded_ptr; }
2783#define STBIR_PROFILE_FIRST_START_ll( info, wh ) { int i; info->current_zone_excluded_ptr = &info->profile.named.total; for(i=0;i<STBIR__ARRAY_SIZE(info->profile.array);i++) info->profile.array[i]=0; } STBIR_PROFILE_START_ll( info, wh );
2784#define STBIR_PROFILE_CLEAR_EXTRAS_ll( info, num ) { int extra; for(extra=1;extra<(num);extra++) { int i; for(i=0;i<STBIR__ARRAY_SIZE((info)->profile.array);i++) (info)[extra].profile.array[i]=0; } }
2787#define STBIR_PROFILE_START( wh ) STBIR_PROFILE_START_ll( split_info, wh )
2788#define STBIR_PROFILE_END( wh ) STBIR_PROFILE_END_ll( split_info, wh )
2789#define STBIR_PROFILE_FIRST_START( wh ) STBIR_PROFILE_FIRST_START_ll( split_info, wh )
2790#define STBIR_PROFILE_CLEAR_EXTRAS() STBIR_PROFILE_CLEAR_EXTRAS_ll( split_info, split_count )
2793#define STBIR_PROFILE_BUILD_START( wh ) STBIR_PROFILE_START_ll( profile_info, wh )
2794#define STBIR_PROFILE_BUILD_END( wh ) STBIR_PROFILE_END_ll( profile_info, wh )
2795#define STBIR_PROFILE_BUILD_FIRST_START( wh ) STBIR_PROFILE_FIRST_START_ll( profile_info, wh )
2796#define STBIR_PROFILE_BUILD_CLEAR( info ) { int i; for(i=0;i<STBIR__ARRAY_SIZE(info->profile.array);i++) info->profile.array[i]=0; }
2800#define STBIR_ONLY_PROFILE_GET_SPLIT_INFO
2801#define STBIR_ONLY_PROFILE_SET_SPLIT_INFO
2803#define STBIR_ONLY_PROFILE_BUILD_GET_INFO
2804#define STBIR_ONLY_PROFILE_BUILD_SET_INFO
2806#define STBIR_PROFILE_START( wh )
2807#define STBIR_PROFILE_END( wh )
2808#define STBIR_PROFILE_FIRST_START( wh )
2809#define STBIR_PROFILE_CLEAR_EXTRAS( )
2811#define STBIR_PROFILE_BUILD_START( wh )
2812#define STBIR_PROFILE_BUILD_END( wh )
2813#define STBIR_PROFILE_BUILD_FIRST_START( wh )
2814#define STBIR_PROFILE_BUILD_CLEAR( info )
2821#define STBIR_CEILF(x) ((float)ceil((float)(x)))
2822#define STBIR_FLOORF(x) ((float)floor((float)(x)))
2824#define STBIR_CEILF(x) ceilf(x)
2825#define STBIR_FLOORF(x) floorf(x)
2832#define STBIR_MEMCPY( dest, src, len ) memcpy( dest, src, len )
2840static void stbir_overlapping_memcpy(
void * dest,
void const * src,
size_t bytes )
2842 char STBIR_SIMD_STREAMOUT_PTR (*) sd = (
char*) src;
2843 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end = ((
char*) src) + bytes;
2844 ptrdiff_t ofs_to_dest = (
char*)dest - (
char*)src;
2846 if ( ofs_to_dest >= 8 )
2848 char STBIR_SIMD_STREAMOUT_PTR( * ) s_end8 = ((
char*) src) + (bytes&~7);
2850 if ( ( ( ((ptrdiff_t)dest)|((ptrdiff_t)src) ) & 7 ) == 0 )
2852 STBIR_NO_UNROLL_LOOP_START
2855 STBIR_NO_UNROLL(sd);
2858 }
while ( sd < s_end8 );
2862 STBIR_NO_UNROLL_LOOP_START
2866 STBIR_NO_UNROLL(sd);
2869 ((
int*)( sd + ofs_to_dest ))[0] = a;
2870 ((
int*)( sd + ofs_to_dest ))[1] = b;
2872 }
while ( sd < s_end8 );
2879 STBIR_NO_UNROLL_LOOP_START
2882 STBIR_NO_UNROLL(sd);
2883 *(
int*)( sd + ofs_to_dest ) = *(
int*) sd;
2885 }
while ( sd < s_end );
2890static float stbir__filter_trapezoid(
float x,
float scale,
void * user_data)
2892 float halfscale = scale / 2;
2893 float t = 0.5f + halfscale;
2894 STBIR_ASSERT(scale <= 1);
2895 STBIR__UNUSED(user_data);
2897 if ( x < 0.0f ) x = -x;
2903 float r = 0.5f - halfscale;
2907 return (t - x) / scale;
2911static float stbir__support_trapezoid(
float scale,
void * user_data)
2913 STBIR__UNUSED(user_data);
2914 return 0.5f + scale / 2.0f;
2917static float stbir__filter_triangle(
float x,
float s,
void * user_data)
2920 STBIR__UNUSED(user_data);
2922 if ( x < 0.0f ) x = -x;
2930static float stbir__filter_point(
float x,
float s,
void * user_data)
2934 STBIR__UNUSED(user_data);
2939static float stbir__filter_cubic(
float x,
float s,
void * user_data)
2942 STBIR__UNUSED(user_data);
2944 if ( x < 0.0f ) x = -x;
2947 return (4.0f + x*x*(3.0f*x - 6.0f))/6.0f;
2949 return (8.0f + x*(-12.0f + x*(6.0f - x)))/6.0f;
2954static float stbir__filter_catmullrom(
float x,
float s,
void * user_data)
2957 STBIR__UNUSED(user_data);
2959 if ( x < 0.0f ) x = -x;
2962 return 1.0f - x*x*(2.5f - 1.5f*x);
2964 return 2.0f - x*(4.0f + x*(0.5f*x - 2.5f));
2969static float stbir__filter_mitchell(
float x,
float s,
void * user_data)
2972 STBIR__UNUSED(user_data);
2974 if ( x < 0.0f ) x = -x;
2977 return (16.0f + x*x*(21.0f * x - 36.0f))/18.0f;
2979 return (32.0f + x*(-60.0f + x*(36.0f - 7.0f*x)))/18.0f;
2984static float stbir__support_zeropoint5(
float s,
void * user_data)
2987 STBIR__UNUSED(user_data);
2991static float stbir__support_one(
float s,
void * user_data)
2994 STBIR__UNUSED(user_data);
2998static float stbir__support_two(
float s,
void * user_data)
3001 STBIR__UNUSED(user_data);
3009 STBIR_ASSERT(support != 0);
3011 if ( scale >= ( 1.0f-stbir__small_float ) )
3012 return (
int)STBIR_CEILF(support(1.0f/scale,user_data) * 2.0f);
3014 return (
int)STBIR_CEILF(support(scale,user_data) * 2.0f / scale);
3019static int stbir__get_coefficient_width(stbir__sampler * samp,
int is_gather,
void * user_data)
3021 float scale = samp->scale_info.scale;
3027 return (
int)STBIR_CEILF(support(1.0f / scale, user_data) * 2.0f);
3029 return (
int)STBIR_CEILF(support(scale, user_data) * 2.0f / scale);
3031 return (
int)STBIR_CEILF(support(scale, user_data) * 2.0f);
3033 STBIR_ASSERT( (is_gather >= 0 ) && (is_gather <= 2 ) );
3038static int stbir__get_contributors(stbir__sampler * samp,
int is_gather)
3041 return samp->scale_info.output_sub_size;
3043 return (samp->scale_info.input_full_size + samp->filter_pixel_margin * 2);
3046static int stbir__edge_zero_full(
int n,
int max )
3053static int stbir__edge_clamp_full(
int n,
int max )
3064static int stbir__edge_reflect_full(
int n,
int max )
3080 return max2 - n - 1;
3086static int stbir__edge_wrap_full(
int n,
int max )
3101typedef int stbir__edge_wrap_func(
int n,
int max );
3102static stbir__edge_wrap_func * stbir__edge_wrap_slow[] =
3104 stbir__edge_clamp_full,
3105 stbir__edge_reflect_full,
3106 stbir__edge_wrap_full,
3107 stbir__edge_zero_full,
3110stbir__inline
static int stbir__edge_wrap(
stbir_edge edge,
int n,
int max)
3113 if (n >= 0 && n < max)
3115 return stbir__edge_wrap_slow[edge]( n, max );
3118#define STBIR__MERGE_RUNS_PIXEL_THRESHOLD 16
3121static void stbir__get_extents( stbir__sampler * samp, stbir__extents * scanline_extents )
3124 int left_margin, right_margin;
3125 int min_n = 0x7fffffff, max_n = -0x7fffffff;
3126 int min_left = 0x7fffffff, max_left = -0x7fffffff;
3127 int min_right = 0x7fffffff, max_right = -0x7fffffff;
3129 stbir__contributors* contributors = samp->contributors;
3130 int output_sub_size = samp->scale_info.output_sub_size;
3131 int input_full_size = samp->scale_info.input_full_size;
3132 int filter_pixel_margin = samp->filter_pixel_margin;
3134 STBIR_ASSERT( samp->is_gather );
3136 stop = output_sub_size;
3137 for (j = 0; j < stop; j++ )
3139 STBIR_ASSERT( contributors[j].n1 >= contributors[j].n0 );
3140 if ( contributors[j].n0 < min_n )
3142 min_n = contributors[j].n0;
3143 stop = j + filter_pixel_margin;
3144 if ( stop > output_sub_size ) stop = output_sub_size;
3149 for (j = output_sub_size - 1; j >= stop; j-- )
3151 STBIR_ASSERT( contributors[j].n1 >= contributors[j].n0 );
3152 if ( contributors[j].n1 > max_n )
3154 max_n = contributors[j].n1;
3155 stop = j - filter_pixel_margin;
3156 if (stop<0) stop = 0;
3160 STBIR_ASSERT( scanline_extents->conservative.n0 <= min_n );
3161 STBIR_ASSERT( scanline_extents->conservative.n1 >= max_n );
3167 left_margin = -min_n;
3172 if ( max_n >= input_full_size )
3174 right_margin = max_n - input_full_size + 1;
3175 max_n = input_full_size - 1;
3179 scanline_extents->edge_sizes[0] = left_margin;
3180 scanline_extents->edge_sizes[1] = right_margin;
3183 scanline_extents->spans[0].n0 = min_n;
3184 scanline_extents->spans[0].n1 = max_n;
3185 scanline_extents->spans[0].pixel_offset_for_input = min_n;
3188 scanline_extents->spans[1].n0 = 0;
3189 scanline_extents->spans[1].n1 = -1;
3190 scanline_extents->spans[1].pixel_offset_for_input = 0;
3197 for( j = -left_margin ; j < 0 ; j++ )
3199 int p = stbir__edge_wrap( edge, j, input_full_size );
3206 for( j = input_full_size ; j < (input_full_size + right_margin) ; j++ )
3208 int p = stbir__edge_wrap( edge, j, input_full_size );
3209 if ( p < min_right )
3211 if ( p > max_right )
3216 if ( min_left != 0x7fffffff )
3218 if ( ( ( min_left <= min_n ) && ( ( max_left + STBIR__MERGE_RUNS_PIXEL_THRESHOLD ) >= min_n ) ) ||
3219 ( ( min_n <= min_left ) && ( ( max_n + STBIR__MERGE_RUNS_PIXEL_THRESHOLD ) >= max_left ) ) )
3221 scanline_extents->spans[0].n0 = min_n = stbir__min( min_n, min_left );
3222 scanline_extents->spans[0].n1 = max_n = stbir__max( max_n, max_left );
3223 scanline_extents->spans[0].pixel_offset_for_input = min_n;
3229 if ( min_right != 0x7fffffff )
3231 if ( ( ( min_right <= min_n ) && ( ( max_right + STBIR__MERGE_RUNS_PIXEL_THRESHOLD ) >= min_n ) ) ||
3232 ( ( min_n <= min_right ) && ( ( max_n + STBIR__MERGE_RUNS_PIXEL_THRESHOLD ) >= max_right ) ) )
3234 scanline_extents->spans[0].n0 = min_n = stbir__min( min_n, min_right );
3235 scanline_extents->spans[0].n1 = max_n = stbir__max( max_n, max_right );
3236 scanline_extents->spans[0].pixel_offset_for_input = min_n;
3241 STBIR_ASSERT( scanline_extents->conservative.n0 <= min_n );
3242 STBIR_ASSERT( scanline_extents->conservative.n1 >= max_n );
3250 if ( ( left_margin ) && ( min_left != 0x7fffffff ) )
3252 stbir__span * newspan = scanline_extents->spans + 1;
3253 STBIR_ASSERT( right_margin == 0 );
3254 if ( min_left < scanline_extents->spans[0].n0 )
3256 scanline_extents->spans[1].pixel_offset_for_input = scanline_extents->spans[0].n0;
3257 scanline_extents->spans[1].n0 = scanline_extents->spans[0].n0;
3258 scanline_extents->spans[1].n1 = scanline_extents->spans[0].n1;
3261 newspan->pixel_offset_for_input = min_left;
3262 newspan->n0 = -left_margin;
3263 newspan->n1 = ( max_left - min_left ) - left_margin;
3264 scanline_extents->edge_sizes[0] = 0;
3268 if ( ( right_margin ) && ( min_right != 0x7fffffff ) )
3270 stbir__span * newspan = scanline_extents->spans + 1;
3271 if ( min_right < scanline_extents->spans[0].n0 )
3273 scanline_extents->spans[1].pixel_offset_for_input = scanline_extents->spans[0].n0;
3274 scanline_extents->spans[1].n0 = scanline_extents->spans[0].n0;
3275 scanline_extents->spans[1].n1 = scanline_extents->spans[0].n1;
3278 newspan->pixel_offset_for_input = min_right;
3279 newspan->n0 = scanline_extents->spans[1].n1 + 1;
3280 newspan->n1 = scanline_extents->spans[1].n1 + 1 + ( max_right - min_right );
3281 scanline_extents->edge_sizes[1] = 0;
3285 if ( ( scanline_extents->spans[1].n1 > scanline_extents->spans[1].n0 ) && ( scanline_extents->spans[0].n0 > scanline_extents->spans[1].n0 ) )
3287 stbir__span tspan = scanline_extents->spans[0];
3288 scanline_extents->spans[0] = scanline_extents->spans[1];
3289 scanline_extents->spans[1] = tspan;
3293static 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 )
3296 float out_pixel_influence_lowerbound = out_pixel_center - out_filter_radius;
3297 float out_pixel_influence_upperbound = out_pixel_center + out_filter_radius;
3299 float in_pixel_influence_lowerbound = (out_pixel_influence_lowerbound + out_shift) * inv_scale;
3300 float in_pixel_influence_upperbound = (out_pixel_influence_upperbound + out_shift) * inv_scale;
3302 first = (int)(STBIR_FLOORF(in_pixel_influence_lowerbound + 0.5f));
3303 last = (int)(STBIR_FLOORF(in_pixel_influence_upperbound - 0.5f));
3304 if ( last < first ) last = first;
3308 if ( first < -input_size )
3309 first = -input_size;
3310 if ( last >= (input_size*2))
3311 last = (input_size*2) - 1;
3314 *first_pixel = first;
3318static void stbir__calculate_coefficients_for_gather_upsample(
float out_filter_radius,
stbir__kernel_callback * kernel, stbir__scale_info * scale_info,
int num_contributors, stbir__contributors* contributors,
float* coefficient_group,
int coefficient_width,
stbir_edge edge,
void * user_data )
3321 float inv_scale = scale_info->inv_scale;
3322 float out_shift = scale_info->pixel_shift;
3323 int input_size = scale_info->input_full_size;
3324 int numerator = scale_info->scale_numerator;
3325 int polyphase = ( ( scale_info->scale_is_rational ) && ( numerator < num_contributors ) );
3328 end = num_contributors;
if ( polyphase ) end = numerator;
3329 for (n = 0; n < end; n++)
3333 float out_pixel_center = (float)n + 0.5f;
3334 float in_center_of_out = (out_pixel_center + out_shift) * inv_scale;
3336 int in_first_pixel, in_last_pixel;
3338 stbir__calculate_in_pixel_range( &in_first_pixel, &in_last_pixel, out_pixel_center, out_filter_radius, inv_scale, out_shift, input_size, edge );
3342 if ( ( in_last_pixel - in_first_pixel + 1 ) > coefficient_width )
3343 in_last_pixel = in_first_pixel + coefficient_width - 1;
3346 for (i = 0; i <= in_last_pixel - in_first_pixel; i++)
3348 float in_pixel_center = (float)(i + in_first_pixel) + 0.5f;
3349 float coeff = kernel(in_center_of_out - in_pixel_center, inv_scale, user_data);
3352 if ( ( ( coeff < stbir__small_float ) && ( coeff > -stbir__small_float ) ) )
3356 STBIR_ASSERT ( ( in_last_pixel - in_first_pixel ) != 0 );
3366 coefficient_group[i] = coeff;
3369 in_last_pixel = last_non_zero+in_first_pixel;
3370 contributors->n0 = in_first_pixel;
3371 contributors->n1 = in_last_pixel;
3373 STBIR_ASSERT(contributors->n1 >= contributors->n0);
3376 coefficient_group += coefficient_width;
3380static void stbir__insert_coeff( stbir__contributors * contribs,
float * coeffs,
int new_pixel,
float new_coeff,
int max_width )
3382 if ( contribs->n1 < contribs->n0 )
3384 contribs->n0 = contribs->n1 = new_pixel;
3385 coeffs[0] = new_coeff;
3387 else if ( new_pixel <= contribs->n1 )
3389 if ( new_pixel < contribs->n0 )
3391 if ( ( contribs->n1 - new_pixel + 1 ) <= max_width )
3393 int j, o = contribs->n0 - new_pixel;
3394 for ( j = contribs->n1 - contribs->n0 ; j >= 0 ; j-- )
3395 coeffs[ j + o ] = coeffs[ j ];
3396 for ( j = 1 ; j < o ; j++ )
3398 coeffs[ 0 ] = new_coeff;
3399 contribs->n0 = new_pixel;
3405 coeffs[ new_pixel - contribs->n0 ] += new_coeff;
3410 if ( ( new_pixel - contribs->n0 + 1 ) <= max_width )
3412 int j, e = new_pixel - contribs->n0;
3413 for( j = ( contribs->n1 - contribs->n0 ) + 1 ; j < e ; j++ )
3416 coeffs[ e ] = new_coeff;
3417 contribs->n1 = new_pixel;
3422static void stbir__calculate_out_pixel_range(
int * first_pixel,
int * last_pixel,
float in_pixel_center,
float in_pixels_radius,
float scale,
float out_shift,
int out_size )
3424 float in_pixel_influence_lowerbound = in_pixel_center - in_pixels_radius;
3425 float in_pixel_influence_upperbound = in_pixel_center + in_pixels_radius;
3426 float out_pixel_influence_lowerbound = in_pixel_influence_lowerbound * scale - out_shift;
3427 float out_pixel_influence_upperbound = in_pixel_influence_upperbound * scale - out_shift;
3428 int out_first_pixel = (int)(STBIR_FLOORF(out_pixel_influence_lowerbound + 0.5f));
3429 int out_last_pixel = (int)(STBIR_FLOORF(out_pixel_influence_upperbound - 0.5f));
3431 if ( out_first_pixel < 0 )
3432 out_first_pixel = 0;
3433 if ( out_last_pixel >= out_size )
3434 out_last_pixel = out_size - 1;
3435 *first_pixel = out_first_pixel;
3436 *last_pixel = out_last_pixel;
3439static void stbir__calculate_coefficients_for_gather_downsample(
int start,
int end,
float in_pixels_radius,
stbir__kernel_callback * kernel, stbir__scale_info * scale_info,
int coefficient_width,
int num_contributors, stbir__contributors * contributors,
float * coefficient_group,
void * user_data )
3443 int first_out_inited = -1;
3444 float scale = scale_info->scale;
3445 float out_shift = scale_info->pixel_shift;
3446 int out_size = scale_info->output_sub_size;
3447 int numerator = scale_info->scale_numerator;
3448 int polyphase = ( ( scale_info->scale_is_rational ) && ( numerator < out_size ) );
3450 STBIR__UNUSED(num_contributors);
3453 for (in_pixel = start; in_pixel < end; in_pixel++)
3455 float in_pixel_center = (float)in_pixel + 0.5f;
3456 float out_center_of_in = in_pixel_center * scale - out_shift;
3457 int out_first_pixel, out_last_pixel;
3459 stbir__calculate_out_pixel_range( &out_first_pixel, &out_last_pixel, in_pixel_center, in_pixels_radius, scale, out_shift, out_size );
3461 if ( out_first_pixel > out_last_pixel )
3468 if ( out_first_pixel == numerator )
3472 if ( out_last_pixel >= numerator )
3473 out_last_pixel = numerator - 1;
3476 for (i = 0; i <= out_last_pixel - out_first_pixel; i++)
3478 float out_pixel_center = (float)(i + out_first_pixel) + 0.5f;
3479 float x = out_pixel_center - out_center_of_in;
3480 float coeff = kernel(x, scale, user_data) * scale;
3483 if ( ( ( coeff < stbir__small_float ) && ( coeff > -stbir__small_float ) ) )
3487 int out = i + out_first_pixel;
3488 float * coeffs = coefficient_group + out * coefficient_width;
3489 stbir__contributors * contribs = contributors + out;
3492 if ( out > first_out_inited )
3494 STBIR_ASSERT( out == ( first_out_inited + 1 ) );
3495 first_out_inited = out;
3496 contribs->n0 = in_pixel;
3497 contribs->n1 = in_pixel;
3503 if ( coeffs[0] == 0.0f )
3505 STBIR_ASSERT( ( in_pixel - contribs->n0 ) == 1 );
3506 contribs->n0 = in_pixel;
3508 contribs->n1 = in_pixel;
3509 STBIR_ASSERT( ( in_pixel - contribs->n0 ) < coefficient_width );
3510 coeffs[in_pixel - contribs->n0] = coeff;
3517#ifdef STBIR_RENORMALIZE_IN_FLOAT
3518#define STBIR_RENORM_TYPE float
3520#define STBIR_RENORM_TYPE double
3523static void stbir__cleanup_gathered_coefficients(
stbir_edge edge, stbir__filter_extent_info* filter_info, stbir__scale_info * scale_info,
int num_contributors, stbir__contributors* contributors,
float * coefficient_group,
int coefficient_width )
3525 int input_size = scale_info->input_full_size;
3526 int input_last_n1 = input_size - 1;
3528 int lowest = 0x7fffffff;
3529 int highest = -0x7fffffff;
3531 int numerator = scale_info->scale_numerator;
3532 int denominator = scale_info->scale_denominator;
3533 int polyphase = ( ( scale_info->scale_is_rational ) && ( numerator < num_contributors ) );
3535 stbir__contributors * contribs;
3538 coeffs = coefficient_group;
3539 contribs = contributors;
3540 end = num_contributors;
if ( polyphase ) end = numerator;
3541 for (n = 0; n < end; n++)
3544 STBIR_RENORM_TYPE filter_scale, total_filter = 0;
3548 e = contribs->n1 - contribs->n0;
3549 for( i = 0 ; i <= e ; i++ )
3551 total_filter += (STBIR_RENORM_TYPE) coeffs[i];
3552 STBIR_ASSERT( ( coeffs[i] >= -2.0f ) && ( coeffs[i] <= 2.0f ) );
3556 if ( ( total_filter < stbir__small_float ) && ( total_filter > -stbir__small_float ) )
3559 contribs->n1 = contribs->n0;
3565 if ( ( total_filter < (1.0f-stbir__small_float) ) || ( total_filter > (1.0f+stbir__small_float) ) )
3567 filter_scale = ((STBIR_RENORM_TYPE)1.0) / total_filter;
3570 for (i = 0; i <= e; i++)
3571 coeffs[i] = (
float) ( coeffs[i] * filter_scale );
3575 coeffs += coefficient_width;
3582 stbir__contributors * prev_contribs = contributors;
3583 stbir__contributors * cur_contribs = contributors + numerator;
3585 for( n = numerator ; n < num_contributors ; n++ )
3587 cur_contribs->n0 = prev_contribs->n0 + denominator;
3588 cur_contribs->n1 = prev_contribs->n1 + denominator;
3592 stbir_overlapping_memcpy( coefficient_group + numerator * coefficient_width, coefficient_group, ( num_contributors - numerator ) * coefficient_width *
sizeof( coeffs[ 0 ] ) );
3595 coeffs = coefficient_group;
3596 contribs = contributors;
3598 for (n = 0; n < num_contributors; n++)
3606 if ( contribs->n1 > input_last_n1 )
3607 contribs->n1 = input_last_n1;
3610 if ( contribs->n0 < 0 )
3612 int j, left, skips = 0;
3614 skips = -contribs->n0;
3618 left = contribs->n1 - contribs->n0 + 1;
3621 for( j = 0 ; j < left ; j++ )
3622 coeffs[ j ] = coeffs[ j + skips ];
3631 if ( contribs->n1 > input_last_n1 )
3633 int start = contribs->n0;
3634 int endi = contribs->n1;
3635 contribs->n1 = input_last_n1;
3636 for( i = input_size; i <= endi; i++ )
3637 stbir__insert_coeff( contribs, coeffs, stbir__edge_wrap_slow[edge]( i, input_size ), coeffs[i-start], coefficient_width );
3641 if ( contribs->n0 < 0 )
3644 float save_n0_coeff;
3645 float * c = coeffs - ( contribs->n0 + 1 );
3648 for( i = -1 ; i > contribs->n0 ; i-- )
3649 stbir__insert_coeff( contribs, coeffs, stbir__edge_wrap_slow[edge]( i, input_size ), *c--, coefficient_width );
3650 save_n0 = contribs->n0;
3651 save_n0_coeff = c[0];
3655 for(i = 0 ; i <= contribs->n1 ; i++ )
3656 coeffs[i] = coeffs[i-save_n0];
3659 stbir__insert_coeff( contribs, coeffs, stbir__edge_wrap_slow[edge]( save_n0, input_size ), save_n0_coeff, coefficient_width );
3663 if ( contribs->n0 <= contribs->n1 )
3665 int diff = contribs->n1 - contribs->n0 + 1;
3666 while ( diff && ( coeffs[ diff-1 ] == 0.0f ) )
3669 contribs->n1 = contribs->n0 + diff - 1;
3671 if ( contribs->n0 <= contribs->n1 )
3673 if ( contribs->n0 < lowest )
3674 lowest = contribs->n0;
3675 if ( contribs->n1 > highest )
3676 highest = contribs->n1;
3677 if ( diff > widest )
3682 for( i = diff ; i < coefficient_width ; i++ )
3687 coeffs += coefficient_width;
3689 filter_info->lowest = lowest;
3690 filter_info->highest = highest;
3691 filter_info->widest = widest;
3694#undef STBIR_RENORM_TYPE
3696static int stbir__pack_coefficients(
int num_contributors, stbir__contributors* contributors,
float * coefficents,
int coefficient_width,
int widest,
int row0,
int row1 )
3698 #define STBIR_MOVE_1( dest, src ) { STBIR_NO_UNROLL(dest); ((stbir_uint32*)(dest))[0] = ((stbir_uint32*)(src))[0]; }
3699 #define STBIR_MOVE_2( dest, src ) { STBIR_NO_UNROLL(dest); ((stbir_uint64*)(dest))[0] = ((stbir_uint64*)(src))[0]; }
3701 #define STBIR_MOVE_4( dest, src ) { stbir__simdf t; STBIR_NO_UNROLL(dest); stbir__simdf_load( t, src ); stbir__simdf_store( dest, t ); }
3703 #define STBIR_MOVE_4( dest, src ) { STBIR_NO_UNROLL(dest); ((stbir_uint64*)(dest))[0] = ((stbir_uint64*)(src))[0]; ((stbir_uint64*)(dest))[1] = ((stbir_uint64*)(src))[1]; }
3706 int row_end = row1 + 1;
3707 STBIR__UNUSED( row0 );
3709 if ( coefficient_width != widest )
3711 float * pc = coefficents;
3712 float * coeffs = coefficents;
3713 float * pc_end = coefficents + num_contributors * widest;
3717 STBIR_NO_UNROLL_LOOP_START
3719 STBIR_MOVE_1( pc, coeffs );
3721 coeffs += coefficient_width;
3722 }
while ( pc < pc_end );
3725 STBIR_NO_UNROLL_LOOP_START
3727 STBIR_MOVE_2( pc, coeffs );
3729 coeffs += coefficient_width;
3730 }
while ( pc < pc_end );
3733 STBIR_NO_UNROLL_LOOP_START
3735 STBIR_MOVE_2( pc, coeffs );
3736 STBIR_MOVE_1( pc+2, coeffs+2 );
3738 coeffs += coefficient_width;
3739 }
while ( pc < pc_end );
3742 STBIR_NO_UNROLL_LOOP_START
3744 STBIR_MOVE_4( pc, coeffs );
3746 coeffs += coefficient_width;
3747 }
while ( pc < pc_end );
3750 STBIR_NO_UNROLL_LOOP_START
3752 STBIR_MOVE_4( pc, coeffs );
3753 STBIR_MOVE_1( pc+4, coeffs+4 );
3755 coeffs += coefficient_width;
3756 }
while ( pc < pc_end );
3759 STBIR_NO_UNROLL_LOOP_START
3761 STBIR_MOVE_4( pc, coeffs );
3762 STBIR_MOVE_2( pc+4, coeffs+4 );
3764 coeffs += coefficient_width;
3765 }
while ( pc < pc_end );
3768 STBIR_NO_UNROLL_LOOP_START
3770 STBIR_MOVE_4( pc, coeffs );
3771 STBIR_MOVE_2( pc+4, coeffs+4 );
3772 STBIR_MOVE_1( pc+6, coeffs+6 );
3774 coeffs += coefficient_width;
3775 }
while ( pc < pc_end );
3778 STBIR_NO_UNROLL_LOOP_START
3780 STBIR_MOVE_4( pc, coeffs );
3781 STBIR_MOVE_4( pc+4, coeffs+4 );
3783 coeffs += coefficient_width;
3784 }
while ( pc < pc_end );
3787 STBIR_NO_UNROLL_LOOP_START
3789 STBIR_MOVE_4( pc, coeffs );
3790 STBIR_MOVE_4( pc+4, coeffs+4 );
3791 STBIR_MOVE_1( pc+8, coeffs+8 );
3793 coeffs += coefficient_width;
3794 }
while ( pc < pc_end );
3797 STBIR_NO_UNROLL_LOOP_START
3799 STBIR_MOVE_4( pc, coeffs );
3800 STBIR_MOVE_4( pc+4, coeffs+4 );
3801 STBIR_MOVE_2( pc+8, coeffs+8 );
3803 coeffs += coefficient_width;
3804 }
while ( pc < pc_end );
3807 STBIR_NO_UNROLL_LOOP_START
3809 STBIR_MOVE_4( pc, coeffs );
3810 STBIR_MOVE_4( pc+4, coeffs+4 );
3811 STBIR_MOVE_2( pc+8, coeffs+8 );
3812 STBIR_MOVE_1( pc+10, coeffs+10 );
3814 coeffs += coefficient_width;
3815 }
while ( pc < pc_end );
3818 STBIR_NO_UNROLL_LOOP_START
3820 STBIR_MOVE_4( pc, coeffs );
3821 STBIR_MOVE_4( pc+4, coeffs+4 );
3822 STBIR_MOVE_4( pc+8, coeffs+8 );
3824 coeffs += coefficient_width;
3825 }
while ( pc < pc_end );
3828 STBIR_NO_UNROLL_LOOP_START
3830 float * copy_end = pc + widest - 4;
3833 STBIR_NO_UNROLL( pc );
3834 STBIR_MOVE_4( pc, c );
3837 }
while ( pc <= copy_end );
3839 STBIR_NO_UNROLL_LOOP_START
3840 while ( pc < copy_end )
3842 STBIR_MOVE_1( pc, c );
3845 coeffs += coefficient_width;
3846 }
while ( pc < pc_end );
3852 coefficents[ widest * num_contributors ] = 8888.0f;
3860 stbir__contributors * contribs = contributors + num_contributors - 1;
3861 float * coeffs = coefficents + widest * ( num_contributors - 1 );
3864 while ( ( contribs >= contributors ) && ( ( contribs->n0 + widest*2 ) >= row_end ) )
3867 if ( ( contribs->n0 + widest ) > row_end )
3869 int stop_range = widest;
3879 stop_range = ( ( ( contribs->n1 - contribs->n0 + 1 ) - mod + 3 ) & ~3 ) + mod;
3882 if ( stop_range < ( 8 + mod ) ) stop_range = 8 + mod;
3886 if ( ( contribs->n0 + stop_range ) > row_end )
3888 int new_n0 = row_end - stop_range;
3889 int num = contribs->n1 - contribs->n0 + 1;
3890 int backup = contribs->n0 - new_n0;
3891 float * from_co = coeffs + num - 1;
3892 float * to_co = from_co + backup;
3894 STBIR_ASSERT( ( new_n0 >= row0 ) && ( new_n0 < contribs->n0 ) );
3899 *to_co-- = *from_co--;
3903 while ( to_co >= coeffs )
3906 contribs->n0 = new_n0;
3913 stop_range = ( ( ( contribs->n1 - contribs->n0 + 1 ) - mod + 3 ) & ~3 ) + mod;
3916 if ( stop_range < ( 8 + mod ) ) stop_range = 8 + mod;
3931static void stbir__calculate_filters( stbir__sampler * samp, stbir__sampler * other_axis_for_pivot,
void * user_data STBIR_ONLY_PROFILE_BUILD_GET_INFO )
3934 float scale = samp->scale_info.scale;
3937 float inv_scale = samp->scale_info.inv_scale;
3938 int input_full_size = samp->scale_info.input_full_size;
3939 int gather_num_contributors = samp->num_contributors;
3940 stbir__contributors* gather_contributors = samp->contributors;
3941 float * gather_coeffs = samp->coefficients;
3942 int gather_coefficient_width = samp->coefficient_width;
3944 switch ( samp->is_gather )
3948 float out_pixels_radius = support(inv_scale,user_data) * scale;
3950 stbir__calculate_coefficients_for_gather_upsample( out_pixels_radius, kernel, &samp->scale_info, gather_num_contributors, gather_contributors, gather_coeffs, gather_coefficient_width, samp->edge, user_data );
3952 STBIR_PROFILE_BUILD_START( cleanup );
3953 stbir__cleanup_gathered_coefficients( samp->edge, &samp->extent_info, &samp->scale_info, gather_num_contributors, gather_contributors, gather_coeffs, gather_coefficient_width );
3954 STBIR_PROFILE_BUILD_END( cleanup );
3961 float in_pixels_radius = support(scale,user_data) * inv_scale;
3962 int filter_pixel_margin = samp->filter_pixel_margin;
3963 int input_end = input_full_size + filter_pixel_margin;
3966 if ( !samp->is_gather )
3970 if ( other_axis_for_pivot )
3972 gather_contributors = other_axis_for_pivot->contributors;
3973 gather_coeffs = other_axis_for_pivot->coefficients;
3974 gather_coefficient_width = other_axis_for_pivot->coefficient_width;
3975 gather_num_contributors = other_axis_for_pivot->num_contributors;
3976 samp->extent_info.lowest = other_axis_for_pivot->extent_info.lowest;
3977 samp->extent_info.highest = other_axis_for_pivot->extent_info.highest;
3978 samp->extent_info.widest = other_axis_for_pivot->extent_info.widest;
3979 goto jump_right_to_pivot;
3982 gather_contributors = samp->gather_prescatter_contributors;
3983 gather_coeffs = samp->gather_prescatter_coefficients;
3984 gather_coefficient_width = samp->gather_prescatter_coefficient_width;
3985 gather_num_contributors = samp->gather_prescatter_num_contributors;
3988 stbir__calculate_coefficients_for_gather_downsample( -filter_pixel_margin, input_end, in_pixels_radius, kernel, &samp->scale_info, gather_coefficient_width, gather_num_contributors, gather_contributors, gather_coeffs, user_data );
3990 STBIR_PROFILE_BUILD_START( cleanup );
3991 stbir__cleanup_gathered_coefficients( samp->edge, &samp->extent_info, &samp->scale_info, gather_num_contributors, gather_contributors, gather_coeffs, gather_coefficient_width );
3992 STBIR_PROFILE_BUILD_END( cleanup );
3994 if ( !samp->is_gather )
3997 stbir__contributors * scatter_contributors;
4000 jump_right_to_pivot:
4002 STBIR_PROFILE_BUILD_START( pivot );
4004 highest_set = (-filter_pixel_margin) - 1;
4005 for (n = 0; n < gather_num_contributors; n++)
4008 int gn0 = gather_contributors->n0, gn1 = gather_contributors->n1;
4009 int scatter_coefficient_width = samp->coefficient_width;
4010 float * scatter_coeffs = samp->coefficients + ( gn0 + filter_pixel_margin ) * scatter_coefficient_width;
4011 float * g_coeffs = gather_coeffs;
4012 scatter_contributors = samp->contributors + ( gn0 + filter_pixel_margin );
4014 for (k = gn0 ; k <= gn1 ; k++ )
4016 float gc = *g_coeffs++;
4020 if ( ( ( gc >= stbir__small_float ) || ( gc <= -stbir__small_float ) ) )
4022 if ( ( k > highest_set ) || ( scatter_contributors->n0 > scatter_contributors->n1 ) )
4026 stbir__contributors * clear_contributors = samp->contributors + ( highest_set + filter_pixel_margin + 1);
4027 while ( clear_contributors < scatter_contributors )
4029 clear_contributors->n0 = 0;
4030 clear_contributors->n1 = -1;
4031 ++clear_contributors;
4034 scatter_contributors->n0 = n;
4035 scatter_contributors->n1 = n;
4036 scatter_coeffs[0] = gc;
4041 stbir__insert_coeff( scatter_contributors, scatter_coeffs, n, gc, scatter_coefficient_width );
4043 STBIR_ASSERT( ( scatter_contributors->n1 - scatter_contributors->n0 + 1 ) <= scatter_coefficient_width );
4045 ++scatter_contributors;
4046 scatter_coeffs += scatter_coefficient_width;
4049 ++gather_contributors;
4050 gather_coeffs += gather_coefficient_width;
4055 stbir__contributors * clear_contributors = samp->contributors + ( highest_set + filter_pixel_margin + 1);
4056 stbir__contributors * end_contributors = samp->contributors + samp->num_contributors;
4057 while ( clear_contributors < end_contributors )
4059 clear_contributors->n0 = 0;
4060 clear_contributors->n1 = -1;
4061 ++clear_contributors;
4065 STBIR_PROFILE_BUILD_END( pivot );
4076#define stbir__coder_min_num 1
4077#define STB_IMAGE_RESIZE_DO_CODERS
4078#include STBIR__HEADER_FILENAME
4080#define stbir__decode_suffix BGRA
4081#define stbir__decode_swizzle
4082#define stbir__decode_order0 2
4083#define stbir__decode_order1 1
4084#define stbir__decode_order2 0
4085#define stbir__decode_order3 3
4086#define stbir__encode_order0 2
4087#define stbir__encode_order1 1
4088#define stbir__encode_order2 0
4089#define stbir__encode_order3 3
4090#define stbir__coder_min_num 4
4091#define STB_IMAGE_RESIZE_DO_CODERS
4092#include STBIR__HEADER_FILENAME
4094#define stbir__decode_suffix ARGB
4095#define stbir__decode_swizzle
4096#define stbir__decode_order0 1
4097#define stbir__decode_order1 2
4098#define stbir__decode_order2 3
4099#define stbir__decode_order3 0
4100#define stbir__encode_order0 3
4101#define stbir__encode_order1 0
4102#define stbir__encode_order2 1
4103#define stbir__encode_order3 2
4104#define stbir__coder_min_num 4
4105#define STB_IMAGE_RESIZE_DO_CODERS
4106#include STBIR__HEADER_FILENAME
4108#define stbir__decode_suffix ABGR
4109#define stbir__decode_swizzle
4110#define stbir__decode_order0 3
4111#define stbir__decode_order1 2
4112#define stbir__decode_order2 1
4113#define stbir__decode_order3 0
4114#define stbir__encode_order0 3
4115#define stbir__encode_order1 2
4116#define stbir__encode_order2 1
4117#define stbir__encode_order3 0
4118#define stbir__coder_min_num 4
4119#define STB_IMAGE_RESIZE_DO_CODERS
4120#include STBIR__HEADER_FILENAME
4122#define stbir__decode_suffix AR
4123#define stbir__decode_swizzle
4124#define stbir__decode_order0 1
4125#define stbir__decode_order1 0
4126#define stbir__decode_order2 3
4127#define stbir__decode_order3 2
4128#define stbir__encode_order0 1
4129#define stbir__encode_order1 0
4130#define stbir__encode_order2 3
4131#define stbir__encode_order3 2
4132#define stbir__coder_min_num 2
4133#define STB_IMAGE_RESIZE_DO_CODERS
4134#include STBIR__HEADER_FILENAME
4138static void stbir__fancy_alpha_weight_4ch(
float * out_buffer,
int width_times_channels )
4140 float STBIR_STREAMOUT_PTR(*) out = out_buffer;
4141 float const * end_decode = out_buffer + ( width_times_channels / 4 ) * 7;
4142 float STBIR_STREAMOUT_PTR(*) decode = (
float*)end_decode - width_times_channels;
4150 STBIR_NO_UNROLL_LOOP_START
4151 while ( decode <= end_decode )
4153 stbir__simdf8 d0,d1,a0,a1,p0,p1;
4154 STBIR_NO_UNROLL(decode);
4155 stbir__simdf8_load( d0, decode-16 );
4156 stbir__simdf8_load( d1, decode-16+8 );
4157 stbir__simdf8_0123to33333333( a0, d0 );
4158 stbir__simdf8_0123to33333333( a1, d1 );
4159 stbir__simdf8_mult( p0, a0, d0 );
4160 stbir__simdf8_mult( p1, a1, d1 );
4161 stbir__simdf8_bot4s( a0, d0, p0 );
4162 stbir__simdf8_bot4s( a1, d1, p1 );
4163 stbir__simdf8_top4s( d0, d0, p0 );
4164 stbir__simdf8_top4s( d1, d1, p1 );
4165 stbir__simdf8_store ( out, a0 );
4166 stbir__simdf8_store ( out+7, d0 );
4167 stbir__simdf8_store ( out+14, a1 );
4168 stbir__simdf8_store ( out+21, d1 );
4175 STBIR_NO_UNROLL_LOOP_START
4176 while ( decode <= end_decode )
4178 stbir__simdf d0,a0,d1,a1,p0,p1;
4179 STBIR_NO_UNROLL(decode);
4180 stbir__simdf_load( d0, decode-8 );
4181 stbir__simdf_load( d1, decode-8+4 );
4182 stbir__simdf_0123to3333( a0, d0 );
4183 stbir__simdf_0123to3333( a1, d1 );
4184 stbir__simdf_mult( p0, a0, d0 );
4185 stbir__simdf_mult( p1, a1, d1 );
4186 stbir__simdf_store ( out, d0 );
4187 stbir__simdf_store ( out+4, p0 );
4188 stbir__simdf_store ( out+7, d1 );
4189 stbir__simdf_store ( out+7+4, p1 );
4198 STBIR_NO_UNROLL_LOOP_START
4199 while ( decode < end_decode )
4201 if ( decode < end_decode )
4205 STBIR_NO_UNROLL(decode);
4206 stbir__simdf_load( d, decode );
4207 stbir__simdf_0123to3333( a, d );
4208 stbir__simdf_mult( p, a, d );
4209 stbir__simdf_store ( out, d );
4210 stbir__simdf_store ( out+4, p );
4217 while( decode < end_decode )
4219 float r = decode[0], g = decode[1], b = decode[2],
alpha = decode[3];
4234static void stbir__fancy_alpha_weight_2ch(
float * out_buffer,
int width_times_channels )
4236 float STBIR_STREAMOUT_PTR(*) out = out_buffer;
4237 float const * end_decode = out_buffer + ( width_times_channels / 2 ) * 3;
4238 float STBIR_STREAMOUT_PTR(*) decode = (
float*)end_decode - width_times_channels;
4245 if ( decode <= end_decode )
4247 STBIR_NO_UNROLL_LOOP_START
4250 stbir__simdf8 d0,a0,p0;
4251 STBIR_NO_UNROLL(decode);
4252 stbir__simdf8_load( d0, decode-8 );
4253 stbir__simdf8_0123to11331133( p0, d0 );
4254 stbir__simdf8_0123to00220022( a0, d0 );
4255 stbir__simdf8_mult( p0, p0, a0 );
4257 stbir__simdf_store2( out, stbir__if_simdf8_cast_to_simdf4( d0 ) );
4258 stbir__simdf_store( out+2, stbir__if_simdf8_cast_to_simdf4( p0 ) );
4259 stbir__simdf_store2h( out+3, stbir__if_simdf8_cast_to_simdf4( d0 ) );
4261 stbir__simdf_store2( out+6, stbir__simdf8_gettop4( d0 ) );
4262 stbir__simdf_store( out+8, stbir__simdf8_gettop4( p0 ) );
4263 stbir__simdf_store2h( out+9, stbir__simdf8_gettop4( d0 ) );
4265 stbir__simdf d0,a0,d1,a1,p0,p1;
4266 STBIR_NO_UNROLL(decode);
4267 stbir__simdf_load( d0, decode-8 );
4268 stbir__simdf_load( d1, decode-8+4 );
4269 stbir__simdf_0123to1133( p0, d0 );
4270 stbir__simdf_0123to1133( p1, d1 );
4271 stbir__simdf_0123to0022( a0, d0 );
4272 stbir__simdf_0123to0022( a1, d1 );
4273 stbir__simdf_mult( p0, p0, a0 );
4274 stbir__simdf_mult( p1, p1, a1 );
4276 stbir__simdf_store2( out, d0 );
4277 stbir__simdf_store( out+2, p0 );
4278 stbir__simdf_store2h( out+3, d0 );
4280 stbir__simdf_store2( out+6, d1 );
4281 stbir__simdf_store( out+8, p1 );
4282 stbir__simdf_store2h( out+9, d1 );
4286 }
while ( decode <= end_decode );
4291 STBIR_SIMD_NO_UNROLL_LOOP_START
4292 while( decode < end_decode )
4294 float x = decode[0],
y = decode[1];
4295 STBIR_SIMD_NO_UNROLL(decode);
4304static void stbir__fancy_alpha_unweight_4ch(
float * encode_buffer,
int width_times_channels )
4306 float STBIR_SIMD_STREAMOUT_PTR(*) encode = encode_buffer;
4307 float STBIR_SIMD_STREAMOUT_PTR(*) input = encode_buffer;
4308 float const * end_output = encode_buffer + width_times_channels;
4312 STBIR_SIMD_NO_UNROLL_LOOP_START
4314 float alpha = input[3];
4317 STBIR_SIMD_NO_UNROLL(encode);
4318 if (
alpha < stbir__small_float )
4320 stbir__simdf_load( i, input );
4321 stbir__simdf_store( encode, i );
4325 stbir__simdf_load1frep4( ia, 1.0f /
alpha );
4326 stbir__simdf_load( i, input+4 );
4327 stbir__simdf_mult( i, i, ia );
4328 stbir__simdf_store( encode, i );
4332 if (
alpha < stbir__small_float )
4334 encode[0] = input[0];
4335 encode[1] = input[1];
4336 encode[2] = input[2];
4340 float ialpha = 1.0f /
alpha;
4341 encode[0] = input[4] * ialpha;
4342 encode[1] = input[5] * ialpha;
4343 encode[2] = input[6] * ialpha;
4350 }
while ( encode < end_output );
4354static void stbir__fancy_alpha_unweight_2ch(
float * encode_buffer,
int width_times_channels )
4356 float STBIR_SIMD_STREAMOUT_PTR(*) encode = encode_buffer;
4357 float STBIR_SIMD_STREAMOUT_PTR(*) input = encode_buffer;
4358 float const * end_output = encode_buffer + width_times_channels;
4361 float alpha = input[1];
4362 encode[0] = input[0];
4363 if (
alpha >= stbir__small_float )
4364 encode[0] = input[2] /
alpha;
4369 }
while ( encode < end_output );
4372static void stbir__simple_alpha_weight_4ch(
float * decode_buffer,
int width_times_channels )
4374 float STBIR_STREAMOUT_PTR(*) decode = decode_buffer;
4375 float const * end_decode = decode_buffer + width_times_channels;
4379 decode += 2 * stbir__simdfX_float_count;
4380 STBIR_NO_UNROLL_LOOP_START
4381 while ( decode <= end_decode )
4383 stbir__simdfX d0,a0,d1,a1;
4384 STBIR_NO_UNROLL(decode);
4385 stbir__simdfX_load( d0, decode-2*stbir__simdfX_float_count );
4386 stbir__simdfX_load( d1, decode-2*stbir__simdfX_float_count+stbir__simdfX_float_count );
4387 stbir__simdfX_aaa1( a0, d0, STBIR_onesX );
4388 stbir__simdfX_aaa1( a1, d1, STBIR_onesX );
4389 stbir__simdfX_mult( d0, d0, a0 );
4390 stbir__simdfX_mult( d1, d1, a1 );
4391 stbir__simdfX_store ( decode-2*stbir__simdfX_float_count, d0 );
4392 stbir__simdfX_store ( decode-2*stbir__simdfX_float_count+stbir__simdfX_float_count, d1 );
4393 decode += 2 * stbir__simdfX_float_count;
4395 decode -= 2 * stbir__simdfX_float_count;
4399 STBIR_NO_UNROLL_LOOP_START
4400 while ( decode < end_decode )
4402 if ( decode < end_decode )
4406 stbir__simdf_load( d, decode );
4407 stbir__simdf_aaa1( a, d, STBIR__CONSTF(STBIR_ones) );
4408 stbir__simdf_mult( d, d, a );
4409 stbir__simdf_store ( decode, d );
4416 while( decode < end_decode )
4418 float alpha = decode[3];
4428static void stbir__simple_alpha_weight_2ch(
float * decode_buffer,
int width_times_channels )
4430 float STBIR_STREAMOUT_PTR(*) decode = decode_buffer;
4431 float const * end_decode = decode_buffer + width_times_channels;
4434 decode += 2 * stbir__simdfX_float_count;
4435 STBIR_NO_UNROLL_LOOP_START
4436 while ( decode <= end_decode )
4438 stbir__simdfX d0,a0,d1,a1;
4439 STBIR_NO_UNROLL(decode);
4440 stbir__simdfX_load( d0, decode-2*stbir__simdfX_float_count );
4441 stbir__simdfX_load( d1, decode-2*stbir__simdfX_float_count+stbir__simdfX_float_count );
4442 stbir__simdfX_a1a1( a0, d0, STBIR_onesX );
4443 stbir__simdfX_a1a1( a1, d1, STBIR_onesX );
4444 stbir__simdfX_mult( d0, d0, a0 );
4445 stbir__simdfX_mult( d1, d1, a1 );
4446 stbir__simdfX_store ( decode-2*stbir__simdfX_float_count, d0 );
4447 stbir__simdfX_store ( decode-2*stbir__simdfX_float_count+stbir__simdfX_float_count, d1 );
4448 decode += 2 * stbir__simdfX_float_count;
4450 decode -= 2 * stbir__simdfX_float_count;
4453 STBIR_SIMD_NO_UNROLL_LOOP_START
4454 while( decode < end_decode )
4456 float alpha = decode[1];
4457 STBIR_SIMD_NO_UNROLL(decode);
4463static void stbir__simple_alpha_unweight_4ch(
float * encode_buffer,
int width_times_channels )
4465 float STBIR_SIMD_STREAMOUT_PTR(*) encode = encode_buffer;
4466 float const * end_output = encode_buffer + width_times_channels;
4468 STBIR_SIMD_NO_UNROLL_LOOP_START
4470 float alpha = encode[3];
4474 STBIR_SIMD_NO_UNROLL(encode);
4475 if (
alpha >= stbir__small_float )
4477 stbir__simdf_load1frep4( ia, 1.0f /
alpha );
4478 stbir__simdf_load( i, encode );
4479 stbir__simdf_mult( i, i, ia );
4480 stbir__simdf_store( encode, i );
4484 if (
alpha >= stbir__small_float )
4486 float ialpha = 1.0f /
alpha;
4487 encode[0] *= ialpha;
4488 encode[1] *= ialpha;
4489 encode[2] *= ialpha;
4493 }
while ( encode < end_output );
4496static void stbir__simple_alpha_unweight_2ch(
float * encode_buffer,
int width_times_channels )
4498 float STBIR_SIMD_STREAMOUT_PTR(*) encode = encode_buffer;
4499 float const * end_output = encode_buffer + width_times_channels;
4502 float alpha = encode[1];
4503 if (
alpha >= stbir__small_float )
4506 }
while ( encode < end_output );
4511static void stbir__simple_flip_3ch(
float * decode_buffer,
int width_times_channels )
4513 float STBIR_STREAMOUT_PTR(*) decode = decode_buffer;
4514 float const * end_decode = decode_buffer + width_times_channels;
4517 #ifdef stbir__simdf_swiz2
4519 STBIR_NO_UNROLL_LOOP_START
4520 while( decode <= end_decode )
4523 stbir__simdf a,b,c,na,nb;
4524 STBIR_SIMD_NO_UNROLL(decode);
4525 stbir__simdf_load( a, decode );
4526 stbir__simdf_load( b, decode+4 );
4527 stbir__simdf_load( c, decode+8 );
4529 na = stbir__simdf_swiz2( a, b, 2, 1, 0, 5 );
4530 b = stbir__simdf_swiz2( a, b, 4, 3, 6, 7 );
4531 nb = stbir__simdf_swiz2( b, c, 0, 1, 4, 3 );
4532 c = stbir__simdf_swiz2( b, c, 2, 7, 6, 5 );
4534 stbir__simdf_store( decode, na );
4535 stbir__simdf_store( decode+4, nb );
4536 stbir__simdf_store( decode+8, c );
4542 STBIR_NO_UNROLL_LOOP_START
4543 while( decode <= end_decode )
4546 stbir__simdf a,b,c,d,e,f,g;
4548 STBIR_SIMD_NO_UNROLL(decode);
4549 stbir__simdf_load( a, decode );
4550 stbir__simdf_load( b, decode+3 );
4551 stbir__simdf_load( c, decode+6 );
4552 stbir__simdf_load( d, decode+9 );
4553 stbir__simdf_load( e, decode+12 );
4554 stbir__simdf_load( f, decode+15 );
4555 stbir__simdf_load( g, decode+18 );
4557 a = stbir__simdf_swiz( a, 2, 1, 0, 3 );
4558 b = stbir__simdf_swiz( b, 2, 1, 0, 3 );
4559 c = stbir__simdf_swiz( c, 2, 1, 0, 3 );
4560 d = stbir__simdf_swiz( d, 2, 1, 0, 3 );
4561 e = stbir__simdf_swiz( e, 2, 1, 0, 3 );
4562 f = stbir__simdf_swiz( f, 2, 1, 0, 3 );
4563 g = stbir__simdf_swiz( g, 2, 1, 0, 3 );
4566 stbir__simdf_store( decode, a );
4568 stbir__simdf_store( decode+3, b );
4570 stbir__simdf_store( decode+6, c );
4571 stbir__simdf_store( decode+9, d );
4572 stbir__simdf_store( decode+12, e );
4573 stbir__simdf_store( decode+15, f );
4574 stbir__simdf_store( decode+18, g );
4583 STBIR_NO_UNROLL_LOOP_START
4584 while( decode <= end_decode )
4588 STBIR_NO_UNROLL(decode);
4589 t0 = decode[0]; t1 = decode[3]; t2 = decode[6]; t3 = decode[9];
4590 decode[0] = decode[2]; decode[3] = decode[5]; decode[6] = decode[8]; decode[9] = decode[11];
4591 decode[2] = t0; decode[5] = t1; decode[8] = t2; decode[11] = t3;
4597 STBIR_NO_UNROLL_LOOP_START
4598 while( decode < end_decode )
4600 float t = decode[0];
4601 STBIR_NO_UNROLL(decode);
4602 decode[0] = decode[2];
4610static void stbir__decode_scanline(
stbir__info const * stbir_info,
int n,
float * output_buffer STBIR_ONLY_PROFILE_GET_SPLIT_INFO )
4612 int channels = stbir_info->channels;
4613 int effective_channels = stbir_info->effective_channels;
4614 int input_sample_in_bytes = stbir__type_size[stbir_info->input_type] * channels;
4615 stbir_edge edge_horizontal = stbir_info->horizontal.edge;
4616 stbir_edge edge_vertical = stbir_info->vertical.edge;
4617 int row = stbir__edge_wrap(edge_vertical, n, stbir_info->vertical.scale_info.input_full_size);
4618 const void* input_plane_data = ( (
char *) stbir_info->input_data ) + (
size_t)row * (
size_t) stbir_info->input_stride_bytes;
4619 stbir__span
const * spans = stbir_info->scanline_extents.spans;
4620 float * full_decode_buffer = output_buffer - stbir_info->scanline_extents.conservative.n0 * effective_channels;
4621 float * last_decoded = 0;
4624 STBIR_ASSERT( !(edge_vertical ==
STBIR_EDGE_ZERO && (n < 0 || n >= stbir_info->vertical.scale_info.input_full_size)) );
4628 float * decode_buffer;
4629 void const * input_data;
4631 int width_times_channels;
4634 if ( spans->n1 < spans->n0 )
4637 width = spans->n1 + 1 - spans->n0;
4638 decode_buffer = full_decode_buffer + spans->n0 * effective_channels;
4639 end_decode = full_decode_buffer + ( spans->n1 + 1 ) * effective_channels;
4640 width_times_channels =
width * channels;
4643 input_data = ( (
char*)input_plane_data ) + spans->pixel_offset_for_input * input_sample_in_bytes;
4646 if ( stbir_info->in_pixels_cb )
4649 input_data = stbir_info->in_pixels_cb( ( (
char*) end_decode ) - (
width * input_sample_in_bytes ) + ( ( stbir_info->input_type !=
STBIR_TYPE_FLOAT ) ? (
sizeof(
float)*STBIR_INPUT_CALLBACK_PADDING ) : 0 ), input_plane_data,
width, spans->pixel_offset_for_input, row, stbir_info->user_data );
4652 STBIR_PROFILE_START( decode );
4654 last_decoded = stbir_info->decode_pixels( (
float*)end_decode - width_times_channels, width_times_channels, input_data );
4655 STBIR_PROFILE_END( decode );
4657 if (stbir_info->alpha_weight)
4659 STBIR_PROFILE_START(
alpha );
4660 stbir_info->alpha_weight( decode_buffer, width_times_channels );
4661 STBIR_PROFILE_END(
alpha );
4665 }
while ( spans <= ( &stbir_info->scanline_extents.spans[1] ) );
4670 if ( ( edge_horizontal ==
STBIR_EDGE_WRAP ) && ( stbir_info->scanline_extents.edge_sizes[0] | stbir_info->scanline_extents.edge_sizes[1] ) )
4674 int input_full_size = stbir_info->horizontal.scale_info.input_full_size;
4676 start_x[0] = -stbir_info->scanline_extents.edge_sizes[0];
4677 start_x[1] = input_full_size;
4679 for( e = 0; e < 2 ; e++ )
4682 int margin = stbir_info->scanline_extents.edge_sizes[e];
4686 float * marg = full_decode_buffer + x * effective_channels;
4687 float const * src = full_decode_buffer + stbir__edge_wrap(edge_horizontal, x, input_full_size) * effective_channels;
4688 STBIR_MEMCPY( marg, src, margin * effective_channels *
sizeof(
float) );
4689 if ( e == 1 ) last_decoded = marg + margin * effective_channels;
4696 last_decoded[0] = 0.0f;
4701 last_decoded[1] = 0.0f;
4710#define stbir__1_coeff_only() \
4711 stbir__simdf tot,c; \
4712 STBIR_SIMD_NO_UNROLL(decode); \
4713 stbir__simdf_load1( c, hc ); \
4714 stbir__simdf_mult1_mem( tot, c, decode );
4716#define stbir__2_coeff_only() \
4717 stbir__simdf tot,c,d; \
4718 STBIR_SIMD_NO_UNROLL(decode); \
4719 stbir__simdf_load2z( c, hc ); \
4720 stbir__simdf_load2( d, decode ); \
4721 stbir__simdf_mult( tot, c, d ); \
4722 stbir__simdf_0123to1230( c, tot ); \
4723 stbir__simdf_add1( tot, tot, c );
4725#define stbir__3_coeff_only() \
4726 stbir__simdf tot,c,t; \
4727 STBIR_SIMD_NO_UNROLL(decode); \
4728 stbir__simdf_load( c, hc ); \
4729 stbir__simdf_mult_mem( tot, c, decode ); \
4730 stbir__simdf_0123to1230( c, tot ); \
4731 stbir__simdf_0123to2301( t, tot ); \
4732 stbir__simdf_add1( tot, tot, c ); \
4733 stbir__simdf_add1( tot, tot, t );
4735#define stbir__store_output_tiny() \
4736 stbir__simdf_store1( output, tot ); \
4737 horizontal_coefficients += coefficient_width; \
4738 ++horizontal_contributors; \
4741#define stbir__4_coeff_start() \
4742 stbir__simdf tot,c; \
4743 STBIR_SIMD_NO_UNROLL(decode); \
4744 stbir__simdf_load( c, hc ); \
4745 stbir__simdf_mult_mem( tot, c, decode ); \
4747#define stbir__4_coeff_continue_from_4( ofs ) \
4748 STBIR_SIMD_NO_UNROLL(decode); \
4749 stbir__simdf_load( c, hc + (ofs) ); \
4750 stbir__simdf_madd_mem( tot, tot, c, decode+(ofs) );
4752#define stbir__1_coeff_remnant( ofs ) \
4754 stbir__simdf_load1z( c, hc + (ofs) ); \
4755 stbir__simdf_load1( d, decode + (ofs) ); \
4756 stbir__simdf_madd( tot, tot, d, c ); }
4758#define stbir__2_coeff_remnant( ofs ) \
4760 stbir__simdf_load2z( c, hc+(ofs) ); \
4761 stbir__simdf_load2( d, decode+(ofs) ); \
4762 stbir__simdf_madd( tot, tot, d, c ); }
4764#define stbir__3_coeff_setup() \
4765 stbir__simdf mask; \
4766 stbir__simdf_load( mask, STBIR_mask + 3 );
4768#define stbir__3_coeff_remnant( ofs ) \
4769 stbir__simdf_load( c, hc+(ofs) ); \
4770 stbir__simdf_and( c, c, mask ); \
4771 stbir__simdf_madd_mem( tot, tot, c, decode+(ofs) );
4773#define stbir__store_output() \
4774 stbir__simdf_0123to2301( c, tot ); \
4775 stbir__simdf_add( tot, tot, c ); \
4776 stbir__simdf_0123to1230( c, tot ); \
4777 stbir__simdf_add1( tot, tot, c ); \
4778 stbir__simdf_store1( output, tot ); \
4779 horizontal_coefficients += coefficient_width; \
4780 ++horizontal_contributors; \
4785#define stbir__1_coeff_only() \
4787 tot = decode[0]*hc[0];
4789#define stbir__2_coeff_only() \
4791 tot = decode[0] * hc[0]; \
4792 tot += decode[1] * hc[1];
4794#define stbir__3_coeff_only() \
4796 tot = decode[0] * hc[0]; \
4797 tot += decode[1] * hc[1]; \
4798 tot += decode[2] * hc[2];
4800#define stbir__store_output_tiny() \
4802 horizontal_coefficients += coefficient_width; \
4803 ++horizontal_contributors; \
4806#define stbir__4_coeff_start() \
4807 float tot0,tot1,tot2,tot3; \
4808 tot0 = decode[0] * hc[0]; \
4809 tot1 = decode[1] * hc[1]; \
4810 tot2 = decode[2] * hc[2]; \
4811 tot3 = decode[3] * hc[3];
4813#define stbir__4_coeff_continue_from_4( ofs ) \
4814 tot0 += decode[0+(ofs)] * hc[0+(ofs)]; \
4815 tot1 += decode[1+(ofs)] * hc[1+(ofs)]; \
4816 tot2 += decode[2+(ofs)] * hc[2+(ofs)]; \
4817 tot3 += decode[3+(ofs)] * hc[3+(ofs)];
4819#define stbir__1_coeff_remnant( ofs ) \
4820 tot0 += decode[0+(ofs)] * hc[0+(ofs)];
4822#define stbir__2_coeff_remnant( ofs ) \
4823 tot0 += decode[0+(ofs)] * hc[0+(ofs)]; \
4824 tot1 += decode[1+(ofs)] * hc[1+(ofs)]; \
4826#define stbir__3_coeff_remnant( ofs ) \
4827 tot0 += decode[0+(ofs)] * hc[0+(ofs)]; \
4828 tot1 += decode[1+(ofs)] * hc[1+(ofs)]; \
4829 tot2 += decode[2+(ofs)] * hc[2+(ofs)];
4831#define stbir__store_output() \
4832 output[0] = (tot0+tot2)+(tot1+tot3); \
4833 horizontal_coefficients += coefficient_width; \
4834 ++horizontal_contributors; \
4839#define STBIR__horizontal_channels 1
4840#define STB_IMAGE_RESIZE_DO_HORIZONTALS
4841#include STBIR__HEADER_FILENAME
4849#define stbir__1_coeff_only() \
4850 stbir__simdf tot,c,d; \
4851 STBIR_SIMD_NO_UNROLL(decode); \
4852 stbir__simdf_load1z( c, hc ); \
4853 stbir__simdf_0123to0011( c, c ); \
4854 stbir__simdf_load2( d, decode ); \
4855 stbir__simdf_mult( tot, d, c );
4857#define stbir__2_coeff_only() \
4858 stbir__simdf tot,c; \
4859 STBIR_SIMD_NO_UNROLL(decode); \
4860 stbir__simdf_load2( c, hc ); \
4861 stbir__simdf_0123to0011( c, c ); \
4862 stbir__simdf_mult_mem( tot, c, decode );
4864#define stbir__3_coeff_only() \
4865 stbir__simdf tot,c,cs,d; \
4866 STBIR_SIMD_NO_UNROLL(decode); \
4867 stbir__simdf_load( cs, hc ); \
4868 stbir__simdf_0123to0011( c, cs ); \
4869 stbir__simdf_mult_mem( tot, c, decode ); \
4870 stbir__simdf_0123to2222( c, cs ); \
4871 stbir__simdf_load2z( d, decode+4 ); \
4872 stbir__simdf_madd( tot, tot, d, c );
4874#define stbir__store_output_tiny() \
4875 stbir__simdf_0123to2301( c, tot ); \
4876 stbir__simdf_add( tot, tot, c ); \
4877 stbir__simdf_store2( output, tot ); \
4878 horizontal_coefficients += coefficient_width; \
4879 ++horizontal_contributors; \
4884#define stbir__4_coeff_start() \
4885 stbir__simdf8 tot0,c,cs; \
4886 STBIR_SIMD_NO_UNROLL(decode); \
4887 stbir__simdf8_load4b( cs, hc ); \
4888 stbir__simdf8_0123to00112233( c, cs ); \
4889 stbir__simdf8_mult_mem( tot0, c, decode );
4891#define stbir__4_coeff_continue_from_4( ofs ) \
4892 STBIR_SIMD_NO_UNROLL(decode); \
4893 stbir__simdf8_load4b( cs, hc + (ofs) ); \
4894 stbir__simdf8_0123to00112233( c, cs ); \
4895 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*2 );
4897#define stbir__1_coeff_remnant( ofs ) \
4898 { stbir__simdf t,d; \
4899 stbir__simdf_load1z( t, hc + (ofs) ); \
4900 stbir__simdf_load2( d, decode + (ofs) * 2 ); \
4901 stbir__simdf_0123to0011( t, t ); \
4902 stbir__simdf_mult( t, t, d ); \
4903 stbir__simdf8_add4( tot0, tot0, t ); }
4905#define stbir__2_coeff_remnant( ofs ) \
4907 stbir__simdf_load2( t, hc + (ofs) ); \
4908 stbir__simdf_0123to0011( t, t ); \
4909 stbir__simdf_mult_mem( t, t, decode+(ofs)*2 ); \
4910 stbir__simdf8_add4( tot0, tot0, t ); }
4912#define stbir__3_coeff_remnant( ofs ) \
4913 { stbir__simdf8 d; \
4914 stbir__simdf8_load4b( cs, hc + (ofs) ); \
4915 stbir__simdf8_0123to00112233( c, cs ); \
4916 stbir__simdf8_load6z( d, decode+(ofs)*2 ); \
4917 stbir__simdf8_madd( tot0, tot0, c, d ); }
4919#define stbir__store_output() \
4920 { stbir__simdf t,d; \
4921 stbir__simdf8_add4halves( t, stbir__if_simdf8_cast_to_simdf4(tot0), tot0 ); \
4922 stbir__simdf_0123to2301( d, t ); \
4923 stbir__simdf_add( t, t, d ); \
4924 stbir__simdf_store2( output, t ); \
4925 horizontal_coefficients += coefficient_width; \
4926 ++horizontal_contributors; \
4931#define stbir__4_coeff_start() \
4932 stbir__simdf tot0,tot1,c,cs; \
4933 STBIR_SIMD_NO_UNROLL(decode); \
4934 stbir__simdf_load( cs, hc ); \
4935 stbir__simdf_0123to0011( c, cs ); \
4936 stbir__simdf_mult_mem( tot0, c, decode ); \
4937 stbir__simdf_0123to2233( c, cs ); \
4938 stbir__simdf_mult_mem( tot1, c, decode+4 );
4940#define stbir__4_coeff_continue_from_4( ofs ) \
4941 STBIR_SIMD_NO_UNROLL(decode); \
4942 stbir__simdf_load( cs, hc + (ofs) ); \
4943 stbir__simdf_0123to0011( c, cs ); \
4944 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*2 ); \
4945 stbir__simdf_0123to2233( c, cs ); \
4946 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*2+4 );
4948#define stbir__1_coeff_remnant( ofs ) \
4950 stbir__simdf_load1z( cs, hc + (ofs) ); \
4951 stbir__simdf_0123to0011( c, cs ); \
4952 stbir__simdf_load2( d, decode + (ofs) * 2 ); \
4953 stbir__simdf_madd( tot0, tot0, d, c ); }
4955#define stbir__2_coeff_remnant( ofs ) \
4956 stbir__simdf_load2( cs, hc + (ofs) ); \
4957 stbir__simdf_0123to0011( c, cs ); \
4958 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*2 );
4960#define stbir__3_coeff_remnant( ofs ) \
4962 stbir__simdf_load( cs, hc + (ofs) ); \
4963 stbir__simdf_0123to0011( c, cs ); \
4964 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*2 ); \
4965 stbir__simdf_0123to2222( c, cs ); \
4966 stbir__simdf_load2z( d, decode + (ofs) * 2 + 4 ); \
4967 stbir__simdf_madd( tot1, tot1, d, c ); }
4969#define stbir__store_output() \
4970 stbir__simdf_add( tot0, tot0, tot1 ); \
4971 stbir__simdf_0123to2301( c, tot0 ); \
4972 stbir__simdf_add( tot0, tot0, c ); \
4973 stbir__simdf_store2( output, tot0 ); \
4974 horizontal_coefficients += coefficient_width; \
4975 ++horizontal_contributors; \
4982#define stbir__1_coeff_only() \
4983 float tota,totb,c; \
4985 tota = decode[0]*c; \
4988#define stbir__2_coeff_only() \
4989 float tota,totb,c; \
4991 tota = decode[0]*c; \
4992 totb = decode[1]*c; \
4994 tota += decode[2]*c; \
4995 totb += decode[3]*c;
4998#define stbir__3_coeff_only() \
4999 float tota,totb,c; \
5001 tota = decode[0]*c; \
5002 totb = decode[1]*c; \
5004 tota += decode[4]*c; \
5005 totb += decode[5]*c; \
5007 tota += decode[2]*c; \
5008 totb += decode[3]*c;
5010#define stbir__store_output_tiny() \
5013 horizontal_coefficients += coefficient_width; \
5014 ++horizontal_contributors; \
5017#define stbir__4_coeff_start() \
5018 float tota0,tota1,tota2,tota3,totb0,totb1,totb2,totb3,c; \
5020 tota0 = decode[0]*c; \
5021 totb0 = decode[1]*c; \
5023 tota1 = decode[2]*c; \
5024 totb1 = decode[3]*c; \
5026 tota2 = decode[4]*c; \
5027 totb2 = decode[5]*c; \
5029 tota3 = decode[6]*c; \
5030 totb3 = decode[7]*c;
5032#define stbir__4_coeff_continue_from_4( ofs ) \
5034 tota0 += decode[0+(ofs)*2]*c; \
5035 totb0 += decode[1+(ofs)*2]*c; \
5037 tota1 += decode[2+(ofs)*2]*c; \
5038 totb1 += decode[3+(ofs)*2]*c; \
5040 tota2 += decode[4+(ofs)*2]*c; \
5041 totb2 += decode[5+(ofs)*2]*c; \
5043 tota3 += decode[6+(ofs)*2]*c; \
5044 totb3 += decode[7+(ofs)*2]*c;
5046#define stbir__1_coeff_remnant( ofs ) \
5048 tota0 += decode[0+(ofs)*2] * c; \
5049 totb0 += decode[1+(ofs)*2] * c;
5051#define stbir__2_coeff_remnant( ofs ) \
5053 tota0 += decode[0+(ofs)*2] * c; \
5054 totb0 += decode[1+(ofs)*2] * c; \
5056 tota1 += decode[2+(ofs)*2] * c; \
5057 totb1 += decode[3+(ofs)*2] * c;
5059#define stbir__3_coeff_remnant( ofs ) \
5061 tota0 += decode[0+(ofs)*2] * c; \
5062 totb0 += decode[1+(ofs)*2] * c; \
5064 tota1 += decode[2+(ofs)*2] * c; \
5065 totb1 += decode[3+(ofs)*2] * c; \
5067 tota2 += decode[4+(ofs)*2] * c; \
5068 totb2 += decode[5+(ofs)*2] * c;
5070#define stbir__store_output() \
5071 output[0] = (tota0+tota2)+(tota1+tota3); \
5072 output[1] = (totb0+totb2)+(totb1+totb3); \
5073 horizontal_coefficients += coefficient_width; \
5074 ++horizontal_contributors; \
5079#define STBIR__horizontal_channels 2
5080#define STB_IMAGE_RESIZE_DO_HORIZONTALS
5081#include STBIR__HEADER_FILENAME
5089#define stbir__1_coeff_only() \
5090 stbir__simdf tot,c,d; \
5091 STBIR_SIMD_NO_UNROLL(decode); \
5092 stbir__simdf_load1z( c, hc ); \
5093 stbir__simdf_0123to0001( c, c ); \
5094 stbir__simdf_load( d, decode ); \
5095 stbir__simdf_mult( tot, d, c );
5097#define stbir__2_coeff_only() \
5098 stbir__simdf tot,c,cs,d; \
5099 STBIR_SIMD_NO_UNROLL(decode); \
5100 stbir__simdf_load2( cs, hc ); \
5101 stbir__simdf_0123to0000( c, cs ); \
5102 stbir__simdf_load( d, decode ); \
5103 stbir__simdf_mult( tot, d, c ); \
5104 stbir__simdf_0123to1111( c, cs ); \
5105 stbir__simdf_load( d, decode+3 ); \
5106 stbir__simdf_madd( tot, tot, d, c );
5108#define stbir__3_coeff_only() \
5109 stbir__simdf tot,c,d,cs; \
5110 STBIR_SIMD_NO_UNROLL(decode); \
5111 stbir__simdf_load( cs, hc ); \
5112 stbir__simdf_0123to0000( c, cs ); \
5113 stbir__simdf_load( d, decode ); \
5114 stbir__simdf_mult( tot, d, c ); \
5115 stbir__simdf_0123to1111( c, cs ); \
5116 stbir__simdf_load( d, decode+3 ); \
5117 stbir__simdf_madd( tot, tot, d, c ); \
5118 stbir__simdf_0123to2222( c, cs ); \
5119 stbir__simdf_load( d, decode+6 ); \
5120 stbir__simdf_madd( tot, tot, d, c );
5122#define stbir__store_output_tiny() \
5123 stbir__simdf_store2( output, tot ); \
5124 stbir__simdf_0123to2301( tot, tot ); \
5125 stbir__simdf_store1( output+2, tot ); \
5126 horizontal_coefficients += coefficient_width; \
5127 ++horizontal_contributors; \
5133#define stbir__4_coeff_start() \
5134 stbir__simdf8 tot0,tot1,c,cs; stbir__simdf t; \
5135 STBIR_SIMD_NO_UNROLL(decode); \
5136 stbir__simdf8_load4b( cs, hc ); \
5137 stbir__simdf8_0123to00001111( c, cs ); \
5138 stbir__simdf8_mult_mem( tot0, c, decode - 1 ); \
5139 stbir__simdf8_0123to22223333( c, cs ); \
5140 stbir__simdf8_mult_mem( tot1, c, decode+6 - 1 );
5142#define stbir__4_coeff_continue_from_4( ofs ) \
5143 STBIR_SIMD_NO_UNROLL(decode); \
5144 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5145 stbir__simdf8_0123to00001111( c, cs ); \
5146 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*3 - 1 ); \
5147 stbir__simdf8_0123to22223333( c, cs ); \
5148 stbir__simdf8_madd_mem( tot1, tot1, c, decode+(ofs)*3 + 6 - 1 );
5150#define stbir__1_coeff_remnant( ofs ) \
5151 STBIR_SIMD_NO_UNROLL(decode); \
5152 stbir__simdf_load1rep4( t, hc + (ofs) ); \
5153 stbir__simdf8_madd_mem4( tot0, tot0, t, decode+(ofs)*3 - 1 );
5155#define stbir__2_coeff_remnant( ofs ) \
5156 STBIR_SIMD_NO_UNROLL(decode); \
5157 stbir__simdf8_load4b( cs, hc + (ofs) - 2 ); \
5158 stbir__simdf8_0123to22223333( c, cs ); \
5159 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*3 - 1 );
5161 #define stbir__3_coeff_remnant( ofs ) \
5162 STBIR_SIMD_NO_UNROLL(decode); \
5163 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5164 stbir__simdf8_0123to00001111( c, cs ); \
5165 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*3 - 1 ); \
5166 stbir__simdf8_0123to2222( t, cs ); \
5167 stbir__simdf8_madd_mem4( tot1, tot1, t, decode+(ofs)*3 + 6 - 1 );
5169#define stbir__store_output() \
5170 stbir__simdf8_add( tot0, tot0, tot1 ); \
5171 stbir__simdf_0123to1230( t, stbir__if_simdf8_cast_to_simdf4( tot0 ) ); \
5172 stbir__simdf8_add4halves( t, t, tot0 ); \
5173 horizontal_coefficients += coefficient_width; \
5174 ++horizontal_contributors; \
5176 if ( output < output_end ) \
5178 stbir__simdf_store( output-3, t ); \
5181 { stbir__simdf tt; stbir__simdf_0123to2301( tt, t ); \
5182 stbir__simdf_store2( output-3, t ); \
5183 stbir__simdf_store1( output+2-3, tt ); } \
5189#define stbir__4_coeff_start() \
5190 stbir__simdf tot0,tot1,tot2,c,cs; \
5191 STBIR_SIMD_NO_UNROLL(decode); \
5192 stbir__simdf_load( cs, hc ); \
5193 stbir__simdf_0123to0001( c, cs ); \
5194 stbir__simdf_mult_mem( tot0, c, decode ); \
5195 stbir__simdf_0123to1122( c, cs ); \
5196 stbir__simdf_mult_mem( tot1, c, decode+4 ); \
5197 stbir__simdf_0123to2333( c, cs ); \
5198 stbir__simdf_mult_mem( tot2, c, decode+8 );
5200#define stbir__4_coeff_continue_from_4( ofs ) \
5201 STBIR_SIMD_NO_UNROLL(decode); \
5202 stbir__simdf_load( cs, hc + (ofs) ); \
5203 stbir__simdf_0123to0001( c, cs ); \
5204 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*3 ); \
5205 stbir__simdf_0123to1122( c, cs ); \
5206 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*3+4 ); \
5207 stbir__simdf_0123to2333( c, cs ); \
5208 stbir__simdf_madd_mem( tot2, tot2, c, decode+(ofs)*3+8 );
5210#define stbir__1_coeff_remnant( ofs ) \
5211 STBIR_SIMD_NO_UNROLL(decode); \
5212 stbir__simdf_load1z( c, hc + (ofs) ); \
5213 stbir__simdf_0123to0001( c, c ); \
5214 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*3 );
5216#define stbir__2_coeff_remnant( ofs ) \
5218 STBIR_SIMD_NO_UNROLL(decode); \
5219 stbir__simdf_load2z( cs, hc + (ofs) ); \
5220 stbir__simdf_0123to0001( c, cs ); \
5221 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*3 ); \
5222 stbir__simdf_0123to1122( c, cs ); \
5223 stbir__simdf_load2z( d, decode+(ofs)*3+4 ); \
5224 stbir__simdf_madd( tot1, tot1, c, d ); }
5226#define stbir__3_coeff_remnant( ofs ) \
5228 STBIR_SIMD_NO_UNROLL(decode); \
5229 stbir__simdf_load( cs, hc + (ofs) ); \
5230 stbir__simdf_0123to0001( c, cs ); \
5231 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*3 ); \
5232 stbir__simdf_0123to1122( c, cs ); \
5233 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*3+4 ); \
5234 stbir__simdf_0123to2222( c, cs ); \
5235 stbir__simdf_load1z( d, decode+(ofs)*3+8 ); \
5236 stbir__simdf_madd( tot2, tot2, c, d ); }
5238#define stbir__store_output() \
5239 stbir__simdf_0123ABCDto3ABx( c, tot0, tot1 ); \
5240 stbir__simdf_0123ABCDto23Ax( cs, tot1, tot2 ); \
5241 stbir__simdf_0123to1230( tot2, tot2 ); \
5242 stbir__simdf_add( tot0, tot0, cs ); \
5243 stbir__simdf_add( c, c, tot2 ); \
5244 stbir__simdf_add( tot0, tot0, c ); \
5245 horizontal_coefficients += coefficient_width; \
5246 ++horizontal_contributors; \
5248 if ( output < output_end ) \
5250 stbir__simdf_store( output-3, tot0 ); \
5253 stbir__simdf_0123to2301( tot1, tot0 ); \
5254 stbir__simdf_store2( output-3, tot0 ); \
5255 stbir__simdf_store1( output+2-3, tot1 ); \
5262#define stbir__1_coeff_only() \
5263 float tot0, tot1, tot2, c; \
5265 tot0 = decode[0]*c; \
5266 tot1 = decode[1]*c; \
5269#define stbir__2_coeff_only() \
5270 float tot0, tot1, tot2, c; \
5272 tot0 = decode[0]*c; \
5273 tot1 = decode[1]*c; \
5274 tot2 = decode[2]*c; \
5276 tot0 += decode[3]*c; \
5277 tot1 += decode[4]*c; \
5278 tot2 += decode[5]*c;
5280#define stbir__3_coeff_only() \
5281 float tot0, tot1, tot2, c; \
5283 tot0 = decode[0]*c; \
5284 tot1 = decode[1]*c; \
5285 tot2 = decode[2]*c; \
5287 tot0 += decode[3]*c; \
5288 tot1 += decode[4]*c; \
5289 tot2 += decode[5]*c; \
5291 tot0 += decode[6]*c; \
5292 tot1 += decode[7]*c; \
5293 tot2 += decode[8]*c;
5295#define stbir__store_output_tiny() \
5299 horizontal_coefficients += coefficient_width; \
5300 ++horizontal_contributors; \
5303#define stbir__4_coeff_start() \
5304 float tota0,tota1,tota2,totb0,totb1,totb2,totc0,totc1,totc2,totd0,totd1,totd2,c; \
5306 tota0 = decode[0]*c; \
5307 tota1 = decode[1]*c; \
5308 tota2 = decode[2]*c; \
5310 totb0 = decode[3]*c; \
5311 totb1 = decode[4]*c; \
5312 totb2 = decode[5]*c; \
5314 totc0 = decode[6]*c; \
5315 totc1 = decode[7]*c; \
5316 totc2 = decode[8]*c; \
5318 totd0 = decode[9]*c; \
5319 totd1 = decode[10]*c; \
5320 totd2 = decode[11]*c;
5322#define stbir__4_coeff_continue_from_4( ofs ) \
5324 tota0 += decode[0+(ofs)*3]*c; \
5325 tota1 += decode[1+(ofs)*3]*c; \
5326 tota2 += decode[2+(ofs)*3]*c; \
5328 totb0 += decode[3+(ofs)*3]*c; \
5329 totb1 += decode[4+(ofs)*3]*c; \
5330 totb2 += decode[5+(ofs)*3]*c; \
5332 totc0 += decode[6+(ofs)*3]*c; \
5333 totc1 += decode[7+(ofs)*3]*c; \
5334 totc2 += decode[8+(ofs)*3]*c; \
5336 totd0 += decode[9+(ofs)*3]*c; \
5337 totd1 += decode[10+(ofs)*3]*c; \
5338 totd2 += decode[11+(ofs)*3]*c;
5340#define stbir__1_coeff_remnant( ofs ) \
5342 tota0 += decode[0+(ofs)*3]*c; \
5343 tota1 += decode[1+(ofs)*3]*c; \
5344 tota2 += decode[2+(ofs)*3]*c;
5346#define stbir__2_coeff_remnant( ofs ) \
5348 tota0 += decode[0+(ofs)*3]*c; \
5349 tota1 += decode[1+(ofs)*3]*c; \
5350 tota2 += decode[2+(ofs)*3]*c; \
5352 totb0 += decode[3+(ofs)*3]*c; \
5353 totb1 += decode[4+(ofs)*3]*c; \
5354 totb2 += decode[5+(ofs)*3]*c; \
5356#define stbir__3_coeff_remnant( ofs ) \
5358 tota0 += decode[0+(ofs)*3]*c; \
5359 tota1 += decode[1+(ofs)*3]*c; \
5360 tota2 += decode[2+(ofs)*3]*c; \
5362 totb0 += decode[3+(ofs)*3]*c; \
5363 totb1 += decode[4+(ofs)*3]*c; \
5364 totb2 += decode[5+(ofs)*3]*c; \
5366 totc0 += decode[6+(ofs)*3]*c; \
5367 totc1 += decode[7+(ofs)*3]*c; \
5368 totc2 += decode[8+(ofs)*3]*c;
5370#define stbir__store_output() \
5371 output[0] = (tota0+totc0)+(totb0+totd0); \
5372 output[1] = (tota1+totc1)+(totb1+totd1); \
5373 output[2] = (tota2+totc2)+(totb2+totd2); \
5374 horizontal_coefficients += coefficient_width; \
5375 ++horizontal_contributors; \
5380#define STBIR__horizontal_channels 3
5381#define STB_IMAGE_RESIZE_DO_HORIZONTALS
5382#include STBIR__HEADER_FILENAME
5389#define stbir__1_coeff_only() \
5390 stbir__simdf tot,c; \
5391 STBIR_SIMD_NO_UNROLL(decode); \
5392 stbir__simdf_load1( c, hc ); \
5393 stbir__simdf_0123to0000( c, c ); \
5394 stbir__simdf_mult_mem( tot, c, decode );
5396#define stbir__2_coeff_only() \
5397 stbir__simdf tot,c,cs; \
5398 STBIR_SIMD_NO_UNROLL(decode); \
5399 stbir__simdf_load2( cs, hc ); \
5400 stbir__simdf_0123to0000( c, cs ); \
5401 stbir__simdf_mult_mem( tot, c, decode ); \
5402 stbir__simdf_0123to1111( c, cs ); \
5403 stbir__simdf_madd_mem( tot, tot, c, decode+4 );
5405#define stbir__3_coeff_only() \
5406 stbir__simdf tot,c,cs; \
5407 STBIR_SIMD_NO_UNROLL(decode); \
5408 stbir__simdf_load( cs, hc ); \
5409 stbir__simdf_0123to0000( c, cs ); \
5410 stbir__simdf_mult_mem( tot, c, decode ); \
5411 stbir__simdf_0123to1111( c, cs ); \
5412 stbir__simdf_madd_mem( tot, tot, c, decode+4 ); \
5413 stbir__simdf_0123to2222( c, cs ); \
5414 stbir__simdf_madd_mem( tot, tot, c, decode+8 );
5416#define stbir__store_output_tiny() \
5417 stbir__simdf_store( output, tot ); \
5418 horizontal_coefficients += coefficient_width; \
5419 ++horizontal_contributors; \
5424#define stbir__4_coeff_start() \
5425 stbir__simdf8 tot0,c,cs; stbir__simdf t; \
5426 STBIR_SIMD_NO_UNROLL(decode); \
5427 stbir__simdf8_load4b( cs, hc ); \
5428 stbir__simdf8_0123to00001111( c, cs ); \
5429 stbir__simdf8_mult_mem( tot0, c, decode ); \
5430 stbir__simdf8_0123to22223333( c, cs ); \
5431 stbir__simdf8_madd_mem( tot0, tot0, c, decode+8 );
5433#define stbir__4_coeff_continue_from_4( ofs ) \
5434 STBIR_SIMD_NO_UNROLL(decode); \
5435 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5436 stbir__simdf8_0123to00001111( c, cs ); \
5437 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*4 ); \
5438 stbir__simdf8_0123to22223333( c, cs ); \
5439 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*4+8 );
5441#define stbir__1_coeff_remnant( ofs ) \
5442 STBIR_SIMD_NO_UNROLL(decode); \
5443 stbir__simdf_load1rep4( t, hc + (ofs) ); \
5444 stbir__simdf8_madd_mem4( tot0, tot0, t, decode+(ofs)*4 );
5446#define stbir__2_coeff_remnant( ofs ) \
5447 STBIR_SIMD_NO_UNROLL(decode); \
5448 stbir__simdf8_load4b( cs, hc + (ofs) - 2 ); \
5449 stbir__simdf8_0123to22223333( c, cs ); \
5450 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*4 );
5452 #define stbir__3_coeff_remnant( ofs ) \
5453 STBIR_SIMD_NO_UNROLL(decode); \
5454 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5455 stbir__simdf8_0123to00001111( c, cs ); \
5456 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*4 ); \
5457 stbir__simdf8_0123to2222( t, cs ); \
5458 stbir__simdf8_madd_mem4( tot0, tot0, t, decode+(ofs)*4+8 );
5460#define stbir__store_output() \
5461 stbir__simdf8_add4halves( t, stbir__if_simdf8_cast_to_simdf4(tot0), tot0 ); \
5462 stbir__simdf_store( output, t ); \
5463 horizontal_coefficients += coefficient_width; \
5464 ++horizontal_contributors; \
5469#define stbir__4_coeff_start() \
5470 stbir__simdf tot0,tot1,c,cs; \
5471 STBIR_SIMD_NO_UNROLL(decode); \
5472 stbir__simdf_load( cs, hc ); \
5473 stbir__simdf_0123to0000( c, cs ); \
5474 stbir__simdf_mult_mem( tot0, c, decode ); \
5475 stbir__simdf_0123to1111( c, cs ); \
5476 stbir__simdf_mult_mem( tot1, c, decode+4 ); \
5477 stbir__simdf_0123to2222( c, cs ); \
5478 stbir__simdf_madd_mem( tot0, tot0, c, decode+8 ); \
5479 stbir__simdf_0123to3333( c, cs ); \
5480 stbir__simdf_madd_mem( tot1, tot1, c, decode+12 );
5482#define stbir__4_coeff_continue_from_4( ofs ) \
5483 STBIR_SIMD_NO_UNROLL(decode); \
5484 stbir__simdf_load( cs, hc + (ofs) ); \
5485 stbir__simdf_0123to0000( c, cs ); \
5486 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4 ); \
5487 stbir__simdf_0123to1111( c, cs ); \
5488 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*4+4 ); \
5489 stbir__simdf_0123to2222( c, cs ); \
5490 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4+8 ); \
5491 stbir__simdf_0123to3333( c, cs ); \
5492 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*4+12 );
5494#define stbir__1_coeff_remnant( ofs ) \
5495 STBIR_SIMD_NO_UNROLL(decode); \
5496 stbir__simdf_load1( c, hc + (ofs) ); \
5497 stbir__simdf_0123to0000( c, c ); \
5498 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4 );
5500#define stbir__2_coeff_remnant( ofs ) \
5501 STBIR_SIMD_NO_UNROLL(decode); \
5502 stbir__simdf_load2( cs, hc + (ofs) ); \
5503 stbir__simdf_0123to0000( c, cs ); \
5504 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4 ); \
5505 stbir__simdf_0123to1111( c, cs ); \
5506 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*4+4 );
5508#define stbir__3_coeff_remnant( ofs ) \
5509 STBIR_SIMD_NO_UNROLL(decode); \
5510 stbir__simdf_load( cs, hc + (ofs) ); \
5511 stbir__simdf_0123to0000( c, cs ); \
5512 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4 ); \
5513 stbir__simdf_0123to1111( c, cs ); \
5514 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*4+4 ); \
5515 stbir__simdf_0123to2222( c, cs ); \
5516 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*4+8 );
5518#define stbir__store_output() \
5519 stbir__simdf_add( tot0, tot0, tot1 ); \
5520 stbir__simdf_store( output, tot0 ); \
5521 horizontal_coefficients += coefficient_width; \
5522 ++horizontal_contributors; \
5529#define stbir__1_coeff_only() \
5530 float p0,p1,p2,p3,c; \
5531 STBIR_SIMD_NO_UNROLL(decode); \
5533 p0 = decode[0] * c; \
5534 p1 = decode[1] * c; \
5535 p2 = decode[2] * c; \
5538#define stbir__2_coeff_only() \
5539 float p0,p1,p2,p3,c; \
5540 STBIR_SIMD_NO_UNROLL(decode); \
5542 p0 = decode[0] * c; \
5543 p1 = decode[1] * c; \
5544 p2 = decode[2] * c; \
5545 p3 = decode[3] * c; \
5547 p0 += decode[4] * c; \
5548 p1 += decode[5] * c; \
5549 p2 += decode[6] * c; \
5550 p3 += decode[7] * c;
5552#define stbir__3_coeff_only() \
5553 float p0,p1,p2,p3,c; \
5554 STBIR_SIMD_NO_UNROLL(decode); \
5556 p0 = decode[0] * c; \
5557 p1 = decode[1] * c; \
5558 p2 = decode[2] * c; \
5559 p3 = decode[3] * c; \
5561 p0 += decode[4] * c; \
5562 p1 += decode[5] * c; \
5563 p2 += decode[6] * c; \
5564 p3 += decode[7] * c; \
5566 p0 += decode[8] * c; \
5567 p1 += decode[9] * c; \
5568 p2 += decode[10] * c; \
5569 p3 += decode[11] * c;
5571#define stbir__store_output_tiny() \
5576 horizontal_coefficients += coefficient_width; \
5577 ++horizontal_contributors; \
5580#define stbir__4_coeff_start() \
5581 float x0,x1,x2,x3,y0,y1,y2,y3,c; \
5582 STBIR_SIMD_NO_UNROLL(decode); \
5584 x0 = decode[0] * c; \
5585 x1 = decode[1] * c; \
5586 x2 = decode[2] * c; \
5587 x3 = decode[3] * c; \
5589 y0 = decode[4] * c; \
5590 y1 = decode[5] * c; \
5591 y2 = decode[6] * c; \
5592 y3 = decode[7] * c; \
5594 x0 += decode[8] * c; \
5595 x1 += decode[9] * c; \
5596 x2 += decode[10] * c; \
5597 x3 += decode[11] * c; \
5599 y0 += decode[12] * c; \
5600 y1 += decode[13] * c; \
5601 y2 += decode[14] * c; \
5602 y3 += decode[15] * c;
5604#define stbir__4_coeff_continue_from_4( ofs ) \
5605 STBIR_SIMD_NO_UNROLL(decode); \
5607 x0 += decode[0+(ofs)*4] * c; \
5608 x1 += decode[1+(ofs)*4] * c; \
5609 x2 += decode[2+(ofs)*4] * c; \
5610 x3 += decode[3+(ofs)*4] * c; \
5612 y0 += decode[4+(ofs)*4] * c; \
5613 y1 += decode[5+(ofs)*4] * c; \
5614 y2 += decode[6+(ofs)*4] * c; \
5615 y3 += decode[7+(ofs)*4] * c; \
5617 x0 += decode[8+(ofs)*4] * c; \
5618 x1 += decode[9+(ofs)*4] * c; \
5619 x2 += decode[10+(ofs)*4] * c; \
5620 x3 += decode[11+(ofs)*4] * c; \
5622 y0 += decode[12+(ofs)*4] * c; \
5623 y1 += decode[13+(ofs)*4] * c; \
5624 y2 += decode[14+(ofs)*4] * c; \
5625 y3 += decode[15+(ofs)*4] * c;
5627#define stbir__1_coeff_remnant( ofs ) \
5628 STBIR_SIMD_NO_UNROLL(decode); \
5630 x0 += decode[0+(ofs)*4] * c; \
5631 x1 += decode[1+(ofs)*4] * c; \
5632 x2 += decode[2+(ofs)*4] * c; \
5633 x3 += decode[3+(ofs)*4] * c;
5635#define stbir__2_coeff_remnant( ofs ) \
5636 STBIR_SIMD_NO_UNROLL(decode); \
5638 x0 += decode[0+(ofs)*4] * c; \
5639 x1 += decode[1+(ofs)*4] * c; \
5640 x2 += decode[2+(ofs)*4] * c; \
5641 x3 += decode[3+(ofs)*4] * c; \
5643 y0 += decode[4+(ofs)*4] * c; \
5644 y1 += decode[5+(ofs)*4] * c; \
5645 y2 += decode[6+(ofs)*4] * c; \
5646 y3 += decode[7+(ofs)*4] * c;
5648#define stbir__3_coeff_remnant( ofs ) \
5649 STBIR_SIMD_NO_UNROLL(decode); \
5651 x0 += decode[0+(ofs)*4] * c; \
5652 x1 += decode[1+(ofs)*4] * c; \
5653 x2 += decode[2+(ofs)*4] * c; \
5654 x3 += decode[3+(ofs)*4] * c; \
5656 y0 += decode[4+(ofs)*4] * c; \
5657 y1 += decode[5+(ofs)*4] * c; \
5658 y2 += decode[6+(ofs)*4] * c; \
5659 y3 += decode[7+(ofs)*4] * c; \
5661 x0 += decode[8+(ofs)*4] * c; \
5662 x1 += decode[9+(ofs)*4] * c; \
5663 x2 += decode[10+(ofs)*4] * c; \
5664 x3 += decode[11+(ofs)*4] * c;
5666#define stbir__store_output() \
5667 output[0] = x0 + y0; \
5668 output[1] = x1 + y1; \
5669 output[2] = x2 + y2; \
5670 output[3] = x3 + y3; \
5671 horizontal_coefficients += coefficient_width; \
5672 ++horizontal_contributors; \
5677#define STBIR__horizontal_channels 4
5678#define STB_IMAGE_RESIZE_DO_HORIZONTALS
5679#include STBIR__HEADER_FILENAME
5688#define stbir__1_coeff_only() \
5689 stbir__simdf tot0,tot1,c; \
5690 STBIR_SIMD_NO_UNROLL(decode); \
5691 stbir__simdf_load1( c, hc ); \
5692 stbir__simdf_0123to0000( c, c ); \
5693 stbir__simdf_mult_mem( tot0, c, decode ); \
5694 stbir__simdf_mult_mem( tot1, c, decode+3 );
5696#define stbir__2_coeff_only() \
5697 stbir__simdf tot0,tot1,c,cs; \
5698 STBIR_SIMD_NO_UNROLL(decode); \
5699 stbir__simdf_load2( cs, hc ); \
5700 stbir__simdf_0123to0000( c, cs ); \
5701 stbir__simdf_mult_mem( tot0, c, decode ); \
5702 stbir__simdf_mult_mem( tot1, c, decode+3 ); \
5703 stbir__simdf_0123to1111( c, cs ); \
5704 stbir__simdf_madd_mem( tot0, tot0, c, decode+7 ); \
5705 stbir__simdf_madd_mem( tot1, tot1, c,decode+10 );
5707#define stbir__3_coeff_only() \
5708 stbir__simdf tot0,tot1,c,cs; \
5709 STBIR_SIMD_NO_UNROLL(decode); \
5710 stbir__simdf_load( cs, hc ); \
5711 stbir__simdf_0123to0000( c, cs ); \
5712 stbir__simdf_mult_mem( tot0, c, decode ); \
5713 stbir__simdf_mult_mem( tot1, c, decode+3 ); \
5714 stbir__simdf_0123to1111( c, cs ); \
5715 stbir__simdf_madd_mem( tot0, tot0, c, decode+7 ); \
5716 stbir__simdf_madd_mem( tot1, tot1, c, decode+10 ); \
5717 stbir__simdf_0123to2222( c, cs ); \
5718 stbir__simdf_madd_mem( tot0, tot0, c, decode+14 ); \
5719 stbir__simdf_madd_mem( tot1, tot1, c, decode+17 );
5721#define stbir__store_output_tiny() \
5722 stbir__simdf_store( output+3, tot1 ); \
5723 stbir__simdf_store( output, tot0 ); \
5724 horizontal_coefficients += coefficient_width; \
5725 ++horizontal_contributors; \
5730#define stbir__4_coeff_start() \
5731 stbir__simdf8 tot0,tot1,c,cs; \
5732 STBIR_SIMD_NO_UNROLL(decode); \
5733 stbir__simdf8_load4b( cs, hc ); \
5734 stbir__simdf8_0123to00000000( c, cs ); \
5735 stbir__simdf8_mult_mem( tot0, c, decode ); \
5736 stbir__simdf8_0123to11111111( c, cs ); \
5737 stbir__simdf8_mult_mem( tot1, c, decode+7 ); \
5738 stbir__simdf8_0123to22222222( c, cs ); \
5739 stbir__simdf8_madd_mem( tot0, tot0, c, decode+14 ); \
5740 stbir__simdf8_0123to33333333( c, cs ); \
5741 stbir__simdf8_madd_mem( tot1, tot1, c, decode+21 );
5743#define stbir__4_coeff_continue_from_4( ofs ) \
5744 STBIR_SIMD_NO_UNROLL(decode); \
5745 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5746 stbir__simdf8_0123to00000000( c, cs ); \
5747 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5748 stbir__simdf8_0123to11111111( c, cs ); \
5749 stbir__simdf8_madd_mem( tot1, tot1, c, decode+(ofs)*7+7 ); \
5750 stbir__simdf8_0123to22222222( c, cs ); \
5751 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7+14 ); \
5752 stbir__simdf8_0123to33333333( c, cs ); \
5753 stbir__simdf8_madd_mem( tot1, tot1, c, decode+(ofs)*7+21 );
5755#define stbir__1_coeff_remnant( ofs ) \
5756 STBIR_SIMD_NO_UNROLL(decode); \
5757 stbir__simdf8_load1b( c, hc + (ofs) ); \
5758 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7 );
5760#define stbir__2_coeff_remnant( ofs ) \
5761 STBIR_SIMD_NO_UNROLL(decode); \
5762 stbir__simdf8_load1b( c, hc + (ofs) ); \
5763 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5764 stbir__simdf8_load1b( c, hc + (ofs)+1 ); \
5765 stbir__simdf8_madd_mem( tot1, tot1, c, decode+(ofs)*7+7 );
5767#define stbir__3_coeff_remnant( ofs ) \
5768 STBIR_SIMD_NO_UNROLL(decode); \
5769 stbir__simdf8_load4b( cs, hc + (ofs) ); \
5770 stbir__simdf8_0123to00000000( c, cs ); \
5771 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5772 stbir__simdf8_0123to11111111( c, cs ); \
5773 stbir__simdf8_madd_mem( tot1, tot1, c, decode+(ofs)*7+7 ); \
5774 stbir__simdf8_0123to22222222( c, cs ); \
5775 stbir__simdf8_madd_mem( tot0, tot0, c, decode+(ofs)*7+14 );
5777#define stbir__store_output() \
5778 stbir__simdf8_add( tot0, tot0, tot1 ); \
5779 horizontal_coefficients += coefficient_width; \
5780 ++horizontal_contributors; \
5782 if ( output < output_end ) \
5784 stbir__simdf8_store( output-7, tot0 ); \
5787 stbir__simdf_store( output-7+3, stbir__simdf_swiz(stbir__simdf8_gettop4(tot0),0,0,1,2) ); \
5788 stbir__simdf_store( output-7, stbir__if_simdf8_cast_to_simdf4(tot0) ); \
5793#define stbir__4_coeff_start() \
5794 stbir__simdf tot0,tot1,tot2,tot3,c,cs; \
5795 STBIR_SIMD_NO_UNROLL(decode); \
5796 stbir__simdf_load( cs, hc ); \
5797 stbir__simdf_0123to0000( c, cs ); \
5798 stbir__simdf_mult_mem( tot0, c, decode ); \
5799 stbir__simdf_mult_mem( tot1, c, decode+3 ); \
5800 stbir__simdf_0123to1111( c, cs ); \
5801 stbir__simdf_mult_mem( tot2, c, decode+7 ); \
5802 stbir__simdf_mult_mem( tot3, c, decode+10 ); \
5803 stbir__simdf_0123to2222( c, cs ); \
5804 stbir__simdf_madd_mem( tot0, tot0, c, decode+14 ); \
5805 stbir__simdf_madd_mem( tot1, tot1, c, decode+17 ); \
5806 stbir__simdf_0123to3333( c, cs ); \
5807 stbir__simdf_madd_mem( tot2, tot2, c, decode+21 ); \
5808 stbir__simdf_madd_mem( tot3, tot3, c, decode+24 );
5810#define stbir__4_coeff_continue_from_4( ofs ) \
5811 STBIR_SIMD_NO_UNROLL(decode); \
5812 stbir__simdf_load( cs, hc + (ofs) ); \
5813 stbir__simdf_0123to0000( c, cs ); \
5814 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5815 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+3 ); \
5816 stbir__simdf_0123to1111( c, cs ); \
5817 stbir__simdf_madd_mem( tot2, tot2, c, decode+(ofs)*7+7 ); \
5818 stbir__simdf_madd_mem( tot3, tot3, c, decode+(ofs)*7+10 ); \
5819 stbir__simdf_0123to2222( c, cs ); \
5820 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7+14 ); \
5821 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+17 ); \
5822 stbir__simdf_0123to3333( c, cs ); \
5823 stbir__simdf_madd_mem( tot2, tot2, c, decode+(ofs)*7+21 ); \
5824 stbir__simdf_madd_mem( tot3, tot3, c, decode+(ofs)*7+24 );
5826#define stbir__1_coeff_remnant( ofs ) \
5827 STBIR_SIMD_NO_UNROLL(decode); \
5828 stbir__simdf_load1( c, hc + (ofs) ); \
5829 stbir__simdf_0123to0000( c, c ); \
5830 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5831 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+3 ); \
5833#define stbir__2_coeff_remnant( ofs ) \
5834 STBIR_SIMD_NO_UNROLL(decode); \
5835 stbir__simdf_load2( cs, hc + (ofs) ); \
5836 stbir__simdf_0123to0000( c, cs ); \
5837 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5838 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+3 ); \
5839 stbir__simdf_0123to1111( c, cs ); \
5840 stbir__simdf_madd_mem( tot2, tot2, c, decode+(ofs)*7+7 ); \
5841 stbir__simdf_madd_mem( tot3, tot3, c, decode+(ofs)*7+10 );
5843#define stbir__3_coeff_remnant( ofs ) \
5844 STBIR_SIMD_NO_UNROLL(decode); \
5845 stbir__simdf_load( cs, hc + (ofs) ); \
5846 stbir__simdf_0123to0000( c, cs ); \
5847 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7 ); \
5848 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+3 ); \
5849 stbir__simdf_0123to1111( c, cs ); \
5850 stbir__simdf_madd_mem( tot2, tot2, c, decode+(ofs)*7+7 ); \
5851 stbir__simdf_madd_mem( tot3, tot3, c, decode+(ofs)*7+10 ); \
5852 stbir__simdf_0123to2222( c, cs ); \
5853 stbir__simdf_madd_mem( tot0, tot0, c, decode+(ofs)*7+14 ); \
5854 stbir__simdf_madd_mem( tot1, tot1, c, decode+(ofs)*7+17 );
5856#define stbir__store_output() \
5857 stbir__simdf_add( tot0, tot0, tot2 ); \
5858 stbir__simdf_add( tot1, tot1, tot3 ); \
5859 stbir__simdf_store( output+3, tot1 ); \
5860 stbir__simdf_store( output, tot0 ); \
5861 horizontal_coefficients += coefficient_width; \
5862 ++horizontal_contributors; \
5869#define stbir__1_coeff_only() \
5870 float tot0, tot1, tot2, tot3, tot4, tot5, tot6, c; \
5872 tot0 = decode[0]*c; \
5873 tot1 = decode[1]*c; \
5874 tot2 = decode[2]*c; \
5875 tot3 = decode[3]*c; \
5876 tot4 = decode[4]*c; \
5877 tot5 = decode[5]*c; \
5880#define stbir__2_coeff_only() \
5881 float tot0, tot1, tot2, tot3, tot4, tot5, tot6, c; \
5883 tot0 = decode[0]*c; \
5884 tot1 = decode[1]*c; \
5885 tot2 = decode[2]*c; \
5886 tot3 = decode[3]*c; \
5887 tot4 = decode[4]*c; \
5888 tot5 = decode[5]*c; \
5889 tot6 = decode[6]*c; \
5891 tot0 += decode[7]*c; \
5892 tot1 += decode[8]*c; \
5893 tot2 += decode[9]*c; \
5894 tot3 += decode[10]*c; \
5895 tot4 += decode[11]*c; \
5896 tot5 += decode[12]*c; \
5897 tot6 += decode[13]*c; \
5899#define stbir__3_coeff_only() \
5900 float tot0, tot1, tot2, tot3, tot4, tot5, tot6, c; \
5902 tot0 = decode[0]*c; \
5903 tot1 = decode[1]*c; \
5904 tot2 = decode[2]*c; \
5905 tot3 = decode[3]*c; \
5906 tot4 = decode[4]*c; \
5907 tot5 = decode[5]*c; \
5908 tot6 = decode[6]*c; \
5910 tot0 += decode[7]*c; \
5911 tot1 += decode[8]*c; \
5912 tot2 += decode[9]*c; \
5913 tot3 += decode[10]*c; \
5914 tot4 += decode[11]*c; \
5915 tot5 += decode[12]*c; \
5916 tot6 += decode[13]*c; \
5918 tot0 += decode[14]*c; \
5919 tot1 += decode[15]*c; \
5920 tot2 += decode[16]*c; \
5921 tot3 += decode[17]*c; \
5922 tot4 += decode[18]*c; \
5923 tot5 += decode[19]*c; \
5924 tot6 += decode[20]*c; \
5926#define stbir__store_output_tiny() \
5934 horizontal_coefficients += coefficient_width; \
5935 ++horizontal_contributors; \
5938#define stbir__4_coeff_start() \
5939 float x0,x1,x2,x3,x4,x5,x6,y0,y1,y2,y3,y4,y5,y6,c; \
5940 STBIR_SIMD_NO_UNROLL(decode); \
5942 x0 = decode[0] * c; \
5943 x1 = decode[1] * c; \
5944 x2 = decode[2] * c; \
5945 x3 = decode[3] * c; \
5946 x4 = decode[4] * c; \
5947 x5 = decode[5] * c; \
5948 x6 = decode[6] * c; \
5950 y0 = decode[7] * c; \
5951 y1 = decode[8] * c; \
5952 y2 = decode[9] * c; \
5953 y3 = decode[10] * c; \
5954 y4 = decode[11] * c; \
5955 y5 = decode[12] * c; \
5956 y6 = decode[13] * c; \
5958 x0 += decode[14] * c; \
5959 x1 += decode[15] * c; \
5960 x2 += decode[16] * c; \
5961 x3 += decode[17] * c; \
5962 x4 += decode[18] * c; \
5963 x5 += decode[19] * c; \
5964 x6 += decode[20] * c; \
5966 y0 += decode[21] * c; \
5967 y1 += decode[22] * c; \
5968 y2 += decode[23] * c; \
5969 y3 += decode[24] * c; \
5970 y4 += decode[25] * c; \
5971 y5 += decode[26] * c; \
5972 y6 += decode[27] * c;
5974#define stbir__4_coeff_continue_from_4( ofs ) \
5975 STBIR_SIMD_NO_UNROLL(decode); \
5977 x0 += decode[0+(ofs)*7] * c; \
5978 x1 += decode[1+(ofs)*7] * c; \
5979 x2 += decode[2+(ofs)*7] * c; \
5980 x3 += decode[3+(ofs)*7] * c; \
5981 x4 += decode[4+(ofs)*7] * c; \
5982 x5 += decode[5+(ofs)*7] * c; \
5983 x6 += decode[6+(ofs)*7] * c; \
5985 y0 += decode[7+(ofs)*7] * c; \
5986 y1 += decode[8+(ofs)*7] * c; \
5987 y2 += decode[9+(ofs)*7] * c; \
5988 y3 += decode[10+(ofs)*7] * c; \
5989 y4 += decode[11+(ofs)*7] * c; \
5990 y5 += decode[12+(ofs)*7] * c; \
5991 y6 += decode[13+(ofs)*7] * c; \
5993 x0 += decode[14+(ofs)*7] * c; \
5994 x1 += decode[15+(ofs)*7] * c; \
5995 x2 += decode[16+(ofs)*7] * c; \
5996 x3 += decode[17+(ofs)*7] * c; \
5997 x4 += decode[18+(ofs)*7] * c; \
5998 x5 += decode[19+(ofs)*7] * c; \
5999 x6 += decode[20+(ofs)*7] * c; \
6001 y0 += decode[21+(ofs)*7] * c; \
6002 y1 += decode[22+(ofs)*7] * c; \
6003 y2 += decode[23+(ofs)*7] * c; \
6004 y3 += decode[24+(ofs)*7] * c; \
6005 y4 += decode[25+(ofs)*7] * c; \
6006 y5 += decode[26+(ofs)*7] * c; \
6007 y6 += decode[27+(ofs)*7] * c;
6009#define stbir__1_coeff_remnant( ofs ) \
6010 STBIR_SIMD_NO_UNROLL(decode); \
6012 x0 += decode[0+(ofs)*7] * c; \
6013 x1 += decode[1+(ofs)*7] * c; \
6014 x2 += decode[2+(ofs)*7] * c; \
6015 x3 += decode[3+(ofs)*7] * c; \
6016 x4 += decode[4+(ofs)*7] * c; \
6017 x5 += decode[5+(ofs)*7] * c; \
6018 x6 += decode[6+(ofs)*7] * c; \
6020#define stbir__2_coeff_remnant( ofs ) \
6021 STBIR_SIMD_NO_UNROLL(decode); \
6023 x0 += decode[0+(ofs)*7] * c; \
6024 x1 += decode[1+(ofs)*7] * c; \
6025 x2 += decode[2+(ofs)*7] * c; \
6026 x3 += decode[3+(ofs)*7] * c; \
6027 x4 += decode[4+(ofs)*7] * c; \
6028 x5 += decode[5+(ofs)*7] * c; \
6029 x6 += decode[6+(ofs)*7] * c; \
6031 y0 += decode[7+(ofs)*7] * c; \
6032 y1 += decode[8+(ofs)*7] * c; \
6033 y2 += decode[9+(ofs)*7] * c; \
6034 y3 += decode[10+(ofs)*7] * c; \
6035 y4 += decode[11+(ofs)*7] * c; \
6036 y5 += decode[12+(ofs)*7] * c; \
6037 y6 += decode[13+(ofs)*7] * c; \
6039#define stbir__3_coeff_remnant( ofs ) \
6040 STBIR_SIMD_NO_UNROLL(decode); \
6042 x0 += decode[0+(ofs)*7] * c; \
6043 x1 += decode[1+(ofs)*7] * c; \
6044 x2 += decode[2+(ofs)*7] * c; \
6045 x3 += decode[3+(ofs)*7] * c; \
6046 x4 += decode[4+(ofs)*7] * c; \
6047 x5 += decode[5+(ofs)*7] * c; \
6048 x6 += decode[6+(ofs)*7] * c; \
6050 y0 += decode[7+(ofs)*7] * c; \
6051 y1 += decode[8+(ofs)*7] * c; \
6052 y2 += decode[9+(ofs)*7] * c; \
6053 y3 += decode[10+(ofs)*7] * c; \
6054 y4 += decode[11+(ofs)*7] * c; \
6055 y5 += decode[12+(ofs)*7] * c; \
6056 y6 += decode[13+(ofs)*7] * c; \
6058 x0 += decode[14+(ofs)*7] * c; \
6059 x1 += decode[15+(ofs)*7] * c; \
6060 x2 += decode[16+(ofs)*7] * c; \
6061 x3 += decode[17+(ofs)*7] * c; \
6062 x4 += decode[18+(ofs)*7] * c; \
6063 x5 += decode[19+(ofs)*7] * c; \
6064 x6 += decode[20+(ofs)*7] * c; \
6066#define stbir__store_output() \
6067 output[0] = x0 + y0; \
6068 output[1] = x1 + y1; \
6069 output[2] = x2 + y2; \
6070 output[3] = x3 + y3; \
6071 output[4] = x4 + y4; \
6072 output[5] = x5 + y5; \
6073 output[6] = x6 + y6; \
6074 horizontal_coefficients += coefficient_width; \
6075 ++horizontal_contributors; \
6080#define STBIR__horizontal_channels 7
6081#define STB_IMAGE_RESIZE_DO_HORIZONTALS
6082#include STBIR__HEADER_FILENAME
6087#define STBIR__vertical_channels 1
6088#define STB_IMAGE_RESIZE_DO_VERTICALS
6089#include STBIR__HEADER_FILENAME
6091#define STBIR__vertical_channels 1
6092#define STB_IMAGE_RESIZE_DO_VERTICALS
6093#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6094#include STBIR__HEADER_FILENAME
6096#define STBIR__vertical_channels 2
6097#define STB_IMAGE_RESIZE_DO_VERTICALS
6098#include STBIR__HEADER_FILENAME
6100#define STBIR__vertical_channels 2
6101#define STB_IMAGE_RESIZE_DO_VERTICALS
6102#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6103#include STBIR__HEADER_FILENAME
6105#define STBIR__vertical_channels 3
6106#define STB_IMAGE_RESIZE_DO_VERTICALS
6107#include STBIR__HEADER_FILENAME
6109#define STBIR__vertical_channels 3
6110#define STB_IMAGE_RESIZE_DO_VERTICALS
6111#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6112#include STBIR__HEADER_FILENAME
6114#define STBIR__vertical_channels 4
6115#define STB_IMAGE_RESIZE_DO_VERTICALS
6116#include STBIR__HEADER_FILENAME
6118#define STBIR__vertical_channels 4
6119#define STB_IMAGE_RESIZE_DO_VERTICALS
6120#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6121#include STBIR__HEADER_FILENAME
6123#define STBIR__vertical_channels 5
6124#define STB_IMAGE_RESIZE_DO_VERTICALS
6125#include STBIR__HEADER_FILENAME
6127#define STBIR__vertical_channels 5
6128#define STB_IMAGE_RESIZE_DO_VERTICALS
6129#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6130#include STBIR__HEADER_FILENAME
6132#define STBIR__vertical_channels 6
6133#define STB_IMAGE_RESIZE_DO_VERTICALS
6134#include STBIR__HEADER_FILENAME
6136#define STBIR__vertical_channels 6
6137#define STB_IMAGE_RESIZE_DO_VERTICALS
6138#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6139#include STBIR__HEADER_FILENAME
6141#define STBIR__vertical_channels 7
6142#define STB_IMAGE_RESIZE_DO_VERTICALS
6143#include STBIR__HEADER_FILENAME
6145#define STBIR__vertical_channels 7
6146#define STB_IMAGE_RESIZE_DO_VERTICALS
6147#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6148#include STBIR__HEADER_FILENAME
6150#define STBIR__vertical_channels 8
6151#define STB_IMAGE_RESIZE_DO_VERTICALS
6152#include STBIR__HEADER_FILENAME
6154#define STBIR__vertical_channels 8
6155#define STB_IMAGE_RESIZE_DO_VERTICALS
6156#define STB_IMAGE_RESIZE_VERTICAL_CONTINUE
6157#include STBIR__HEADER_FILENAME
6159typedef void STBIR_VERTICAL_GATHERFUNC(
float * output,
float const * coeffs,
float const ** inputs,
float const * input0_end );
6161static STBIR_VERTICAL_GATHERFUNC * stbir__vertical_gathers[ 8 ] =
6163 stbir__vertical_gather_with_1_coeffs,stbir__vertical_gather_with_2_coeffs,stbir__vertical_gather_with_3_coeffs,stbir__vertical_gather_with_4_coeffs,stbir__vertical_gather_with_5_coeffs,stbir__vertical_gather_with_6_coeffs,stbir__vertical_gather_with_7_coeffs,stbir__vertical_gather_with_8_coeffs
6166static STBIR_VERTICAL_GATHERFUNC * stbir__vertical_gathers_continues[ 8 ] =
6168 stbir__vertical_gather_with_1_coeffs_cont,stbir__vertical_gather_with_2_coeffs_cont,stbir__vertical_gather_with_3_coeffs_cont,stbir__vertical_gather_with_4_coeffs_cont,stbir__vertical_gather_with_5_coeffs_cont,stbir__vertical_gather_with_6_coeffs_cont,stbir__vertical_gather_with_7_coeffs_cont,stbir__vertical_gather_with_8_coeffs_cont
6171typedef void STBIR_VERTICAL_SCATTERFUNC(
float ** outputs,
float const * coeffs,
float const * input,
float const * input_end );
6173static STBIR_VERTICAL_SCATTERFUNC * stbir__vertical_scatter_sets[ 8 ] =
6175 stbir__vertical_scatter_with_1_coeffs,stbir__vertical_scatter_with_2_coeffs,stbir__vertical_scatter_with_3_coeffs,stbir__vertical_scatter_with_4_coeffs,stbir__vertical_scatter_with_5_coeffs,stbir__vertical_scatter_with_6_coeffs,stbir__vertical_scatter_with_7_coeffs,stbir__vertical_scatter_with_8_coeffs
6178static STBIR_VERTICAL_SCATTERFUNC * stbir__vertical_scatter_blends[ 8 ] =
6180 stbir__vertical_scatter_with_1_coeffs_cont,stbir__vertical_scatter_with_2_coeffs_cont,stbir__vertical_scatter_with_3_coeffs_cont,stbir__vertical_scatter_with_4_coeffs_cont,stbir__vertical_scatter_with_5_coeffs_cont,stbir__vertical_scatter_with_6_coeffs_cont,stbir__vertical_scatter_with_7_coeffs_cont,stbir__vertical_scatter_with_8_coeffs_cont
6184static void stbir__encode_scanline(
stbir__info const * stbir_info,
void *output_buffer_data,
float * encode_buffer,
int row STBIR_ONLY_PROFILE_GET_SPLIT_INFO )
6186 int num_pixels = stbir_info->horizontal.scale_info.output_sub_size;
6187 int channels = stbir_info->channels;
6188 int width_times_channels = num_pixels * channels;
6189 void * output_buffer;
6192 if ( stbir_info->alpha_unweight )
6194 STBIR_PROFILE_START( unalpha );
6195 stbir_info->alpha_unweight( encode_buffer, width_times_channels );
6196 STBIR_PROFILE_END( unalpha );
6200 output_buffer = output_buffer_data;
6203 if ( stbir_info->out_pixels_cb )
6204 output_buffer = encode_buffer;
6206 STBIR_PROFILE_START( encode );
6208 stbir_info->encode_pixels( output_buffer, width_times_channels, encode_buffer );
6209 STBIR_PROFILE_END( encode );
6212 if ( stbir_info->out_pixels_cb )
6213 stbir_info->out_pixels_cb( output_buffer, num_pixels, row, stbir_info->user_data );
6218static float* stbir__get_ring_buffer_entry(
stbir__info const * stbir_info, stbir__per_split_info
const * split_info,
int index )
6222 #ifdef STBIR__SEPARATE_ALLOCATIONS
6223 return split_info->ring_buffers[
index ];
6225 return (
float*) ( ( (
char*) split_info->ring_buffer ) + (
index * stbir_info->ring_buffer_length_bytes ) );
6230static float* stbir__get_ring_buffer_scanline(
stbir__info const * stbir_info, stbir__per_split_info
const * split_info,
int get_scanline)
6232 int ring_buffer_index = (split_info->ring_buffer_begin_index + (get_scanline - split_info->ring_buffer_first_scanline)) % stbir_info->ring_buffer_num_entries;
6233 return stbir__get_ring_buffer_entry( stbir_info, split_info, ring_buffer_index );
6236static void stbir__resample_horizontal_gather(
stbir__info const * stbir_info,
float* output_buffer,
float const * input_buffer STBIR_ONLY_PROFILE_GET_SPLIT_INFO )
6238 float const * decode_buffer = input_buffer - ( stbir_info->scanline_extents.conservative.n0 * stbir_info->effective_channels );
6240 STBIR_PROFILE_START( horizontal );
6241 if ( ( stbir_info->horizontal.filter_enum ==
STBIR_FILTER_POINT_SAMPLE ) && ( stbir_info->horizontal.scale_info.scale == 1.0f ) )
6242 STBIR_MEMCPY( output_buffer, input_buffer, stbir_info->horizontal.scale_info.output_sub_size *
sizeof(
float ) * stbir_info->effective_channels );
6244 stbir_info->horizontal_gather_channels( output_buffer, stbir_info->horizontal.scale_info.output_sub_size, decode_buffer, stbir_info->horizontal.contributors, stbir_info->horizontal.coefficients, stbir_info->horizontal.coefficient_width );
6245 STBIR_PROFILE_END( horizontal );
6248static void stbir__resample_vertical_gather(
stbir__info const * stbir_info, stbir__per_split_info* split_info,
int n,
int contrib_n0,
int contrib_n1,
float const * vertical_coefficients )
6250 float* encode_buffer = split_info->vertical_buffer;
6251 float* decode_buffer = split_info->decode_buffer;
6252 int vertical_first = stbir_info->vertical_first;
6253 int width = (vertical_first) ? ( stbir_info->scanline_extents.conservative.n1-stbir_info->scanline_extents.conservative.n0+1 ) : stbir_info->horizontal.scale_info.output_sub_size;
6254 int width_times_channels = stbir_info->effective_channels *
width;
6256 STBIR_ASSERT( stbir_info->vertical.is_gather );
6259 STBIR_PROFILE_START( vertical );
6261 int k = 0, total = contrib_n1 - contrib_n0 + 1;
6262 STBIR_ASSERT( total > 0 );
6264 float const * inputs[8];
6265 int i, cnt = total;
if ( cnt > 8 ) cnt = 8;
6266 for( i = 0 ; i < cnt ; i++ )
6267 inputs[ i ] = stbir__get_ring_buffer_scanline(stbir_info, split_info, k+i+contrib_n0 );
6270 ((k==0)?stbir__vertical_gathers:stbir__vertical_gathers_continues)[cnt-1]( (vertical_first) ? decode_buffer : encode_buffer, vertical_coefficients + k, inputs, inputs[0] + width_times_channels );
6275 STBIR_PROFILE_END( vertical );
6277 if ( vertical_first )
6280 decode_buffer[ width_times_channels ] = 0.0f;
6281 decode_buffer[ width_times_channels+1 ] = 0.0f;
6282 stbir__resample_horizontal_gather(stbir_info, encode_buffer, decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6285 stbir__encode_scanline( stbir_info, ( (
char *) stbir_info->output_data ) + ((
size_t)n * (
size_t)stbir_info->output_stride_bytes),
6286 encode_buffer, n STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6289static void stbir__decode_and_resample_for_vertical_gather_loop(
stbir__info const * stbir_info, stbir__per_split_info* split_info,
int n)
6291 int ring_buffer_index;
6295 stbir__decode_scanline( stbir_info, n, split_info->decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6298 split_info->ring_buffer_last_scanline = n;
6301 ring_buffer_index = (split_info->ring_buffer_begin_index + (split_info->ring_buffer_last_scanline - split_info->ring_buffer_first_scanline)) % stbir_info->ring_buffer_num_entries;
6302 ring_buffer = stbir__get_ring_buffer_entry(stbir_info, split_info, ring_buffer_index);
6305 stbir__resample_horizontal_gather( stbir_info, ring_buffer, split_info->decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6310static void stbir__vertical_gather_loop(
stbir__info const * stbir_info, stbir__per_split_info* split_info,
int split_count )
6312 int y, start_output_y, end_output_y;
6313 stbir__contributors* vertical_contributors = stbir_info->vertical.contributors;
6314 float const * vertical_coefficients = stbir_info->vertical.coefficients;
6316 STBIR_ASSERT( stbir_info->vertical.is_gather );
6318 start_output_y = split_info->start_output_y;
6319 end_output_y = split_info[split_count-1].end_output_y;
6321 vertical_contributors += start_output_y;
6322 vertical_coefficients += start_output_y * stbir_info->vertical.coefficient_width;
6325 split_info->ring_buffer_begin_index = 0;
6326 split_info->ring_buffer_first_scanline = vertical_contributors->n0;
6327 split_info->ring_buffer_last_scanline = split_info->ring_buffer_first_scanline - 1;
6329 for (
y = start_output_y;
y < end_output_y;
y++)
6331 int in_first_scanline, in_last_scanline;
6333 in_first_scanline = vertical_contributors->n0;
6334 in_last_scanline = vertical_contributors->n1;
6337 STBIR_ASSERT( in_first_scanline >= split_info->ring_buffer_first_scanline );
6340 while (in_last_scanline > split_info->ring_buffer_last_scanline)
6342 STBIR_ASSERT( ( split_info->ring_buffer_last_scanline - split_info->ring_buffer_first_scanline + 1 ) <= stbir_info->ring_buffer_num_entries );
6345 if ( ( split_info->ring_buffer_last_scanline - split_info->ring_buffer_first_scanline + 1 ) == stbir_info->ring_buffer_num_entries )
6347 split_info->ring_buffer_first_scanline++;
6348 split_info->ring_buffer_begin_index++;
6351 if ( stbir_info->vertical_first )
6353 float * ring_buffer = stbir__get_ring_buffer_scanline( stbir_info, split_info, ++split_info->ring_buffer_last_scanline );
6355 stbir__decode_scanline( stbir_info, split_info->ring_buffer_last_scanline, ring_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6359 stbir__decode_and_resample_for_vertical_gather_loop(stbir_info, split_info, split_info->ring_buffer_last_scanline + 1);
6364 stbir__resample_vertical_gather(stbir_info, split_info,
y, in_first_scanline, in_last_scanline, vertical_coefficients );
6366 ++vertical_contributors;
6367 vertical_coefficients += stbir_info->vertical.coefficient_width;
6371#define STBIR__FLOAT_EMPTY_MARKER 3.0e+38F
6372#define STBIR__FLOAT_BUFFER_IS_EMPTY(ptr) ((ptr)[0]==STBIR__FLOAT_EMPTY_MARKER)
6374static void stbir__encode_first_scanline_from_scatter(
stbir__info const * stbir_info, stbir__per_split_info* split_info)
6377 float* ring_buffer_entry = stbir__get_ring_buffer_entry(stbir_info, split_info, split_info->ring_buffer_begin_index );
6380 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 );
6383 ring_buffer_entry[ 0 ] = STBIR__FLOAT_EMPTY_MARKER;
6386 split_info->ring_buffer_first_scanline++;
6387 if ( ++split_info->ring_buffer_begin_index == stbir_info->ring_buffer_num_entries )
6388 split_info->ring_buffer_begin_index = 0;
6391static void stbir__horizontal_resample_and_encode_first_scanline_from_scatter(
stbir__info const * stbir_info, stbir__per_split_info* split_info)
6395 float* ring_buffer_entry = stbir__get_ring_buffer_entry(stbir_info, split_info, split_info->ring_buffer_begin_index );
6398 stbir__resample_horizontal_gather( stbir_info, split_info->vertical_buffer, ring_buffer_entry STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6401 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 );
6404 ring_buffer_entry[ 0 ] = STBIR__FLOAT_EMPTY_MARKER;
6407 split_info->ring_buffer_first_scanline++;
6408 if ( ++split_info->ring_buffer_begin_index == stbir_info->ring_buffer_num_entries )
6409 split_info->ring_buffer_begin_index = 0;
6412static void stbir__resample_vertical_scatter(
stbir__info const * stbir_info, stbir__per_split_info* split_info,
int n0,
int n1,
float const * vertical_coefficients,
float const * vertical_buffer,
float const * vertical_buffer_end )
6414 STBIR_ASSERT( !stbir_info->vertical.is_gather );
6416 STBIR_PROFILE_START( vertical );
6418 int k = 0, total = n1 - n0 + 1;
6419 STBIR_ASSERT( total > 0 );
6422 int i, n = total;
if ( n > 8 ) n = 8;
6423 for( i = 0 ; i < n ; i++ )
6425 outputs[ i ] = stbir__get_ring_buffer_scanline(stbir_info, split_info, k+i+n0 );
6426 if ( ( i ) && ( STBIR__FLOAT_BUFFER_IS_EMPTY( outputs[i] ) != STBIR__FLOAT_BUFFER_IS_EMPTY( outputs[0] ) ) )
6433 ((STBIR__FLOAT_BUFFER_IS_EMPTY( outputs[0] ))?stbir__vertical_scatter_sets:stbir__vertical_scatter_blends)[n-1]( outputs, vertical_coefficients + k, vertical_buffer, vertical_buffer_end );
6439 STBIR_PROFILE_END( vertical );
6442typedef void stbir__handle_scanline_for_scatter_func(
stbir__info const * stbir_info, stbir__per_split_info* split_info);
6444static void stbir__vertical_scatter_loop(
stbir__info const * stbir_info, stbir__per_split_info* split_info,
int split_count )
6446 int y, start_output_y, end_output_y, start_input_y, end_input_y;
6447 stbir__contributors* vertical_contributors = stbir_info->vertical.contributors;
6448 float const * vertical_coefficients = stbir_info->vertical.coefficients;
6449 stbir__handle_scanline_for_scatter_func * handle_scanline_for_scatter;
6450 void * scanline_scatter_buffer;
6451 void * scanline_scatter_buffer_end;
6452 int on_first_input_y, last_input_y;
6453 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;
6454 int width_times_channels = stbir_info->effective_channels *
width;
6456 STBIR_ASSERT( !stbir_info->vertical.is_gather );
6458 start_output_y = split_info->start_output_y;
6459 end_output_y = split_info[split_count-1].end_output_y;
6461 start_input_y = split_info->start_input_y;
6462 end_input_y = split_info[split_count-1].end_input_y;
6465 y = start_input_y + stbir_info->vertical.filter_pixel_margin;
6466 vertical_contributors +=
y ;
6467 vertical_coefficients += stbir_info->vertical.coefficient_width *
y;
6469 if ( stbir_info->vertical_first )
6471 handle_scanline_for_scatter = stbir__horizontal_resample_and_encode_first_scanline_from_scatter;
6472 scanline_scatter_buffer = split_info->decode_buffer;
6473 scanline_scatter_buffer_end = ( (
char*) scanline_scatter_buffer ) +
sizeof( float ) * stbir_info->effective_channels * (stbir_info->scanline_extents.conservative.n1-stbir_info->scanline_extents.conservative.n0+1);
6477 handle_scanline_for_scatter = stbir__encode_first_scanline_from_scatter;
6478 scanline_scatter_buffer = split_info->vertical_buffer;
6479 scanline_scatter_buffer_end = ( (
char*) scanline_scatter_buffer ) +
sizeof( float ) * stbir_info->effective_channels * stbir_info->horizontal.scale_info.output_sub_size;
6483 split_info->ring_buffer_first_scanline = start_output_y;
6484 split_info->ring_buffer_last_scanline = -1;
6485 split_info->ring_buffer_begin_index = -1;
6488 for(
y = 0 ;
y < stbir_info->ring_buffer_num_entries ;
y++ )
6490 float * decode_buffer = stbir__get_ring_buffer_entry( stbir_info, split_info,
y );
6491 decode_buffer[ width_times_channels ] = 0.0f;
6492 decode_buffer[ width_times_channels+1 ] = 0.0f;
6493 decode_buffer[0] = STBIR__FLOAT_EMPTY_MARKER;
6497 on_first_input_y = 1; last_input_y = start_input_y;
6498 for (
y = start_input_y ;
y < end_input_y;
y++)
6500 int out_first_scanline, out_last_scanline;
6502 out_first_scanline = vertical_contributors->n0;
6503 out_last_scanline = vertical_contributors->n1;
6505 STBIR_ASSERT(out_last_scanline - out_first_scanline + 1 <= stbir_info->ring_buffer_num_entries);
6507 if ( ( out_last_scanline >= out_first_scanline ) && ( ( ( out_first_scanline >= start_output_y ) && ( out_first_scanline < end_output_y ) ) || ( ( out_last_scanline >= start_output_y ) && ( out_last_scanline < end_output_y ) ) ) )
6509 float const * vc = vertical_coefficients;
6513 if ( ( on_first_input_y ) && (
y > start_input_y ) )
6514 split_info->start_input_y =
y;
6515 on_first_input_y = 0;
6518 if ( out_first_scanline < start_output_y )
6520 vc += start_output_y - out_first_scanline;
6521 out_first_scanline = start_output_y;
6524 if ( out_last_scanline >= end_output_y )
6525 out_last_scanline = end_output_y - 1;
6528 if (split_info->ring_buffer_begin_index < 0)
6529 split_info->ring_buffer_begin_index = out_first_scanline - start_output_y;
6531 STBIR_ASSERT( split_info->ring_buffer_begin_index <= out_first_scanline );
6534 stbir__decode_scanline( stbir_info,
y, split_info->decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6537 if ( !stbir_info->vertical_first )
6538 stbir__resample_horizontal_gather( stbir_info, split_info->vertical_buffer, split_info->decode_buffer STBIR_ONLY_PROFILE_SET_SPLIT_INFO );
6543 if ( ( ( split_info->ring_buffer_last_scanline - split_info->ring_buffer_first_scanline + 1 ) == stbir_info->ring_buffer_num_entries ) &&
6544 ( out_last_scanline > split_info->ring_buffer_last_scanline ) )
6545 handle_scanline_for_scatter( stbir_info, split_info );
6548 stbir__resample_vertical_scatter(stbir_info, split_info, out_first_scanline, out_last_scanline, vc, (
float*)scanline_scatter_buffer, (
float*)scanline_scatter_buffer_end );
6551 if ( out_last_scanline > split_info->ring_buffer_last_scanline )
6552 split_info->ring_buffer_last_scanline = out_last_scanline;
6554 ++vertical_contributors;
6555 vertical_coefficients += stbir_info->vertical.coefficient_width;
6559 while ( split_info->ring_buffer_first_scanline < end_output_y )
6560 handle_scanline_for_scatter(stbir_info, split_info);
6564 for(
y = 0 ;
y < split_count;
y++ )
6565 if ( split_info[
y].end_input_y > last_input_y )
6566 split_info[
y].end_input_y = last_input_y;
6570static stbir__kernel_callback * stbir__builtin_kernels[] = { 0, stbir__filter_trapezoid, stbir__filter_triangle, stbir__filter_cubic, stbir__filter_catmullrom, stbir__filter_mitchell, stbir__filter_point };
6571static stbir__support_callback * stbir__builtin_supports[] = { 0, stbir__support_trapezoid, stbir__support_one, stbir__support_two, stbir__support_two, stbir__support_two, stbir__support_zeropoint5 };
6578 filter = STBIR_DEFAULT_FILTER_DOWNSAMPLE;
6579 if (scale_info->scale >= ( 1.0f - stbir__small_float ) )
6581 if ( (scale_info->scale <= ( 1.0f + stbir__small_float ) ) && ( STBIR_CEILF(scale_info->pixel_shift) == scale_info->pixel_shift ) )
6584 filter = STBIR_DEFAULT_FILTER_UPSAMPLE;
6587 samp->filter_enum = filter;
6589 STBIR_ASSERT(samp->filter_enum != 0);
6591 samp->filter_kernel = stbir__builtin_kernels[ filter ];
6592 samp->filter_support = stbir__builtin_supports[ filter ];
6594 if ( kernel && support )
6596 samp->filter_kernel = kernel;
6597 samp->filter_support = support;
6602 samp->filter_pixel_width = stbir__get_filter_pixel_width (samp->filter_support, scale_info->scale, user_data );
6607 samp->is_gather = 0;
6608 if ( scale_info->scale >= ( 1.0f - stbir__small_float ) )
6609 samp->is_gather = 1;
6610 else if ( ( always_gather ) || ( samp->filter_pixel_width <= STBIR_FORCE_GATHER_FILTER_SCANLINES_AMOUNT ) )
6611 samp->is_gather = 2;
6614 samp->coefficient_width = stbir__get_coefficient_width(samp, samp->is_gather, user_data);
6624 if ( samp->filter_pixel_width > ( scale_info->input_full_size * 3 ) )
6625 samp->filter_pixel_width = scale_info->input_full_size * 3;
6629 samp->filter_pixel_margin = samp->filter_pixel_width / 2;
6636 if ( samp->filter_pixel_margin > scale_info->input_full_size )
6637 samp->filter_pixel_margin = scale_info->input_full_size;
6639 samp->num_contributors = stbir__get_contributors(samp, samp->is_gather);
6641 samp->contributors_size = samp->num_contributors *
sizeof(stbir__contributors);
6642 samp->coefficients_size = samp->num_contributors * samp->coefficient_width *
sizeof(float) +
sizeof(
float)*STBIR_INPUT_CALLBACK_PADDING;
6644 samp->gather_prescatter_contributors = 0;
6645 samp->gather_prescatter_coefficients = 0;
6646 if ( samp->is_gather == 0 )
6648 samp->gather_prescatter_coefficient_width = samp->filter_pixel_width;
6649 samp->gather_prescatter_num_contributors = stbir__get_contributors(samp, 2);
6650 samp->gather_prescatter_contributors_size = samp->gather_prescatter_num_contributors *
sizeof(stbir__contributors);
6651 samp->gather_prescatter_coefficients_size = samp->gather_prescatter_num_contributors * samp->gather_prescatter_coefficient_width *
sizeof(float);
6655static void stbir__get_conservative_extents( stbir__sampler * samp, stbir__contributors * range,
void * user_data )
6657 float scale = samp->scale_info.scale;
6658 float out_shift = samp->scale_info.pixel_shift;
6660 int input_full_size = samp->scale_info.input_full_size;
6662 float inv_scale = samp->scale_info.inv_scale;
6664 STBIR_ASSERT( samp->is_gather != 0 );
6666 if ( samp->is_gather == 1 )
6668 int in_first_pixel, in_last_pixel;
6669 float out_filter_radius = support(inv_scale, user_data) * scale;
6671 stbir__calculate_in_pixel_range( &in_first_pixel, &in_last_pixel, 0.5, out_filter_radius, inv_scale, out_shift, input_full_size, edge );
6672 range->n0 = in_first_pixel;
6673 stbir__calculate_in_pixel_range( &in_first_pixel, &in_last_pixel, ( (
float)(samp->scale_info.output_sub_size-1) ) + 0.5f, out_filter_radius, inv_scale, out_shift, input_full_size, edge );
6674 range->n1 = in_last_pixel;
6676 else if ( samp->is_gather == 2 )
6678 float in_pixels_radius = support(scale, user_data) * inv_scale;
6679 int filter_pixel_margin = samp->filter_pixel_margin;
6680 int output_sub_size = samp->scale_info.output_sub_size;
6683 int in_first_pixel, in_last_pixel;
6686 stbir__calculate_in_pixel_range( &in_first_pixel, &in_last_pixel, 0, 0, inv_scale, out_shift, input_full_size, edge );
6687 range->n0 = in_first_pixel;
6688 stbir__calculate_in_pixel_range( &in_first_pixel, &in_last_pixel, (
float)output_sub_size, 0, inv_scale, out_shift, input_full_size, edge );
6689 range->n1 = in_last_pixel;
6693 input_end = -filter_pixel_margin;
6694 while( n >= input_end )
6696 int out_first_pixel, out_last_pixel;
6697 stbir__calculate_out_pixel_range( &out_first_pixel, &out_last_pixel, ((
float)n)+0.5f, in_pixels_radius, scale, out_shift, output_sub_size );
6698 if ( out_first_pixel > out_last_pixel )
6701 if ( ( out_first_pixel < output_sub_size ) || ( out_last_pixel >= 0 ) )
6708 input_end = n + 1 + filter_pixel_margin;
6709 while( n <= input_end )
6711 int out_first_pixel, out_last_pixel;
6712 stbir__calculate_out_pixel_range( &out_first_pixel, &out_last_pixel, ((
float)n)+0.5f, in_pixels_radius, scale, out_shift, output_sub_size );
6713 if ( out_first_pixel > out_last_pixel )
6715 if ( ( out_first_pixel < output_sub_size ) || ( out_last_pixel >= 0 ) )
6724 if ( ( range->n0 > 0 ) && ( range->n1 >= input_full_size ) )
6726 int marg = range->n1 - input_full_size + 1;
6727 if ( ( marg + STBIR__MERGE_RUNS_PIXEL_THRESHOLD ) >= range->n0 )
6730 if ( ( range->n0 < 0 ) && ( range->n1 < (input_full_size-1) ) )
6732 int marg = -range->n0;
6733 if ( ( input_full_size - marg - STBIR__MERGE_RUNS_PIXEL_THRESHOLD - 1 ) <= range->n1 )
6734 range->n1 = input_full_size - 1;
6740 if ( range->n0 < 0 )
6742 if ( range->n1 >= input_full_size )
6743 range->n1 = input_full_size - 1;
6747static void stbir__get_split_info( stbir__per_split_info* split_info,
int splits,
int output_height,
int vertical_pixel_margin,
int input_full_height,
int is_gather, stbir__contributors * contribs )
6750 int left = output_height;
6753 for( i = 0 ; i < splits ; i++ )
6757 split_info[i].start_output_y = cur;
6758 each = left / ( splits - i );
6759 split_info[i].end_output_y = cur + each;
6777 if ( ( is_gather ) && ( i ) )
6779 stbir__contributors * small_contribs;
6780 int j, smallest, stop, start_n0;
6781 stbir__contributors * split_contribs = contribs + cur;
6784 stop = vertical_pixel_margin * 3;
6790 small_contribs = split_contribs;
6791 start_n0 = small_contribs->n0;
6792 for( j = 1 ; j <= stop ; j++ )
6795 if ( split_contribs->n0 > start_n0 )
6797 if ( split_contribs->n0 < small_contribs->n0 )
6799 small_contribs = split_contribs;
6804 split_info[i-1].end_output_y += smallest;
6805 split_info[i].start_output_y += smallest;
6812 split_info[i].start_input_y = -vertical_pixel_margin;
6813 split_info[i].end_input_y = input_full_height + vertical_pixel_margin;
6817static void stbir__free_internal_mem(
stbir__info *info )
6819 #define STBIR__FREE_AND_CLEAR( ptr ) { if ( ptr ) { void * p = (ptr); (ptr) = 0; STBIR_FREE( p, info->user_data); } }
6823 #ifndef STBIR__SEPARATE_ALLOCATIONS
6824 STBIR__FREE_AND_CLEAR( info->alloced_mem );
6828 if ( ( info->vertical.gather_prescatter_contributors ) && ( (
void*)info->vertical.gather_prescatter_contributors != (
void*)info->split_info[0].decode_buffer ) )
6830 STBIR__FREE_AND_CLEAR( info->vertical.gather_prescatter_coefficients );
6831 STBIR__FREE_AND_CLEAR( info->vertical.gather_prescatter_contributors );
6833 for( i = 0 ; i < info->splits ; i++ )
6835 for( j = 0 ; j < info->alloc_ring_buffer_num_entries ; j++ )
6838 if ( info->effective_channels == 3 )
6839 --info->split_info[i].ring_buffers[j];
6841 STBIR__FREE_AND_CLEAR( info->split_info[i].ring_buffers[j] );
6845 if ( info->effective_channels == 3 )
6846 --info->split_info[i].decode_buffer;
6848 STBIR__FREE_AND_CLEAR( info->split_info[i].decode_buffer );
6849 STBIR__FREE_AND_CLEAR( info->split_info[i].ring_buffers );
6850 STBIR__FREE_AND_CLEAR( info->split_info[i].vertical_buffer );
6852 STBIR__FREE_AND_CLEAR( info->split_info );
6853 if ( info->vertical.coefficients != info->horizontal.coefficients )
6855 STBIR__FREE_AND_CLEAR( info->vertical.coefficients );
6856 STBIR__FREE_AND_CLEAR( info->vertical.contributors );
6858 STBIR__FREE_AND_CLEAR( info->horizontal.coefficients );
6859 STBIR__FREE_AND_CLEAR( info->horizontal.contributors );
6860 STBIR__FREE_AND_CLEAR( info->alloced_mem );
6861 STBIR_FREE( info, info->user_data );
6865 #undef STBIR__FREE_AND_CLEAR
6868static int stbir__get_max_split(
int splits,
int height )
6873 for( i = 0 ; i < splits ; i++ )
6875 int each =
height / ( splits - i );
6883static stbir__horizontal_gather_channels_func ** stbir__horizontal_gather_n_coeffs_funcs[8] =
6885 0, stbir__horizontal_gather_1_channels_with_n_coeffs_funcs, stbir__horizontal_gather_2_channels_with_n_coeffs_funcs, stbir__horizontal_gather_3_channels_with_n_coeffs_funcs, stbir__horizontal_gather_4_channels_with_n_coeffs_funcs, 0,0, stbir__horizontal_gather_7_channels_with_n_coeffs_funcs
6888static stbir__horizontal_gather_channels_func ** stbir__horizontal_gather_channels_funcs[8] =
6890 0, stbir__horizontal_gather_1_channels_funcs, stbir__horizontal_gather_2_channels_funcs, stbir__horizontal_gather_3_channels_funcs, stbir__horizontal_gather_4_channels_funcs, 0,0, stbir__horizontal_gather_7_channels_funcs
6894#define STBIR_RESIZE_CLASSIFICATIONS 8
6896static float stbir__compute_weights[5][STBIR_RESIZE_CLASSIFICATIONS][4]=
6899 { 1.00000f, 1.00000f, 0.31250f, 1.00000f },
6900 { 0.56250f, 0.59375f, 0.00000f, 0.96875f },
6901 { 1.00000f, 0.06250f, 0.00000f, 1.00000f },
6902 { 0.00000f, 0.09375f, 1.00000f, 1.00000f },
6903 { 1.00000f, 1.00000f, 0.31250f, 1.00000f },
6904 { 0.03125f, 0.12500f, 1.00000f, 1.00000f },
6905 { 1.00000f, 1.00000f, 0.06250f, 1.00000f },
6906 { 0.00000f, 1.00000f, 0.00000f, 0.03125f },
6908 { 0.00000f, 0.84375f, 0.00000f, 0.03125f },
6909 { 0.09375f, 0.93750f, 0.00000f, 0.78125f },
6910 { 0.87500f, 0.21875f, 0.00000f, 0.96875f },
6911 { 0.09375f, 0.09375f, 1.00000f, 1.00000f },
6912 { 0.00000f, 0.84375f, 0.00000f, 0.03125f },
6913 { 0.03125f, 0.12500f, 1.00000f, 1.00000f },
6914 { 1.00000f, 1.00000f, 0.06250f, 1.00000f },
6915 { 0.00000f, 1.00000f, 0.00000f, 0.53125f },
6917 { 0.00000f, 0.53125f, 0.00000f, 0.03125f },
6918 { 0.06250f, 0.96875f, 0.00000f, 0.53125f },
6919 { 0.87500f, 0.18750f, 0.00000f, 0.93750f },
6920 { 0.00000f, 0.09375f, 1.00000f, 1.00000f },
6921 { 0.00000f, 0.53125f, 0.00000f, 0.03125f },
6922 { 0.03125f, 0.12500f, 1.00000f, 1.00000f },
6923 { 1.00000f, 1.00000f, 0.06250f, 1.00000f },
6924 { 0.00000f, 1.00000f, 0.00000f, 0.56250f },
6926 { 0.00000f, 0.50000f, 0.00000f, 0.71875f },
6927 { 0.06250f, 0.84375f, 0.00000f, 0.87500f },
6928 { 1.00000f, 0.50000f, 0.50000f, 0.96875f },
6929 { 1.00000f, 0.09375f, 0.31250f, 0.50000f },
6930 { 0.00000f, 0.50000f, 0.00000f, 0.71875f },
6931 { 1.00000f, 0.03125f, 0.03125f, 0.53125f },
6932 { 1.00000f, 1.00000f, 0.06250f, 1.00000f },
6933 { 0.00000f, 1.00000f, 0.03125f, 0.18750f },
6935 { 0.00000f, 0.59375f, 0.00000f, 0.96875f },
6936 { 0.06250f, 0.81250f, 0.06250f, 0.59375f },
6937 { 0.75000f, 0.43750f, 0.12500f, 0.96875f },
6938 { 0.87500f, 0.06250f, 0.18750f, 0.43750f },
6939 { 0.00000f, 0.59375f, 0.00000f, 0.96875f },
6940 { 0.15625f, 0.12500f, 1.00000f, 1.00000f },
6941 { 1.00000f, 1.00000f, 0.06250f, 1.00000f },
6942 { 0.00000f, 1.00000f, 0.03125f, 0.34375f },
6947typedef struct STBIR__V_FIRST_INFO
6949 double v_cost, h_cost;
6950 int control_v_first;
6952 int v_resize_classification;
6954} STBIR__V_FIRST_INFO;
6956#ifdef STBIR__V_FIRST_INFO_BUFFER
6957static STBIR__V_FIRST_INFO STBIR__V_FIRST_INFO_BUFFER = {0};
6958#define STBIR__V_FIRST_INFO_POINTER &STBIR__V_FIRST_INFO_BUFFER
6960#define STBIR__V_FIRST_INFO_POINTER 0
6985static int stbir__should_do_vertical_first(
float weights_table[STBIR_RESIZE_CLASSIFICATIONS][4],
int horizontal_filter_pixel_width,
float horizontal_scale,
int horizontal_output_size,
int vertical_filter_pixel_width,
float vertical_scale,
int vertical_output_size,
int is_gather, STBIR__V_FIRST_INFO * info )
6987 double v_cost, h_cost;
6990 int v_classification;
6993 if ( ( vertical_output_size <= 4 ) || ( horizontal_output_size <= 4 ) )
6994 v_classification = ( vertical_output_size < horizontal_output_size ) ? 6 : 7;
6995 else if ( ( !is_gather ) && ( ( vertical_output_size <= 16 ) || ( horizontal_output_size <= 16 ) ) )
6996 v_classification = 4;
6997 else if ( vertical_scale <= 1.0f )
6998 v_classification = ( is_gather ) ? 1 : 0;
6999 else if ( vertical_scale <= 2.0f)
7000 v_classification = 2;
7001 else if ( vertical_scale <= 3.0f)
7002 v_classification = 3;
7004 v_classification = 5;
7007 weights = weights_table[ v_classification ];
7010 h_cost = (float)horizontal_filter_pixel_width * weights[0] + horizontal_scale * (
float)vertical_filter_pixel_width * weights[1];
7011 v_cost = (float)vertical_filter_pixel_width * weights[2] + vertical_scale * (
float)horizontal_filter_pixel_width * weights[3];
7014 vertical_first = ( v_cost <= h_cost ) ? 1 : 0;
7019 info->h_cost = h_cost;
7020 info->v_cost = v_cost;
7021 info->v_resize_classification = v_classification;
7022 info->v_first = vertical_first;
7023 info->is_gather = is_gather;
7027 if ( ( info ) && ( info->control_v_first ) )
7028 vertical_first = ( info->control_v_first == 2 ) ? 1 : 0;
7030 return vertical_first;
7034static unsigned char stbir__pixel_channels[] = {
7042static stbir_internal_pixel_layout stbir__pixel_layout_convert_public_to_internal[] = {
7043 STBIRI_BGR, STBIRI_1CHANNEL, STBIRI_2CHANNEL, STBIRI_RGB, STBIRI_RGBA,
7044 STBIRI_4CHANNEL, STBIRI_BGRA, STBIRI_ARGB, STBIRI_ABGR, STBIRI_RA, STBIRI_AR,
7045 STBIRI_RGBA_PM, STBIRI_BGRA_PM, STBIRI_ARGB_PM, STBIRI_ABGR_PM, STBIRI_RA_PM, STBIRI_AR_PM,
7048static stbir__info * stbir__alloc_internal_mem_and_build_samplers( stbir__sampler * horizontal, stbir__sampler * vertical, stbir__contributors * conservative,
stbir_pixel_layout input_pixel_layout_public,
stbir_pixel_layout output_pixel_layout_public,
int splits,
int new_x,
int new_y,
int fast_alpha,
void * user_data STBIR_ONLY_PROFILE_BUILD_GET_INFO )
7050 static char stbir_channel_count_index[8]={ 9,0,1,2, 3,9,9,4 };
7054 size_t alloced_total = 0;
7056 size_t decode_buffer_size, ring_buffer_length_bytes, ring_buffer_size, vertical_buffer_size;
7057 int alloc_ring_buffer_num_entries;
7059 int alpha_weighting_type = 0;
7060 int conservative_split_output_size = stbir__get_max_split( splits, vertical->scale_info.output_sub_size );
7061 stbir_internal_pixel_layout input_pixel_layout = stbir__pixel_layout_convert_public_to_internal[ input_pixel_layout_public ];
7062 stbir_internal_pixel_layout output_pixel_layout = stbir__pixel_layout_convert_public_to_internal[ output_pixel_layout_public ];
7063 int channels = stbir__pixel_channels[ input_pixel_layout ];
7064 int effective_channels = channels;
7069 if ( ( input_pixel_layout >= STBIRI_RGBA ) && ( input_pixel_layout <= STBIRI_AR ) && ( output_pixel_layout >= STBIRI_RGBA ) && ( output_pixel_layout <= STBIRI_AR ) )
7073 alpha_weighting_type = 4;
7077 static int fancy_alpha_effective_cnts[6] = { 7, 7, 7, 7, 3, 3 };
7078 alpha_weighting_type = 2;
7079 effective_channels = fancy_alpha_effective_cnts[ input_pixel_layout - STBIRI_RGBA ];
7082 else if ( ( input_pixel_layout >= STBIRI_RGBA_PM ) && ( input_pixel_layout <= STBIRI_AR_PM ) && ( output_pixel_layout >= STBIRI_RGBA ) && ( output_pixel_layout <= STBIRI_AR ) )
7085 alpha_weighting_type = 3;
7087 else if ( ( input_pixel_layout >= STBIRI_RGBA ) && ( input_pixel_layout <= STBIRI_AR ) && ( output_pixel_layout >= STBIRI_RGBA_PM ) && ( output_pixel_layout <= STBIRI_AR_PM ) )
7090 alpha_weighting_type = 1;
7095 if ( channels != stbir__pixel_channels[ output_pixel_layout ] )
7099 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 );
7104 decode_buffer_size = ( conservative->n1 - conservative->n0 + 1 ) * effective_channels *
sizeof(
float) +
sizeof(float)*STBIR_INPUT_CALLBACK_PADDING;
7106#if defined( STBIR__SEPARATE_ALLOCATIONS ) && defined(STBIR_SIMD8)
7107 if ( effective_channels == 3 )
7108 decode_buffer_size +=
sizeof(float);
7111 ring_buffer_length_bytes = (
size_t)horizontal->scale_info.output_sub_size * (
size_t)effective_channels *
sizeof(float) +
sizeof(
float)*STBIR_INPUT_CALLBACK_PADDING;
7114 if ( vertical_first )
7115 ring_buffer_length_bytes = ( decode_buffer_size + 15 ) & ~15;
7117 if ( ( ring_buffer_length_bytes & 4095 ) == 0 ) ring_buffer_length_bytes += 64*3;
7120 alloc_ring_buffer_num_entries = vertical->filter_pixel_width + 1;
7123 if ( ( !vertical->is_gather ) && ( alloc_ring_buffer_num_entries > conservative_split_output_size ) )
7124 alloc_ring_buffer_num_entries = conservative_split_output_size;
7126 ring_buffer_size = (
size_t)alloc_ring_buffer_num_entries * (
size_t)ring_buffer_length_bytes;
7132 vertical_buffer_size = (
size_t)horizontal->scale_info.output_sub_size * (
size_t)effective_channels *
sizeof(float) +
sizeof(
float);
7138 void * advance_mem = alloced;
7139 int copy_horizontal = 0;
7140 stbir__sampler * possibly_use_horizontal_for_pivot = 0;
7142#ifdef STBIR__SEPARATE_ALLOCATIONS
7143 #define STBIR__NEXT_PTR( ptr, size, ntype ) if ( alloced ) { void * p = STBIR_MALLOC( size, user_data); if ( p == 0 ) { stbir__free_internal_mem( info ); return 0; } (ptr) = (ntype*)p; }
7145 #define STBIR__NEXT_PTR( ptr, size, ntype ) advance_mem = (void*) ( ( ((size_t)advance_mem) + 15 ) & ~15 ); if ( alloced ) ptr = (ntype*)advance_mem; advance_mem = (char*)(((size_t)advance_mem) + (size));
7150 STBIR__NEXT_PTR( info->split_info,
sizeof( stbir__per_split_info ) * splits, stbir__per_split_info );
7154 static stbir__alpha_weight_func * fancy_alpha_weights[6] = { stbir__fancy_alpha_weight_4ch, stbir__fancy_alpha_weight_4ch, stbir__fancy_alpha_weight_4ch, stbir__fancy_alpha_weight_4ch, stbir__fancy_alpha_weight_2ch, stbir__fancy_alpha_weight_2ch };
7155 static stbir__alpha_unweight_func * fancy_alpha_unweights[6] = { stbir__fancy_alpha_unweight_4ch, stbir__fancy_alpha_unweight_4ch, stbir__fancy_alpha_unweight_4ch, stbir__fancy_alpha_unweight_4ch, stbir__fancy_alpha_unweight_2ch, stbir__fancy_alpha_unweight_2ch };
7156 static stbir__alpha_weight_func * simple_alpha_weights[6] = { stbir__simple_alpha_weight_4ch, stbir__simple_alpha_weight_4ch, stbir__simple_alpha_weight_4ch, stbir__simple_alpha_weight_4ch, stbir__simple_alpha_weight_2ch, stbir__simple_alpha_weight_2ch };
7157 static stbir__alpha_unweight_func * simple_alpha_unweights[6] = { stbir__simple_alpha_unweight_4ch, stbir__simple_alpha_unweight_4ch, stbir__simple_alpha_unweight_4ch, stbir__simple_alpha_unweight_4ch, stbir__simple_alpha_unweight_2ch, stbir__simple_alpha_unweight_2ch };
7160 info->alloced_mem = alloced;
7161 info->alloced_total = alloced_total;
7163 info->channels = channels;
7164 info->effective_channels = effective_channels;
7166 info->offset_x = new_x;
7167 info->offset_y = new_y;
7168 info->alloc_ring_buffer_num_entries = (int)alloc_ring_buffer_num_entries;
7169 info->ring_buffer_num_entries = 0;
7170 info->ring_buffer_length_bytes = (int)ring_buffer_length_bytes;
7171 info->splits = splits;
7172 info->vertical_first = vertical_first;
7174 info->input_pixel_layout_internal = input_pixel_layout;
7175 info->output_pixel_layout_internal = output_pixel_layout;
7178 info->alpha_weight = 0;
7179 info->alpha_unweight = 0;
7182 if ( alpha_weighting_type == 2 )
7185 info->alpha_weight = fancy_alpha_weights[ input_pixel_layout - STBIRI_RGBA ];
7186 info->alpha_unweight = fancy_alpha_unweights[ output_pixel_layout - STBIRI_RGBA ];
7188 else if ( alpha_weighting_type == 4 )
7191 info->alpha_weight = simple_alpha_weights[ input_pixel_layout - STBIRI_RGBA ];
7192 info->alpha_unweight = simple_alpha_unweights[ output_pixel_layout - STBIRI_RGBA ];
7194 else if ( alpha_weighting_type == 1 )
7197 info->alpha_weight = simple_alpha_weights[ input_pixel_layout - STBIRI_RGBA ];
7199 else if ( alpha_weighting_type == 3 )
7202 info->alpha_unweight = simple_alpha_unweights[ output_pixel_layout - STBIRI_RGBA ];
7206 if ( ( ( input_pixel_layout == STBIRI_RGB ) && ( output_pixel_layout == STBIRI_BGR ) ) ||
7207 ( ( input_pixel_layout == STBIRI_BGR ) && ( output_pixel_layout == STBIRI_RGB ) ) )
7210 if ( horizontal->scale_info.scale < 1.0f )
7211 info->alpha_unweight = stbir__simple_flip_3ch;
7213 info->alpha_weight = stbir__simple_flip_3ch;
7219 for( i = 0 ; i < splits ; i++ )
7221 STBIR__NEXT_PTR( info->split_info[i].decode_buffer, decode_buffer_size,
float );
7223#ifdef STBIR__SEPARATE_ALLOCATIONS
7226 if ( ( info ) && ( effective_channels == 3 ) )
7227 ++info->split_info[i].decode_buffer;
7230 STBIR__NEXT_PTR( info->split_info[i].ring_buffers, alloc_ring_buffer_num_entries *
sizeof(
float*),
float* );
7233 for( j = 0 ; j < alloc_ring_buffer_num_entries ; j++ )
7235 STBIR__NEXT_PTR( info->split_info[i].ring_buffers[j], ring_buffer_length_bytes,
float );
7237 if ( ( info ) && ( effective_channels == 3 ) )
7238 ++info->split_info[i].ring_buffers[j];
7243 STBIR__NEXT_PTR( info->split_info[i].ring_buffer, ring_buffer_size,
float );
7245 STBIR__NEXT_PTR( info->split_info[i].vertical_buffer, vertical_buffer_size,
float );
7249 if ( vertical->is_gather == 0 )
7252 size_t temp_mem_amt;
7258 both = (
size_t)vertical->gather_prescatter_contributors_size + (
size_t)vertical->gather_prescatter_coefficients_size;
7260#ifdef STBIR__SEPARATE_ALLOCATIONS
7261 temp_mem_amt = decode_buffer_size;
7264 if ( effective_channels == 3 )
7268 temp_mem_amt = (
size_t)( decode_buffer_size + ring_buffer_size + vertical_buffer_size ) * (
size_t)splits;
7270 if ( temp_mem_amt >= both )
7274 vertical->gather_prescatter_contributors = (stbir__contributors*)info->split_info[0].decode_buffer;
7275 vertical->gather_prescatter_coefficients = (
float*) ( ( (
char*)info->split_info[0].decode_buffer ) + vertical->gather_prescatter_contributors_size );
7281 STBIR__NEXT_PTR( vertical->gather_prescatter_contributors, vertical->gather_prescatter_contributors_size, stbir__contributors );
7282 STBIR__NEXT_PTR( vertical->gather_prescatter_coefficients, vertical->gather_prescatter_coefficients_size,
float );
7286 STBIR__NEXT_PTR( horizontal->contributors, horizontal->contributors_size, stbir__contributors );
7287 STBIR__NEXT_PTR( horizontal->coefficients, horizontal->coefficients_size,
float );
7290 if ( ( horizontal->filter_kernel == vertical->filter_kernel ) && ( horizontal->filter_support == vertical->filter_support ) && ( horizontal->edge == vertical->edge ) && ( horizontal->scale_info.output_sub_size == vertical->scale_info.output_sub_size ) )
7292 float diff_scale = horizontal->scale_info.scale - vertical->scale_info.scale;
7293 float diff_shift = horizontal->scale_info.pixel_shift - vertical->scale_info.pixel_shift;
7294 if ( diff_scale < 0.0f ) diff_scale = -diff_scale;
7295 if ( diff_shift < 0.0f ) diff_shift = -diff_shift;
7296 if ( ( diff_scale <= stbir__small_float ) && ( diff_shift <= stbir__small_float ) )
7298 if ( horizontal->is_gather == vertical->is_gather )
7300 copy_horizontal = 1;
7304 possibly_use_horizontal_for_pivot = horizontal;
7308 STBIR__NEXT_PTR( vertical->contributors, vertical->contributors_size, stbir__contributors );
7309 STBIR__NEXT_PTR( vertical->coefficients, vertical->coefficients_size,
float );
7315 STBIR_PROFILE_BUILD_START( horizontal );
7317 stbir__calculate_filters( horizontal, 0, user_data STBIR_ONLY_PROFILE_BUILD_SET_INFO );
7321 info->horizontal_gather_channels = stbir__horizontal_gather_n_coeffs_funcs[ effective_channels ][ horizontal->extent_info.widest & 3 ];
7323 if ( horizontal->extent_info.widest <= 12 )
7324 info->horizontal_gather_channels = stbir__horizontal_gather_channels_funcs[ effective_channels ][ horizontal->extent_info.widest - 1 ];
7326 info->scanline_extents.conservative.n0 = conservative->n0;
7327 info->scanline_extents.conservative.n1 = conservative->n1;
7330 stbir__get_extents( horizontal, &info->scanline_extents );
7333 horizontal->coefficient_width = stbir__pack_coefficients(horizontal->num_contributors, horizontal->contributors, horizontal->coefficients, horizontal->coefficient_width, horizontal->extent_info.widest, info->scanline_extents.conservative.n0, info->scanline_extents.conservative.n1 );
7335 STBIR_MEMCPY( &info->horizontal, horizontal,
sizeof( stbir__sampler ) );
7337 STBIR_PROFILE_BUILD_END( horizontal );
7339 if ( copy_horizontal )
7341 STBIR_MEMCPY( &info->vertical, horizontal,
sizeof( stbir__sampler ) );
7345 STBIR_PROFILE_BUILD_START( vertical );
7347 stbir__calculate_filters( vertical, possibly_use_horizontal_for_pivot, user_data STBIR_ONLY_PROFILE_BUILD_SET_INFO );
7348 STBIR_MEMCPY( &info->vertical, vertical,
sizeof( stbir__sampler ) );
7350 STBIR_PROFILE_BUILD_END( vertical );
7354 stbir__get_split_info( info->split_info, info->splits, info->vertical.scale_info.output_sub_size, info->vertical.filter_pixel_margin, info->vertical.scale_info.input_full_size, info->vertical.is_gather, info->vertical.contributors );
7357 info->ring_buffer_num_entries = info->vertical.extent_info.widest;
7360 if ( ( !info->vertical.is_gather ) && ( info->ring_buffer_num_entries > conservative_split_output_size ) )
7361 info->ring_buffer_num_entries = conservative_split_output_size;
7362 STBIR_ASSERT( info->ring_buffer_num_entries <= info->alloc_ring_buffer_num_entries );
7364 #undef STBIR__NEXT_PTR
7370 alloced_total = ( 15 + (
size_t)advance_mem );
7371 alloced = STBIR_MALLOC( alloced_total, user_data );
7380static int stbir__perform_resize(
stbir__info const * info,
int split_start,
int split_count )
7382 stbir__per_split_info * split_info = info->split_info + split_start;
7384 STBIR_PROFILE_CLEAR_EXTRAS();
7386 STBIR_PROFILE_FIRST_START( looping );
7387 if (info->vertical.is_gather)
7388 stbir__vertical_gather_loop( info, split_info, split_count );
7390 stbir__vertical_scatter_loop( info, split_info, split_count );
7391 STBIR_PROFILE_END( looping );
7400 stbir__decode_uint8_srgb, stbir__decode_uint8_srgb, 0, stbir__decode_float_linear, stbir__decode_half_float_linear,
7405 { stbir__decode_uint8_srgb4_linearalpha, stbir__decode_uint8_srgb, 0, stbir__decode_float_linear, stbir__decode_half_float_linear },
7406 { stbir__decode_uint8_srgb4_linearalpha_BGRA, stbir__decode_uint8_srgb_BGRA, 0, stbir__decode_float_linear_BGRA, stbir__decode_half_float_linear_BGRA },
7407 { stbir__decode_uint8_srgb4_linearalpha_ARGB, stbir__decode_uint8_srgb_ARGB, 0, stbir__decode_float_linear_ARGB, stbir__decode_half_float_linear_ARGB },
7408 { stbir__decode_uint8_srgb4_linearalpha_ABGR, stbir__decode_uint8_srgb_ABGR, 0, stbir__decode_float_linear_ABGR, stbir__decode_half_float_linear_ABGR },
7409 { stbir__decode_uint8_srgb2_linearalpha, stbir__decode_uint8_srgb, 0, stbir__decode_float_linear, stbir__decode_half_float_linear },
7410 { stbir__decode_uint8_srgb2_linearalpha_AR, stbir__decode_uint8_srgb_AR, 0, stbir__decode_float_linear_AR, stbir__decode_half_float_linear_AR },
7413 static stbir__decode_pixels_func * decode_simple_scaled_or_not[2][2]=
7415 { stbir__decode_uint8_linear_scaled, stbir__decode_uint8_linear }, { stbir__decode_uint16_linear_scaled, stbir__decode_uint16_linear },
7418 static stbir__decode_pixels_func * decode_alphas_scaled_or_not[STBIRI_AR-STBIRI_RGBA+1][2][2]=
7420 { { stbir__decode_uint8_linear_scaled, stbir__decode_uint8_linear }, { stbir__decode_uint16_linear_scaled, stbir__decode_uint16_linear } },
7421 { { stbir__decode_uint8_linear_scaled_BGRA, stbir__decode_uint8_linear_BGRA }, { stbir__decode_uint16_linear_scaled_BGRA, stbir__decode_uint16_linear_BGRA } },
7422 { { stbir__decode_uint8_linear_scaled_ARGB, stbir__decode_uint8_linear_ARGB }, { stbir__decode_uint16_linear_scaled_ARGB, stbir__decode_uint16_linear_ARGB } },
7423 { { stbir__decode_uint8_linear_scaled_ABGR, stbir__decode_uint8_linear_ABGR }, { stbir__decode_uint16_linear_scaled_ABGR, stbir__decode_uint16_linear_ABGR } },
7424 { { stbir__decode_uint8_linear_scaled, stbir__decode_uint8_linear }, { stbir__decode_uint16_linear_scaled, stbir__decode_uint16_linear } },
7425 { { stbir__decode_uint8_linear_scaled_AR, stbir__decode_uint8_linear_AR }, { stbir__decode_uint16_linear_scaled_AR, stbir__decode_uint16_linear_AR } }
7430 stbir__encode_uint8_srgb, stbir__encode_uint8_srgb, 0, stbir__encode_float_linear, stbir__encode_half_float_linear,
7435 { stbir__encode_uint8_srgb4_linearalpha, stbir__encode_uint8_srgb, 0, stbir__encode_float_linear, stbir__encode_half_float_linear },
7436 { stbir__encode_uint8_srgb4_linearalpha_BGRA, stbir__encode_uint8_srgb_BGRA, 0, stbir__encode_float_linear_BGRA, stbir__encode_half_float_linear_BGRA },
7437 { stbir__encode_uint8_srgb4_linearalpha_ARGB, stbir__encode_uint8_srgb_ARGB, 0, stbir__encode_float_linear_ARGB, stbir__encode_half_float_linear_ARGB },
7438 { stbir__encode_uint8_srgb4_linearalpha_ABGR, stbir__encode_uint8_srgb_ABGR, 0, stbir__encode_float_linear_ABGR, stbir__encode_half_float_linear_ABGR },
7439 { stbir__encode_uint8_srgb2_linearalpha, stbir__encode_uint8_srgb, 0, stbir__encode_float_linear, stbir__encode_half_float_linear },
7440 { stbir__encode_uint8_srgb2_linearalpha_AR, stbir__encode_uint8_srgb_AR, 0, stbir__encode_float_linear_AR, stbir__encode_half_float_linear_AR }
7443 static stbir__encode_pixels_func * encode_simple_scaled_or_not[2][2]=
7445 { stbir__encode_uint8_linear_scaled, stbir__encode_uint8_linear }, { stbir__encode_uint16_linear_scaled, stbir__encode_uint16_linear },
7448 static stbir__encode_pixels_func * encode_alphas_scaled_or_not[STBIRI_AR-STBIRI_RGBA+1][2][2]=
7450 { { stbir__encode_uint8_linear_scaled, stbir__encode_uint8_linear }, { stbir__encode_uint16_linear_scaled, stbir__encode_uint16_linear } },
7451 { { stbir__encode_uint8_linear_scaled_BGRA, stbir__encode_uint8_linear_BGRA }, { stbir__encode_uint16_linear_scaled_BGRA, stbir__encode_uint16_linear_BGRA } },
7452 { { stbir__encode_uint8_linear_scaled_ARGB, stbir__encode_uint8_linear_ARGB }, { stbir__encode_uint16_linear_scaled_ARGB, stbir__encode_uint16_linear_ARGB } },
7453 { { stbir__encode_uint8_linear_scaled_ABGR, stbir__encode_uint8_linear_ABGR }, { stbir__encode_uint16_linear_scaled_ABGR, stbir__encode_uint16_linear_ABGR } },
7454 { { stbir__encode_uint8_linear_scaled, stbir__encode_uint8_linear }, { stbir__encode_uint16_linear_scaled, stbir__encode_uint16_linear } },
7455 { { stbir__encode_uint8_linear_scaled_AR, stbir__encode_uint8_linear_AR }, { stbir__encode_uint16_linear_scaled_AR, stbir__encode_uint16_linear_AR } }
7458 stbir__decode_pixels_func * decode_pixels = 0;
7459 stbir__encode_pixels_func * encode_pixels = 0;
7480 if ( info->input_stride_bytes == 0 )
7481 info->input_stride_bytes = info->channels * info->horizontal.scale_info.input_full_size * stbir__type_size[input_type];
7483 if ( info->output_stride_bytes == 0 )
7484 info->output_stride_bytes = info->channels * info->horizontal.scale_info.output_sub_size * stbir__type_size[output_type];
7489 info->in_pixels_cb = resize->
input_cb;
7491 info->out_pixels_cb = resize->
output_cb;
7499 if ( ( !info->alpha_weight ) && ( !info->alpha_unweight ) )
7503 if ( info->input_pixel_layout_internal <= STBIRI_4CHANNEL )
7504 decode_pixels = decode_simple_scaled_or_not[ input_type ==
STBIR_TYPE_UINT16 ][ non_scaled ];
7506 decode_pixels = decode_alphas_scaled_or_not[ ( info->input_pixel_layout_internal - STBIRI_RGBA ) % ( STBIRI_AR-STBIRI_RGBA+1 ) ][ input_type ==
STBIR_TYPE_UINT16 ][ non_scaled ];
7510 if ( info->input_pixel_layout_internal <= STBIRI_4CHANNEL )
7513 decode_pixels = decode_alphas[ ( info->input_pixel_layout_internal - STBIRI_RGBA ) % ( STBIRI_AR-STBIRI_RGBA+1 ) ][ input_type -
STBIR_TYPE_UINT8_SRGB ];
7522 if ( ( !info->alpha_weight ) && ( !info->alpha_unweight ) )
7526 if ( info->output_pixel_layout_internal <= STBIRI_4CHANNEL )
7527 encode_pixels = encode_simple_scaled_or_not[ output_type ==
STBIR_TYPE_UINT16 ][ non_scaled ];
7529 encode_pixels = encode_alphas_scaled_or_not[ ( info->output_pixel_layout_internal - STBIRI_RGBA ) % ( STBIRI_AR-STBIRI_RGBA+1 ) ][ output_type ==
STBIR_TYPE_UINT16 ][ non_scaled ];
7533 if ( info->output_pixel_layout_internal <= STBIRI_4CHANNEL )
7536 encode_pixels = encode_alphas[ ( info->output_pixel_layout_internal - STBIRI_RGBA ) % ( STBIRI_AR-STBIRI_RGBA+1 ) ][ output_type -
STBIR_TYPE_UINT8_SRGB ];
7539 info->input_type = input_type;
7540 info->output_type = output_type;
7541 info->decode_pixels = decode_pixels;
7542 info->encode_pixels = encode_pixels;
7545static void stbir__clip(
int * outx,
int * outsubw,
int outw,
double * u0,
double * u1 )
7553 per = ( (double)*outx ) / ( (
double)*outsubw );
7554 adj = per * ( *u1 - *u0 );
7560 over = outw - ( *outx + *outsubw );
7563 per = ( (double)over ) / ( (
double)*outsubw );
7564 adj = per * ( *u1 - *u0 );
7566 *outsubw = outw - *outx;
7590 if ( ( ( limit_denom ) ? denom_estimate : numer_estimate ) >= limit )
7594 if ( denom_estimate )
7596 err = ( (double)numer_estimate / (double)denom_estimate ) - f;
7597 if ( err < 0.0 ) err = -err;
7598 if ( err < ( 1.0 / (
double)(1<<24) ) )
7618 temp = est * denom_estimate + denom_last;
7619 denom_last = denom_estimate;
7620 denom_estimate = temp;
7623 temp = est * numer_estimate + numer_last;
7624 numer_last = numer_estimate;
7625 numer_estimate = temp;
7631 numer_estimate= (
stbir_uint64)( f * (
double)limit + 0.5 );
7632 denom_estimate = limit;
7636 numer_estimate = limit;
7637 denom_estimate = (
stbir_uint64)( ( (
double)limit / f ) + 0.5 );
7643 err = ( denom_estimate ) ? ( ( (
double)(
stbir_uint32)numer_estimate / (
double)(
stbir_uint32)denom_estimate ) - f ) : 1.0;
7644 if ( err < 0.0 ) err = -err;
7645 return ( err < ( 1.0 / (
double)(1<<24) ) ) ? 1 : 0;
7648static int stbir__calculate_region_transform( stbir__scale_info * scale_info,
int output_full_range,
int * output_offset,
int output_sub_range,
int input_full_range,
double input_s0,
double input_s1 )
7650 double output_range, input_range, output_s, input_s, ratio, scale;
7652 input_s = input_s1 - input_s0;
7655 if ( ( output_full_range == 0 ) || ( input_full_range == 0 ) ||
7656 ( output_sub_range == 0 ) || ( input_s <= stbir__small_float ) )
7660 if ( ( *output_offset >= output_full_range ) || ( ( *output_offset + output_sub_range ) <= 0 ) || ( input_s0 >= (1.0f-stbir__small_float) ) || ( input_s1 <= stbir__small_float ) )
7663 output_range = (double)output_full_range;
7664 input_range = (double)input_full_range;
7666 output_s = ( (double)output_sub_range) / output_range;
7669 ratio = output_s / input_s;
7672 scale = ( output_range / input_range ) * ratio;
7673 scale_info->scale = (float)scale;
7674 scale_info->inv_scale = (float)( 1.0 / scale );
7677 stbir__clip( output_offset, &output_sub_range, output_full_range, &input_s0, &input_s1 );
7680 input_s = input_s1 - input_s0;
7683 if ( input_s <= stbir__small_float )
7687 scale_info->pixel_shift = (float) ( input_s0 * ratio * output_range );
7689 scale_info->scale_is_rational = stbir__double_to_rational( scale, ( scale <= 1.0 ) ? output_full_range : input_full_range, &scale_info->scale_numerator, &scale_info->scale_denominator, ( scale >= 1.0 ) );
7691 scale_info->input_full_size = input_full_range;
7692 scale_info->output_sub_size = output_sub_range;
7721 const void *input_pixels,
int input_w,
int input_h,
int input_stride_in_bytes,
7722 void *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
7735 stbir__init_and_set_layout( resize, pixel_layout, data_type );
7744 stbir__update_info_from_resize( resize->
samplers, resize );
7754 resize->
samplers->in_pixels_cb = input_cb;
7755 resize->
samplers->out_pixels_cb = output_cb;
7763 resize->
samplers->user_data = user_data;
7773 stbir__update_info_from_resize( resize->
samplers, resize );
7812 resize->
fast_alpha = non_pma_alpha_speed_over_quality;
7826 if ( ( s1 < stbir__small_float ) || ( (s1-s0) < stbir__small_float ) ||
7827 ( t1 < stbir__small_float ) || ( (t1-t0) < stbir__small_float ) ||
7828 ( s0 > (1.0f-stbir__small_float) ) ||
7829 ( t0 > (1.0f-stbir__small_float) ) )
7844 if ( ( subx >= resize->
output_w ) || ( ( subx + subw ) <= 0 ) || ( suby >= resize->
output_h ) || ( ( suby + subh ) <= 0 ) || ( subw == 0 ) || ( subh == 0 ) )
7852 double s0, t0, s1, t1;
7854 s0 = ( (double)subx ) / ( (
double)resize->
output_w );
7855 t0 = ( (double)suby ) / ( (
double)resize->
output_h );
7856 s1 = ( (double)(subx+subw) ) / ( (
double)resize->
output_w );
7857 t1 = ( (double)(suby+subh) ) / ( (
double)resize->
output_h );
7870 if ( ( subx >= resize->
output_w ) || ( ( subx + subw ) <= 0 ) || ( suby >= resize->
output_h ) || ( ( suby + subh ) <= 0 ) || ( subw == 0 ) || ( subh == 0 ) )
7876static int stbir__perform_build(
STBIR_RESIZE * resize,
int splits )
7878 stbir__contributors conservative = { 0, 0 };
7879 stbir__sampler horizontal, vertical;
7880 int new_output_subx, new_output_suby;
7882 #ifdef STBIR_PROFILE
7891 #define STBIR_RETURN_ERROR_AND_ASSERT( exp ) STBIR_ASSERT( !(exp) ); if (exp) return 0;
7894 #undef STBIR_RETURN_ERROR_AND_ASSERT
7899 STBIR_PROFILE_BUILD_FIRST_START( build );
7913 if ( ( horizontal.scale_info.output_sub_size == 0 ) || ( vertical.scale_info.output_sub_size == 0 ) )
7917 stbir__get_conservative_extents( &horizontal, &conservative, resize->
user_data );
7920 if ( ( vertical.scale_info.output_sub_size / splits ) < STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS )
7922 splits = vertical.scale_info.output_sub_size / STBIR_FORCE_MINIMUM_SCANLINES_FOR_SPLITS;
7923 if ( splits == 0 ) splits = 1;
7926 STBIR_PROFILE_BUILD_START( alloc );
7928 STBIR_PROFILE_BUILD_END( alloc );
7929 STBIR_PROFILE_BUILD_END( build );
7936 #ifdef STBIR_PROFILE
7937 STBIR_MEMCPY( &out_info->profile, &profile_infod.profile,
sizeof( out_info->profile ) );
7941 stbir__update_info_from_resize( out_info, resize );
7953 stbir__free_internal_mem( resize->
samplers );
7967 return stbir__perform_build( resize, splits );
7970 STBIR_PROFILE_BUILD_CLEAR( resize->
samplers );
7990 stbir__free_internal_mem( resize->
samplers );
8008 STBIR_PROFILE_BUILD_CLEAR( resize->
samplers );
8029 if ( ( split_start == -1 ) || ( ( split_start == 0 ) && ( split_count == resize->
splits ) ) )
8036 if ( ( split_start >= resize->
splits ) || ( split_start < 0 ) || ( ( split_start + split_count ) > resize->
splits ) || ( split_count <= 0 ) )
8040 return stbir__perform_resize( resize->
samplers, split_start, split_count );
8044static void * stbir_quick_resize_helper(
const void *input_pixels ,
int input_w ,
int input_h,
int input_stride_in_bytes,
8045 void *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
8049 int scanline_output_in_bytes;
8050 int positive_output_stride_in_bytes;
8054 scanline_output_in_bytes = output_w * stbir__type_size[ data_type ] * stbir__pixel_channels[ stbir__pixel_layout_convert_public_to_internal[ pixel_layout ] ];
8055 if ( scanline_output_in_bytes == 0 )
8059 if ( output_stride_in_bytes == 0 )
8060 output_stride_in_bytes = scanline_output_in_bytes;
8063 positive_output_stride_in_bytes = output_stride_in_bytes;
8064 if ( positive_output_stride_in_bytes < 0 )
8065 positive_output_stride_in_bytes = -positive_output_stride_in_bytes;
8068 if ( positive_output_stride_in_bytes < scanline_output_in_bytes )
8071 start_ptr = output_pixels;
8075 if ( output_pixels == 0 )
8080 size = (
size_t)positive_output_stride_in_bytes * (
size_t)output_h;
8084 ptr = (
char*) STBIR_MALLOC(
size, 0 );
8091 if ( output_stride_in_bytes < 0 )
8092 start_ptr = ptr + ( (
size_t)positive_output_stride_in_bytes * (
size_t)( output_h - 1 ) );
8099 input_pixels, input_w, input_h, input_stride_in_bytes,
8100 start_ptr, output_w, output_h, output_stride_in_bytes,
8101 pixel_layout, data_type );
8111 STBIR_FREE( free_ptr, 0 );
8115 return (free_ptr) ? free_ptr : start_ptr;
8121 unsigned char *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
8124 return (
unsigned char *) stbir_quick_resize_helper( input_pixels , input_w , input_h, input_stride_in_bytes,
8125 output_pixels, output_w, output_h, output_stride_in_bytes,
8130 unsigned char *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
8133 return (
unsigned char *) stbir_quick_resize_helper( input_pixels , input_w , input_h, input_stride_in_bytes,
8134 output_pixels, output_w, output_h, output_stride_in_bytes,
8140 float *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
8143 return (
float *) stbir_quick_resize_helper( input_pixels , input_w , input_h, input_stride_in_bytes,
8144 output_pixels, output_w, output_h, output_stride_in_bytes,
8149STBIRDEF void *
stbir_resize(
const void *input_pixels ,
int input_w ,
int input_h,
int input_stride_in_bytes,
8150 void *output_pixels,
int output_w,
int output_h,
int output_stride_in_bytes,
8154 return (
void *) stbir_quick_resize_helper( input_pixels , input_w , input_h, input_stride_in_bytes,
8155 output_pixels, output_w, output_h, output_stride_in_bytes,
8156 pixel_layout, data_type, edge, filter );
8161STBIRDEF void stbir_resize_build_profile_info( STBIR_PROFILE_INFO * info,
STBIR_RESIZE const * resize )
8163 static char const * bdescriptions[6] = {
"Building",
"Allocating",
"Horizontal sampler",
"Vertical sampler",
"Coefficient cleanup",
"Coefficient pivot" } ;
8167 typedef int testa[ (STBIR__ARRAY_SIZE( bdescriptions ) == (STBIR__ARRAY_SIZE( samp->profile.array )-1) )?1:-1];
8168 typedef int testb[ (
sizeof( samp->profile.array ) == (
sizeof(samp->profile.named)) )?1:-1];
8169 typedef int testc[ (
sizeof( info->clocks ) >= (
sizeof(samp->profile.named)) )?1:-1];
8171 for( i = 0 ; i < STBIR__ARRAY_SIZE( bdescriptions ) ; i++)
8172 info->clocks[i] = samp->profile.array[i+1];
8174 info->total_clocks = samp->profile.named.total;
8175 info->descriptions = bdescriptions;
8176 info->count = STBIR__ARRAY_SIZE( bdescriptions );
8179STBIRDEF void stbir_resize_split_profile_info( STBIR_PROFILE_INFO * info,
STBIR_RESIZE const * resize,
int split_start,
int split_count )
8181 static char const * descriptions[7] = {
"Looping",
"Vertical sampling",
"Horizontal sampling",
"Scanline input",
"Scanline output",
"Alpha weighting",
"Alpha unweighting" };
8182 stbir__per_split_info * split_info;
8185 typedef int testa[ (STBIR__ARRAY_SIZE( descriptions ) == (STBIR__ARRAY_SIZE( split_info->profile.array )-1) )?1:-1];
8186 typedef int testb[ (
sizeof( split_info->profile.array ) == (
sizeof(split_info->profile.named)) )?1:-1];
8187 typedef int testc[ (
sizeof( info->clocks ) >= (
sizeof(split_info->profile.named)) )?1:-1];
8189 if ( split_start == -1 )
8192 split_count = resize->
samplers->splits;
8195 if ( ( split_start >= resize->
splits ) || ( split_start < 0 ) || ( ( split_start + split_count ) > resize->
splits ) || ( split_count <= 0 ) )
8197 info->total_clocks = 0;
8198 info->descriptions = 0;
8203 split_info = resize->
samplers->split_info + split_start;
8206 for( i = 0 ; i < STBIR__ARRAY_SIZE( descriptions ) ; i++ )
8209 for( s = 0 ; s < split_count ; s++ )
8210 sum += split_info[s].profile.array[i+1];
8211 info->clocks[i] = sum;
8214 info->total_clocks = split_info->profile.named.total;
8215 info->descriptions = descriptions;
8216 info->count = STBIR__ARRAY_SIZE( descriptions );
8219STBIRDEF void stbir_resize_extended_profile_info( STBIR_PROFILE_INFO * info,
STBIR_RESIZE const * resize )
8221 stbir_resize_split_profile_info( info, resize, -1, 0 );
8227#undef STBIR_1CHANNEL
8228#undef STBIR_2CHANNEL
8231#undef STBIR_4CHANNEL
8253#define STBIR_strs_join2( start, mid, end ) start##mid##end
8254#define STBIR_strs_join1( start, mid, end ) STBIR_strs_join2( start, mid, end )
8256#define STBIR_strs_join24( start, mid1, mid2, end ) start##mid1##mid2##end
8257#define STBIR_strs_join14( start, mid1, mid2, end ) STBIR_strs_join24( start, mid1, mid2, end )
8259#ifdef STB_IMAGE_RESIZE_DO_CODERS
8261#ifdef stbir__decode_suffix
8262#define STBIR__CODER_NAME( name ) STBIR_strs_join1( name, _, stbir__decode_suffix )
8264#define STBIR__CODER_NAME( name ) name
8267#ifdef stbir__decode_swizzle
8268#define stbir__decode_simdf8_flip(reg) STBIR_strs_join1( STBIR_strs_join1( STBIR_strs_join1( STBIR_strs_join1( stbir__simdf8_0123to,stbir__decode_order0,stbir__decode_order1),stbir__decode_order2,stbir__decode_order3),stbir__decode_order0,stbir__decode_order1),stbir__decode_order2,stbir__decode_order3)(reg, reg)
8269#define stbir__decode_simdf4_flip(reg) STBIR_strs_join1( STBIR_strs_join1( stbir__simdf_0123to,stbir__decode_order0,stbir__decode_order1),stbir__decode_order2,stbir__decode_order3)(reg, reg)
8270#define stbir__encode_simdf8_unflip(reg) STBIR_strs_join1( STBIR_strs_join1( STBIR_strs_join1( STBIR_strs_join1( stbir__simdf8_0123to,stbir__encode_order0,stbir__encode_order1),stbir__encode_order2,stbir__encode_order3),stbir__encode_order0,stbir__encode_order1),stbir__encode_order2,stbir__encode_order3)(reg, reg)
8271#define stbir__encode_simdf4_unflip(reg) STBIR_strs_join1( STBIR_strs_join1( stbir__simdf_0123to,stbir__encode_order0,stbir__encode_order1),stbir__encode_order2,stbir__encode_order3)(reg, reg)
8273#define stbir__decode_order0 0
8274#define stbir__decode_order1 1
8275#define stbir__decode_order2 2
8276#define stbir__decode_order3 3
8277#define stbir__encode_order0 0
8278#define stbir__encode_order1 1
8279#define stbir__encode_order2 2
8280#define stbir__encode_order3 3
8281#define stbir__decode_simdf8_flip(reg)
8282#define stbir__decode_simdf4_flip(reg)
8283#define stbir__encode_simdf8_unflip(reg)
8284#define stbir__encode_simdf4_unflip(reg)
8288#define stbir__encode_simdfX_unflip stbir__encode_simdf8_unflip
8290#define stbir__encode_simdfX_unflip stbir__encode_simdf4_unflip
8293static float * STBIR__CODER_NAME( stbir__decode_uint8_linear_scaled )(
float * decodep,
int width_times_channels,
void const * inputp )
8295 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
8296 float * decode_end = (
float*) decode + width_times_channels;
8297 unsigned char const * input = (
unsigned char const*)inputp;
8300 unsigned char const * end_input_m16 = input + width_times_channels - 16;
8301 if ( width_times_channels >= 16 )
8304 STBIR_NO_UNROLL_LOOP_START_INF_FOR
8308 stbir__simdi i; stbir__simdi8 o0,o1;
8309 stbir__simdf8 of0, of1;
8310 STBIR_NO_UNROLL(decode);
8311 stbir__simdi_load( i, input );
8312 stbir__simdi8_expand_u8_to_u32( o0, o1, i );
8313 stbir__simdi8_convert_i32_to_float( of0, o0 );
8314 stbir__simdi8_convert_i32_to_float( of1, o1 );
8315 stbir__simdf8_mult( of0, of0, STBIR_max_uint8_as_float_inverted8);
8316 stbir__simdf8_mult( of1, of1, STBIR_max_uint8_as_float_inverted8);
8317 stbir__decode_simdf8_flip( of0 );
8318 stbir__decode_simdf8_flip( of1 );
8319 stbir__simdf8_store( decode + 0, of0 );
8320 stbir__simdf8_store( decode + 8, of1 );
8322 stbir__simdi i, o0, o1, o2, o3;
8323 stbir__simdf of0, of1, of2, of3;
8324 STBIR_NO_UNROLL(decode);
8325 stbir__simdi_load( i, input );
8326 stbir__simdi_expand_u8_to_u32( o0,o1,o2,o3,i);
8327 stbir__simdi_convert_i32_to_float( of0, o0 );
8328 stbir__simdi_convert_i32_to_float( of1, o1 );
8329 stbir__simdi_convert_i32_to_float( of2, o2 );
8330 stbir__simdi_convert_i32_to_float( of3, o3 );
8331 stbir__simdf_mult( of0, of0, STBIR__CONSTF(STBIR_max_uint8_as_float_inverted) );
8332 stbir__simdf_mult( of1, of1, STBIR__CONSTF(STBIR_max_uint8_as_float_inverted) );
8333 stbir__simdf_mult( of2, of2, STBIR__CONSTF(STBIR_max_uint8_as_float_inverted) );
8334 stbir__simdf_mult( of3, of3, STBIR__CONSTF(STBIR_max_uint8_as_float_inverted) );
8335 stbir__decode_simdf4_flip( of0 );
8336 stbir__decode_simdf4_flip( of1 );
8337 stbir__decode_simdf4_flip( of2 );
8338 stbir__decode_simdf4_flip( of3 );
8339 stbir__simdf_store( decode + 0, of0 );
8340 stbir__simdf_store( decode + 4, of1 );
8341 stbir__simdf_store( decode + 8, of2 );
8342 stbir__simdf_store( decode + 12, of3 );
8346 if ( decode <= decode_end )
8348 if ( decode == ( decode_end + 16 ) )
8350 decode = decode_end;
8351 input = end_input_m16;
8353 return decode_end + 16;
8358 #if stbir__coder_min_num != 3
8360 STBIR_SIMD_NO_UNROLL_LOOP_START
8361 while( decode <= decode_end )
8363 STBIR_SIMD_NO_UNROLL(decode);
8364 decode[0-4] = ((float)(input[stbir__decode_order0])) * stbir__max_uint8_as_float_inverted;
8365 decode[1-4] = ((float)(input[stbir__decode_order1])) * stbir__max_uint8_as_float_inverted;
8366 decode[2-4] = ((float)(input[stbir__decode_order2])) * stbir__max_uint8_as_float_inverted;
8367 decode[3-4] = ((float)(input[stbir__decode_order3])) * stbir__max_uint8_as_float_inverted;
8375 #if stbir__coder_min_num < 4
8376 STBIR_NO_UNROLL_LOOP_START
8377 while( decode < decode_end )
8379 STBIR_NO_UNROLL(decode);
8380 decode[0] = ((float)(input[stbir__decode_order0])) * stbir__max_uint8_as_float_inverted;
8381 #if stbir__coder_min_num >= 2
8382 decode[1] = ((float)(input[stbir__decode_order1])) * stbir__max_uint8_as_float_inverted;
8384 #if stbir__coder_min_num >= 3
8385 decode[2] = ((float)(input[stbir__decode_order2])) * stbir__max_uint8_as_float_inverted;
8387 decode += stbir__coder_min_num;
8388 input += stbir__coder_min_num;
8395static void STBIR__CODER_NAME( stbir__encode_uint8_linear_scaled )(
void * outputp,
int width_times_channels,
float const * encode )
8397 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned char *) outputp;
8398 unsigned char * end_output = ( (
unsigned char *) output ) + width_times_channels;
8401 if ( width_times_channels >= stbir__simdfX_float_count*2 )
8403 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;
8404 end_output -= stbir__simdfX_float_count*2;
8405 STBIR_NO_UNROLL_LOOP_START_INF_FOR
8408 stbir__simdfX e0, e1;
8410 STBIR_SIMD_NO_UNROLL(encode);
8411 stbir__simdfX_madd_mem( e0, STBIR_simd_point5X, STBIR_max_uint8_as_floatX, encode );
8412 stbir__simdfX_madd_mem( e1, STBIR_simd_point5X, STBIR_max_uint8_as_floatX, encode+stbir__simdfX_float_count );
8413 stbir__encode_simdfX_unflip( e0 );
8414 stbir__encode_simdfX_unflip( e1 );
8416 stbir__simdf8_pack_to_16bytes( i, e0, e1 );
8417 stbir__simdi_store( output, i );
8419 stbir__simdf_pack_to_8bytes( i, e0, e1 );
8420 stbir__simdi_store2( output, i );
8422 encode += stbir__simdfX_float_count*2;
8423 output += stbir__simdfX_float_count*2;
8424 if ( output <= end_output )
8426 if ( output == ( end_output + stbir__simdfX_float_count*2 ) )
8428 output = end_output;
8429 encode = end_encode_m8;
8435 #if stbir__coder_min_num != 3
8437 STBIR_NO_UNROLL_LOOP_START
8438 while( output <= end_output )
8442 STBIR_NO_UNROLL(encode);
8443 stbir__simdf_load( e0, encode );
8444 stbir__simdf_madd( e0, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint8_as_float), e0 );
8445 stbir__encode_simdf4_unflip( e0 );
8446 stbir__simdf_pack_to_8bytes( i0, e0, e0 );
8447 *(
int*)(output-4) = stbir__simdi_to_int( i0 );
8455 #if stbir__coder_min_num < 4
8456 STBIR_NO_UNROLL_LOOP_START
8457 while( output < end_output )
8460 STBIR_NO_UNROLL(encode);
8461 stbir__simdf_madd1_mem( e0, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint8_as_float), encode+stbir__encode_order0 ); output[0] = stbir__simdf_convert_float_to_uint8( e0 );
8462 #if stbir__coder_min_num >= 2
8463 stbir__simdf_madd1_mem( e0, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint8_as_float), encode+stbir__encode_order1 ); output[1] = stbir__simdf_convert_float_to_uint8( e0 );
8465 #if stbir__coder_min_num >= 3
8466 stbir__simdf_madd1_mem( e0, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint8_as_float), encode+stbir__encode_order2 ); output[2] = stbir__simdf_convert_float_to_uint8( e0 );
8468 output += stbir__coder_min_num;
8469 encode += stbir__coder_min_num;
8476 #if stbir__coder_min_num != 3
8478 while( output <= end_output )
8481 f = encode[stbir__encode_order0] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[0-4] = (
unsigned char)f;
8482 f = encode[stbir__encode_order1] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[1-4] = (
unsigned char)f;
8483 f = encode[stbir__encode_order2] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[2-4] = (
unsigned char)f;
8484 f = encode[stbir__encode_order3] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[3-4] = (
unsigned char)f;
8492 #if stbir__coder_min_num < 4
8493 STBIR_NO_UNROLL_LOOP_START
8494 while( output < end_output )
8497 STBIR_NO_UNROLL(encode);
8498 f = encode[stbir__encode_order0] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[0] = (
unsigned char)f;
8499 #if stbir__coder_min_num >= 2
8500 f = encode[stbir__encode_order1] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[1] = (
unsigned char)f;
8502 #if stbir__coder_min_num >= 3
8503 f = encode[stbir__encode_order2] * stbir__max_uint8_as_float + 0.5f; STBIR_CLAMP(f, 0, 255); output[2] = (
unsigned char)f;
8505 output += stbir__coder_min_num;
8506 encode += stbir__coder_min_num;
8512static float * STBIR__CODER_NAME(stbir__decode_uint8_linear)(
float * decodep,
int width_times_channels,
void const * inputp )
8514 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
8515 float * decode_end = (
float*) decode + width_times_channels;
8516 unsigned char const * input = (
unsigned char const*)inputp;
8519 unsigned char const * end_input_m16 = input + width_times_channels - 16;
8520 if ( width_times_channels >= 16 )
8523 STBIR_NO_UNROLL_LOOP_START_INF_FOR
8527 stbir__simdi i; stbir__simdi8 o0,o1;
8528 stbir__simdf8 of0, of1;
8529 STBIR_NO_UNROLL(decode);
8530 stbir__simdi_load( i, input );
8531 stbir__simdi8_expand_u8_to_u32( o0, o1, i );
8532 stbir__simdi8_convert_i32_to_float( of0, o0 );
8533 stbir__simdi8_convert_i32_to_float( of1, o1 );
8534 stbir__decode_simdf8_flip( of0 );
8535 stbir__decode_simdf8_flip( of1 );
8536 stbir__simdf8_store( decode + 0, of0 );
8537 stbir__simdf8_store( decode + 8, of1 );
8539 stbir__simdi i, o0, o1, o2, o3;
8540 stbir__simdf of0, of1, of2, of3;
8541 STBIR_NO_UNROLL(decode);
8542 stbir__simdi_load( i, input );
8543 stbir__simdi_expand_u8_to_u32( o0,o1,o2,o3,i);
8544 stbir__simdi_convert_i32_to_float( of0, o0 );
8545 stbir__simdi_convert_i32_to_float( of1, o1 );
8546 stbir__simdi_convert_i32_to_float( of2, o2 );
8547 stbir__simdi_convert_i32_to_float( of3, o3 );
8548 stbir__decode_simdf4_flip( of0 );
8549 stbir__decode_simdf4_flip( of1 );
8550 stbir__decode_simdf4_flip( of2 );
8551 stbir__decode_simdf4_flip( of3 );
8552 stbir__simdf_store( decode + 0, of0 );
8553 stbir__simdf_store( decode + 4, of1 );
8554 stbir__simdf_store( decode + 8, of2 );
8555 stbir__simdf_store( decode + 12, of3 );
8559 if ( decode <= decode_end )
8561 if ( decode == ( decode_end + 16 ) )
8563 decode = decode_end;
8564 input = end_input_m16;
8566 return decode_end + 16;
8571 #if stbir__coder_min_num != 3
8573 STBIR_SIMD_NO_UNROLL_LOOP_START
8574 while( decode <= decode_end )
8576 STBIR_SIMD_NO_UNROLL(decode);
8577 decode[0-4] = ((float)(input[stbir__decode_order0]));
8578 decode[1-4] = ((float)(input[stbir__decode_order1]));
8579 decode[2-4] = ((float)(input[stbir__decode_order2]));
8580 decode[3-4] = ((float)(input[stbir__decode_order3]));
8588 #if stbir__coder_min_num < 4
8589 STBIR_NO_UNROLL_LOOP_START
8590 while( decode < decode_end )
8592 STBIR_NO_UNROLL(decode);
8593 decode[0] = ((float)(input[stbir__decode_order0]));
8594 #if stbir__coder_min_num >= 2
8595 decode[1] = ((float)(input[stbir__decode_order1]));
8597 #if stbir__coder_min_num >= 3
8598 decode[2] = ((float)(input[stbir__decode_order2]));
8600 decode += stbir__coder_min_num;
8601 input += stbir__coder_min_num;
8607static void STBIR__CODER_NAME( stbir__encode_uint8_linear )(
void * outputp,
int width_times_channels,
float const * encode )
8609 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned char *) outputp;
8610 unsigned char * end_output = ( (
unsigned char *) output ) + width_times_channels;
8613 if ( width_times_channels >= stbir__simdfX_float_count*2 )
8615 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;
8616 end_output -= stbir__simdfX_float_count*2;
8617 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
8620 stbir__simdfX e0, e1;
8622 STBIR_SIMD_NO_UNROLL(encode);
8623 stbir__simdfX_add_mem( e0, STBIR_simd_point5X, encode );
8624 stbir__simdfX_add_mem( e1, STBIR_simd_point5X, encode+stbir__simdfX_float_count );
8625 stbir__encode_simdfX_unflip( e0 );
8626 stbir__encode_simdfX_unflip( e1 );
8628 stbir__simdf8_pack_to_16bytes( i, e0, e1 );
8629 stbir__simdi_store( output, i );
8631 stbir__simdf_pack_to_8bytes( i, e0, e1 );
8632 stbir__simdi_store2( output, i );
8634 encode += stbir__simdfX_float_count*2;
8635 output += stbir__simdfX_float_count*2;
8636 if ( output <= end_output )
8638 if ( output == ( end_output + stbir__simdfX_float_count*2 ) )
8640 output = end_output;
8641 encode = end_encode_m8;
8647 #if stbir__coder_min_num != 3
8649 STBIR_NO_UNROLL_LOOP_START
8650 while( output <= end_output )
8654 STBIR_NO_UNROLL(encode);
8655 stbir__simdf_load( e0, encode );
8656 stbir__simdf_add( e0, STBIR__CONSTF(STBIR_simd_point5), e0 );
8657 stbir__encode_simdf4_unflip( e0 );
8658 stbir__simdf_pack_to_8bytes( i0, e0, e0 );
8659 *(
int*)(output-4) = stbir__simdi_to_int( i0 );
8669 #if stbir__coder_min_num != 3
8671 while( output <= end_output )
8674 f = encode[stbir__encode_order0] + 0.5f; STBIR_CLAMP(f, 0, 255); output[0-4] = (
unsigned char)f;
8675 f = encode[stbir__encode_order1] + 0.5f; STBIR_CLAMP(f, 0, 255); output[1-4] = (
unsigned char)f;
8676 f = encode[stbir__encode_order2] + 0.5f; STBIR_CLAMP(f, 0, 255); output[2-4] = (
unsigned char)f;
8677 f = encode[stbir__encode_order3] + 0.5f; STBIR_CLAMP(f, 0, 255); output[3-4] = (
unsigned char)f;
8687 #if stbir__coder_min_num < 4
8688 STBIR_NO_UNROLL_LOOP_START
8689 while( output < end_output )
8692 STBIR_NO_UNROLL(encode);
8693 f = encode[stbir__encode_order0] + 0.5f; STBIR_CLAMP(f, 0, 255); output[0] = (
unsigned char)f;
8694 #if stbir__coder_min_num >= 2
8695 f = encode[stbir__encode_order1] + 0.5f; STBIR_CLAMP(f, 0, 255); output[1] = (
unsigned char)f;
8697 #if stbir__coder_min_num >= 3
8698 f = encode[stbir__encode_order2] + 0.5f; STBIR_CLAMP(f, 0, 255); output[2] = (
unsigned char)f;
8700 output += stbir__coder_min_num;
8701 encode += stbir__coder_min_num;
8706static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb)(
float * decodep,
int width_times_channels,
void const * inputp )
8708 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
8709 float * decode_end = (
float*) decode + width_times_channels;
8710 unsigned char const * input = (
unsigned char const *)inputp;
8713 #if stbir__coder_min_num != 3
8715 while( decode <= decode_end )
8717 decode[0-4] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order0 ] ];
8718 decode[1-4] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order1 ] ];
8719 decode[2-4] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order2 ] ];
8720 decode[3-4] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order3 ] ];
8728 #if stbir__coder_min_num < 4
8729 STBIR_NO_UNROLL_LOOP_START
8730 while( decode < decode_end )
8732 STBIR_NO_UNROLL(decode);
8733 decode[0] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order0 ] ];
8734 #if stbir__coder_min_num >= 2
8735 decode[1] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order1 ] ];
8737 #if stbir__coder_min_num >= 3
8738 decode[2] = stbir__srgb_uchar_to_linear_float[ input[ stbir__decode_order2 ] ];
8740 decode += stbir__coder_min_num;
8741 input += stbir__coder_min_num;
8747#define stbir__min_max_shift20( i, f ) \
8748 stbir__simdf_max( f, f, stbir_simdf_casti(STBIR__CONSTI( STBIR_almost_zero )) ); \
8749 stbir__simdf_min( f, f, stbir_simdf_casti(STBIR__CONSTI( STBIR_almost_one )) ); \
8750 stbir__simdi_32shr( i, stbir_simdi_castf( f ), 20 );
8752#define stbir__scale_and_convert( i, f ) \
8753 stbir__simdf_madd( f, STBIR__CONSTF( STBIR_simd_point5 ), STBIR__CONSTF( STBIR_max_uint8_as_float ), f ); \
8754 stbir__simdf_max( f, f, stbir__simdf_zeroP() ); \
8755 stbir__simdf_min( f, f, STBIR__CONSTF( STBIR_max_uint8_as_float ) ); \
8756 stbir__simdf_convert_float_to_i32( i, f );
8758#define stbir__linear_to_srgb_finish( i, f ) \
8760 stbir__simdi temp; \
8761 stbir__simdi_32shr( temp, stbir_simdi_castf( f ), 12 ) ; \
8762 stbir__simdi_and( temp, temp, STBIR__CONSTI(STBIR_mantissa_mask) ); \
8763 stbir__simdi_or( temp, temp, STBIR__CONSTI(STBIR_topscale) ); \
8764 stbir__simdi_16madd( i, i, temp ); \
8765 stbir__simdi_32shr( i, i, 16 ); \
8768#define stbir__simdi_table_lookup2( v0,v1, table ) \
8770 stbir__simdi_u32 temp0,temp1; \
8771 temp0.m128i_i128 = v0; \
8772 temp1.m128i_i128 = v1; \
8773 temp0.m128i_u32[0] = table[temp0.m128i_i32[0]]; temp0.m128i_u32[1] = table[temp0.m128i_i32[1]]; temp0.m128i_u32[2] = table[temp0.m128i_i32[2]]; temp0.m128i_u32[3] = table[temp0.m128i_i32[3]]; \
8774 temp1.m128i_u32[0] = table[temp1.m128i_i32[0]]; temp1.m128i_u32[1] = table[temp1.m128i_i32[1]]; temp1.m128i_u32[2] = table[temp1.m128i_i32[2]]; temp1.m128i_u32[3] = table[temp1.m128i_i32[3]]; \
8775 v0 = temp0.m128i_i128; \
8776 v1 = temp1.m128i_i128; \
8779#define stbir__simdi_table_lookup3( v0,v1,v2, table ) \
8781 stbir__simdi_u32 temp0,temp1,temp2; \
8782 temp0.m128i_i128 = v0; \
8783 temp1.m128i_i128 = v1; \
8784 temp2.m128i_i128 = v2; \
8785 temp0.m128i_u32[0] = table[temp0.m128i_i32[0]]; temp0.m128i_u32[1] = table[temp0.m128i_i32[1]]; temp0.m128i_u32[2] = table[temp0.m128i_i32[2]]; temp0.m128i_u32[3] = table[temp0.m128i_i32[3]]; \
8786 temp1.m128i_u32[0] = table[temp1.m128i_i32[0]]; temp1.m128i_u32[1] = table[temp1.m128i_i32[1]]; temp1.m128i_u32[2] = table[temp1.m128i_i32[2]]; temp1.m128i_u32[3] = table[temp1.m128i_i32[3]]; \
8787 temp2.m128i_u32[0] = table[temp2.m128i_i32[0]]; temp2.m128i_u32[1] = table[temp2.m128i_i32[1]]; temp2.m128i_u32[2] = table[temp2.m128i_i32[2]]; temp2.m128i_u32[3] = table[temp2.m128i_i32[3]]; \
8788 v0 = temp0.m128i_i128; \
8789 v1 = temp1.m128i_i128; \
8790 v2 = temp2.m128i_i128; \
8793#define stbir__simdi_table_lookup4( v0,v1,v2,v3, table ) \
8795 stbir__simdi_u32 temp0,temp1,temp2,temp3; \
8796 temp0.m128i_i128 = v0; \
8797 temp1.m128i_i128 = v1; \
8798 temp2.m128i_i128 = v2; \
8799 temp3.m128i_i128 = v3; \
8800 temp0.m128i_u32[0] = table[temp0.m128i_i32[0]]; temp0.m128i_u32[1] = table[temp0.m128i_i32[1]]; temp0.m128i_u32[2] = table[temp0.m128i_i32[2]]; temp0.m128i_u32[3] = table[temp0.m128i_i32[3]]; \
8801 temp1.m128i_u32[0] = table[temp1.m128i_i32[0]]; temp1.m128i_u32[1] = table[temp1.m128i_i32[1]]; temp1.m128i_u32[2] = table[temp1.m128i_i32[2]]; temp1.m128i_u32[3] = table[temp1.m128i_i32[3]]; \
8802 temp2.m128i_u32[0] = table[temp2.m128i_i32[0]]; temp2.m128i_u32[1] = table[temp2.m128i_i32[1]]; temp2.m128i_u32[2] = table[temp2.m128i_i32[2]]; temp2.m128i_u32[3] = table[temp2.m128i_i32[3]]; \
8803 temp3.m128i_u32[0] = table[temp3.m128i_i32[0]]; temp3.m128i_u32[1] = table[temp3.m128i_i32[1]]; temp3.m128i_u32[2] = table[temp3.m128i_i32[2]]; temp3.m128i_u32[3] = table[temp3.m128i_i32[3]]; \
8804 v0 = temp0.m128i_i128; \
8805 v1 = temp1.m128i_i128; \
8806 v2 = temp2.m128i_i128; \
8807 v3 = temp3.m128i_i128; \
8810static void STBIR__CODER_NAME( stbir__encode_uint8_srgb )(
void * outputp,
int width_times_channels,
float const * encode )
8812 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned char*) outputp;
8813 unsigned char * end_output = ( (
unsigned char*) output ) + width_times_channels;
8817 if ( width_times_channels >= 16 )
8819 float const * end_encode_m16 = encode + width_times_channels - 16;
8821 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
8824 stbir__simdf f0, f1, f2, f3;
8825 stbir__simdi i0, i1, i2, i3;
8826 STBIR_SIMD_NO_UNROLL(encode);
8828 stbir__simdf_load4_transposed( f0, f1, f2, f3, encode );
8830 stbir__min_max_shift20( i0, f0 );
8831 stbir__min_max_shift20( i1, f1 );
8832 stbir__min_max_shift20( i2, f2 );
8833 stbir__min_max_shift20( i3, f3 );
8835 stbir__simdi_table_lookup4( i0, i1, i2, i3, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );
8837 stbir__linear_to_srgb_finish( i0, f0 );
8838 stbir__linear_to_srgb_finish( i1, f1 );
8839 stbir__linear_to_srgb_finish( i2, f2 );
8840 stbir__linear_to_srgb_finish( i3, f3 );
8842 stbir__interleave_pack_and_store_16_u8( output, STBIR_strs_join1(i, ,stbir__encode_order0), STBIR_strs_join1(i, ,stbir__encode_order1), STBIR_strs_join1(i, ,stbir__encode_order2), STBIR_strs_join1(i, ,stbir__encode_order3) );
8846 if ( output <= end_output )
8848 if ( output == ( end_output + 16 ) )
8850 output = end_output;
8851 encode = end_encode_m16;
8858 #if stbir__coder_min_num != 3
8860 STBIR_SIMD_NO_UNROLL_LOOP_START
8861 while ( output <= end_output )
8863 STBIR_SIMD_NO_UNROLL(encode);
8865 output[0-4] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order0] );
8866 output[1-4] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order1] );
8867 output[2-4] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order2] );
8868 output[3-4] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order3] );
8877 #if stbir__coder_min_num < 4
8878 STBIR_NO_UNROLL_LOOP_START
8879 while( output < end_output )
8881 STBIR_NO_UNROLL(encode);
8882 output[0] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order0] );
8883 #if stbir__coder_min_num >= 2
8884 output[1] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order1] );
8886 #if stbir__coder_min_num >= 3
8887 output[2] = stbir__linear_to_srgb_uchar( encode[stbir__encode_order2] );
8889 output += stbir__coder_min_num;
8890 encode += stbir__coder_min_num;
8895#if ( stbir__coder_min_num == 4 ) || ( ( stbir__coder_min_num == 1 ) && ( !defined(stbir__decode_swizzle) ) )
8897static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb4_linearalpha)(
float * decodep,
int width_times_channels,
void const * inputp )
8899 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
8900 float * decode_end = (
float*) decode + width_times_channels;
8901 unsigned char const * input = (
unsigned char const *)inputp;
8904 decode[0] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0] ];
8905 decode[1] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order1] ];
8906 decode[2] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order2] ];
8907 decode[3] = ( (float) input[stbir__decode_order3] ) * stbir__max_uint8_as_float_inverted;
8910 }
while( decode < decode_end );
8915static void STBIR__CODER_NAME( stbir__encode_uint8_srgb4_linearalpha )(
void * outputp,
int width_times_channels,
float const * encode )
8917 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned char*) outputp;
8918 unsigned char * end_output = ( (
unsigned char*) output ) + width_times_channels;
8922 if ( width_times_channels >= 16 )
8924 float const * end_encode_m16 = encode + width_times_channels - 16;
8926 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
8929 stbir__simdf f0, f1, f2, f3;
8930 stbir__simdi i0, i1, i2, i3;
8932 STBIR_SIMD_NO_UNROLL(encode);
8933 stbir__simdf_load4_transposed( f0, f1, f2, f3, encode );
8935 stbir__min_max_shift20( i0, f0 );
8936 stbir__min_max_shift20( i1, f1 );
8937 stbir__min_max_shift20( i2, f2 );
8938 stbir__scale_and_convert( i3, f3 );
8940 stbir__simdi_table_lookup3( i0, i1, i2, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );
8942 stbir__linear_to_srgb_finish( i0, f0 );
8943 stbir__linear_to_srgb_finish( i1, f1 );
8944 stbir__linear_to_srgb_finish( i2, f2 );
8946 stbir__interleave_pack_and_store_16_u8( output, STBIR_strs_join1(i, ,stbir__encode_order0), STBIR_strs_join1(i, ,stbir__encode_order1), STBIR_strs_join1(i, ,stbir__encode_order2), STBIR_strs_join1(i, ,stbir__encode_order3) );
8951 if ( output <= end_output )
8953 if ( output == ( end_output + 16 ) )
8955 output = end_output;
8956 encode = end_encode_m16;
8962 STBIR_SIMD_NO_UNROLL_LOOP_START
8965 STBIR_SIMD_NO_UNROLL(encode);
8967 output[stbir__decode_order0] = stbir__linear_to_srgb_uchar( encode[0] );
8968 output[stbir__decode_order1] = stbir__linear_to_srgb_uchar( encode[1] );
8969 output[stbir__decode_order2] = stbir__linear_to_srgb_uchar( encode[2] );
8971 f = encode[3] * stbir__max_uint8_as_float + 0.5f;
8972 STBIR_CLAMP(f, 0, 255);
8973 output[stbir__decode_order3] = (
unsigned char) f;
8977 }
while( output < end_output );
8982#if ( stbir__coder_min_num == 2 ) || ( ( stbir__coder_min_num == 1 ) && ( !defined(stbir__decode_swizzle) ) )
8984static float * STBIR__CODER_NAME(stbir__decode_uint8_srgb2_linearalpha)(
float * decodep,
int width_times_channels,
void const * inputp )
8986 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
8987 float * decode_end = (
float*) decode + width_times_channels;
8988 unsigned char const * input = (
unsigned char const *)inputp;
8991 while( decode <= decode_end )
8993 decode[0-4] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0] ];
8994 decode[1-4] = ( (float) input[stbir__decode_order1] ) * stbir__max_uint8_as_float_inverted;
8995 decode[2-4] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0+2] ];
8996 decode[3-4] = ( (float) input[stbir__decode_order1+2] ) * stbir__max_uint8_as_float_inverted;
9001 if( decode < decode_end )
9003 decode[0] = stbir__srgb_uchar_to_linear_float[ input[stbir__decode_order0] ];
9004 decode[1] = ( (float) input[stbir__decode_order1] ) * stbir__max_uint8_as_float_inverted;
9009static void STBIR__CODER_NAME( stbir__encode_uint8_srgb2_linearalpha )(
void * outputp,
int width_times_channels,
float const * encode )
9011 unsigned char STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned char*) outputp;
9012 unsigned char * end_output = ( (
unsigned char*) output ) + width_times_channels;
9016 if ( width_times_channels >= 16 )
9018 float const * end_encode_m16 = encode + width_times_channels - 16;
9020 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
9023 stbir__simdf f0, f1, f2, f3;
9024 stbir__simdi i0, i1, i2, i3;
9026 STBIR_SIMD_NO_UNROLL(encode);
9027 stbir__simdf_load4_transposed( f0, f1, f2, f3, encode );
9029 stbir__min_max_shift20( i0, f0 );
9030 stbir__scale_and_convert( i1, f1 );
9031 stbir__min_max_shift20( i2, f2 );
9032 stbir__scale_and_convert( i3, f3 );
9034 stbir__simdi_table_lookup2( i0, i2, ( fp32_to_srgb8_tab4 - (127-13)*8 ) );
9036 stbir__linear_to_srgb_finish( i0, f0 );
9037 stbir__linear_to_srgb_finish( i2, f2 );
9039 stbir__interleave_pack_and_store_16_u8( output, STBIR_strs_join1(i, ,stbir__encode_order0), STBIR_strs_join1(i, ,stbir__encode_order1), STBIR_strs_join1(i, ,stbir__encode_order2), STBIR_strs_join1(i, ,stbir__encode_order3) );
9043 if ( output <= end_output )
9045 if ( output == ( end_output + 16 ) )
9047 output = end_output;
9048 encode = end_encode_m16;
9054 STBIR_SIMD_NO_UNROLL_LOOP_START
9057 STBIR_SIMD_NO_UNROLL(encode);
9059 output[stbir__decode_order0] = stbir__linear_to_srgb_uchar( encode[0] );
9061 f = encode[1] * stbir__max_uint8_as_float + 0.5f;
9062 STBIR_CLAMP(f, 0, 255);
9063 output[stbir__decode_order1] = (
unsigned char) f;
9067 }
while( output < end_output );
9072static float * STBIR__CODER_NAME(stbir__decode_uint16_linear_scaled)(
float * decodep,
int width_times_channels,
void const * inputp )
9074 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
9075 float * decode_end = (
float*) decode + width_times_channels;
9076 unsigned short const * input = (
unsigned short const *)inputp;
9079 unsigned short const * end_input_m8 = input + width_times_channels - 8;
9080 if ( width_times_channels >= 8 )
9083 STBIR_NO_UNROLL_LOOP_START_INF_FOR
9087 stbir__simdi i; stbir__simdi8 o;
9089 STBIR_NO_UNROLL(decode);
9090 stbir__simdi_load( i, input );
9091 stbir__simdi8_expand_u16_to_u32( o, i );
9092 stbir__simdi8_convert_i32_to_float( of, o );
9093 stbir__simdf8_mult( of, of, STBIR_max_uint16_as_float_inverted8);
9094 stbir__decode_simdf8_flip( of );
9095 stbir__simdf8_store( decode + 0, of );
9097 stbir__simdi i, o0, o1;
9098 stbir__simdf of0, of1;
9099 STBIR_NO_UNROLL(decode);
9100 stbir__simdi_load( i, input );
9101 stbir__simdi_expand_u16_to_u32( o0,o1,i );
9102 stbir__simdi_convert_i32_to_float( of0, o0 );
9103 stbir__simdi_convert_i32_to_float( of1, o1 );
9104 stbir__simdf_mult( of0, of0, STBIR__CONSTF(STBIR_max_uint16_as_float_inverted) );
9105 stbir__simdf_mult( of1, of1, STBIR__CONSTF(STBIR_max_uint16_as_float_inverted));
9106 stbir__decode_simdf4_flip( of0 );
9107 stbir__decode_simdf4_flip( of1 );
9108 stbir__simdf_store( decode + 0, of0 );
9109 stbir__simdf_store( decode + 4, of1 );
9113 if ( decode <= decode_end )
9115 if ( decode == ( decode_end + 8 ) )
9117 decode = decode_end;
9118 input = end_input_m8;
9120 return decode_end + 8;
9125 #if stbir__coder_min_num != 3
9127 STBIR_SIMD_NO_UNROLL_LOOP_START
9128 while( decode <= decode_end )
9130 STBIR_SIMD_NO_UNROLL(decode);
9131 decode[0-4] = ((float)(input[stbir__decode_order0])) * stbir__max_uint16_as_float_inverted;
9132 decode[1-4] = ((float)(input[stbir__decode_order1])) * stbir__max_uint16_as_float_inverted;
9133 decode[2-4] = ((float)(input[stbir__decode_order2])) * stbir__max_uint16_as_float_inverted;
9134 decode[3-4] = ((float)(input[stbir__decode_order3])) * stbir__max_uint16_as_float_inverted;
9142 #if stbir__coder_min_num < 4
9143 STBIR_NO_UNROLL_LOOP_START
9144 while( decode < decode_end )
9146 STBIR_NO_UNROLL(decode);
9147 decode[0] = ((float)(input[stbir__decode_order0])) * stbir__max_uint16_as_float_inverted;
9148 #if stbir__coder_min_num >= 2
9149 decode[1] = ((float)(input[stbir__decode_order1])) * stbir__max_uint16_as_float_inverted;
9151 #if stbir__coder_min_num >= 3
9152 decode[2] = ((float)(input[stbir__decode_order2])) * stbir__max_uint16_as_float_inverted;
9154 decode += stbir__coder_min_num;
9155 input += stbir__coder_min_num;
9162static void STBIR__CODER_NAME(stbir__encode_uint16_linear_scaled)(
void * outputp,
int width_times_channels,
float const * encode )
9164 unsigned short STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned short*) outputp;
9165 unsigned short * end_output = ( (
unsigned short*) output ) + width_times_channels;
9169 if ( width_times_channels >= stbir__simdfX_float_count*2 )
9171 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;
9172 end_output -= stbir__simdfX_float_count*2;
9173 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
9176 stbir__simdfX e0, e1;
9178 STBIR_SIMD_NO_UNROLL(encode);
9179 stbir__simdfX_madd_mem( e0, STBIR_simd_point5X, STBIR_max_uint16_as_floatX, encode );
9180 stbir__simdfX_madd_mem( e1, STBIR_simd_point5X, STBIR_max_uint16_as_floatX, encode+stbir__simdfX_float_count );
9181 stbir__encode_simdfX_unflip( e0 );
9182 stbir__encode_simdfX_unflip( e1 );
9183 stbir__simdfX_pack_to_words( i, e0, e1 );
9184 stbir__simdiX_store( output, i );
9185 encode += stbir__simdfX_float_count*2;
9186 output += stbir__simdfX_float_count*2;
9187 if ( output <= end_output )
9189 if ( output == ( end_output + stbir__simdfX_float_count*2 ) )
9191 output = end_output;
9192 encode = end_encode_m8;
9199 #if stbir__coder_min_num != 3
9201 STBIR_NO_UNROLL_LOOP_START
9202 while( output <= end_output )
9206 STBIR_NO_UNROLL(encode);
9207 stbir__simdf_load( e, encode );
9208 stbir__simdf_madd( e, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint16_as_float), e );
9209 stbir__encode_simdf4_unflip( e );
9210 stbir__simdf_pack_to_8words( i, e, e );
9211 stbir__simdi_store2( output-4, i );
9219 #if stbir__coder_min_num < 4
9220 STBIR_NO_UNROLL_LOOP_START
9221 while( output < end_output )
9224 STBIR_NO_UNROLL(encode);
9225 stbir__simdf_madd1_mem( e, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint16_as_float), encode+stbir__encode_order0 ); output[0] = stbir__simdf_convert_float_to_short( e );
9226 #if stbir__coder_min_num >= 2
9227 stbir__simdf_madd1_mem( e, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint16_as_float), encode+stbir__encode_order1 ); output[1] = stbir__simdf_convert_float_to_short( e );
9229 #if stbir__coder_min_num >= 3
9230 stbir__simdf_madd1_mem( e, STBIR__CONSTF(STBIR_simd_point5), STBIR__CONSTF(STBIR_max_uint16_as_float), encode+stbir__encode_order2 ); output[2] = stbir__simdf_convert_float_to_short( e );
9232 output += stbir__coder_min_num;
9233 encode += stbir__coder_min_num;
9240 #if stbir__coder_min_num != 3
9242 STBIR_SIMD_NO_UNROLL_LOOP_START
9243 while( output <= end_output )
9246 STBIR_SIMD_NO_UNROLL(encode);
9247 f = encode[stbir__encode_order0] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[0-4] = (
unsigned short)f;
9248 f = encode[stbir__encode_order1] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[1-4] = (
unsigned short)f;
9249 f = encode[stbir__encode_order2] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[2-4] = (
unsigned short)f;
9250 f = encode[stbir__encode_order3] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[3-4] = (
unsigned short)f;
9258 #if stbir__coder_min_num < 4
9259 STBIR_NO_UNROLL_LOOP_START
9260 while( output < end_output )
9263 STBIR_NO_UNROLL(encode);
9264 f = encode[stbir__encode_order0] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[0] = (
unsigned short)f;
9265 #if stbir__coder_min_num >= 2
9266 f = encode[stbir__encode_order1] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[1] = (
unsigned short)f;
9268 #if stbir__coder_min_num >= 3
9269 f = encode[stbir__encode_order2] * stbir__max_uint16_as_float + 0.5f; STBIR_CLAMP(f, 0, 65535); output[2] = (
unsigned short)f;
9271 output += stbir__coder_min_num;
9272 encode += stbir__coder_min_num;
9278static float * STBIR__CODER_NAME(stbir__decode_uint16_linear)(
float * decodep,
int width_times_channels,
void const * inputp )
9280 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
9281 float * decode_end = (
float*) decode + width_times_channels;
9282 unsigned short const * input = (
unsigned short const *)inputp;
9285 unsigned short const * end_input_m8 = input + width_times_channels - 8;
9286 if ( width_times_channels >= 8 )
9289 STBIR_NO_UNROLL_LOOP_START_INF_FOR
9293 stbir__simdi i; stbir__simdi8 o;
9295 STBIR_NO_UNROLL(decode);
9296 stbir__simdi_load( i, input );
9297 stbir__simdi8_expand_u16_to_u32( o, i );
9298 stbir__simdi8_convert_i32_to_float( of, o );
9299 stbir__decode_simdf8_flip( of );
9300 stbir__simdf8_store( decode + 0, of );
9302 stbir__simdi i, o0, o1;
9303 stbir__simdf of0, of1;
9304 STBIR_NO_UNROLL(decode);
9305 stbir__simdi_load( i, input );
9306 stbir__simdi_expand_u16_to_u32( o0, o1, i );
9307 stbir__simdi_convert_i32_to_float( of0, o0 );
9308 stbir__simdi_convert_i32_to_float( of1, o1 );
9309 stbir__decode_simdf4_flip( of0 );
9310 stbir__decode_simdf4_flip( of1 );
9311 stbir__simdf_store( decode + 0, of0 );
9312 stbir__simdf_store( decode + 4, of1 );
9316 if ( decode <= decode_end )
9318 if ( decode == ( decode_end + 8 ) )
9320 decode = decode_end;
9321 input = end_input_m8;
9323 return decode_end + 8;
9328 #if stbir__coder_min_num != 3
9330 STBIR_SIMD_NO_UNROLL_LOOP_START
9331 while( decode <= decode_end )
9333 STBIR_SIMD_NO_UNROLL(decode);
9334 decode[0-4] = ((float)(input[stbir__decode_order0]));
9335 decode[1-4] = ((float)(input[stbir__decode_order1]));
9336 decode[2-4] = ((float)(input[stbir__decode_order2]));
9337 decode[3-4] = ((float)(input[stbir__decode_order3]));
9345 #if stbir__coder_min_num < 4
9346 STBIR_NO_UNROLL_LOOP_START
9347 while( decode < decode_end )
9349 STBIR_NO_UNROLL(decode);
9350 decode[0] = ((float)(input[stbir__decode_order0]));
9351 #if stbir__coder_min_num >= 2
9352 decode[1] = ((float)(input[stbir__decode_order1]));
9354 #if stbir__coder_min_num >= 3
9355 decode[2] = ((float)(input[stbir__decode_order2]));
9357 decode += stbir__coder_min_num;
9358 input += stbir__coder_min_num;
9364static void STBIR__CODER_NAME(stbir__encode_uint16_linear)(
void * outputp,
int width_times_channels,
float const * encode )
9366 unsigned short STBIR_SIMD_STREAMOUT_PTR( * ) output = (
unsigned short*) outputp;
9367 unsigned short * end_output = ( (
unsigned short*) output ) + width_times_channels;
9371 if ( width_times_channels >= stbir__simdfX_float_count*2 )
9373 float const * end_encode_m8 = encode + width_times_channels - stbir__simdfX_float_count*2;
9374 end_output -= stbir__simdfX_float_count*2;
9375 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
9378 stbir__simdfX e0, e1;
9380 STBIR_SIMD_NO_UNROLL(encode);
9381 stbir__simdfX_add_mem( e0, STBIR_simd_point5X, encode );
9382 stbir__simdfX_add_mem( e1, STBIR_simd_point5X, encode+stbir__simdfX_float_count );
9383 stbir__encode_simdfX_unflip( e0 );
9384 stbir__encode_simdfX_unflip( e1 );
9385 stbir__simdfX_pack_to_words( i, e0, e1 );
9386 stbir__simdiX_store( output, i );
9387 encode += stbir__simdfX_float_count*2;
9388 output += stbir__simdfX_float_count*2;
9389 if ( output <= end_output )
9391 if ( output == ( end_output + stbir__simdfX_float_count*2 ) )
9393 output = end_output;
9394 encode = end_encode_m8;
9401 #if stbir__coder_min_num != 3
9403 STBIR_NO_UNROLL_LOOP_START
9404 while( output <= end_output )
9408 STBIR_NO_UNROLL(encode);
9409 stbir__simdf_load( e, encode );
9410 stbir__simdf_add( e, STBIR__CONSTF(STBIR_simd_point5), e );
9411 stbir__encode_simdf4_unflip( e );
9412 stbir__simdf_pack_to_8words( i, e, e );
9413 stbir__simdi_store2( output-4, i );
9423 #if stbir__coder_min_num != 3
9425 STBIR_SIMD_NO_UNROLL_LOOP_START
9426 while( output <= end_output )
9429 STBIR_SIMD_NO_UNROLL(encode);
9430 f = encode[stbir__encode_order0] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[0-4] = (
unsigned short)f;
9431 f = encode[stbir__encode_order1] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[1-4] = (
unsigned short)f;
9432 f = encode[stbir__encode_order2] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[2-4] = (
unsigned short)f;
9433 f = encode[stbir__encode_order3] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[3-4] = (
unsigned short)f;
9443 #if stbir__coder_min_num < 4
9444 STBIR_NO_UNROLL_LOOP_START
9445 while( output < end_output )
9448 STBIR_NO_UNROLL(encode);
9449 f = encode[stbir__encode_order0] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[0] = (
unsigned short)f;
9450 #if stbir__coder_min_num >= 2
9451 f = encode[stbir__encode_order1] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[1] = (
unsigned short)f;
9453 #if stbir__coder_min_num >= 3
9454 f = encode[stbir__encode_order2] + 0.5f; STBIR_CLAMP(f, 0, 65535); output[2] = (
unsigned short)f;
9456 output += stbir__coder_min_num;
9457 encode += stbir__coder_min_num;
9462static float * STBIR__CODER_NAME(stbir__decode_half_float_linear)(
float * decodep,
int width_times_channels,
void const * inputp )
9464 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
9465 float * decode_end = (
float*) decode + width_times_channels;
9466 stbir__FP16 const * input = (stbir__FP16 const *)inputp;
9469 if ( width_times_channels >= 8 )
9471 stbir__FP16
const * end_input_m8 = input + width_times_channels - 8;
9473 STBIR_NO_UNROLL_LOOP_START_INF_FOR
9476 STBIR_NO_UNROLL(decode);
9478 stbir__half_to_float_SIMD( decode, input );
9479 #ifdef stbir__decode_swizzle
9483 stbir__simdf8_load( of, decode );
9484 stbir__decode_simdf8_flip( of );
9485 stbir__simdf8_store( decode, of );
9489 stbir__simdf of0,of1;
9490 stbir__simdf_load( of0, decode );
9491 stbir__simdf_load( of1, decode+4 );
9492 stbir__decode_simdf4_flip( of0 );
9493 stbir__decode_simdf4_flip( of1 );
9494 stbir__simdf_store( decode, of0 );
9495 stbir__simdf_store( decode+4, of1 );
9501 if ( decode <= decode_end )
9503 if ( decode == ( decode_end + 8 ) )
9505 decode = decode_end;
9506 input = end_input_m8;
9508 return decode_end + 8;
9513 #if stbir__coder_min_num != 3
9515 STBIR_SIMD_NO_UNROLL_LOOP_START
9516 while( decode <= decode_end )
9518 STBIR_SIMD_NO_UNROLL(decode);
9519 decode[0-4] = stbir__half_to_float(input[stbir__decode_order0]);
9520 decode[1-4] = stbir__half_to_float(input[stbir__decode_order1]);
9521 decode[2-4] = stbir__half_to_float(input[stbir__decode_order2]);
9522 decode[3-4] = stbir__half_to_float(input[stbir__decode_order3]);
9530 #if stbir__coder_min_num < 4
9531 STBIR_NO_UNROLL_LOOP_START
9532 while( decode < decode_end )
9534 STBIR_NO_UNROLL(decode);
9535 decode[0] = stbir__half_to_float(input[stbir__decode_order0]);
9536 #if stbir__coder_min_num >= 2
9537 decode[1] = stbir__half_to_float(input[stbir__decode_order1]);
9539 #if stbir__coder_min_num >= 3
9540 decode[2] = stbir__half_to_float(input[stbir__decode_order2]);
9542 decode += stbir__coder_min_num;
9543 input += stbir__coder_min_num;
9549static void STBIR__CODER_NAME( stbir__encode_half_float_linear )(
void * outputp,
int width_times_channels,
float const * encode )
9551 stbir__FP16 STBIR_SIMD_STREAMOUT_PTR( * ) output = (stbir__FP16*) outputp;
9552 stbir__FP16 * end_output = ( (stbir__FP16*) output ) + width_times_channels;
9555 if ( width_times_channels >= 8 )
9557 float const * end_encode_m8 = encode + width_times_channels - 8;
9559 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
9562 STBIR_SIMD_NO_UNROLL(encode);
9563 #ifdef stbir__decode_swizzle
9567 stbir__simdf8_load( of, encode );
9568 stbir__encode_simdf8_unflip( of );
9569 stbir__float_to_half_SIMD( output, (
float*)&of );
9574 stbir__simdf_load( of[0], encode );
9575 stbir__simdf_load( of[1], encode+4 );
9576 stbir__encode_simdf4_unflip( of[0] );
9577 stbir__encode_simdf4_unflip( of[1] );
9578 stbir__float_to_half_SIMD( output, (
float*)of );
9582 stbir__float_to_half_SIMD( output, encode );
9586 if ( output <= end_output )
9588 if ( output == ( end_output + 8 ) )
9590 output = end_output;
9591 encode = end_encode_m8;
9598 #if stbir__coder_min_num != 3
9600 STBIR_SIMD_NO_UNROLL_LOOP_START
9601 while( output <= end_output )
9603 STBIR_SIMD_NO_UNROLL(output);
9604 output[0-4] = stbir__float_to_half(encode[stbir__encode_order0]);
9605 output[1-4] = stbir__float_to_half(encode[stbir__encode_order1]);
9606 output[2-4] = stbir__float_to_half(encode[stbir__encode_order2]);
9607 output[3-4] = stbir__float_to_half(encode[stbir__encode_order3]);
9615 #if stbir__coder_min_num < 4
9616 STBIR_NO_UNROLL_LOOP_START
9617 while( output < end_output )
9619 STBIR_NO_UNROLL(output);
9620 output[0] = stbir__float_to_half(encode[stbir__encode_order0]);
9621 #if stbir__coder_min_num >= 2
9622 output[1] = stbir__float_to_half(encode[stbir__encode_order1]);
9624 #if stbir__coder_min_num >= 3
9625 output[2] = stbir__float_to_half(encode[stbir__encode_order2]);
9627 output += stbir__coder_min_num;
9628 encode += stbir__coder_min_num;
9633static float * STBIR__CODER_NAME(stbir__decode_float_linear)(
float * decodep,
int width_times_channels,
void const * inputp )
9635 #ifdef stbir__decode_swizzle
9636 float STBIR_STREAMOUT_PTR( * ) decode = decodep;
9637 float * decode_end = (
float*) decode + width_times_channels;
9638 float const * input = (
float const *)inputp;
9641 if ( width_times_channels >= 16 )
9643 float const * end_input_m16 = input + width_times_channels - 16;
9645 STBIR_NO_UNROLL_LOOP_START_INF_FOR
9648 STBIR_NO_UNROLL(decode);
9649 #ifdef stbir__decode_swizzle
9652 stbir__simdf8 of0,of1;
9653 stbir__simdf8_load( of0, input );
9654 stbir__simdf8_load( of1, input+8 );
9655 stbir__decode_simdf8_flip( of0 );
9656 stbir__decode_simdf8_flip( of1 );
9657 stbir__simdf8_store( decode, of0 );
9658 stbir__simdf8_store( decode+8, of1 );
9662 stbir__simdf of0,of1,of2,of3;
9663 stbir__simdf_load( of0, input );
9664 stbir__simdf_load( of1, input+4 );
9665 stbir__simdf_load( of2, input+8 );
9666 stbir__simdf_load( of3, input+12 );
9667 stbir__decode_simdf4_flip( of0 );
9668 stbir__decode_simdf4_flip( of1 );
9669 stbir__decode_simdf4_flip( of2 );
9670 stbir__decode_simdf4_flip( of3 );
9671 stbir__simdf_store( decode, of0 );
9672 stbir__simdf_store( decode+4, of1 );
9673 stbir__simdf_store( decode+8, of2 );
9674 stbir__simdf_store( decode+12, of3 );
9680 if ( decode <= decode_end )
9682 if ( decode == ( decode_end + 16 ) )
9684 decode = decode_end;
9685 input = end_input_m16;
9687 return decode_end + 16;
9692 #if stbir__coder_min_num != 3
9694 STBIR_SIMD_NO_UNROLL_LOOP_START
9695 while( decode <= decode_end )
9697 STBIR_SIMD_NO_UNROLL(decode);
9698 decode[0-4] = input[stbir__decode_order0];
9699 decode[1-4] = input[stbir__decode_order1];
9700 decode[2-4] = input[stbir__decode_order2];
9701 decode[3-4] = input[stbir__decode_order3];
9709 #if stbir__coder_min_num < 4
9710 STBIR_NO_UNROLL_LOOP_START
9711 while( decode < decode_end )
9713 STBIR_NO_UNROLL(decode);
9714 decode[0] = input[stbir__decode_order0];
9715 #if stbir__coder_min_num >= 2
9716 decode[1] = input[stbir__decode_order1];
9718 #if stbir__coder_min_num >= 3
9719 decode[2] = input[stbir__decode_order2];
9721 decode += stbir__coder_min_num;
9722 input += stbir__coder_min_num;
9729 if ( (
void*)decodep != inputp )
9730 STBIR_MEMCPY( decodep, inputp, width_times_channels *
sizeof(
float ) );
9732 return decodep + width_times_channels;
9737static void STBIR__CODER_NAME( stbir__encode_float_linear )(
void * outputp,
int width_times_channels,
float const * encode )
9739 #if !defined( STBIR_FLOAT_HIGH_CLAMP ) && !defined(STBIR_FLOAT_LOW_CLAMP) && !defined(stbir__decode_swizzle)
9741 if ( (
void*)outputp != (
void*) encode )
9742 STBIR_MEMCPY( outputp, encode, width_times_channels *
sizeof(
float ) );
9746 float STBIR_SIMD_STREAMOUT_PTR( * ) output = (
float*) outputp;
9747 float * end_output = ( (
float*) output ) + width_times_channels;
9749 #ifdef STBIR_FLOAT_HIGH_CLAMP
9750 #define stbir_scalar_hi_clamp( v ) if ( v > STBIR_FLOAT_HIGH_CLAMP ) v = STBIR_FLOAT_HIGH_CLAMP;
9752 #define stbir_scalar_hi_clamp( v )
9754 #ifdef STBIR_FLOAT_LOW_CLAMP
9755 #define stbir_scalar_lo_clamp( v ) if ( v < STBIR_FLOAT_LOW_CLAMP ) v = STBIR_FLOAT_LOW_CLAMP;
9757 #define stbir_scalar_lo_clamp( v )
9762 #ifdef STBIR_FLOAT_HIGH_CLAMP
9763 const stbir__simdfX high_clamp = stbir__simdf_frepX(STBIR_FLOAT_HIGH_CLAMP);
9765 #ifdef STBIR_FLOAT_LOW_CLAMP
9766 const stbir__simdfX low_clamp = stbir__simdf_frepX(STBIR_FLOAT_LOW_CLAMP);
9769 if ( width_times_channels >= ( stbir__simdfX_float_count * 2 ) )
9771 float const * end_encode_m8 = encode + width_times_channels - ( stbir__simdfX_float_count * 2 );
9772 end_output -= ( stbir__simdfX_float_count * 2 );
9773 STBIR_SIMD_NO_UNROLL_LOOP_START_INF_FOR
9776 stbir__simdfX e0, e1;
9777 STBIR_SIMD_NO_UNROLL(encode);
9778 stbir__simdfX_load( e0, encode );
9779 stbir__simdfX_load( e1, encode+stbir__simdfX_float_count );
9780#ifdef STBIR_FLOAT_HIGH_CLAMP
9781 stbir__simdfX_min( e0, e0, high_clamp );
9782 stbir__simdfX_min( e1, e1, high_clamp );
9784#ifdef STBIR_FLOAT_LOW_CLAMP
9785 stbir__simdfX_max( e0, e0, low_clamp );
9786 stbir__simdfX_max( e1, e1, low_clamp );
9788 stbir__encode_simdfX_unflip( e0 );
9789 stbir__encode_simdfX_unflip( e1 );
9790 stbir__simdfX_store( output, e0 );
9791 stbir__simdfX_store( output+stbir__simdfX_float_count, e1 );
9792 encode += stbir__simdfX_float_count * 2;
9793 output += stbir__simdfX_float_count * 2;
9794 if ( output <= end_output )
9796 if ( output == ( end_output + ( stbir__simdfX_float_count * 2 ) ) )
9798 output = end_output;
9799 encode = end_encode_m8;
9805 #if stbir__coder_min_num != 3
9807 STBIR_NO_UNROLL_LOOP_START
9808 while( output <= end_output )
9811 STBIR_NO_UNROLL(encode);
9812 stbir__simdf_load( e0, encode );
9813#ifdef STBIR_FLOAT_HIGH_CLAMP
9814 stbir__simdf_min( e0, e0, high_clamp );
9816#ifdef STBIR_FLOAT_LOW_CLAMP
9817 stbir__simdf_max( e0, e0, low_clamp );
9819 stbir__encode_simdf4_unflip( e0 );
9820 stbir__simdf_store( output-4, e0 );
9830 #if stbir__coder_min_num != 3
9832 STBIR_SIMD_NO_UNROLL_LOOP_START
9833 while( output <= end_output )
9836 STBIR_SIMD_NO_UNROLL(encode);
9837 e = encode[ stbir__encode_order0 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[0-4] = e;
9838 e = encode[ stbir__encode_order1 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[1-4] = e;
9839 e = encode[ stbir__encode_order2 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[2-4] = e;
9840 e = encode[ stbir__encode_order3 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[3-4] = e;
9851 #if stbir__coder_min_num < 4
9852 STBIR_NO_UNROLL_LOOP_START
9853 while( output < end_output )
9856 STBIR_NO_UNROLL(encode);
9857 e = encode[ stbir__encode_order0 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[0] = e;
9858 #if stbir__coder_min_num >= 2
9859 e = encode[ stbir__encode_order1 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[1] = e;
9861 #if stbir__coder_min_num >= 3
9862 e = encode[ stbir__encode_order2 ]; stbir_scalar_hi_clamp( e ); stbir_scalar_lo_clamp( e ); output[2] = e;
9864 output += stbir__coder_min_num;
9865 encode += stbir__coder_min_num;
9872#undef stbir__decode_suffix
9873#undef stbir__decode_simdf8_flip
9874#undef stbir__decode_simdf4_flip
9875#undef stbir__decode_order0
9876#undef stbir__decode_order1
9877#undef stbir__decode_order2
9878#undef stbir__decode_order3
9879#undef stbir__encode_order0
9880#undef stbir__encode_order1
9881#undef stbir__encode_order2
9882#undef stbir__encode_order3
9883#undef stbir__encode_simdf8_unflip
9884#undef stbir__encode_simdf4_unflip
9885#undef stbir__encode_simdfX_unflip
9886#undef STBIR__CODER_NAME
9887#undef stbir__coder_min_num
9888#undef stbir__decode_swizzle
9889#undef stbir_scalar_hi_clamp
9890#undef stbir_scalar_lo_clamp
9891#undef STB_IMAGE_RESIZE_DO_CODERS
9893#elif defined( STB_IMAGE_RESIZE_DO_VERTICALS)
9895#ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
9896#define STBIR_chans( start, end ) STBIR_strs_join14(start,STBIR__vertical_channels,end,_cont)
9898#define STBIR_chans( start, end ) STBIR_strs_join1(start,STBIR__vertical_channels,end)
9901#if STBIR__vertical_channels >= 1
9902#define stbIF0( code ) code
9904#define stbIF0( code )
9906#if STBIR__vertical_channels >= 2
9907#define stbIF1( code ) code
9909#define stbIF1( code )
9911#if STBIR__vertical_channels >= 3
9912#define stbIF2( code ) code
9914#define stbIF2( code )
9916#if STBIR__vertical_channels >= 4
9917#define stbIF3( code ) code
9919#define stbIF3( code )
9921#if STBIR__vertical_channels >= 5
9922#define stbIF4( code ) code
9924#define stbIF4( code )
9926#if STBIR__vertical_channels >= 6
9927#define stbIF5( code ) code
9929#define stbIF5( code )
9931#if STBIR__vertical_channels >= 7
9932#define stbIF6( code ) code
9934#define stbIF6( code )
9936#if STBIR__vertical_channels >= 8
9937#define stbIF7( code ) code
9939#define stbIF7( code )
9942static void STBIR_chans( stbir__vertical_scatter_with_,_coeffs)(
float ** outputs,
float const * vertical_coefficients,
float const * input,
float const * input_end )
9944 stbIF0(
float STBIR_SIMD_STREAMOUT_PTR( * ) output0 = outputs[0];
float c0s = vertical_coefficients[0]; )
9945 stbIF1(
float STBIR_SIMD_STREAMOUT_PTR( * ) output1 = outputs[1];
float c1s = vertical_coefficients[1]; )
9946 stbIF2(
float STBIR_SIMD_STREAMOUT_PTR( * ) output2 = outputs[2];
float c2s = vertical_coefficients[2]; )
9947 stbIF3(
float STBIR_SIMD_STREAMOUT_PTR( * ) output3 = outputs[3];
float c3s = vertical_coefficients[3]; )
9948 stbIF4(
float STBIR_SIMD_STREAMOUT_PTR( * ) output4 = outputs[4];
float c4s = vertical_coefficients[4]; )
9949 stbIF5(
float STBIR_SIMD_STREAMOUT_PTR( * ) output5 = outputs[5];
float c5s = vertical_coefficients[5]; )
9950 stbIF6(
float STBIR_SIMD_STREAMOUT_PTR( * ) output6 = outputs[6];
float c6s = vertical_coefficients[6]; )
9951 stbIF7(
float STBIR_SIMD_STREAMOUT_PTR( * ) output7 = outputs[7];
float c7s = vertical_coefficients[7]; )
9955 stbIF0(stbir__simdfX c0 = stbir__simdf_frepX( c0s ); )
9956 stbIF1(stbir__simdfX c1 = stbir__simdf_frepX( c1s ); )
9957 stbIF2(stbir__simdfX c2 = stbir__simdf_frepX( c2s ); )
9958 stbIF3(stbir__simdfX c3 = stbir__simdf_frepX( c3s ); )
9959 stbIF4(stbir__simdfX c4 = stbir__simdf_frepX( c4s ); )
9960 stbIF5(stbir__simdfX c5 = stbir__simdf_frepX( c5s ); )
9961 stbIF6(stbir__simdfX c6 = stbir__simdf_frepX( c6s ); )
9962 stbIF7(stbir__simdfX c7 = stbir__simdf_frepX( c7s ); )
9963 STBIR_SIMD_NO_UNROLL_LOOP_START
9964 while ( ( (
char*)input_end - (
char*) input ) >= (16*stbir__simdfX_float_count) )
9966 stbir__simdfX o0, o1, o2, o3, r0, r1, r2, r3;
9967 STBIR_SIMD_NO_UNROLL(output0);
9969 stbir__simdfX_load( r0, input ); stbir__simdfX_load( r1, input+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input+(3*stbir__simdfX_float_count) );
9971 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
9972 stbIF0( stbir__simdfX_load( o0, output0 ); stbir__simdfX_load( o1, output0+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output0+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output0+(3*stbir__simdfX_float_count) );
9973 stbir__simdfX_madd( o0, o0, r0, c0 ); stbir__simdfX_madd( o1, o1, r1, c0 ); stbir__simdfX_madd( o2, o2, r2, c0 ); stbir__simdfX_madd( o3, o3, r3, c0 );
9974 stbir__simdfX_store( output0, o0 ); stbir__simdfX_store( output0+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output0+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output0+(3*stbir__simdfX_float_count), o3 ); )
9975 stbIF1( stbir__simdfX_load( o0, output1 ); stbir__simdfX_load( o1, output1+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output1+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output1+(3*stbir__simdfX_float_count) );
9976 stbir__simdfX_madd( o0, o0, r0, c1 ); stbir__simdfX_madd( o1, o1, r1, c1 ); stbir__simdfX_madd( o2, o2, r2, c1 ); stbir__simdfX_madd( o3, o3, r3, c1 );
9977 stbir__simdfX_store( output1, o0 ); stbir__simdfX_store( output1+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output1+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output1+(3*stbir__simdfX_float_count), o3 ); )
9978 stbIF2( stbir__simdfX_load( o0, output2 ); stbir__simdfX_load( o1, output2+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output2+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output2+(3*stbir__simdfX_float_count) );
9979 stbir__simdfX_madd( o0, o0, r0, c2 ); stbir__simdfX_madd( o1, o1, r1, c2 ); stbir__simdfX_madd( o2, o2, r2, c2 ); stbir__simdfX_madd( o3, o3, r3, c2 );
9980 stbir__simdfX_store( output2, o0 ); stbir__simdfX_store( output2+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output2+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output2+(3*stbir__simdfX_float_count), o3 ); )
9981 stbIF3( stbir__simdfX_load( o0, output3 ); stbir__simdfX_load( o1, output3+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output3+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output3+(3*stbir__simdfX_float_count) );
9982 stbir__simdfX_madd( o0, o0, r0, c3 ); stbir__simdfX_madd( o1, o1, r1, c3 ); stbir__simdfX_madd( o2, o2, r2, c3 ); stbir__simdfX_madd( o3, o3, r3, c3 );
9983 stbir__simdfX_store( output3, o0 ); stbir__simdfX_store( output3+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output3+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output3+(3*stbir__simdfX_float_count), o3 ); )
9984 stbIF4( stbir__simdfX_load( o0, output4 ); stbir__simdfX_load( o1, output4+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output4+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output4+(3*stbir__simdfX_float_count) );
9985 stbir__simdfX_madd( o0, o0, r0, c4 ); stbir__simdfX_madd( o1, o1, r1, c4 ); stbir__simdfX_madd( o2, o2, r2, c4 ); stbir__simdfX_madd( o3, o3, r3, c4 );
9986 stbir__simdfX_store( output4, o0 ); stbir__simdfX_store( output4+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output4+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output4+(3*stbir__simdfX_float_count), o3 ); )
9987 stbIF5( stbir__simdfX_load( o0, output5 ); stbir__simdfX_load( o1, output5+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output5+(2*stbir__simdfX_float_count)); stbir__simdfX_load( o3, output5+(3*stbir__simdfX_float_count) );
9988 stbir__simdfX_madd( o0, o0, r0, c5 ); stbir__simdfX_madd( o1, o1, r1, c5 ); stbir__simdfX_madd( o2, o2, r2, c5 ); stbir__simdfX_madd( o3, o3, r3, c5 );
9989 stbir__simdfX_store( output5, o0 ); stbir__simdfX_store( output5+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output5+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output5+(3*stbir__simdfX_float_count), o3 ); )
9990 stbIF6( stbir__simdfX_load( o0, output6 ); stbir__simdfX_load( o1, output6+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output6+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output6+(3*stbir__simdfX_float_count) );
9991 stbir__simdfX_madd( o0, o0, r0, c6 ); stbir__simdfX_madd( o1, o1, r1, c6 ); stbir__simdfX_madd( o2, o2, r2, c6 ); stbir__simdfX_madd( o3, o3, r3, c6 );
9992 stbir__simdfX_store( output6, o0 ); stbir__simdfX_store( output6+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output6+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output6+(3*stbir__simdfX_float_count), o3 ); )
9993 stbIF7( stbir__simdfX_load( o0, output7 ); stbir__simdfX_load( o1, output7+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output7+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output7+(3*stbir__simdfX_float_count) );
9994 stbir__simdfX_madd( o0, o0, r0, c7 ); stbir__simdfX_madd( o1, o1, r1, c7 ); stbir__simdfX_madd( o2, o2, r2, c7 ); stbir__simdfX_madd( o3, o3, r3, c7 );
9995 stbir__simdfX_store( output7, o0 ); stbir__simdfX_store( output7+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output7+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output7+(3*stbir__simdfX_float_count), o3 ); )
9997 stbIF0( stbir__simdfX_mult( o0, r0, c0 ); stbir__simdfX_mult( o1, r1, c0 ); stbir__simdfX_mult( o2, r2, c0 ); stbir__simdfX_mult( o3, r3, c0 );
9998 stbir__simdfX_store( output0, o0 ); stbir__simdfX_store( output0+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output0+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output0+(3*stbir__simdfX_float_count), o3 ); )
9999 stbIF1( stbir__simdfX_mult( o0, r0, c1 ); stbir__simdfX_mult( o1, r1, c1 ); stbir__simdfX_mult( o2, r2, c1 ); stbir__simdfX_mult( o3, r3, c1 );
10000 stbir__simdfX_store( output1, o0 ); stbir__simdfX_store( output1+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output1+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output1+(3*stbir__simdfX_float_count), o3 ); )
10001 stbIF2( stbir__simdfX_mult( o0, r0, c2 ); stbir__simdfX_mult( o1, r1, c2 ); stbir__simdfX_mult( o2, r2, c2 ); stbir__simdfX_mult( o3, r3, c2 );
10002 stbir__simdfX_store( output2, o0 ); stbir__simdfX_store( output2+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output2+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output2+(3*stbir__simdfX_float_count), o3 ); )
10003 stbIF3( stbir__simdfX_mult( o0, r0, c3 ); stbir__simdfX_mult( o1, r1, c3 ); stbir__simdfX_mult( o2, r2, c3 ); stbir__simdfX_mult( o3, r3, c3 );
10004 stbir__simdfX_store( output3, o0 ); stbir__simdfX_store( output3+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output3+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output3+(3*stbir__simdfX_float_count), o3 ); )
10005 stbIF4( stbir__simdfX_mult( o0, r0, c4 ); stbir__simdfX_mult( o1, r1, c4 ); stbir__simdfX_mult( o2, r2, c4 ); stbir__simdfX_mult( o3, r3, c4 );
10006 stbir__simdfX_store( output4, o0 ); stbir__simdfX_store( output4+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output4+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output4+(3*stbir__simdfX_float_count), o3 ); )
10007 stbIF5( stbir__simdfX_mult( o0, r0, c5 ); stbir__simdfX_mult( o1, r1, c5 ); stbir__simdfX_mult( o2, r2, c5 ); stbir__simdfX_mult( o3, r3, c5 );
10008 stbir__simdfX_store( output5, o0 ); stbir__simdfX_store( output5+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output5+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output5+(3*stbir__simdfX_float_count), o3 ); )
10009 stbIF6( stbir__simdfX_mult( o0, r0, c6 ); stbir__simdfX_mult( o1, r1, c6 ); stbir__simdfX_mult( o2, r2, c6 ); stbir__simdfX_mult( o3, r3, c6 );
10010 stbir__simdfX_store( output6, o0 ); stbir__simdfX_store( output6+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output6+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output6+(3*stbir__simdfX_float_count), o3 ); )
10011 stbIF7( stbir__simdfX_mult( o0, r0, c7 ); stbir__simdfX_mult( o1, r1, c7 ); stbir__simdfX_mult( o2, r2, c7 ); stbir__simdfX_mult( o3, r3, c7 );
10012 stbir__simdfX_store( output7, o0 ); stbir__simdfX_store( output7+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output7+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output7+(3*stbir__simdfX_float_count), o3 ); )
10015 input += (4*stbir__simdfX_float_count);
10016 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); )
10018 STBIR_SIMD_NO_UNROLL_LOOP_START
10019 while ( ( (
char*)input_end - (
char*) input ) >= 16 )
10021 stbir__simdf o0, r0;
10022 STBIR_SIMD_NO_UNROLL(output0);
10024 stbir__simdf_load( r0, input );
10026 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10027 stbIF0( stbir__simdf_load( o0, output0 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c0 ) ); stbir__simdf_store( output0, o0 ); )
10028 stbIF1( stbir__simdf_load( o0, output1 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c1 ) ); stbir__simdf_store( output1, o0 ); )
10029 stbIF2( stbir__simdf_load( o0, output2 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c2 ) ); stbir__simdf_store( output2, o0 ); )
10030 stbIF3( stbir__simdf_load( o0, output3 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c3 ) ); stbir__simdf_store( output3, o0 ); )
10031 stbIF4( stbir__simdf_load( o0, output4 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c4 ) ); stbir__simdf_store( output4, o0 ); )
10032 stbIF5( stbir__simdf_load( o0, output5 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c5 ) ); stbir__simdf_store( output5, o0 ); )
10033 stbIF6( stbir__simdf_load( o0, output6 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c6 ) ); stbir__simdf_store( output6, o0 ); )
10034 stbIF7( stbir__simdf_load( o0, output7 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c7 ) ); stbir__simdf_store( output7, o0 ); )
10036 stbIF0( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c0 ) ); stbir__simdf_store( output0, o0 ); )
10037 stbIF1( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c1 ) ); stbir__simdf_store( output1, o0 ); )
10038 stbIF2( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c2 ) ); stbir__simdf_store( output2, o0 ); )
10039 stbIF3( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c3 ) ); stbir__simdf_store( output3, o0 ); )
10040 stbIF4( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c4 ) ); stbir__simdf_store( output4, o0 ); )
10041 stbIF5( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c5 ) ); stbir__simdf_store( output5, o0 ); )
10042 stbIF6( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c6 ) ); stbir__simdf_store( output6, o0 ); )
10043 stbIF7( stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c7 ) ); stbir__simdf_store( output7, o0 ); )
10047 stbIF0( output0 += 4; ) stbIF1( output1 += 4; ) stbIF2( output2 += 4; ) stbIF3( output3 += 4; ) stbIF4( output4 += 4; ) stbIF5( output5 += 4; ) stbIF6( output6 += 4; ) stbIF7( output7 += 4; )
10051 STBIR_NO_UNROLL_LOOP_START
10052 while ( ( (
char*)input_end - (
char*) input ) >= 16 )
10054 float r0, r1, r2, r3;
10055 STBIR_NO_UNROLL(input);
10057 r0 = input[0], r1 = input[1], r2 = input[2], r3 = input[3];
10059 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10060 stbIF0( output0[0] += ( r0 * c0s ); output0[1] += ( r1 * c0s ); output0[2] += ( r2 * c0s ); output0[3] += ( r3 * c0s ); )
10061 stbIF1( output1[0] += ( r0 * c1s ); output1[1] += ( r1 * c1s ); output1[2] += ( r2 * c1s ); output1[3] += ( r3 * c1s ); )
10062 stbIF2( output2[0] += ( r0 * c2s ); output2[1] += ( r1 * c2s ); output2[2] += ( r2 * c2s ); output2[3] += ( r3 * c2s ); )
10063 stbIF3( output3[0] += ( r0 * c3s ); output3[1] += ( r1 * c3s ); output3[2] += ( r2 * c3s ); output3[3] += ( r3 * c3s ); )
10064 stbIF4( output4[0] += ( r0 * c4s ); output4[1] += ( r1 * c4s ); output4[2] += ( r2 * c4s ); output4[3] += ( r3 * c4s ); )
10065 stbIF5( output5[0] += ( r0 * c5s ); output5[1] += ( r1 * c5s ); output5[2] += ( r2 * c5s ); output5[3] += ( r3 * c5s ); )
10066 stbIF6( output6[0] += ( r0 * c6s ); output6[1] += ( r1 * c6s ); output6[2] += ( r2 * c6s ); output6[3] += ( r3 * c6s ); )
10067 stbIF7( output7[0] += ( r0 * c7s ); output7[1] += ( r1 * c7s ); output7[2] += ( r2 * c7s ); output7[3] += ( r3 * c7s ); )
10069 stbIF0( output0[0] = ( r0 * c0s ); output0[1] = ( r1 * c0s ); output0[2] = ( r2 * c0s ); output0[3] = ( r3 * c0s ); )
10070 stbIF1( output1[0] = ( r0 * c1s ); output1[1] = ( r1 * c1s ); output1[2] = ( r2 * c1s ); output1[3] = ( r3 * c1s ); )
10071 stbIF2( output2[0] = ( r0 * c2s ); output2[1] = ( r1 * c2s ); output2[2] = ( r2 * c2s ); output2[3] = ( r3 * c2s ); )
10072 stbIF3( output3[0] = ( r0 * c3s ); output3[1] = ( r1 * c3s ); output3[2] = ( r2 * c3s ); output3[3] = ( r3 * c3s ); )
10073 stbIF4( output4[0] = ( r0 * c4s ); output4[1] = ( r1 * c4s ); output4[2] = ( r2 * c4s ); output4[3] = ( r3 * c4s ); )
10074 stbIF5( output5[0] = ( r0 * c5s ); output5[1] = ( r1 * c5s ); output5[2] = ( r2 * c5s ); output5[3] = ( r3 * c5s ); )
10075 stbIF6( output6[0] = ( r0 * c6s ); output6[1] = ( r1 * c6s ); output6[2] = ( r2 * c6s ); output6[3] = ( r3 * c6s ); )
10076 stbIF7( output7[0] = ( r0 * c7s ); output7[1] = ( r1 * c7s ); output7[2] = ( r2 * c7s ); output7[3] = ( r3 * c7s ); )
10080 stbIF0( output0 += 4; ) stbIF1( output1 += 4; ) stbIF2( output2 += 4; ) stbIF3( output3 += 4; ) stbIF4( output4 += 4; ) stbIF5( output5 += 4; ) stbIF6( output6 += 4; ) stbIF7( output7 += 4; )
10083 STBIR_NO_UNROLL_LOOP_START
10084 while ( input < input_end )
10086 float r = input[0];
10087 STBIR_NO_UNROLL(output0);
10089 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10090 stbIF0( output0[0] += ( r * c0s ); )
10091 stbIF1( output1[0] += ( r * c1s ); )
10092 stbIF2( output2[0] += ( r * c2s ); )
10093 stbIF3( output3[0] += ( r * c3s ); )
10094 stbIF4( output4[0] += ( r * c4s ); )
10095 stbIF5( output5[0] += ( r * c5s ); )
10096 stbIF6( output6[0] += ( r * c6s ); )
10097 stbIF7( output7[0] += ( r * c7s ); )
10099 stbIF0( output0[0] = ( r * c0s ); )
10100 stbIF1( output1[0] = ( r * c1s ); )
10101 stbIF2( output2[0] = ( r * c2s ); )
10102 stbIF3( output3[0] = ( r * c3s ); )
10103 stbIF4( output4[0] = ( r * c4s ); )
10104 stbIF5( output5[0] = ( r * c5s ); )
10105 stbIF6( output6[0] = ( r * c6s ); )
10106 stbIF7( output7[0] = ( r * c7s ); )
10110 stbIF0( ++output0; ) stbIF1( ++output1; ) stbIF2( ++output2; ) stbIF3( ++output3; ) stbIF4( ++output4; ) stbIF5( ++output5; ) stbIF6( ++output6; ) stbIF7( ++output7; )
10114static void STBIR_chans( stbir__vertical_gather_with_,_coeffs)(
float * outputp,
float const * vertical_coefficients,
float const ** inputs,
float const * input0_end )
10116 float STBIR_SIMD_STREAMOUT_PTR( * ) output = outputp;
10118 stbIF0(
float const * input0 = inputs[0];
float c0s = vertical_coefficients[0]; )
10119 stbIF1(
float const * input1 = inputs[1];
float c1s = vertical_coefficients[1]; )
10120 stbIF2(
float const * input2 = inputs[2];
float c2s = vertical_coefficients[2]; )
10121 stbIF3(
float const * input3 = inputs[3];
float c3s = vertical_coefficients[3]; )
10122 stbIF4(
float const * input4 = inputs[4];
float c4s = vertical_coefficients[4]; )
10123 stbIF5(
float const * input5 = inputs[5];
float c5s = vertical_coefficients[5]; )
10124 stbIF6(
float const * input6 = inputs[6];
float c6s = vertical_coefficients[6]; )
10125 stbIF7(
float const * input7 = inputs[7];
float c7s = vertical_coefficients[7]; )
10127#if ( STBIR__vertical_channels == 1 ) && !defined(STB_IMAGE_RESIZE_VERTICAL_CONTINUE)
10129 if ( ( c0s >= (1.0f-0.000001f) ) && ( c0s <= (1.0f+0.000001f) ) )
10131 STBIR_MEMCPY( output, input0, (
char*)input0_end - (
char*)input0 );
10138 stbIF0(stbir__simdfX c0 = stbir__simdf_frepX( c0s ); )
10139 stbIF1(stbir__simdfX c1 = stbir__simdf_frepX( c1s ); )
10140 stbIF2(stbir__simdfX c2 = stbir__simdf_frepX( c2s ); )
10141 stbIF3(stbir__simdfX c3 = stbir__simdf_frepX( c3s ); )
10142 stbIF4(stbir__simdfX c4 = stbir__simdf_frepX( c4s ); )
10143 stbIF5(stbir__simdfX c5 = stbir__simdf_frepX( c5s ); )
10144 stbIF6(stbir__simdfX c6 = stbir__simdf_frepX( c6s ); )
10145 stbIF7(stbir__simdfX c7 = stbir__simdf_frepX( c7s ); )
10147 STBIR_SIMD_NO_UNROLL_LOOP_START
10148 while ( ( (
char*)input0_end - (
char*) input0 ) >= (16*stbir__simdfX_float_count) )
10150 stbir__simdfX o0, o1, o2, o3, r0, r1, r2, r3;
10151 STBIR_SIMD_NO_UNROLL(output);
10154 stbIF0( stbir__prefetch( input0 + (16*stbir__simdfX_float_count) ); )
10155 stbIF1( stbir__prefetch( input1 + (16*stbir__simdfX_float_count) ); )
10156 stbIF2( stbir__prefetch( input2 + (16*stbir__simdfX_float_count) ); )
10157 stbIF3( stbir__prefetch( input3 + (16*stbir__simdfX_float_count) ); )
10158 stbIF4( stbir__prefetch( input4 + (16*stbir__simdfX_float_count) ); )
10159 stbIF5( stbir__prefetch( input5 + (16*stbir__simdfX_float_count) ); )
10160 stbIF6( stbir__prefetch( input6 + (16*stbir__simdfX_float_count) ); )
10161 stbIF7( stbir__prefetch( input7 + (16*stbir__simdfX_float_count) ); )
10163 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10164 stbIF0( stbir__simdfX_load( o0, output ); stbir__simdfX_load( o1, output+stbir__simdfX_float_count ); stbir__simdfX_load( o2, output+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( o3, output+(3*stbir__simdfX_float_count) );
10165 stbir__simdfX_load( r0, input0 ); stbir__simdfX_load( r1, input0+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input0+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input0+(3*stbir__simdfX_float_count) );
10166 stbir__simdfX_madd( o0, o0, r0, c0 ); stbir__simdfX_madd( o1, o1, r1, c0 ); stbir__simdfX_madd( o2, o2, r2, c0 ); stbir__simdfX_madd( o3, o3, r3, c0 ); )
10168 stbIF0( stbir__simdfX_load( r0, input0 ); stbir__simdfX_load( r1, input0+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input0+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input0+(3*stbir__simdfX_float_count) );
10169 stbir__simdfX_mult( o0, r0, c0 ); stbir__simdfX_mult( o1, r1, c0 ); stbir__simdfX_mult( o2, r2, c0 ); stbir__simdfX_mult( o3, r3, c0 ); )
10172 stbIF1( stbir__simdfX_load( r0, input1 ); stbir__simdfX_load( r1, input1+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input1+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input1+(3*stbir__simdfX_float_count) );
10173 stbir__simdfX_madd( o0, o0, r0, c1 ); stbir__simdfX_madd( o1, o1, r1, c1 ); stbir__simdfX_madd( o2, o2, r2, c1 ); stbir__simdfX_madd( o3, o3, r3, c1 ); )
10174 stbIF2( stbir__simdfX_load( r0, input2 ); stbir__simdfX_load( r1, input2+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input2+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input2+(3*stbir__simdfX_float_count) );
10175 stbir__simdfX_madd( o0, o0, r0, c2 ); stbir__simdfX_madd( o1, o1, r1, c2 ); stbir__simdfX_madd( o2, o2, r2, c2 ); stbir__simdfX_madd( o3, o3, r3, c2 ); )
10176 stbIF3( stbir__simdfX_load( r0, input3 ); stbir__simdfX_load( r1, input3+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input3+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input3+(3*stbir__simdfX_float_count) );
10177 stbir__simdfX_madd( o0, o0, r0, c3 ); stbir__simdfX_madd( o1, o1, r1, c3 ); stbir__simdfX_madd( o2, o2, r2, c3 ); stbir__simdfX_madd( o3, o3, r3, c3 ); )
10178 stbIF4( stbir__simdfX_load( r0, input4 ); stbir__simdfX_load( r1, input4+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input4+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input4+(3*stbir__simdfX_float_count) );
10179 stbir__simdfX_madd( o0, o0, r0, c4 ); stbir__simdfX_madd( o1, o1, r1, c4 ); stbir__simdfX_madd( o2, o2, r2, c4 ); stbir__simdfX_madd( o3, o3, r3, c4 ); )
10180 stbIF5( stbir__simdfX_load( r0, input5 ); stbir__simdfX_load( r1, input5+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input5+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input5+(3*stbir__simdfX_float_count) );
10181 stbir__simdfX_madd( o0, o0, r0, c5 ); stbir__simdfX_madd( o1, o1, r1, c5 ); stbir__simdfX_madd( o2, o2, r2, c5 ); stbir__simdfX_madd( o3, o3, r3, c5 ); )
10182 stbIF6( stbir__simdfX_load( r0, input6 ); stbir__simdfX_load( r1, input6+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input6+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input6+(3*stbir__simdfX_float_count) );
10183 stbir__simdfX_madd( o0, o0, r0, c6 ); stbir__simdfX_madd( o1, o1, r1, c6 ); stbir__simdfX_madd( o2, o2, r2, c6 ); stbir__simdfX_madd( o3, o3, r3, c6 ); )
10184 stbIF7( stbir__simdfX_load( r0, input7 ); stbir__simdfX_load( r1, input7+stbir__simdfX_float_count ); stbir__simdfX_load( r2, input7+(2*stbir__simdfX_float_count) ); stbir__simdfX_load( r3, input7+(3*stbir__simdfX_float_count) );
10185 stbir__simdfX_madd( o0, o0, r0, c7 ); stbir__simdfX_madd( o1, o1, r1, c7 ); stbir__simdfX_madd( o2, o2, r2, c7 ); stbir__simdfX_madd( o3, o3, r3, c7 ); )
10187 stbir__simdfX_store( output, o0 ); stbir__simdfX_store( output+stbir__simdfX_float_count, o1 ); stbir__simdfX_store( output+(2*stbir__simdfX_float_count), o2 ); stbir__simdfX_store( output+(3*stbir__simdfX_float_count), o3 );
10188 output += (4*stbir__simdfX_float_count);
10189 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); )
10192 STBIR_SIMD_NO_UNROLL_LOOP_START
10193 while ( ( (
char*)input0_end - (
char*) input0 ) >= 16 )
10195 stbir__simdf o0, r0;
10196 STBIR_SIMD_NO_UNROLL(output);
10198 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10199 stbIF0( stbir__simdf_load( o0, output ); stbir__simdf_load( r0, input0 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c0 ) ); )
10201 stbIF0( stbir__simdf_load( r0, input0 ); stbir__simdf_mult( o0, r0, stbir__if_simdf8_cast_to_simdf4( c0 ) ); )
10203 stbIF1( stbir__simdf_load( r0, input1 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c1 ) ); )
10204 stbIF2( stbir__simdf_load( r0, input2 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c2 ) ); )
10205 stbIF3( stbir__simdf_load( r0, input3 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c3 ) ); )
10206 stbIF4( stbir__simdf_load( r0, input4 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c4 ) ); )
10207 stbIF5( stbir__simdf_load( r0, input5 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c5 ) ); )
10208 stbIF6( stbir__simdf_load( r0, input6 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c6 ) ); )
10209 stbIF7( stbir__simdf_load( r0, input7 ); stbir__simdf_madd( o0, o0, r0, stbir__if_simdf8_cast_to_simdf4( c7 ) ); )
10211 stbir__simdf_store( output, o0 );
10213 stbIF0( input0 += 4; ) stbIF1( input1 += 4; ) stbIF2( input2 += 4; ) stbIF3( input3 += 4; ) stbIF4( input4 += 4; ) stbIF5( input5 += 4; ) stbIF6( input6 += 4; ) stbIF7( input7 += 4; )
10217 STBIR_NO_UNROLL_LOOP_START
10218 while ( ( (
char*)input0_end - (
char*) input0 ) >= 16 )
10220 float o0, o1, o2, o3;
10221 STBIR_NO_UNROLL(output);
10222 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10223 stbIF0( o0 = output[0] + input0[0] * c0s; o1 = output[1] + input0[1] * c0s; o2 = output[2] + input0[2] * c0s; o3 = output[3] + input0[3] * c0s; )
10225 stbIF0( o0 = input0[0] * c0s; o1 = input0[1] * c0s; o2 = input0[2] * c0s; o3 = input0[3] * c0s; )
10227 stbIF1( o0 += input1[0] * c1s; o1 += input1[1] * c1s; o2 += input1[2] * c1s; o3 += input1[3] * c1s; )
10228 stbIF2( o0 += input2[0] * c2s; o1 += input2[1] * c2s; o2 += input2[2] * c2s; o3 += input2[3] * c2s; )
10229 stbIF3( o0 += input3[0] * c3s; o1 += input3[1] * c3s; o2 += input3[2] * c3s; o3 += input3[3] * c3s; )
10230 stbIF4( o0 += input4[0] * c4s; o1 += input4[1] * c4s; o2 += input4[2] * c4s; o3 += input4[3] * c4s; )
10231 stbIF5( o0 += input5[0] * c5s; o1 += input5[1] * c5s; o2 += input5[2] * c5s; o3 += input5[3] * c5s; )
10232 stbIF6( o0 += input6[0] * c6s; o1 += input6[1] * c6s; o2 += input6[2] * c6s; o3 += input6[3] * c6s; )
10233 stbIF7( o0 += input7[0] * c7s; o1 += input7[1] * c7s; o2 += input7[2] * c7s; o3 += input7[3] * c7s; )
10234 output[0] = o0; output[1] = o1; output[2] = o2; output[3] = o3;
10236 stbIF0( input0 += 4; ) stbIF1( input1 += 4; ) stbIF2( input2 += 4; ) stbIF3( input3 += 4; ) stbIF4( input4 += 4; ) stbIF5( input5 += 4; ) stbIF6( input6 += 4; ) stbIF7( input7 += 4; )
10239 STBIR_NO_UNROLL_LOOP_START
10240 while ( input0 < input0_end )
10243 STBIR_NO_UNROLL(output);
10244 #ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10245 stbIF0( o0 = output[0] + input0[0] * c0s; )
10247 stbIF0( o0 = input0[0] * c0s; )
10249 stbIF1( o0 += input1[0] * c1s; )
10250 stbIF2( o0 += input2[0] * c2s; )
10251 stbIF3( o0 += input3[0] * c3s; )
10252 stbIF4( o0 += input4[0] * c4s; )
10253 stbIF5( o0 += input5[0] * c5s; )
10254 stbIF6( o0 += input6[0] * c6s; )
10255 stbIF7( o0 += input7[0] * c7s; )
10258 stbIF0( ++input0; ) stbIF1( ++input1; ) stbIF2( ++input2; ) stbIF3( ++input3; ) stbIF4( ++input4; ) stbIF5( ++input5; ) stbIF6( ++input6; ) stbIF7( ++input7; )
10270#undef STB_IMAGE_RESIZE_DO_VERTICALS
10271#undef STBIR__vertical_channels
10272#undef STB_IMAGE_RESIZE_DO_HORIZONTALS
10273#undef STBIR_strs_join24
10274#undef STBIR_strs_join14
10276#ifdef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10277#undef STB_IMAGE_RESIZE_VERTICAL_CONTINUE
10282#define STBIR_chans( start, end ) STBIR_strs_join1(start,STBIR__horizontal_channels,end)
10284#ifndef stbir__2_coeff_only
10285#define stbir__2_coeff_only() \
10286 stbir__1_coeff_only(); \
10287 stbir__1_coeff_remnant(1);
10290#ifndef stbir__2_coeff_remnant
10291#define stbir__2_coeff_remnant( ofs ) \
10292 stbir__1_coeff_remnant(ofs); \
10293 stbir__1_coeff_remnant((ofs)+1);
10296#ifndef stbir__3_coeff_only
10297#define stbir__3_coeff_only() \
10298 stbir__2_coeff_only(); \
10299 stbir__1_coeff_remnant(2);
10302#ifndef stbir__3_coeff_remnant
10303#define stbir__3_coeff_remnant( ofs ) \
10304 stbir__2_coeff_remnant(ofs); \
10305 stbir__1_coeff_remnant((ofs)+2);
10308#ifndef stbir__3_coeff_setup
10309#define stbir__3_coeff_setup()
10312#ifndef stbir__4_coeff_start
10313#define stbir__4_coeff_start() \
10314 stbir__2_coeff_only(); \
10315 stbir__2_coeff_remnant(2);
10318#ifndef stbir__4_coeff_continue_from_4
10319#define stbir__4_coeff_continue_from_4( ofs ) \
10320 stbir__2_coeff_remnant(ofs); \
10321 stbir__2_coeff_remnant((ofs)+2);
10324#ifndef stbir__store_output_tiny
10325#define stbir__store_output_tiny stbir__store_output
10328static 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 )
10330 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10331 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10332 STBIR_SIMD_NO_UNROLL_LOOP_START
10334 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10335 float const * hc = horizontal_coefficients;
10336 stbir__1_coeff_only();
10337 stbir__store_output_tiny();
10338 }
while ( output < output_end );
10341static 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 )
10343 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10344 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10345 STBIR_SIMD_NO_UNROLL_LOOP_START
10347 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10348 float const * hc = horizontal_coefficients;
10349 stbir__2_coeff_only();
10350 stbir__store_output_tiny();
10351 }
while ( output < output_end );
10354static 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 )
10356 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10357 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10358 STBIR_SIMD_NO_UNROLL_LOOP_START
10360 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10361 float const * hc = horizontal_coefficients;
10362 stbir__3_coeff_only();
10363 stbir__store_output_tiny();
10364 }
while ( output < output_end );
10367static 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 )
10369 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10370 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10371 STBIR_SIMD_NO_UNROLL_LOOP_START
10373 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10374 float const * hc = horizontal_coefficients;
10375 stbir__4_coeff_start();
10376 stbir__store_output();
10377 }
while ( output < output_end );
10380static 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 )
10382 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10383 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10384 STBIR_SIMD_NO_UNROLL_LOOP_START
10386 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10387 float const * hc = horizontal_coefficients;
10388 stbir__4_coeff_start();
10389 stbir__1_coeff_remnant(4);
10390 stbir__store_output();
10391 }
while ( output < output_end );
10394static 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 )
10396 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10397 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10398 STBIR_SIMD_NO_UNROLL_LOOP_START
10400 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10401 float const * hc = horizontal_coefficients;
10402 stbir__4_coeff_start();
10403 stbir__2_coeff_remnant(4);
10404 stbir__store_output();
10405 }
while ( output < output_end );
10408static void STBIR_chans( stbir__horizontal_gather_,_channels_with_7_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 )
10410 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10411 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10412 stbir__3_coeff_setup();
10413 STBIR_SIMD_NO_UNROLL_LOOP_START
10415 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10416 float const * hc = horizontal_coefficients;
10418 stbir__4_coeff_start();
10419 stbir__3_coeff_remnant(4);
10420 stbir__store_output();
10421 }
while ( output < output_end );
10424static 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 )
10426 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10427 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10428 STBIR_SIMD_NO_UNROLL_LOOP_START
10430 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10431 float const * hc = horizontal_coefficients;
10432 stbir__4_coeff_start();
10433 stbir__4_coeff_continue_from_4(4);
10434 stbir__store_output();
10435 }
while ( output < output_end );
10438static 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 )
10440 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10441 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10442 STBIR_SIMD_NO_UNROLL_LOOP_START
10444 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10445 float const * hc = horizontal_coefficients;
10446 stbir__4_coeff_start();
10447 stbir__4_coeff_continue_from_4(4);
10448 stbir__1_coeff_remnant(8);
10449 stbir__store_output();
10450 }
while ( output < output_end );
10453static 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 )
10455 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10456 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10457 STBIR_SIMD_NO_UNROLL_LOOP_START
10459 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10460 float const * hc = horizontal_coefficients;
10461 stbir__4_coeff_start();
10462 stbir__4_coeff_continue_from_4(4);
10463 stbir__2_coeff_remnant(8);
10464 stbir__store_output();
10465 }
while ( output < output_end );
10468static void STBIR_chans( stbir__horizontal_gather_,_channels_with_11_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 )
10470 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10471 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10472 stbir__3_coeff_setup();
10473 STBIR_SIMD_NO_UNROLL_LOOP_START
10475 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10476 float const * hc = horizontal_coefficients;
10477 stbir__4_coeff_start();
10478 stbir__4_coeff_continue_from_4(4);
10479 stbir__3_coeff_remnant(8);
10480 stbir__store_output();
10481 }
while ( output < output_end );
10484static 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 )
10486 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10487 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10488 STBIR_SIMD_NO_UNROLL_LOOP_START
10490 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10491 float const * hc = horizontal_coefficients;
10492 stbir__4_coeff_start();
10493 stbir__4_coeff_continue_from_4(4);
10494 stbir__4_coeff_continue_from_4(8);
10495 stbir__store_output();
10496 }
while ( output < output_end );
10499static 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 )
10501 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10502 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10503 STBIR_SIMD_NO_UNROLL_LOOP_START
10505 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10506 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 4 + 3 ) >> 2;
10507 float const * hc = horizontal_coefficients;
10509 stbir__4_coeff_start();
10510 STBIR_SIMD_NO_UNROLL_LOOP_START
10513 decode += STBIR__horizontal_channels * 4;
10514 stbir__4_coeff_continue_from_4( 0 );
10517 stbir__store_output();
10518 }
while ( output < output_end );
10521static 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 )
10523 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10524 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10525 STBIR_SIMD_NO_UNROLL_LOOP_START
10527 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10528 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 5 + 3 ) >> 2;
10529 float const * hc = horizontal_coefficients;
10531 stbir__4_coeff_start();
10532 STBIR_SIMD_NO_UNROLL_LOOP_START
10535 decode += STBIR__horizontal_channels * 4;
10536 stbir__4_coeff_continue_from_4( 0 );
10539 stbir__1_coeff_remnant( 4 );
10540 stbir__store_output();
10541 }
while ( output < output_end );
10544static 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 )
10546 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10547 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10548 STBIR_SIMD_NO_UNROLL_LOOP_START
10550 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10551 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 6 + 3 ) >> 2;
10552 float const * hc = horizontal_coefficients;
10554 stbir__4_coeff_start();
10555 STBIR_SIMD_NO_UNROLL_LOOP_START
10558 decode += STBIR__horizontal_channels * 4;
10559 stbir__4_coeff_continue_from_4( 0 );
10562 stbir__2_coeff_remnant( 4 );
10564 stbir__store_output();
10565 }
while ( output < output_end );
10568static void STBIR_chans( stbir__horizontal_gather_,_channels_with_n_coeffs_mod3 )(
float * output_buffer,
unsigned int output_sub_size,
float const * decode_buffer, stbir__contributors
const * horizontal_contributors,
float const * horizontal_coefficients,
int coefficient_width )
10570 float const * output_end = output_buffer + output_sub_size * STBIR__horizontal_channels;
10571 float STBIR_SIMD_STREAMOUT_PTR( * ) output = output_buffer;
10572 stbir__3_coeff_setup();
10573 STBIR_SIMD_NO_UNROLL_LOOP_START
10575 float const * decode = decode_buffer + horizontal_contributors->n0 * STBIR__horizontal_channels;
10576 int n = ( ( horizontal_contributors->n1 - horizontal_contributors->n0 + 1 ) - 7 + 3 ) >> 2;
10577 float const * hc = horizontal_coefficients;
10579 stbir__4_coeff_start();
10580 STBIR_SIMD_NO_UNROLL_LOOP_START
10583 decode += STBIR__horizontal_channels * 4;
10584 stbir__4_coeff_continue_from_4( 0 );
10587 stbir__3_coeff_remnant( 4 );
10589 stbir__store_output();
10590 }
while ( output < output_end );
10593static stbir__horizontal_gather_channels_func * STBIR_chans(stbir__horizontal_gather_,_channels_with_n_coeffs_funcs)[4]=
10595 STBIR_chans(stbir__horizontal_gather_,_channels_with_n_coeffs_mod0),
10596 STBIR_chans(stbir__horizontal_gather_,_channels_with_n_coeffs_mod1),
10597 STBIR_chans(stbir__horizontal_gather_,_channels_with_n_coeffs_mod2),
10598 STBIR_chans(stbir__horizontal_gather_,_channels_with_n_coeffs_mod3),
10601static stbir__horizontal_gather_channels_func * STBIR_chans(stbir__horizontal_gather_,_channels_funcs)[12]=
10603 STBIR_chans(stbir__horizontal_gather_,_channels_with_1_coeff),
10604 STBIR_chans(stbir__horizontal_gather_,_channels_with_2_coeffs),
10605 STBIR_chans(stbir__horizontal_gather_,_channels_with_3_coeffs),
10606 STBIR_chans(stbir__horizontal_gather_,_channels_with_4_coeffs),
10607 STBIR_chans(stbir__horizontal_gather_,_channels_with_5_coeffs),
10608 STBIR_chans(stbir__horizontal_gather_,_channels_with_6_coeffs),
10609 STBIR_chans(stbir__horizontal_gather_,_channels_with_7_coeffs),
10610 STBIR_chans(stbir__horizontal_gather_,_channels_with_8_coeffs),
10611 STBIR_chans(stbir__horizontal_gather_,_channels_with_9_coeffs),
10612 STBIR_chans(stbir__horizontal_gather_,_channels_with_10_coeffs),
10613 STBIR_chans(stbir__horizontal_gather_,_channels_with_11_coeffs),
10614 STBIR_chans(stbir__horizontal_gather_,_channels_with_12_coeffs),
10617#undef STBIR__horizontal_channels
10618#undef STB_IMAGE_RESIZE_DO_HORIZONTALS
10619#undef stbir__1_coeff_only
10620#undef stbir__1_coeff_remnant
10621#undef stbir__2_coeff_only
10622#undef stbir__2_coeff_remnant
10623#undef stbir__3_coeff_only
10624#undef stbir__3_coeff_remnant
10625#undef stbir__3_coeff_setup
10626#undef stbir__4_coeff_start
10627#undef stbir__4_coeff_continue_from_4
10628#undef stbir__store_output
10629#undef stbir__store_output_tiny
10634#undef STBIR_strs_join2
10635#undef STBIR_strs_join1
GLfloat GLfloat GLfloat alpha
Definition imgui_impl_opengl3_loader.h:195
GLint GLsizei width
Definition imgui_impl_opengl3_loader.h:191
GLsizeiptr size
Definition imgui_impl_opengl3_loader.h:277
GLint y
Definition imgui_impl_opengl3_loader.h:191
GLsizei count
Definition imgui_impl_opengl3_loader.h:229
GLint GLsizei GLsizei height
Definition imgui_impl_opengl3_loader.h:191
GLuint GLuint64EXT * result
Definition imgui_impl_opengl3_loader.h:457
GLuint index
Definition imgui_impl_opengl3_loader.h:371
decltype(sizeof(void *)) size_t
Definition doctest.h:524
STBIRDEF int stbir_set_pixel_layouts(STBIR_RESIZE *resize, stbir_pixel_layout input_pixel_layout, stbir_pixel_layout output_pixel_layout)
STBIRDEF void stbir_set_user_data(STBIR_RESIZE *resize, void *user_data)
STBIRDEF int stbir_resize_extended(STBIR_RESIZE *resize)
STBIRDEF int stbir_set_non_pm_alpha_speed_over_quality(STBIR_RESIZE *resize, int non_pma_alpha_speed_over_quality)
STBIRDEF int stbir_set_pixel_subrect(STBIR_RESIZE *resize, int subx, int suby, int subw, int subh)
STBIRDEF void stbir_set_pixel_callbacks(STBIR_RESIZE *resize, stbir_input_callback *input_cb, stbir_output_callback *output_cb)
void const * stbir_input_callback(void *optional_output, void const *input_ptr, int num_pixels, int x, int y, void *context)
Definition stb_image_resize2.h:562
struct stbir__info stbir__info
Definition stb_image_resize2.h:572
STBIRDEF int stbir_set_input_subrect(STBIR_RESIZE *resize, double s0, double t0, double s1, double t1)
STBIRDEF int stbir_build_samplers_with_splits(STBIR_RESIZE *resize, int try_splits)
It might be less if the image resize can't be split up that many ways.
stbir_filter
Definition stb_image_resize2.h:504
@ STBIR_FILTER_OTHER
Definition stb_image_resize2.h:512
@ STBIR_FILTER_DEFAULT
Definition stb_image_resize2.h:505
@ STBIR_FILTER_POINT_SAMPLE
Definition stb_image_resize2.h:511
@ STBIR_FILTER_MITCHELL
Definition stb_image_resize2.h:510
@ STBIR_FILTER_BOX
Definition stb_image_resize2.h:506
@ STBIR_FILTER_TRIANGLE
Definition stb_image_resize2.h:507
@ STBIR_FILTER_CATMULLROM
Definition stb_image_resize2.h:509
@ STBIR_FILTER_CUBICBSPLINE
Definition stb_image_resize2.h:508
STBIRDEF int stbir_set_edgemodes(STBIR_RESIZE *resize, stbir_edge horizontal_edge, stbir_edge vertical_edge)
STBIRDEF unsigned char * stbir_resize_uint8_linear(const unsigned char *input_pixels, int input_w, int input_h, int input_stride_in_bytes, unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_type)
STBIRDEF void * stbir_resize(const void *input_pixels, int input_w, int input_h, int input_stride_in_bytes, void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_layout, stbir_datatype data_type, stbir_edge edge, stbir_filter filter)
uint8_t stbir_uint8
Definition stb_image_resize2.h:399
STBIRDEF void stbir_set_buffer_ptrs(STBIR_RESIZE *resize, const void *input_pixels, int input_stride_in_bytes, void *output_pixels, int output_stride_in_bytes)
STBIRDEF void stbir_resize_init(STBIR_RESIZE *resize, const void *input_pixels, int input_w, int input_h, int input_stride_in_bytes, void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_layout, stbir_datatype data_type)
stbir_edge
Definition stb_image_resize2.h:496
@ STBIR_EDGE_WRAP
Definition stb_image_resize2.h:499
@ STBIR_EDGE_CLAMP
Definition stb_image_resize2.h:497
@ STBIR_EDGE_ZERO
Definition stb_image_resize2.h:500
@ STBIR_EDGE_REFLECT
Definition stb_image_resize2.h:498
STBIRDEF void stbir_free_samplers(STBIR_RESIZE *resize)
STBIRDEF int stbir_resize_extended_split(STBIR_RESIZE *resize, int split_start, int split_count)
uint16_t stbir_uint16
Definition stb_image_resize2.h:400
STBIRDEF int stbir_set_filters(STBIR_RESIZE *resize, stbir_filter horizontal_filter, stbir_filter vertical_filter)
void stbir_output_callback(void const *output_ptr, int num_pixels, int y, void *context)
Definition stb_image_resize2.h:565
STBIRDEF int stbir_set_filter_callbacks(STBIR_RESIZE *resize, stbir__kernel_callback *horizontal_filter, stbir__support_callback *horizontal_support, stbir__kernel_callback *vertical_filter, stbir__support_callback *vertical_support)
STBIRDEF unsigned char * stbir_resize_uint8_srgb(const unsigned char *input_pixels, int input_w, int input_h, int input_stride_in_bytes, unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_type)
float stbir__kernel_callback(float x, float scale, void *user_data)
Definition stb_image_resize2.h:568
STBIRDEF float * stbir_resize_float_linear(const float *input_pixels, int input_w, int input_h, int input_stride_in_bytes, float *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_pixel_layout pixel_type)
uint32_t stbir_uint32
Definition stb_image_resize2.h:401
float stbir__support_callback(float scale, void *user_data)
Definition stb_image_resize2.h:569
STBIRDEF void stbir_set_datatypes(STBIR_RESIZE *resize, stbir_datatype input_type, stbir_datatype output_type)
STBIRDEF int stbir_set_output_pixel_subrect(STBIR_RESIZE *resize, int subx, int suby, int subw, int subh)
#define STBIRDEF
Definition stb_image_resize2.h:412
stbir_pixel_layout
Definition stb_image_resize2.h:436
@ STBIR_RA
Definition stb_image_resize2.h:447
@ STBIR_ARGB
Definition stb_image_resize2.h:445
@ STBIR_BGRA
Definition stb_image_resize2.h:444
@ STBIR_ABGR_NO_AW
Definition stb_image_resize2.h:460
@ STBIR_ARGB_NO_AW
Definition stb_image_resize2.h:459
@ STBIR_ABGR
Definition stb_image_resize2.h:446
@ STBIR_RGB
Definition stb_image_resize2.h:439
@ STBIR_1CHANNEL
Definition stb_image_resize2.h:437
@ STBIR_RA_NO_AW
Definition stb_image_resize2.h:461
@ STBIR_BGRA_PM
Definition stb_image_resize2.h:451
@ STBIR_4CHANNEL
Definition stb_image_resize2.h:441
@ STBIR_BGRA_NO_AW
Definition stb_image_resize2.h:458
@ STBIR_BGR
Definition stb_image_resize2.h:440
@ STBIR_AR_NO_AW
Definition stb_image_resize2.h:462
@ STBIR_ABGR_PM
Definition stb_image_resize2.h:453
@ STBIR_RGBA
Definition stb_image_resize2.h:443
@ STBIR_RGBA_NO_AW
Definition stb_image_resize2.h:457
@ STBIR_RGBA_PM
Definition stb_image_resize2.h:450
@ STBIR_2CHANNEL
Definition stb_image_resize2.h:438
@ STBIR_ARGB_PM
Definition stb_image_resize2.h:452
@ STBIR_AR_PM
Definition stb_image_resize2.h:455
@ STBIR_RA_PM
Definition stb_image_resize2.h:454
@ STBIR_AR
Definition stb_image_resize2.h:448
STBIRDEF int stbir_build_samplers(STBIR_RESIZE *resize)
stbir_datatype
Definition stb_image_resize2.h:516
@ STBIR_TYPE_UINT8_SRGB_ALPHA
Definition stb_image_resize2.h:519
@ STBIR_TYPE_UINT16
Definition stb_image_resize2.h:520
@ STBIR_TYPE_HALF_FLOAT
Definition stb_image_resize2.h:522
@ STBIR_TYPE_UINT8
Definition stb_image_resize2.h:517
@ STBIR_TYPE_UINT8_SRGB
Definition stb_image_resize2.h:518
@ STBIR_TYPE_FLOAT
Definition stb_image_resize2.h:521
uint64_t stbir_uint64
Definition stb_image_resize2.h:402
Definition stb_image_resize2.h:575
stbir__support_callback * vertical_filter_support
Definition stb_image_resize2.h:598
int input_stride_in_bytes
Definition stb_image_resize2.h:585
stbir_edge vertical_edge
Definition stb_image_resize2.h:596
stbir_pixel_layout output_pixel_layout_public
Definition stb_image_resize2.h:592
void * output_pixels
Definition stb_image_resize2.h:581
double input_s0
Definition stb_image_resize2.h:579
stbir_edge horizontal_edge
Definition stb_image_resize2.h:596
int splits
Definition stb_image_resize2.h:587
int output_subw
Definition stb_image_resize2.h:583
int output_stride_in_bytes
Definition stb_image_resize2.h:586
int called_alloc
Definition stb_image_resize2.h:590
stbir__info * samplers
Definition stb_image_resize2.h:599
stbir__kernel_callback * vertical_filter_kernel
Definition stb_image_resize2.h:598
stbir_input_callback * input_cb
Definition stb_image_resize2.h:580
stbir__kernel_callback * horizontal_filter_kernel
Definition stb_image_resize2.h:597
double input_t0
Definition stb_image_resize2.h:579
int input_h
Definition stb_image_resize2.h:578
int input_w
Definition stb_image_resize2.h:578
double input_t1
Definition stb_image_resize2.h:579
void * user_data
Definition stb_image_resize2.h:576
int fast_alpha
Definition stb_image_resize2.h:588
stbir_output_callback * output_cb
Definition stb_image_resize2.h:584
stbir__support_callback * horizontal_filter_support
Definition stb_image_resize2.h:597
stbir_pixel_layout input_pixel_layout_public
Definition stb_image_resize2.h:591
stbir_filter horizontal_filter
Definition stb_image_resize2.h:595
stbir_datatype input_data_type
Definition stb_image_resize2.h:593
double input_s1
Definition stb_image_resize2.h:579
void const * input_pixels
Definition stb_image_resize2.h:577
int output_subh
Definition stb_image_resize2.h:583
int output_h
Definition stb_image_resize2.h:582
stbir_datatype output_data_type
Definition stb_image_resize2.h:594
int output_suby
Definition stb_image_resize2.h:583
int output_w
Definition stb_image_resize2.h:582
int needs_rebuild
Definition stb_image_resize2.h:589
stbir_filter vertical_filter
Definition stb_image_resize2.h:595
int output_subx
Definition stb_image_resize2.h:583